MerkleTree
Provides functions for calculating Merkle roots
Functions
calculateMerkleRoot
Calculates the Merkle root of an array of SSZ-encoded data using sha256 for hashing
function calculateMerkleRoot(bytes32[] memory data)
internal
pure
returns (bytes32 root);
Parameters
Name | Type | Description |
---|---|---|
data | bytes32[] | The array of SSZ-encoded data (as bytes32 values) |
Returns
Name | Type | Description |
---|---|---|
root | bytes32 | The Merkle root of the data |
verifyMerkleLeaf
Verifies the inclusion of a leaf node in a Merkle tree using a given proof.
Follows a bottom-up approach by iteratively hashing the leaf with proof elements based on the index and comparing the computed root with the provided Merkle root.
function verifyMerkleLeaf(
bytes32[] memory proof,
bytes32 root,
bytes32 leaf,
uint256 index
) public pure returns (bool);
Parameters
Name | Type | Description |
---|---|---|
proof | bytes32[] | Array of bytes32 values representing the Merkle proof. |
root | bytes32 | The Merkle root to verify the leaf node against. |
leaf | bytes32 | The leaf node whose inclusion in the Merkle tree is being verified. |
index | uint256 | The index of the leaf node in the tree, used to determine proof element order. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True if the computed Merkle root matches the provided root, indicating valid inclusion; otherwise, false. |
calculateMerkleRootFromProof
Calculates the Merkle root from a leaf, proof, and index.
function calculateMerkleRootFromProof(
bytes32[] memory proof,
bytes32 leaf,
uint256 index
) public pure returns (bytes32 root);
Parameters
Name | Type | Description |
---|---|---|
proof | bytes32[] | Array of bytes32 values representing the Merkle proof. |
leaf | bytes32 | The leaf node whose inclusion in the Merkle tree is being verified. |
index | uint256 | The index of the leaf node in the tree, used to determine proof element order. |
Returns
Name | Type | Description |
---|---|---|
root | bytes32 | The computed Merkle root. |