Skip to main content

SparseMerkleProof

Account​

The Account struct represents the state of the account including the storage root, nonce, balance and codesize

This is mapped directly to the output of the storage proof

struct Account {
uint64 nonce;
uint256 balance;
bytes32 storageRoot;
bytes32 mimcCodeHash;
bytes32 keccakCodeHash;
uint64 codeSize;
}

Leaf​

Represents the leaf structure in both account and storage tries

This is mapped directly to the output of the storage proof

struct Leaf {
uint256 prev;
uint256 next;
bytes32 hKey;
bytes32 hValue;
}

WrongBytesLength​

error WrongBytesLength(uint256 expectedLength, uint256 bytesLength)

Thrown when expected bytes length is incorrect

LengthNotMod32​

error LengthNotMod32()

Thrown when the length of bytes is not in exactly 32 byte chunks

MaxTreeLeafIndexExceed​

error MaxTreeLeafIndexExceed()

Thrown when the leaf index is higher than the tree depth

WrongProofLength​

error WrongProofLength(uint256 expectedLength, uint256 actualLength)

Thrown when the length of the unformatted proof is not provided exactly as expected (UNFORMATTED_PROOF_LENGTH)

TREE_DEPTH​

uint256 TREE_DEPTH

UNFORMATTED_PROOF_LENGTH​

uint256 UNFORMATTED_PROOF_LENGTH

ZERO_HASH​

bytes32 ZERO_HASH

MAX_TREE_LEAF_INDEX​

uint256 MAX_TREE_LEAF_INDEX

verifyProof​

function verifyProof(bytes[] _rawProof, uint256 _leafIndex, bytes32 _root) external pure returns (bool)

Formats input, computes root and returns true if it matches the provided merkle root

Parameters​

NameTypeDescription
_rawProofbytes[]Raw sparse merkle tree proof
_leafIndexuint256Index of the leaf
_rootbytes32Sparse merkle root

Return Values​

NameTypeDescription
[0]boolIf the computed merkle root matches the provided one

mimcHash​

function mimcHash(bytes _input) external pure returns (bytes32)

Hash a value using MIMC hash

Parameters​

NameTypeDescription
_inputbytesValue to hash

Return Values​

NameTypeDescription
[0]bytes32bytes32 Mimc hash

getLeaf​

function getLeaf(bytes _encodedLeaf) external pure returns (struct SparseMerkleProof.Leaf)

Get leaf

Parameters​

NameTypeDescription
_encodedLeafbytesEncoded leaf bytes (prev, next, hKey, hValue)

Return Values​

NameTypeDescription
[0]struct SparseMerkleProof.LeafLeaf Formatted leaf struct

getAccount​

function getAccount(bytes _encodedAccountValue) external pure returns (struct SparseMerkleProof.Account)

Get account

Parameters​

NameTypeDescription
_encodedAccountValuebytesEncoded account value bytes (nonce, balance, storageRoot, mimcCodeHash, keccakCodeHash, codeSize)

Return Values​

NameTypeDescription
[0]struct SparseMerkleProof.AccountAccount Formatted account struct

hashAccountValue​

function hashAccountValue(bytes _value) external pure returns (bytes32)

Hash account value

Parameters​

NameTypeDescription
_valuebytesEncoded account value bytes (nonce, balance, storageRoot, mimcCodeHash, keccakCodeHash, codeSize)

Return Values​

NameTypeDescription
[0]bytes32bytes32 Account value hash

hashStorageValue​

function hashStorageValue(bytes32 _value) external pure returns (bytes32)

Hash storage value

Parameters​

NameTypeDescription
_valuebytes32Encoded storage value bytes

Return Values​

NameTypeDescription
[0]bytes32bytes32 Storage value hash

Was this page helpful?