# Merkle Proof

Allows users to verify Merkle Tree proofs. It is based on the OZ implementation. The tree and the proofs can be generated using <https://github.com/merkletreejs/merkletreejs>.

{% hint style="danger" %}

```
You should avoid using leaf values that are 64 bytes long prior to hashing.
```

{% endhint %}

## Interface

### <mark style="color:blue;">verify</mark>

**Returns true if a `leaf` can be proved to be a part of a Merkle tree defined by `root`.**

```rust
public fun verify(
    proof: &vector<vector<u8>>,
    root: vector<u8>,
    leaf: vector<u8>
  ): bool
```

* **@param proof:** The Merkle proof.
* **@param root:** The root of Merkle Tree.
* **@param leaf:** The `leaf` we wish to prove if it is part of the tree.
* **@return bool.** If it is part of the Merkle tree.

### <mark style="color:blue;">verify\_with\_index</mark>

**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.**

{% hint style="success" %}
The index logic is from ENS token: <https://etherscan.io/token/0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72#code>
{% endhint %}

```rust
public fun verify_with_index(
    proof: &vector<vector<u8>>,
    root: vector<u8>,
    leaf: vector<u8>
): (bool, u256)
```

* **@param proof:** The Merkle proof.
* **@param root:** The root of Merkle Tree.
* **@param leaf:** The `leaf` we wish to prove if it is part of the tree.
* **@return bool.** If it is part of the Merkle tree.
* **@return u256.** The index of the `leaf.`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.interestprotocol.com/overview/deprecated/sui-tears/utils/merkle-proof.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
