Skip to content

Commit

Permalink
fix(group): after a sequence of updates a proof is invalid (#910)
Browse files Browse the repository at this point in the history
* fix(group): after a sequence of updates a proof is invalid

* fix(group): after a sequence of updates a proof is invalid
  • Loading branch information
Lauman authored Dec 9, 2024
1 parent 31c776e commit 5b92c0a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
55 changes: 54 additions & 1 deletion packages/contracts/test/Semaphore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,62 @@ 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.
await semaphoreContract["createGroup(address)"](accountAddresses[0])

const groupId = 2

// Adding members to group

await semaphoreContract.addMembers(groupId, members)

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

await semaphoreContract.removeMember(groupId, members[2], siblings)
}

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

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

// Validate a proof.

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

const 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

0 comments on commit 5b92c0a

Please sign in to comment.