Solidity API
MerkleProof
_These functions deal with verification of Merkle Tree proofs.
note that this is a stripped down version of Open Zeppelin's MerkleProof. https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3200
The proofs can be generated using the JavaScript library https://github.com/miguelmota/merkletreejs[merkletreejs]. Note: the hashing algorithm should be keccak256 and pair sorting should be enabled.
See test/utils/cryptography/MerkleProof.test.ts
for some examples.
WARNING: You should avoid using leaf values that are 64 bytes long prior to hashing, or use a hash function other than keccak256 for hashing leaves. This is because the concatenation of a sorted pair of internal nodes in the merkle tree could be reinterpreted as a leaf value._
verifyCalldata
function verifyCalldata(bytes32[] proof, bytes32 root, bytes32 leaf) internal pure returns (bool)
Returns true if a leaf
can be proved to be a part of a Merkle tree
defined by root
. For this, a proof
must be provided, containing
sibling hashes on the branch from the leaf to the root of the tree. Each
pair of leaves and each pair of pre-images are assumed to be sorted.
processProofCalldata
function processProofCalldata(bytes32[] proof, bytes32 leaf) internal pure returns (bytes32)
Returns the rebuilt hash obtained by traversing a Merkle tree up
from leaf
using proof
. A proof
is valid if and only if the rebuilt
hash matches the root of the tree. When processing the proof, the pairs
of leafs & pre-images are assumed to be sorted.
_hashPair
function _hashPair(bytes32 a, bytes32 b) private pure returns (bytes32)
_efficientHash
function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value)