Skip to content

Commit

Permalink
refactor(proof)!: set tree depth = 1 when a group has 1 member (#831)
Browse files Browse the repository at this point in the history
re #812
  • Loading branch information
cedoor committed Jul 19, 2024
1 parent af4fe8d commit af4aec2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/proof/src/generate-proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { SemaphoreProof } from "./types"
* If it is not defined, it will be inferred from the group or Merkle proof passed as the second parameter.
* Finally, the artifacts themselves can be passed manually with file paths,
* or they will be automatically fetched.
* Please keep in mind that groups with 1 member or 2 members cannot be considered anonymous.
* @param identity The Semaphore identity.
* @param groupOrMerkleProof The Semaphore group or its Merkle proof.
* @param message The Semaphore message.
Expand Down Expand Up @@ -79,7 +80,7 @@ export default async function generateProof(
throw new TypeError(`The tree depth must be a number between ${MIN_DEPTH} and ${MAX_DEPTH}`)
}
} else {
merkleTreeDepth = merkleProofLength
merkleTreeDepth = merkleProofLength !== 0 ? merkleProofLength : 1
}

// If the Snark artifacts are not defined they will be automatically downloaded.
Expand Down
9 changes: 9 additions & 0 deletions packages/proof/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ describe("Proof", () => {
expect(BigInt(proof.merkleTreeRoot)).toBe(group.root)
}, 80000)

it("Should generate a Semaphore proof for a group with 1 member", async () => {
const group = new Group([identity.commitment])

const proof = await generateProof(identity, group, message, scope)

expect(typeof proof).toBe("object")
expect(BigInt(proof.merkleTreeRoot)).toBe(group.root)
}, 80000)

it("Should generate a Semaphore proof passing a Merkle proof instead of a group", async () => {
const group = new Group([1n, 2n, identity.commitment])

Expand Down

0 comments on commit af4aec2

Please sign in to comment.