question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiproof stops working starting with 9 leaves

See original GitHub issue

The following test reverts

it('multiproof', async () => {
  const leaves = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'].map(keccak256).sort(Buffer.compare)
  const merkleTree = new MerkleTree(leaves, keccak256, { sort: true })
  const root = merkleTree.getRoot()
  const proof = merkleTree.getMultiProof(leaves)
  const proofFlags = merkleTree.getProofFlags(leaves, proof)
  await merkleProof.multiProofVerifyCalldata(proof, proofFlags, root, leaves)
})

Versions:

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:20 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
frangiocommented, Oct 6, 2022

The algorithm for multiproofs doesn’t allow the construction of multiproofs for trees with particularly unbalanced shapes. The merkletree.js library can currently easily produce such trees, as in the example above. Unfortunately this is not something we knew of before.

It’s important to note that it is always possible to produce a multiproof for a single leaf.

The problem for multiple leaves is solved by better balancing the merkle tree. The tree should be a complete (not perfect) full binary tree (definitions in Wikipedia). This kind of tree exists for any needed total number of leaves.

Additionally, the array of leaves that will be proven with a multiproof needs to be sorted in a particular way to be able to produce a multiproof. The ordering should be the reverse of the “general indices” defined in this document. The proof array will be sorted in the same way.

The plan I propose is:

  1. Document that in order to use multiproofs there are requirements on the tree shape and the leaves array. (Note: This kind of requirement is not entirely new, because even for single proofs you want the tree to be well balanced as well.)
  2. Add a flag in merkletree.js to build trees of this shape, add a warning if a multiproof is requested for a tree that was built without this flag, and verify that leaves are properly ordered when a multiproof is requested.
1reaction
frangiocommented, Oct 7, 2022

Yes we will want to add a test case. At the moment the next step we’re working on is to modify the merkletreejs library to construct the tree as needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compact Merkle Multiproofs – arXiv Vanity
The compact Merkle multiproof is a new and significantly more memory-efficient way to generate and verify sparse Merkle multiproofs. A standard sparse Merkle ......
Read more >
Compact Merkle Multiproofs - arXiv
Wuille's multiproof approach is different from both our work and Champine's work, as it does not rely on leaf indices for multiproof ......
Read more >
Merkle proof formats - SSZ
Notice how despite being a multiproof for 3 values, it requires only 3 auxiliary nodes, only one node more than would be required...
Read more >
Streaming Merkle Proofs within Binary Numeral Trees
11-BNT, we begin by merging the new leaf—itself a. 20 subtree—with the existing 20 ... Most existing work on Merkle trees is concerned....
Read more >
(PDF) Compact Merkle Multiproofs - ResearchGate
Wuille's multiproof approach is different. from both our work and Champine's work, as it does not rely. on leaf indices for multiproof ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found