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

> 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/messageservice/lib/sparsemerkletreeverifier.md](https://docs.linea.build/api/linea-smart-contracts/messageservice/lib/sparsemerkletreeverifier.md).

# SparseMerkleTreeVerifier

# `SparseMerkleTreeVerifier`

### SafeCastOverflowedUintDowncast

```solidity
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value)
```

_Value doesn't fit in a uint of `bits` size. This is based on OpenZeppelin's SafeCast library._

### LeafIndexOutOfBounds

```solidity
error LeafIndexOutOfBounds(uint32 leafIndex, uint32 maxAllowedIndex)
```

_Custom error for when the leaf index is out of bounds._

### _verifyMerkleProof

```solidity
function _verifyMerkleProof(bytes32 _leafHash, bytes32[] _proof, uint32 _leafIndex, bytes32 _root) internal pure returns (bool proofIsValid)
```

Verify merkle proof

_The depth of the tree is expected to be validated elsewhere beforehand._

#### Parameters

| Name | Type | Description |
| --- | --- | --- |
| _leafHash | bytes32 | Leaf hash. |
| _proof | bytes32[] | Sparse merkle tree proof. |
| _leafIndex | uint32 | Index of the leaf. |
| _root | bytes32 | Merkle root. |

#### Return Values

| Name | Type | Description |
| --- | --- | --- |
| proofIsValid | bool | Returns if the proof is valid or not. |

### safeCastToUint32

```solidity
function safeCastToUint32(uint256 _value) internal pure returns (uint32 castUint32)
```

Tries to safely cast to uint32.

_This is based on OpenZeppelin's SafeCast library._

#### Parameters

| Name | Type | Description |
| --- | --- | --- |
| _value | uint256 | The value being cast to uint32. |

#### Return Values

| Name | Type | Description |
| --- | --- | --- |
| castUint32 | uint32 | Returns a uint32 safely cast. |

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.
