forked from 0xPolygon/edge-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fixes * fix * Fix BridgeStorage and Gateway hardhat tests * Fix forge tests * Fix * Fix * comments fix --------- Co-authored-by: filip <[email protected]>
- Loading branch information
1 parent
0ca2c99
commit 8158051
Showing
12 changed files
with
349 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.19; | ||
|
||
/** | ||
* @title Merkle tree Lib | ||
* @notice merkle tree helper functions | ||
*/ | ||
library Merkle { | ||
/** | ||
* @notice helper function to compute the Merkle Root from an array of already hashed leaves | ||
* @param leaves hashed leaves of the merkle tree | ||
*/ | ||
function computeMerkleRoot(bytes32[] memory leaves) internal pure returns (bytes32) { | ||
if (leaves.length == 1) { | ||
return leaves[0]; // If there's only one leaf, it is the root | ||
} | ||
|
||
// Continue hashing pairs of nodes until the root is obtained | ||
while (leaves.length > 1) { | ||
uint256 nextLevelSize = (leaves.length + 1) / 2; | ||
bytes32[] memory nextLevel = new bytes32[](nextLevelSize); | ||
|
||
for (uint256 i = 0; i < leaves.length / 2; i++) { | ||
nextLevel[i] = keccak256(abi.encodePacked(leaves[2 * i], leaves[2 * i + 1])); | ||
} | ||
|
||
// If the number of leaves is odd, carry forward the last leaf | ||
if (leaves.length % 2 == 1) { | ||
nextLevel[nextLevel.length - 1] = leaves[leaves.length - 1]; | ||
} | ||
|
||
leaves = nextLevel; | ||
} | ||
|
||
return leaves[0]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Merkle | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.