Support memory arrays in MerkleTree multiproof (#3493)

(cherry picked from commit 2894059775)
Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
Hadrien Croubois
2022-06-27 13:15:52 +02:00
parent b9710923a8
commit e4748fbba1
3 changed files with 110 additions and 9 deletions

View File

@ -79,6 +79,7 @@ contract('MerkleProof', function (accounts) {
const proofFlags = merkleTree.getProofFlags(proofLeaves, proof);
expect(await this.merkleProof.multiProofVerify(proof, proofFlags, root, proofLeaves)).to.equal(true);
expect(await this.merkleProof.multiProofVerifyCalldata(proof, proofFlags, root, proofLeaves)).to.equal(true);
});
it('returns false for an invalid Merkle multi proof', async function () {
@ -91,7 +92,10 @@ contract('MerkleProof', function (accounts) {
const badProof = badMerkleTree.getMultiProof(badProofLeaves);
const badProofFlags = badMerkleTree.getProofFlags(badProofLeaves, badProof);
expect(await this.merkleProof.multiProofVerify(badProof, badProofFlags, root, badProofLeaves)).to.equal(false);
expect(await this.merkleProof.multiProofVerify(badProof, badProofFlags, root, badProofLeaves))
.to.equal(false);
expect(await this.merkleProof.multiProofVerifyCalldata(badProof, badProofFlags, root, badProofLeaves))
.to.equal(false);
});
it('revert with invalid multi proof #1', async function () {
@ -111,6 +115,15 @@ contract('MerkleProof', function (accounts) {
),
'MerkleProof: invalid multiproof',
);
await expectRevert(
this.merkleProof.multiProofVerifyCalldata(
[ leaves[1], fill, merkleTree.layers[1][1] ],
[ false, false, false ],
root,
[ leaves[0], badLeaf ], // A, E
),
'MerkleProof: invalid multiproof',
);
});
it('revert with invalid multi proof #2', async function () {
@ -130,6 +143,15 @@ contract('MerkleProof', function (accounts) {
),
'reverted with panic code 0x32',
);
await expectRevert(
this.merkleProof.multiProofVerifyCalldata(
[ leaves[1], fill, merkleTree.layers[1][1] ],
[ false, false, false, false ],
root,
[ badLeaf, leaves[0] ], // A, E
),
'reverted with panic code 0x32',
);
});
it('limit case: works for tree containing a single leaf', async function () {
@ -142,6 +164,7 @@ contract('MerkleProof', function (accounts) {
const proofFlags = merkleTree.getProofFlags(proofLeaves, proof);
expect(await this.merkleProof.multiProofVerify(proof, proofFlags, root, proofLeaves)).to.equal(true);
expect(await this.merkleProof.multiProofVerifyCalldata(proof, proofFlags, root, proofLeaves)).to.equal(true);
});
it('limit case: can prove empty leaves', async function () {
@ -150,6 +173,7 @@ contract('MerkleProof', function (accounts) {
const root = merkleTree.getRoot();
expect(await this.merkleProof.multiProofVerify([ root ], [], root, [])).to.equal(true);
expect(await this.merkleProof.multiProofVerifyCalldata([ root ], [], root, [])).to.equal(true);
});
});
});