Skip to content

Commit 409bfee

Browse files
committed
refactor(lazy-imt): target depth calculation
1 parent a4e7136 commit 409bfee

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/lazy-imt/contracts/InternalLazyIMT.sol

+7-2
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,14 @@ library InternalLazyIMT {
221221
uint40 numberOfLeaves = self.numberOfLeaves;
222222
require(index < numberOfLeaves, "LazyIMT: leaf must exist");
223223

224+
// targetDepth = log2_floor(numberOfLeaves)
224225
uint8 targetDepth = 1;
225-
while (uint40(2) ** uint40(targetDepth) < numberOfLeaves) {
226-
targetDepth++;
226+
{
227+
uint40 exp = 2;
228+
while (exp < numberOfLeaves) {
229+
exp <<= 1;
230+
targetDepth++;
231+
}
227232
}
228233
require(depth >= targetDepth, "LazyIMT: proof depth");
229234
// pass depth -1 because we don't need the root value

0 commit comments

Comments
 (0)