Question: Merkle root generation

How could I successfully construct the correct values of the Merkle root, note hash path, and note commitment that actually works with Merkle-tree-involving stdlib functions and uses in Noir?

For example
1: noir/ at 50fcb3cded8cf37403a2dc3839bf99b7df4261b5 · noir-lang/noir · GitHub
2: noir/ at 50fcb3cded8cf37403a2dc3839bf99b7df4261b5 · noir-lang/noir · GitHub

In these tests, merkle roots and relating input values are already written in Prover.toml, but since my goal is to create my own app that involves these values, I’d like to know how to get the correct ones that don’t cause errors with latest nargo versions.

The only thing I found is this repo: simple shield. But those values generated from this repo’s js/ts tests don’t work with the copied circuit codes of the above tests in my nargo environment whose version is 0.6.0. I suppose it’s because that the packages such as @noir-lang/barretenberg are out of date.

Is there any repo that contains working JS/TS or solidity implementation for creating merkle root and producing the input values?


Hello. The JS/TS packages are indeed quite outdated, we’re working on them as we speak so we shouldn’t have to wait much longer.

The simple shield is a good example, but you can find another one in the noir-starter if you check the “ec” branch (not yet merged but it’s a working example).

Just keep in mind that the Pedersen implementation, used in merkle trees, changed between 0.4.1 and 0.5 (ultraplonk). Since the latest JS/TS packages are not up-to-date with ultraplonk, their implementation of Pedersen is still the “old one”. In practice this means you should use 0.4.1 if you’re comparing the merkle trees generated by barretenberg/aztec_backend and those generated/verified by Noir 0.5+.

Again, we’re working on it and soon you’ll be able to create merkle trees in JS/TS using the upcoming new packages, and verify them in-circuit using Noir 0.5+

TL;DR use Noir 0.4.1


Is there an update on this?


The NoirJS package and the new Pedersen implementation have respectively been in place. You can call the compute_merkle_root from the standard library for computing merkle roots in Noir. (Example: simple_shield test)

Separately, we are working on Expose black box function solvers into TS #2811 for computing Pedersen values in JavaScript. To retrieve computed values in the meantime, you could write a Noir program that computes and returns such values and grab them from Verifier.toml.

Let us know if there is anything else we could help!