Skip to content

Commit ed0a501

Browse files
author
tilo-14
committed
refactor(circuits): Reorganize nullifier circuits following circomlib pattern
- nullifier.circom: template-only library (Nullifier + BatchNullifier) - nullifier_1.circom: entry point for single nullifier - nullifier_4.circom: entry point for batch of 4 nullifiers - Update setup.sh to compile new circuit files Following circomlib best practice: templates in library files, minimal entry points.
1 parent 9a921f8 commit ed0a501

5 files changed

Lines changed: 46 additions & 48 deletions

File tree

‎zk/zk-nullifier/circuits/batchnullifier.circom‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎zk/zk-nullifier/circuits/nullifier.circom‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@ pragma circom 2.0.0;
22

33
include "../node_modules/circomlib/circuits/poseidon.circom";
44

5-
// Proves: nullifier === Poseidon(verification_id, secret)
5+
// Single nullifier: proves nullifier = Poseidon(verification_id, secret)
66
template Nullifier() {
7-
signal input verification_id; // public: context (vote ID, airdrop ID, etc.)
8-
signal input nullifier; // public: prevents double-spend
9-
signal input secret; // private: only owner knows
7+
signal input verification_id;
8+
signal input nullifier;
9+
signal input secret;
1010

1111
component hasher = Poseidon(2);
1212
hasher.inputs[0] <== verification_id;
1313
hasher.inputs[1] <== secret;
1414
nullifier === hasher.out;
1515
}
1616

17+
// Batch nullifier: proves n nullifiers with single proof
18+
template BatchNullifier(n) {
19+
signal input verification_id;
20+
signal input nullifier[n];
21+
signal input secret[n];
22+
23+
component nullifiers[n];
24+
for (var i = 0; i < n; i++) {
25+
nullifiers[i] = Nullifier();
26+
nullifiers[i].verification_id <== verification_id;
27+
nullifiers[i].nullifier <== nullifier[i];
28+
nullifiers[i].secret <== secret[i];
29+
}
30+
}
File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pragma circom 2.0.0;
2+
3+
include "./nullifier.circom";
4+
5+
component main { public [verification_id, nullifier] } = BatchNullifier(4);

‎zk/zk-nullifier/scripts/setup.sh‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,57 +59,57 @@ fi
5959
echo ""
6060

6161
# Single nullifier circuit
62-
echo -e "${BLUE}[5/9]${NC} Compiling nullifier.circom..."
63-
circom circuits/nullifier_main.circom \
62+
echo -e "${BLUE}[5/9]${NC} Compiling nullifier_1.circom..."
63+
circom circuits/nullifier_1.circom \
6464
--r1cs --wasm --sym -o build
6565
echo -e "${GREEN}✓${NC} Single circuit compiled"
6666
echo ""
6767

68-
echo -e "${BLUE}[6/9]${NC} Generating nullifier zkey..."
68+
echo -e "${BLUE}[6/9]${NC} Generating nullifier_1 zkey..."
6969
npx snarkjs groth16 setup \
70-
build/nullifier.r1cs \
70+
build/nullifier_1.r1cs \
7171
"$PTAU_FILE" \
72-
build/nullifier_0000.zkey
72+
build/nullifier_1_0000.zkey
7373

7474
RANDOM_ENTROPY=$(head -c 32 /dev/urandom | xxd -p -c 256)
7575
npx snarkjs zkey contribute \
76-
build/nullifier_0000.zkey \
77-
build/nullifier_final.zkey \
76+
build/nullifier_1_0000.zkey \
77+
build/nullifier_1_final.zkey \
7878
--name="contribution" -v -e="$RANDOM_ENTROPY"
7979

8080
npx snarkjs zkey export verificationkey \
81-
build/nullifier_final.zkey \
82-
build/verification_key.json
81+
build/nullifier_1_final.zkey \
82+
build/nullifier_1_verification_key.json
8383
echo -e "${GREEN}✓${NC} Single nullifier zkey done"
8484
echo ""
8585

8686
# Batch nullifier circuit (4 nullifiers)
87-
echo -e "${BLUE}[7/9]${NC} Compiling batchnullifier.circom..."
88-
circom circuits/batchnullifier.circom \
87+
echo -e "${BLUE}[7/9]${NC} Compiling nullifier_4.circom..."
88+
circom circuits/nullifier_4.circom \
8989
--r1cs --wasm --sym -o build
9090
echo -e "${GREEN}✓${NC} Batch circuit compiled"
9191
echo ""
9292

93-
echo -e "${BLUE}[8/9]${NC} Generating batchnullifier zkey..."
93+
echo -e "${BLUE}[8/9]${NC} Generating nullifier_4 zkey..."
9494
npx snarkjs groth16 setup \
95-
build/batchnullifier.r1cs \
95+
build/nullifier_4.r1cs \
9696
"$PTAU_FILE" \
97-
build/batchnullifier_0000.zkey
97+
build/nullifier_4_0000.zkey
9898

9999
RANDOM_ENTROPY=$(head -c 32 /dev/urandom | xxd -p -c 256)
100100
npx snarkjs zkey contribute \
101-
build/batchnullifier_0000.zkey \
102-
build/batchnullifier_final.zkey \
101+
build/nullifier_4_0000.zkey \
102+
build/nullifier_4_final.zkey \
103103
--name="contribution" -v -e="$RANDOM_ENTROPY"
104104

105105
npx snarkjs zkey export verificationkey \
106-
build/batchnullifier_final.zkey \
107-
build/batch_verification_key.json
106+
build/nullifier_4_final.zkey \
107+
build/nullifier_4_verification_key.json
108108
echo -e "${GREEN}✓${NC} Batch nullifier zkey done"
109109
echo ""
110110

111111
echo -e "${BLUE}[9/9]${NC} Cleanup intermediate files..."
112-
rm -f build/nullifier_0000.zkey build/batchnullifier_0000.zkey
112+
rm -f build/nullifier_1_0000.zkey build/nullifier_4_0000.zkey
113113
echo -e "${GREEN}✓${NC} Cleanup done"
114114
echo ""
115115

@@ -118,11 +118,11 @@ echo -e "${GREEN}Setup Complete!${NC}"
118118
echo -e "${GREEN}======================================${NC}"
119119
echo ""
120120
echo "Single nullifier:"
121-
echo " - build/nullifier_final.zkey"
122-
echo " - build/verification_key.json"
121+
echo " - build/nullifier_1_final.zkey"
122+
echo " - build/nullifier_1_verification_key.json"
123123
echo ""
124124
echo "Batch nullifier (4x):"
125-
echo " - build/batchnullifier_final.zkey"
126-
echo " - build/batch_verification_key.json"
125+
echo " - build/nullifier_4_final.zkey"
126+
echo " - build/nullifier_4_verification_key.json"
127127
echo ""
128128
echo "Next: cargo build-sbf && cargo test-sbf"

0 commit comments

Comments
 (0)