revert error from verification of multiproof flags

This commit is contained in:
Francisco Giordano 2022-10-26 20:18:41 -03:00
parent dda5c23cbc
commit 35f512bdb3
2 changed files with 3 additions and 21 deletions

View File

@ -906,12 +906,12 @@ export class MerkleTree extends Base {
throw new Error('Invalid Inputs!')
}
let ids : number[]
if (leaves.every(Number.isInteger)) {
leaves = leaves
ids = leaves.sort((a, b) => a === b ? 0 : a > b ? 1 : -1) // Indices where passed
} else {
leaves = leaves.map((el) => this._bufferIndexOf(this.leaves, el))
ids = leaves.map((el) => this._bufferIndexOf(this.leaves, el)).sort((a, b) => a === b ? 0 : a > b ? 1 : -1)
}
let ids : number[] = [...leaves].sort((a, b) => a === b ? 0 : a > b ? 1 : -1)
if (!ids.every((idx: number) => idx !== -1)) {
throw new Error('Element does not exist in Merkle tree')
@ -937,11 +937,6 @@ export class MerkleTree extends Base {
}, [])
}
const leafValues = leaves.map(i => this.leaves[i]);
if (!this.verifyMultiProofWithFlags(this.getRoot(), leafValues, proofs, flags)) {
throw new Error('cannot generate multiProof flags for parameters')
}
return flags
}

View File

@ -1185,16 +1185,3 @@ test('complete option with incompatible options', t => {
/option "complete" is incompatible with "duplicateOdd"/,
)
})
test('bad multiproof', t => {
t.plan(1);
const leaves = 'abcdefghi'.split('').map(keccak256).sort(Buffer.compare);
const merkleTree = new MerkleTree(leaves, keccak256, { complete: true });
const reqLeaves = leaves;
const root = merkleTree.getHexRoot();
const proof = merkleTree.getMultiProof(reqLeaves);
t.throws(
() => merkleTree.getProofFlags(reqLeaves, proof),
/cannot generate multiProof flags for parameters/,
);
});