Skip to content

Commit

Permalink
fix: major audit issue (sub tree root)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanseob committed Oct 10, 2021
1 parent 52b7cf6 commit c3a447c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ contract UserInteractable is Storage {
"Prepay data is different with the given withdrawal note."
);
require(
prepayRequest.prepayer == address(0) || prepayRequest.prepayer == msg.sender,
prepayRequest.prepayer == address(0) ||
prepayRequest.prepayer == msg.sender,
"This tx should be from the prepayer."
);

Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/contracts/zkopru/libraries/MerkleTree.sol
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ library SubTreeLib {
require(leaves.length <= treeSize, "Overflowed");

uint256[] memory nodes = new uint256[](treeSize << 1); // we'll not use nodes[0]
uint256 emptyNode = treeSize + leaves.length; // we do not hash if we can use pre hashed zeroes
uint256 lastNotEmptyNode = treeSize + leaves.length - 1;

// From the bottom to the top
for (uint256 level = 0; level <= subTreeDepth; level++) {
Expand All @@ -366,7 +366,7 @@ library SubTreeLib {
nodeIndex >= leftMostOfTheFloor;
nodeIndex--
) {
if (nodeIndex < emptyNode) {
if (nodeIndex <= lastNotEmptyNode) {
// This node is not an empty node
if (level == 0) {
// Leaf node
Expand All @@ -385,7 +385,7 @@ library SubTreeLib {
nodes[nodeIndex] = self.preHashedZero[level];
}
}
emptyNode >>= 1;
lastNotEmptyNode >>= 1;
}
return nodes[1];
}
Expand Down

0 comments on commit c3a447c

Please # to comment.