diff --git a/packages/cli-template-contracts-hardhat/test/Feedback.ts b/packages/cli-template-contracts-hardhat/test/Feedback.ts index 73206093..213eb295 100644 --- a/packages/cli-template-contracts-hardhat/test/Feedback.ts +++ b/packages/cli-template-contracts-hardhat/test/Feedback.ts @@ -45,26 +45,26 @@ describe("Feedback", () => { it("Should allow users to send feedback anonymously", async () => { const feedback = encodeBytes32String("Hello World") - const fullProof = await generateProof(users[1], group, feedback, groupId) + const proof = await generateProof(users[1], group, feedback, groupId) const transaction = feedbackContract.sendFeedback( - fullProof.merkleTreeDepth, - fullProof.merkleTreeRoot, - fullProof.nullifier, + proof.merkleTreeDepth, + proof.merkleTreeRoot, + proof.nullifier, feedback, - fullProof.points + proof.points ) await expect(transaction) .to.emit(semaphoreContract, "ProofValidated") .withArgs( groupId, - fullProof.merkleTreeDepth, - fullProof.merkleTreeRoot, - fullProof.nullifier, - fullProof.message, + proof.merkleTreeDepth, + proof.merkleTreeRoot, + proof.nullifier, + proof.message, groupId, - fullProof.points + proof.points ) }) }) diff --git a/packages/cli-template-monorepo-ethers/apps/contracts/test/Feedback.ts b/packages/cli-template-monorepo-ethers/apps/contracts/test/Feedback.ts index 836adbd6..df47ef46 100644 --- a/packages/cli-template-monorepo-ethers/apps/contracts/test/Feedback.ts +++ b/packages/cli-template-monorepo-ethers/apps/contracts/test/Feedback.ts @@ -43,26 +43,26 @@ describe("Feedback", () => { it("Should allow users to send feedback anonymously", async () => { const feedback = encodeBytes32String("Hello World") - const fullProof = await generateProof(users[1], group, feedback, groupId) + const proof = await generateProof(users[1], group, feedback, groupId) const transaction = feedbackContract.sendFeedback( - fullProof.merkleTreeDepth, - fullProof.merkleTreeRoot, - fullProof.nullifier, + proof.merkleTreeDepth, + proof.merkleTreeRoot, + proof.nullifier, feedback, - fullProof.points + proof.points ) await expect(transaction) .to.emit(semaphoreContract, "ProofValidated") .withArgs( groupId, - fullProof.merkleTreeDepth, - fullProof.merkleTreeRoot, - fullProof.nullifier, - fullProof.message, + proof.merkleTreeDepth, + proof.merkleTreeRoot, + proof.nullifier, + proof.message, groupId, - fullProof.points + proof.points ) }) }) diff --git a/packages/cli-template-monorepo-subgraph/apps/contracts/test/Feedback.ts b/packages/cli-template-monorepo-subgraph/apps/contracts/test/Feedback.ts index 836adbd6..df47ef46 100644 --- a/packages/cli-template-monorepo-subgraph/apps/contracts/test/Feedback.ts +++ b/packages/cli-template-monorepo-subgraph/apps/contracts/test/Feedback.ts @@ -43,26 +43,26 @@ describe("Feedback", () => { it("Should allow users to send feedback anonymously", async () => { const feedback = encodeBytes32String("Hello World") - const fullProof = await generateProof(users[1], group, feedback, groupId) + const proof = await generateProof(users[1], group, feedback, groupId) const transaction = feedbackContract.sendFeedback( - fullProof.merkleTreeDepth, - fullProof.merkleTreeRoot, - fullProof.nullifier, + proof.merkleTreeDepth, + proof.merkleTreeRoot, + proof.nullifier, feedback, - fullProof.points + proof.points ) await expect(transaction) .to.emit(semaphoreContract, "ProofValidated") .withArgs( groupId, - fullProof.merkleTreeDepth, - fullProof.merkleTreeRoot, - fullProof.nullifier, - fullProof.message, + proof.merkleTreeDepth, + proof.merkleTreeRoot, + proof.nullifier, + proof.message, groupId, - fullProof.points + proof.points ) }) }) diff --git a/packages/contracts/test/Semaphore.ts b/packages/contracts/test/Semaphore.ts index 785da2de..4ca01e7c 100644 --- a/packages/contracts/test/Semaphore.ts +++ b/packages/contracts/test/Semaphore.ts @@ -4,6 +4,7 @@ import { Group, Identity, SemaphoreProof, generateProof } from "@semaphore-proto import { expect } from "chai" import { Signer, ZeroAddress } from "ethers" import { run } from "hardhat" +// @ts-ignore import { Semaphore } from "../typechain-types" describe("Semaphore", () => { @@ -227,24 +228,24 @@ describe("Semaphore", () => { group.addMembers(members) - let fullProof: SemaphoreProof + let proof: SemaphoreProof before(async () => { await semaphoreContract["createGroup(uint256,address)"](groupId, accountAddresses[0]) await semaphoreContract.addMembers(groupId, members) - fullProof = await generateProof(identity, group, message, group.root as string, merkleTreeDepth) + proof = await generateProof(identity, group, message, group.root as string, merkleTreeDepth) }) it("Should not verify a proof if the group does not exist", async () => { - const transaction = semaphoreContract.verifyProof(11, fullProof) + const transaction = semaphoreContract.verifyProof(11, proof) await expect(transaction).to.be.revertedWithCustomError(semaphoreContract, "Semaphore__GroupDoesNotExist") }) it("Should not verify a proof if the Merkle tree root is not part of the group", async () => { - const transaction = semaphoreContract.verifyProof(groupId, { ...fullProof, merkleTreeRoot: 1 }) + const transaction = semaphoreContract.verifyProof(groupId, { ...proof, merkleTreeRoot: 1 }) await expect(transaction).to.be.revertedWithCustomError( semaphoreContract, @@ -253,7 +254,7 @@ describe("Semaphore", () => { }) it("Should verify a proof for an onchain group", async () => { - const validProof = await semaphoreContract.verifyProof(groupId, fullProof) + const validProof = await semaphoreContract.verifyProof(groupId, proof) expect(validProof).to.equal(true) }) @@ -265,9 +266,9 @@ describe("Semaphore", () => { group.addMembers([members[0], members[1]]) - const fullProof = await generateProof(identity, group, message, group.root as string, merkleTreeDepth) + const proof = await generateProof(identity, group, message, group.root as string, merkleTreeDepth) - const transaction = semaphoreContract.verifyProof(groupId, fullProof) + const transaction = semaphoreContract.verifyProof(groupId, proof) await expect(transaction).to.be.revertedWithCustomError( semaphoreContract, @@ -287,8 +288,8 @@ describe("Semaphore", () => { group.addMembers(members) groupOneMember.addMember(members[0]) - let fullProof: SemaphoreProof - let fullProofOneMember: SemaphoreProof + let proof: SemaphoreProof + let proofOneMember: SemaphoreProof before(async () => { await semaphoreContract["createGroup(uint256,address)"](groupOneMemberId, accountAddresses[0]) @@ -296,8 +297,8 @@ describe("Semaphore", () => { await semaphoreContract.addMembers(groupId, [members[1], members[2]]) await semaphoreContract.addMember(groupOneMemberId, members[0]) - fullProof = await generateProof(identity, group, message, group.root as string, merkleTreeDepth) - fullProofOneMember = await generateProof( + proof = await generateProof(identity, group, message, group.root as string, merkleTreeDepth) + proofOneMember = await generateProof( identity, groupOneMember, message, @@ -307,45 +308,45 @@ describe("Semaphore", () => { }) it("Should throw an exception if the proof is not valid", async () => { - const transaction = semaphoreContract.validateProof(groupId, { ...fullProof, scope: 0 }) + const transaction = semaphoreContract.validateProof(groupId, { ...proof, scope: 0 }) await expect(transaction).to.be.revertedWithCustomError(semaphoreContract, "Semaphore__InvalidProof") }) it("Should validate a proof for an onchain group with one member correctly", async () => { - const transaction = semaphoreContract.validateProof(groupOneMemberId, fullProofOneMember) + const transaction = semaphoreContract.validateProof(groupOneMemberId, proofOneMember) await expect(transaction) .to.emit(semaphoreContract, "ProofValidated") .withArgs( groupOneMemberId, - fullProofOneMember.merkleTreeDepth, - fullProofOneMember.merkleTreeRoot, - fullProofOneMember.nullifier, - fullProofOneMember.message, - fullProofOneMember.merkleTreeRoot, - fullProofOneMember.points + proofOneMember.merkleTreeDepth, + proofOneMember.merkleTreeRoot, + proofOneMember.nullifier, + proofOneMember.message, + proofOneMember.merkleTreeRoot, + proofOneMember.points ) }) it("Should validate a proof for an onchain group with more than one member correctly", async () => { - const transaction = semaphoreContract.validateProof(groupId, fullProof) + const transaction = semaphoreContract.validateProof(groupId, proof) await expect(transaction) .to.emit(semaphoreContract, "ProofValidated") .withArgs( groupId, - fullProof.merkleTreeDepth, - fullProof.merkleTreeRoot, - fullProof.nullifier, - fullProof.message, - fullProof.merkleTreeRoot, - fullProof.points + proof.merkleTreeDepth, + proof.merkleTreeRoot, + proof.nullifier, + proof.message, + proof.merkleTreeRoot, + proof.points ) }) it("Should not validate the same proof for an onchain group twice", async () => { - const transaction = semaphoreContract.validateProof(groupId, fullProof) + const transaction = semaphoreContract.validateProof(groupId, proof) await expect(transaction).to.be.revertedWithCustomError( semaphoreContract, diff --git a/packages/proof/README.md b/packages/proof/README.md index 618af1ce..5f7f855a 100644 --- a/packages/proof/README.md +++ b/packages/proof/README.md @@ -93,13 +93,13 @@ const message = utils.formatBytes32String("Hello world") group.addMembers([...identityCommitments, identity.generateCommitment()]) -const fullProof1 = await generateProof(identity, group, message, scope) +const proof1 = await generateProof(identity, group, message, scope) // You can also specify the maximum tree depth supported by the proof. -const fullProof2 = await generateProof(identity, group, message, scope, 20) +const proof2 = await generateProof(identity, group, message, scope, 20) // You can also specify the default zkey/wasm files. -const fullProof3 = await generateProof(identity, group, message, scope, 20, { +const proof3 = await generateProof(identity, group, message, scope, 20, { wasmFilePath: "./semaphore.wasm", zkeyFilePath: "./semaphore.zkey" }) @@ -110,5 +110,5 @@ const fullProof3 = await generateProof(identity, group, message, scope, 20, { ```typescript import { verifyProof } from "@semaphore-protocol/proof" -await verifyProof(fullProof) +await verifyProof(proof1) ``` diff --git a/packages/proof/src/verify-proof.ts b/packages/proof/src/verify-proof.ts index 6b44b5f9..bb80a6f9 100644 --- a/packages/proof/src/verify-proof.ts +++ b/packages/proof/src/verify-proof.ts @@ -6,8 +6,7 @@ import verificationKeys from "./verification-keys.json" /** * Verifies a Semaphore proof. - * @param fullProof The SnarkJS Semaphore proof. - * @param treeDepth The depth of the tree. + * @param proof The Semaphore proof. * @returns True if the proof is valid, false otherwise. */ export default async function verifyProof({ diff --git a/packages/proof/tests/index.test.ts b/packages/proof/tests/index.test.ts index 8ed0639e..035111c5 100644 --- a/packages/proof/tests/index.test.ts +++ b/packages/proof/tests/index.test.ts @@ -12,7 +12,7 @@ describe("Proof", () => { const identity = new Identity(42) - let fullProof: SemaphoreProof + let proof: SemaphoreProof let curve: any beforeAll(async () => { @@ -43,31 +43,31 @@ describe("Proof", () => { it("Should generate a Semaphore proof", async () => { const group = new Group([BigInt(1), BigInt(2), identity.commitment]) - fullProof = await generateProof(identity, group, message, scope, treeDepth) + proof = await generateProof(identity, group, message, scope, treeDepth) - expect(typeof fullProof).toBe("object") - expect(fullProof.merkleTreeRoot).toBe(group.root) + expect(typeof proof).toBe("object") + expect(proof.merkleTreeRoot).toBe(group.root) }, 20000) it("Should generate a Semaphore proof passing a Merkle proof instead of a group", async () => { const group = new Group([BigInt(1), BigInt(2), identity.commitment]) - fullProof = await generateProof(identity, group.generateMerkleProof(2), message, scope, treeDepth) + proof = await generateProof(identity, group.generateMerkleProof(2), message, scope, treeDepth) - expect(typeof fullProof).toBe("object") - expect(fullProof.merkleTreeRoot).toBe(group.root) + expect(typeof proof).toBe("object") + expect(proof.merkleTreeRoot).toBe(group.root) }, 20000) }) describe("# verifyProof", () => { it("Should not verify a Semaphore proof if the tree depth is not supported", async () => { - const fun = () => verifyProof({ ...fullProof, merkleTreeDepth: 40 }) + const fun = () => verifyProof({ ...proof, merkleTreeDepth: 40 }) await expect(fun).rejects.toThrow("tree depth must be") }) it("Should verify a Semaphore proof", async () => { - const response = await verifyProof(fullProof) + const response = await verifyProof(proof) expect(response).toBe(true) }) @@ -75,10 +75,10 @@ describe("Proof", () => { describe("# packProof/unpackProof", () => { it("Should return a packed proof", async () => { - const originalProof = unpackPoints(fullProof.points) - const proof = packPoints(originalProof) + const originalPoints = unpackPoints(proof.points) + const points = packPoints(originalPoints) - expect(proof).toStrictEqual(fullProof.points) + expect(points).toStrictEqual(proof.points) }) }) })