Add test and docs describing a misuse of MerkleProof (#3090)

Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
This commit is contained in:
Doug Hoyte
2022-01-31 10:10:13 -05:00
committed by GitHub
parent a81b07ce91
commit 4f8af2dceb
2 changed files with 12 additions and 1 deletions

View File

@ -24,6 +24,12 @@ contract('MerkleProof', function (accounts) {
const proof = merkleTree.getHexProof(leaf);
expect(await this.merkleProof.verify(proof, root, leaf)).to.equal(true);
// For demonstration, it is also possible to create valid proofs for certain 64-byte values *not* in elements:
const noSuchLeaf = keccak256(
Buffer.concat([keccak256(elements[0]), keccak256(elements[1])].sort(Buffer.compare)),
);
expect(await this.merkleProof.verify(proof.slice(1), root, noSuchLeaf)).to.equal(true);
});
it('returns false for an invalid Merkle proof', async function () {