Files
linea-monorepo/contracts/docs/api/lib/SparseMerkleProof.mdx
kyzooghost ea79b2d2be [Feat] Automate smart contract docgen and PR branch creation into Linea docs repo (#446)
* did poc for autogenerated *.mdx into docs.linea.build

* changed sparseMerkleProof

* first draft of contracts-docgen

* fix typos

* try different github token

* cleanup

* created create-docs-website-pr-branch

* cleanup for doc website repo scripts

* created first docs-repo pr using create-docs-website-pr-branch.sh

* improve comments

* added bash script segment to change filename to lowercase

* fix *.mdx headers to make more docusarus friendly

* update scripts for updated docs pr

* added comments to updateSidebar.js

* fix scripts after local test

* added installation checks

* Update contracts/docs/scripts/create-docs-website-pr-branch.sh

Co-authored-by: The Dark Jester <thedarkjester@users.noreply.github.com>
Signed-off-by: kyzooghost <73516204+kyzooghost@users.noreply.github.com>

---------

Signed-off-by: kyzooghost <73516204+kyzooghost@users.noreply.github.com>
Co-authored-by: The Dark Jester <thedarkjester@users.noreply.github.com>
2024-12-20 20:45:36 +11:00

213 lines
4.1 KiB
Plaintext

# `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_
```solidity
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_
```solidity
struct Leaf {
uint256 prev;
uint256 next;
bytes32 hKey;
bytes32 hValue;
}
```
### WrongBytesLength
```solidity
error WrongBytesLength(uint256 expectedLength, uint256 bytesLength)
```
Thrown when expected bytes length is incorrect
### LengthNotMod32
```solidity
error LengthNotMod32()
```
Thrown when the length of bytes is not in exactly 32 byte chunks
### MaxTreeLeafIndexExceed
```solidity
error MaxTreeLeafIndexExceed()
```
Thrown when the leaf index is higher than the tree depth
### WrongProofLength
```solidity
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
```solidity
uint256 TREE_DEPTH
```
### UNFORMATTED_PROOF_LENGTH
```solidity
uint256 UNFORMATTED_PROOF_LENGTH
```
### ZERO_HASH
```solidity
bytes32 ZERO_HASH
```
### MAX_TREE_LEAF_INDEX
```solidity
uint256 MAX_TREE_LEAF_INDEX
```
### verifyProof
```solidity
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
| Name | Type | Description |
| ---- | ---- | ----------- |
| _rawProof | bytes[] | Raw sparse merkle tree proof |
| _leafIndex | uint256 | Index of the leaf |
| _root | bytes32 | Sparse merkle root |
#### Return Values
| Name | Type | Description |
| ---- | ---- | ----------- |
| [0] | bool | If the computed merkle root matches the provided one |
### mimcHash
```solidity
function mimcHash(bytes _input) external pure returns (bytes32)
```
Hash a value using MIMC hash
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _input | bytes | Value to hash |
#### Return Values
| Name | Type | Description |
| ---- | ---- | ----------- |
| [0] | bytes32 | bytes32 Mimc hash |
### getLeaf
```solidity
function getLeaf(bytes _encodedLeaf) external pure returns (struct SparseMerkleProof.Leaf)
```
Get leaf
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _encodedLeaf | bytes | Encoded leaf bytes (prev, next, hKey, hValue) |
#### Return Values
| Name | Type | Description |
| ---- | ---- | ----------- |
| [0] | struct SparseMerkleProof.Leaf | Leaf Formatted leaf struct |
### getAccount
```solidity
function getAccount(bytes _encodedAccountValue) external pure returns (struct SparseMerkleProof.Account)
```
Get account
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _encodedAccountValue | bytes | Encoded account value bytes (nonce, balance, storageRoot, mimcCodeHash, keccakCodeHash, codeSize) |
#### Return Values
| Name | Type | Description |
| ---- | ---- | ----------- |
| [0] | struct SparseMerkleProof.Account | Account Formatted account struct |
### hashAccountValue
```solidity
function hashAccountValue(bytes _value) external pure returns (bytes32)
```
Hash account value
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _value | bytes | Encoded account value bytes (nonce, balance, storageRoot, mimcCodeHash, keccakCodeHash, codeSize) |
#### Return Values
| Name | Type | Description |
| ---- | ---- | ----------- |
| [0] | bytes32 | bytes32 Account value hash |
### hashStorageValue
```solidity
function hashStorageValue(bytes32 _value) external pure returns (bytes32)
```
Hash storage value
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _value | bytes32 | Encoded storage value bytes |
#### Return Values
| Name | Type | Description |
| ---- | ---- | ----------- |
| [0] | bytes32 | bytes32 Storage value hash |