@@ -6,10 +6,11 @@ import {Test} from "forge-std-1.16.2/src/Test.sol";
66import {MerkleTree} from "./../../src/libs/MerkleTree.sol " ;
77import {SHA256} from "./../../src/libs/SHA256.sol " ;
88import {MerkleTreeExample} from "./../examples/MerkleTree.e.sol " ;
9+ import {MerkleTreeReference} from "./../libs/MerkleTreeReference.sol " ;
910
1011contract MerkleTreeTest is Test , MerkleTreeExample {
1112 using MerkleTree for MerkleTree.Tree;
12- using MerkleTree for bytes32 [];
13+ using MerkleTreeReference for bytes32 [];
1314 using OzMerkleTree for OzMerkleTree.Bytes32PushTree;
1415
1516 MerkleTree.Tree internal _merkleTree;
@@ -114,10 +115,10 @@ contract MerkleTreeTest is Test, MerkleTreeExample {
114115 function test_compare_le () public pure {
115116 assertEq (
116117 _computeMinimalTreeDepthNaive (0 ),
117- MerkleTree .computeMinimalTreeDepth (0 ),
118+ MerkleTreeReference .computeMinimalTreeDepth (0 ),
118119 "naive and optimized should match for 0 leaves "
119120 );
120- assertEq (MerkleTree .computeMinimalTreeDepth (0 ), 0 , "minimal tree depth for 0 leaves should be 0 " );
121+ assertEq (MerkleTreeReference .computeMinimalTreeDepth (0 ), 0 , "minimal tree depth for 0 leaves should be 0 " );
121122 }
122123
123124 function test_computeMinimalTreeDepth_computes_the_right_tree_depths () public pure {
@@ -126,7 +127,9 @@ contract MerkleTreeTest is Test, MerkleTreeExample {
126127
127128 for (uint256 i = 0 ; i < depths.length ; ++ i) {
128129 assertEq (
129- MerkleTree.computeMinimalTreeDepth ({leavesCount: i}), depths[i], "tree depth should match expected "
130+ MerkleTreeReference.computeMinimalTreeDepth ({leavesCount: i}),
131+ depths[i],
132+ "tree depth should match expected "
130133 );
131134 }
132135 }
@@ -137,7 +140,7 @@ contract MerkleTreeTest is Test, MerkleTreeExample {
137140 for (uint256 i = 0 ; i < maxLeafCount; ++ i) {
138141 assertEq (
139142 _computeMinimalTreeDepthNaive ({leavesCount: i}),
140- MerkleTree .computeMinimalTreeDepth ({leavesCount: i}),
143+ MerkleTreeReference .computeMinimalTreeDepth ({leavesCount: i}),
141144 "naive and optimized implementations should match "
142145 );
143146 }
@@ -152,21 +155,21 @@ contract MerkleTreeTest is Test, MerkleTreeExample {
152155
153156 assertEq (
154157 _computeMinimalTreeDepthNaive (powerOfTwo - 1 ),
155- MerkleTree .computeMinimalTreeDepth (powerOfTwo - 1 ),
158+ MerkleTreeReference .computeMinimalTreeDepth (powerOfTwo - 1 ),
156159 "should match for power of 2 minus 1 "
157160 );
158161
159162 // Test power of 2
160163 assertEq (
161164 _computeMinimalTreeDepthNaive (powerOfTwo),
162- MerkleTree .computeMinimalTreeDepth (powerOfTwo),
165+ MerkleTreeReference .computeMinimalTreeDepth (powerOfTwo),
163166 "should match for power of 2 "
164167 );
165168
166169 // Test power of 2 + 1
167170 assertEq (
168171 _computeMinimalTreeDepthNaive (powerOfTwo + 1 ),
169- MerkleTree .computeMinimalTreeDepth (powerOfTwo + 1 ),
172+ MerkleTreeReference .computeMinimalTreeDepth (powerOfTwo + 1 ),
170173 "should match for power of 2 plus 1 "
171174 );
172175 }
@@ -179,7 +182,7 @@ contract MerkleTreeTest is Test, MerkleTreeExample {
179182 for (uint256 i = 0 ; i < testCases.length ; i++ ) {
180183 assertEq (
181184 _computeMinimalTreeDepthNaive (testCases[i]),
182- MerkleTree .computeMinimalTreeDepth (testCases[i]),
185+ MerkleTreeReference .computeMinimalTreeDepth (testCases[i]),
183186 "should match for large values "
184187 );
185188 }
@@ -190,7 +193,7 @@ contract MerkleTreeTest is Test, MerkleTreeExample {
190193 leavesCount = bound (leavesCount, 0 , type (uint128 ).max);
191194
192195 uint8 original = _computeMinimalTreeDepthNaive (leavesCount);
193- uint8 optimized = MerkleTree .computeMinimalTreeDepth (leavesCount);
196+ uint8 optimized = MerkleTreeReference .computeMinimalTreeDepth (leavesCount);
194197
195198 assertEq (original, optimized, "Implementations must match " );
196199 }
@@ -200,7 +203,7 @@ contract MerkleTreeTest is Test, MerkleTreeExample {
200203 leavesCount = bound (leavesCount, 0 , 1000 );
201204
202205 uint8 original = _computeMinimalTreeDepthNaive (leavesCount);
203- uint8 optimized = MerkleTree .computeMinimalTreeDepth (leavesCount);
206+ uint8 optimized = MerkleTreeReference .computeMinimalTreeDepth (leavesCount);
204207
205208 assertEq (original, optimized, "Implementations must match " );
206209 }
@@ -210,7 +213,7 @@ contract MerkleTreeTest is Test, MerkleTreeExample {
210213 leavesCount = bound (leavesCount, 1000 , 1000000 );
211214
212215 uint8 original = _computeMinimalTreeDepthNaive (leavesCount);
213- uint8 optimized = MerkleTree .computeMinimalTreeDepth (leavesCount);
216+ uint8 optimized = MerkleTreeReference .computeMinimalTreeDepth (leavesCount);
214217
215218 assertEq (original, optimized, "Implementations must match " );
216219 }
@@ -223,7 +226,7 @@ contract MerkleTreeTest is Test, MerkleTreeExample {
223226 /// @notice Fuzz test - Optimized implementation only (to measure gas)
224227 function testFuzz_gas_optimized (uint256 leavesCount ) public pure {
225228 leavesCount = bound (leavesCount, 0 , 1000000 );
226- MerkleTree .computeMinimalTreeDepth (leavesCount);
229+ MerkleTreeReference .computeMinimalTreeDepth (leavesCount);
227230 }
228231
229232 /// @notice Hashes two `bytes32` values.
0 commit comments