# Help needed regarding merkle implementation in noir

**URL:** <https://forum.aztec.network/t/help-needed-regarding-merkle-implementation-in-noir/591>\
**Category:** Noir\
**Created:** [June 12, 2023, 5:02pm UTC](https://forum.aztec.network/t/help-needed-regarding-merkle-implementation-in-noir/591 "2023-06-12T17:02:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![supernovahs](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@supernovahs](https://forum.aztec.network/u/supernovahs)\
**Post date:** [June 12, 2023, 5:02pm UTC](https://forum.aztec.network/t/help-needed-regarding-merkle-implementation-in-noir/591/1 "2023-06-12T17:02:58Z")

</div>

````auto
let is_member = std::merkle::check_membership(root, leaf, index, hashpath);
```|

In the above , what is index? In the examples, we are using index = 0 . Why is that the case?

is index used to denote the position of the leaf, left or right?
````

---

<div class="post-metadata">

**Author:** ![vezenovm](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.aztec.network/vezenovm/32/163_2.png) [@vezenovm](https://forum.aztec.network/u/vezenovm)\
**Post date:** [June 13, 2023, 8:42am UTC](https://forum.aztec.network/t/help-needed-regarding-merkle-implementation-in-noir/591/2 "2023-06-13T08:42:40Z")

</div>

So the index is the position of the leaf in the tree. In a binary merkle tree it is broken down into a bit array where each bit is used to determine whether the current leaf we are hashing is on the left or right. In our stdlib you can see this in more detail: [noir/noir\_stdlib/src/merkle.nr at bd8379e2e847ab5196ff01e23add5a277fc6eb1c · noir-lang/noir · GitHub](https://github.com/noir-lang/noir/blob/bd8379e2e847ab5196ff01e23add5a277fc6eb1c/noir_stdlib/src/merkle.nr#L6). We are going to be deprecating the `check_membership` method in favor of the method linked in the next version of Noir.

---

<div class="post-metadata">

**Author:** ![david-banks](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.aztec.network/david-banks/32/31_2.png) [@david-banks](https://forum.aztec.network/u/david-banks)\
**Post date:** [June 13, 2023, 10:44am UTC](https://forum.aztec.network/t/help-needed-regarding-merkle-implementation-in-noir/591/3 "2023-06-13T10:44:22Z")

</div>

Just to supplement the other answer, I think the “position of the leaf in the tree” means that leftmost “leaf index” is 0 and the rightmost is `( 2^height)-1` (if height does not include root).

```auto
                                  ┏━━━┓
root: ╭─────────────┨ r ┠─────────────╮
                    │ ┗━━━┛ │
                  ┏━┷━┓ ┏━┷━┓
lyr2: ╭─────┨ x ┠─────╮ ╭─────┨ x ┠─────╮
            │ ┗━━━┛ │ │ ┗━━━┛ │
          ┏━┷━┓ ┏━┷━┓ ┏━┷━┓ ┏━┷━┓
lyr1: ╭─┨ x ┠─╮ ╭─┨ x ┠─╮ ╭─┨ x ┠─╮ ╭─┨ x ┠─╮
        │ ┗━━━┛ │ │ ┗━━━┛ │ │ ┗━━━┛ │ │ ┗━━━┛ │
      ┏━┷━┓ ┏━┷━┓ ┏━┷━┓ ┏━┷━┓ ┏━┷━┓ ┏━┷━┓ ┏━┷━┓ ┏━┷━┓
lry0: ┃ 0 ┃ ┃ 1 ┃ ┃ 2 ┃ ┃ 3 ┃ ┃ 4 ┃ ┃ 5 ┃ ┃ 6 ┃ ┃ 7 ┃
      ┗━━━┛ ┗━━━┛ ┗━━━┛ ┗━━━┛ ┗━━━┛ ┗━━━┛ ┗━━━┛ ┗━━━┛

height = 3
num_leaves = (2^height) = 2^3 = 8

```

---

<div class="post-metadata">

**Author:** ![supernovahs](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@supernovahs](https://forum.aztec.network/u/supernovahs)\
**Post date:** [June 14, 2023, 11:14am UTC](https://forum.aztec.network/t/help-needed-regarding-merkle-implementation-in-noir/591/4 "2023-06-14T11:14:46Z")

</div>

Thanks for the explanation
