Skip to content

Commit af4aec2

Browse files
authored
refactor(proof)!: set tree depth = 1 when a group has 1 member (#831)
re #812
1 parent af4fe8d commit af4aec2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/proof/src/generate-proof.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type { SemaphoreProof } from "./types"
2222
* If it is not defined, it will be inferred from the group or Merkle proof passed as the second parameter.
2323
* Finally, the artifacts themselves can be passed manually with file paths,
2424
* or they will be automatically fetched.
25+
* Please keep in mind that groups with 1 member or 2 members cannot be considered anonymous.
2526
* @param identity The Semaphore identity.
2627
* @param groupOrMerkleProof The Semaphore group or its Merkle proof.
2728
* @param message The Semaphore message.
@@ -79,7 +80,7 @@ export default async function generateProof(
7980
throw new TypeError(`The tree depth must be a number between ${MIN_DEPTH} and ${MAX_DEPTH}`)
8081
}
8182
} else {
82-
merkleTreeDepth = merkleProofLength
83+
merkleTreeDepth = merkleProofLength !== 0 ? merkleProofLength : 1
8384
}
8485

8586
// If the Snark artifacts are not defined they will be automatically downloaded.

packages/proof/tests/index.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ describe("Proof", () => {
4848
expect(BigInt(proof.merkleTreeRoot)).toBe(group.root)
4949
}, 80000)
5050

51+
it("Should generate a Semaphore proof for a group with 1 member", async () => {
52+
const group = new Group([identity.commitment])
53+
54+
const proof = await generateProof(identity, group, message, scope)
55+
56+
expect(typeof proof).toBe("object")
57+
expect(BigInt(proof.merkleTreeRoot)).toBe(group.root)
58+
}, 80000)
59+
5160
it("Should generate a Semaphore proof passing a Merkle proof instead of a group", async () => {
5261
const group = new Group([1n, 2n, identity.commitment])
5362

0 commit comments

Comments
 (0)