Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"semver": "^7.6.2",
"snarkjs": "0.7.4",
"snarkjs": "0.7.5",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/circuits/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
"access": "public"
},
"dependencies": {
"@zk-kit/binary-merkle-root.circom": "1.0.0",
"@zk-kit/binary-merkle-root.circom": "2.0.0",
"circomlib": "2.0.5"
},
"devDependencies": {
"@semaphore-protocol/core": "workspace:^",
"@types/mocha": "^10.0.6",
"@zk-kit/baby-jubjub": "1.0.3",
"circomkit": "0.0.19",
"circomkit": "0.3.3",
"mocha": "^10.2.0",
"poseidon-lite": "^0.3.0"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/circuits/src/semaphore.circom
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ template Semaphore(MAX_DEPTH) {
// See the Semaphore identity package to know more about how the identity is generated:
// https://github.com/semaphore-protocol/semaphore/tree/main/packages/identity.
signal input secret;
signal input merkleProofLength, merkleProofIndices[MAX_DEPTH], merkleProofSiblings[MAX_DEPTH];
signal input merkleProofLength, merkleProofIndex, merkleProofSiblings[MAX_DEPTH];
signal input message;
signal input scope;

Expand Down Expand Up @@ -58,7 +58,7 @@ template Semaphore(MAX_DEPTH) {
// the circuit through the inputs of the Merkle proof.
// See https://github.com/privacy-scaling-explorations/zk-kit.circom/blob/main/packages/binary-merkle-root/src/binary-merkle-root.circom
// to know more about how the 'BinaryMerkleRoot' template works.
merkleRoot <== BinaryMerkleRoot(MAX_DEPTH)(identityCommitment, merkleProofLength, merkleProofIndices, merkleProofSiblings);
merkleRoot <== BinaryMerkleRoot(MAX_DEPTH)(identityCommitment, merkleProofLength, merkleProofIndex, merkleProofSiblings);

// Nullifier generation.
// The nullifier is a value that essentially identifies the proof generated in a specific scope
Expand Down
15 changes: 6 additions & 9 deletions packages/circuits/tests/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,18 @@ export const circomkit = new Circomkit({
})

export function generateMerkleProof(group: Group, _index: number, maxDepth: number) {
const { siblings: merkleProofSiblings, index } = group.generateMerkleProof(_index)
const { siblings: merkleProofSiblings, index: merkleProofIndex } = group.generateMerkleProof(_index)

// The index must be converted to a list of indices, 1 for each tree level.
// The circuit tree depth is 20, so the number of siblings must be 20, even if
// the tree depth is actually 3. The missing siblings can be set to 0, as they
// won't be used to calculate the root in the circuit.
const merkleProofIndices: number[] = []
// For example, if the circuit expects a Merkle tree of depth 20,
// the input must always include 20 sibling nodes, even if the actual
// tree depth is smaller (e.g., 3). The unused sibling positions can be
// filled with 0, as they won't affect the root calculation in the circuit.

for (let i = 0; i < maxDepth; i += 1) {
merkleProofIndices.push((index >> i) & 1)

if (merkleProofSiblings[i] === undefined) {
merkleProofSiblings[i] = BigInt(0)
}
}

return { merkleProofSiblings, merkleProofIndices }
return { merkleProofSiblings, merkleProofIndex }
}
18 changes: 9 additions & 9 deletions packages/circuits/tests/semaphore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const r = 2188824287183927522224640574525727508854836440041603434369820418657580

describe("semaphore", () => {
let circuit: WitnessTester<
["secret", "merkleProofLength", "merkleProofIndices", "merkleProofSiblings", "scope", "message"],
["secret", "merkleProofLength", "merkleProofIndex", "merkleProofSiblings", "scope", "message"],
["nullifier", "merkleRoot"]
>

Expand All @@ -36,12 +36,12 @@ describe("semaphore", () => {

const group = new Group([commitment, 2n, 3n])

const { merkleProofSiblings, merkleProofIndices } = generateMerkleProof(group, 0, MAX_DEPTH)
const { merkleProofSiblings, merkleProofIndex } = generateMerkleProof(group, 0, MAX_DEPTH)

const INPUT = {
secret,
merkleProofLength: group.depth,
merkleProofIndices,
merkleProofIndex,
merkleProofSiblings,
scope,
message
Expand All @@ -61,12 +61,12 @@ describe("semaphore", () => {
const commitment = poseidon2(mulPointEscalar(Base8, secret))
const group = new Group([commitment, 2n, 3n])

const { merkleProofSiblings, merkleProofIndices } = generateMerkleProof(group, 0, MAX_DEPTH)
const { merkleProofSiblings, merkleProofIndex } = generateMerkleProof(group, 0, MAX_DEPTH)

const INPUT = {
secret,
merkleProofLength: group.depth,
merkleProofIndices,
merkleProofIndex,
merkleProofSiblings,
scope,
message
Expand All @@ -81,12 +81,12 @@ describe("semaphore", () => {
const commitment = poseidon2(mulPointEscalar(Base8, secret))
const group = new Group([commitment, 2n, 3n])

const { merkleProofSiblings, merkleProofIndices } = generateMerkleProof(group, 0, MAX_DEPTH)
const { merkleProofSiblings, merkleProofIndex } = generateMerkleProof(group, 0, MAX_DEPTH)

const INPUT = {
secret,
merkleProofLength: group.depth,
merkleProofIndices,
merkleProofIndex,
merkleProofSiblings,
scope,
message
Expand All @@ -100,12 +100,12 @@ describe("semaphore", () => {

const group = new Group([commitment, 2n, 3n])

const { merkleProofSiblings, merkleProofIndices } = generateMerkleProof(group, 0, MAX_DEPTH)
const { merkleProofSiblings, merkleProofIndex } = generateMerkleProof(group, 0, MAX_DEPTH)

const INPUT = {
secret,
merkleProofLength: group.depth,
merkleProofIndices,
merkleProofIndex,
merkleProofSiblings,
scope,
message
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/contracts/base/Constants.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.23 <=0.8.28;
pragma solidity >=0.8.23 <0.9.0;

/// @dev Minimum supported tree depth.
uint8 constant MIN_DEPTH = 1;
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/contracts/base/SemaphoreGroups.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.23 <=0.8.28;
pragma solidity >=0.8.23 <0.9.0;

import {ISemaphoreGroups} from "../interfaces/ISemaphoreGroups.sol";
import {InternalLeanIMT, LeanIMTData} from "@zk-kit/lean-imt.sol/InternalLeanIMT.sol";
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/contracts/base/SemaphoreVerifier.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// Part of this file was generated with [snarkJS](https://github.com/iden3/snarkjs).

pragma solidity >=0.8.23 <=0.8.28;
pragma solidity >=0.8.23 <0.9.0;

import {MAX_DEPTH} from "./Constants.sol";
import {SemaphoreVerifierKeyPts} from "./SemaphoreVerifierKeyPts.sol";
Expand Down
Loading
Loading