Multiproof stops working starting with 9 leaves
See original GitHub issueThe 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:
- merkletreejs:
0.2.32
- keccak256:
1.0.6
- @openzeppelin/contracts:
4.7.3
Issue Analytics
- State:
- Created a year ago
- Comments:20 (14 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
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.