<!-- Canonical: https://docs.linea.build/api/linea-smart-contracts/lib/sparsemerkleproof -->

> For the complete Linea documentation index, see [llms.txt](/llms.txt).
> Agents can fetch this page as Markdown at [https://docs.linea.build/api/linea-smart-contracts/lib/sparsemerkleproof.md](https://docs.linea.build/api/linea-smart-contracts/lib/sparsemerkleproof.md).

# SparseMerkleProof

# `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 |

Contributions not accepted

These reference pages are automatically generated based on Linea's [smart contracts](https://github.com/Consensys/linea-monorepo/tree/main/contracts/src). To ensure they accurately match the deployed smart contracts, we cannot accept any contributions that edit these pages.
