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(group): after a sequence of updates a proof is invalid #910

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
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
59 changes: 58 additions & 1 deletion packages/contracts/test/Semaphore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,66 @@ describe("Semaphore", () => {

const proof = await generateProof(identity, group, message, group.root, merkleTreeDepth)

return { semaphoreContract, groupId, proof }
return { semaphoreContract, groupId, proof, accountAddresses }
}

it("Should insert members,remove member,update member and verifyProof", async () => {
const { semaphoreContract, accountAddresses } = await loadFixture(deployValidateProofFixture)

const identity = new Identity("0")
const members = Array.from({ length: 3 }, (_, i) => new Identity(i.toString())).map(
({ commitment }) => commitment
)
const group = new Group(members)

// Create a group and add 3 members.
let transaction = await semaphoreContract["createGroup(address)"](accountAddresses[0])

const { logs } = (await transaction.wait()) as any

const [groupId] = logs[0].args
Lauman marked this conversation as resolved.
Show resolved Hide resolved

// Adding members to group

transaction = await semaphoreContract.addMembers(groupId, members)
await transaction.wait()

// Remove the third member.
{
group.removeMember(2)
const { siblings } = group.generateMerkleProof(2)

transaction = await semaphoreContract.removeMember(groupId, members[2], siblings)
await transaction.wait()
Lauman marked this conversation as resolved.
Show resolved Hide resolved
}

// Update the second member.
{
group.updateMember(1, members[2])
const { siblings } = group.generateMerkleProof(1)

transaction = await semaphoreContract.updateMember(groupId, members[1], members[2], siblings)
await transaction.wait()
}

// Validate a proof.
const proof = await generateProof(identity, group, 42, group.root)

transaction = await semaphoreContract.validateProof(groupId, proof)

await expect(transaction)
.to.emit(semaphoreContract, "ProofValidated")
.withArgs(
groupId,
proof.merkleTreeDepth,
proof.merkleTreeRoot,
proof.nullifier,
proof.message,
proof.merkleTreeRoot,
proof.points
)
})

it("Should throw an exception if the proof is not valid", async () => {
const { semaphoreContract, groupId, proof } = await loadFixture(deployValidateProofFixture)

Expand Down
2 changes: 1 addition & 1 deletion packages/group/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"rollup-plugin-cleanup": "^3.2.1"
},
"dependencies": {
"@zk-kit/lean-imt": "2.2.1",
"@zk-kit/lean-imt": "2.2.2",
"@zk-kit/utils": "1.2.1",
"poseidon-lite": "0.3.0"
}
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7451,7 +7451,7 @@ __metadata:
resolution: "@semaphore-protocol/group@workspace:packages/group"
dependencies:
"@rollup/plugin-typescript": "npm:^11.1.6"
"@zk-kit/lean-imt": "npm:2.2.1"
"@zk-kit/lean-imt": "npm:2.2.2"
"@zk-kit/utils": "npm:1.2.1"
poseidon-lite: "npm:0.3.0"
rimraf: "npm:^5.0.5"
Expand Down Expand Up @@ -9589,12 +9589,12 @@ __metadata:
languageName: node
linkType: hard

"@zk-kit/lean-imt@npm:2.2.1":
version: 2.2.1
resolution: "@zk-kit/lean-imt@npm:2.2.1"
"@zk-kit/lean-imt@npm:2.2.2":
version: 2.2.2
resolution: "@zk-kit/lean-imt@npm:2.2.2"
dependencies:
"@zk-kit/utils": "npm:1.2.1"
checksum: 10/f57ba0ab15ff38609c352862b21023d370bd250c37c7ef15d4ee7724c8179a7fdd6647ac8a555e6cf523032d1c769fb9eae6de5364a97574224ff7de1a34f8a8
checksum: 10/321e1964a4a0b7a19083c01743f5ee2a7311b1eede6775ce952a6fecf07d347dc4cdb250a557ff459bc6d3bff030e2a571f5116510c2392ca523f50c4d02311d
languageName: node
linkType: hard

Expand Down
Loading