Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lean-imt): After a sequence of updates a proof is invalid. #355

Merged
merged 7 commits into from
Dec 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: lean-imt-update-member
When a member is removed from the tree (update a leaf with 0n) and then another member is updated, the root that is saved is not correct, so the proof that is generated is not valid.This was caused by a type validation failure.
This fix the behavior described above.
I detected this when I was testing in Semphore groups.
Lauman committed Dec 3, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit f559a28fa335b20b656c72af2b839063dbedf76c
2 changes: 1 addition & 1 deletion packages/lean-imt/src/lean-imt.ts
Original file line number Diff line number Diff line change
@@ -222,7 +222,7 @@ export default class LeanIMT<N = bigint> {
// (like the 'insert' function).
const sibling = this._nodes[level][index + 1]

if (sibling) {
if (sibling !== undefined) {
node = this._hash(node, sibling)
}
}
24 changes: 24 additions & 0 deletions packages/lean-imt/tests/lean-imt.test.ts
Original file line number Diff line number Diff line change
@@ -443,6 +443,30 @@ describe("Lean IMT", () => {
}
expect(LeanIMT.verifyProof(proof, badHash)).toBe(false)
})

it(`Should insert members,remove member,update member and verifyProof`, () => {
const tree = new LeanIMT(poseidon)

tree.insert(BigInt(1))

tree.insert(BigInt(2))

tree.insert(BigInt(3))

// Remove the third member.
tree.update(2, BigInt(0))

let proof = tree.generateProof(1)

expect(tree.verifyProof(proof)).toBe(true)

// Update the second member.
tree.update(1, BigInt(2))

// Validating a proof generated by the first member
proof = tree.generateProof(1)
expect(tree.verifyProof(proof)).toBe(true)
})
})

describe("# import/export", () => {