Skip to content

Commit

Permalink
Merge pull request #220 from privacy-scaling-explorations/fix/merkle-…
Browse files Browse the repository at this point in the history
…proof-length

Remove merkle proof length check in the `update` function
  • Loading branch information
cedoor committed Mar 20, 2024
2 parents b4c91e3 + 18b8ed9 commit 863415e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 0 additions & 2 deletions packages/imt.sol/contracts/internal/InternalLeanIMT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ library InternalLeanIMT {
revert LeafDoesNotExist();
} else if (newLeaf != 0 && _has(self, newLeaf)) {
revert LeafAlreadyExists();
} else if (siblingNodes.length == 0) {
revert WrongSiblingNodes();
}

uint256 index = _indexOf(self, oldLeaf);
Expand Down
10 changes: 6 additions & 4 deletions packages/imt.sol/test/LeanIMT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,22 @@ describe("LeanIMT", () => {
await expect(transaction).to.be.revertedWithCustomError(leanIMT, "LeafGreaterThanSnarkScalarField")
})

it("Should not update a leaf if there are no sibling nodes", async () => {
it("Should update a leaf if that's the only leaf in the tree", async () => {
await leanIMTTest.insert(1)

jsLeanIMT.insert(BigInt(1))
jsLeanIMT.update(0, BigInt(2))

const { siblings } = jsLeanIMT.generateProof(0)

const transaction = leanIMTTest.update(1, 2, siblings)
await leanIMTTest.update(1, 2, siblings)

await expect(transaction).to.be.revertedWithCustomError(leanIMT, "WrongSiblingNodes")
const root = await leanIMTTest.root()

expect(root).to.equal(jsLeanIMT.root)
})

it("Should update a leaf", async () => {
it("Should update a leaf if there's more than 1 leaf in the tree", async () => {
await leanIMTTest.insert(1)
await leanIMTTest.insert(2)

Expand Down

0 comments on commit 863415e

Please sign in to comment.