From 18b8ed9fe2fc089af9ff8ac67a05b096fe7cc470 Mon Sep 17 00:00:00 2001 From: cedoor Date: Wed, 20 Mar 2024 10:52:01 +0000 Subject: [PATCH] fix(imt.sol): remove merkle proof length check Updating LeanIMT of size 1 (tree with 1 leaf inserted), the update function should not revert. re #210 --- .../imt.sol/contracts/internal/InternalLeanIMT.sol | 2 -- packages/imt.sol/test/LeanIMT.ts | 10 ++++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/imt.sol/contracts/internal/InternalLeanIMT.sol b/packages/imt.sol/contracts/internal/InternalLeanIMT.sol index 572dbde29..d665f9b27 100644 --- a/packages/imt.sol/contracts/internal/InternalLeanIMT.sol +++ b/packages/imt.sol/contracts/internal/InternalLeanIMT.sol @@ -218,8 +218,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); diff --git a/packages/imt.sol/test/LeanIMT.ts b/packages/imt.sol/test/LeanIMT.ts index 507e49feb..24c0e65c7 100644 --- a/packages/imt.sol/test/LeanIMT.ts +++ b/packages/imt.sol/test/LeanIMT.ts @@ -137,7 +137,7 @@ 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)) @@ -145,12 +145,14 @@ describe("LeanIMT", () => { 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)