Skip to content

Commit

Permalink
refactor(lazy-imt): target depth calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
chancehudson committed Sep 18, 2024
1 parent a4e7136 commit 409bfee
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/lazy-imt/contracts/InternalLazyIMT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,14 @@ library InternalLazyIMT {
uint40 numberOfLeaves = self.numberOfLeaves;
require(index < numberOfLeaves, "LazyIMT: leaf must exist");

// targetDepth = log2_floor(numberOfLeaves)
uint8 targetDepth = 1;
while (uint40(2) ** uint40(targetDepth) < numberOfLeaves) {
targetDepth++;
{
uint40 exp = 2;
while (exp < numberOfLeaves) {
exp <<= 1;
targetDepth++;
}
}
require(depth >= targetDepth, "LazyIMT: proof depth");
// pass depth -1 because we don't need the root value
Expand Down

0 comments on commit 409bfee

Please sign in to comment.