diff --git a/src/MerkleTree.ts b/src/MerkleTree.ts index c6f3629..a961992 100644 --- a/src/MerkleTree.ts +++ b/src/MerkleTree.ts @@ -531,7 +531,13 @@ export class MerkleTree extends Base { const proof = [] if (!Number.isInteger(index)) { - index = this._bufferIndexOf(this.leaves, leaf, this.sortLeaves) + index = -1 + + for (let i = 0; i < this.leaves.length; i++) { + if (Buffer.compare(leaf, this.leaves[i]) === 0) { + index = i + } + } } if (index <= -1) { diff --git a/test/MerkleTree.test.js b/test/MerkleTree.test.js index 5292419..e8ba601 100644 --- a/test/MerkleTree.test.js +++ b/test/MerkleTree.test.js @@ -1291,3 +1291,13 @@ test('complete option with incompatible options', t => { ) }) +test('simple bad proof', t => { + t.plan(2) + + const leaves = ['d', 'e', 'f'] + const tree = new MerkleTree(leaves) + + const proof = tree.getHexProof(leaves[0]) + t.equal(proof.length, 1) + t.equal(proof[0], '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855') +})