Skip to content

Commit 9083dda

Browse files
authored
Merge pull request #16 from semaphore-protocol/chore/update-semaphore-version
refactor: update semaphore artifacts
2 parents ad1c878 + eb35cb5 commit 9083dda

37 files changed

+61
-16
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
/target
22
/zkey
33
.DS_Store
4+
5+
# witness graph
6+
semaphore/
7+
circom-witnesscalc/

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,9 @@ cargo clippy
9696
```bash
9797
cargo test
9898
```
99+
100+
### Update `witness_graph` with [`circom-witnesscalc`](https://github.com/iden3/circom-witnesscalc)
101+
102+
```bash
103+
./script build_witness_graph.sh
104+
```

script/build_witness_graph.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#! /bin/bash
2+
3+
CIRCOM_WITNESSCALC_DIR="circom-witnesscalc"
4+
SEMAPHORE_DIR="semaphore"
5+
WITNESS_GRAPH_DIR="witness_graph"
6+
CURRENT_DIR=$(pwd)
7+
8+
# download the circom-witnesscalc repository
9+
if [ ! -d "$CIRCOM_WITNESSCALC_DIR" ]; then
10+
git clone https://github.com/iden3/circom-witnesscalc.git
11+
fi
12+
# download the semaphore circuit repository
13+
if [ ! -d "$SEMAPHORE_DIR" ]; then
14+
git clone https://github.com/semaphore-protocol/semaphore.git
15+
fi
16+
# Function to generate Circom circuit code for a given depth
17+
create_circuit_code() {
18+
local depth=$1
19+
cat <<EOF
20+
pragma circom 2.1.5;
21+
22+
include "semaphore.circom";
23+
24+
component main {public [message, scope]} = Semaphore(${depth});
25+
EOF
26+
}
27+
28+
# install the dependencies
29+
cd $CURRENT_DIR/$SEMAPHORE_DIR
30+
yarn install
31+
# build all semaphore circuits
32+
for depth in {1..32}; do
33+
create_circuit_code $depth > $CURRENT_DIR/$SEMAPHORE_DIR/semaphore-${depth}.circom
34+
done
35+
# build the witness graph
36+
cd $CURRENT_DIR/$CIRCOM_WITNESSCALC_DIR
37+
for depth in {1..32}; do
38+
cargo run --package build-circuit --bin build-circuit --release $CURRENT_DIR/$SEMAPHORE_DIR/semaphore-${depth}.circom $CURRENT_DIR/$WITNESS_GRAPH_DIR/semaphore-${depth}.bin -l $CURRENT_DIR/$SEMAPHORE_DIR/node_modules/@zk-kit/binary-merkle-root.circom/src -l $CURRENT_DIR/$SEMAPHORE_DIR/node_modules/circomlib/circuits -l $CURRENT_DIR/$SEMAPHORE_DIR/packages/circuits/src
39+
done
40+
# save the witness graph to the witness_graph directory

src/proof.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,8 @@ impl Proof {
124124
let merkle_proof = group.merkle_proof(&to_element(*identity.commitment()));
125125
let merkle_proof_length = merkle_proof.siblings.len();
126126

127-
// The index must be converted to a list of indices, 1 for each tree level.
128-
// The missing siblings can be set to 0, as they won"t be used in the circuit.
129-
let mut merkle_proof_indices = Vec::new();
130127
let mut merkle_proof_siblings = Vec::<Element>::new();
131128
for i in 0..merkle_tree_depth {
132-
merkle_proof_indices.push((merkle_proof.index >> i) & 1);
133-
134129
if let Some(sibling) = merkle_proof.siblings.get(i as usize) {
135130
merkle_proof_siblings.push(*sibling);
136131
} else {
@@ -150,8 +145,8 @@ impl Proof {
150145
vec![merkle_proof_length.to_string()],
151146
),
152147
(
153-
"merkleProofIndices".to_string(),
154-
merkle_proof_indices.iter().map(|i| i.to_string()).collect(),
148+
"merkleProofIndex".to_string(),
149+
vec![merkle_proof.index.to_string()],
155150
),
156151
(
157152
"merkleProofSiblings".to_string(),
@@ -516,14 +511,14 @@ mod tests {
516511
fn test_semaphore_js_proof() {
517512
let points = [
518513
// Proof generated from `Semaphore-js`
519-
"12803714274658725282520630356048215594611199462892068647123162130999777821470",
520-
"14790427909013880978103423555540996578520237818660256715698081866578524307407",
521-
"3103638479093034897036418556462341694689838452017242207620861422678426008987",
522-
"13727581952519649861097277152692845564872363841132502933894854130976607522628",
523-
"9411534790044921634269896122419705846815252106674427620586249081562203834159",
524-
"10009619289272081097084761045154085973406496068797344071367935854823051916935",
525-
"19672409605818107675150930119466509196235828486217699330399295338263828234556",
526-
"15472461797587690185190826432462453505284546376663377924961837387512711582919",
514+
"2448901300518098096993075752654536134313649038239216706400667219963346227679",
515+
"11383357624181217239434984412545229801919536849542936327488167664579097021171",
516+
"4740704242184999702574958393302343834384154042177684026319208048433986938524",
517+
"2103898499672759617084297744151588687300569178309824227315704845907524437637",
518+
"18126651739688030584140960766793516019865850111238360168731489534891060767936",
519+
"13293264290162772264887787723520088518667325866686508255341288441681546077334",
520+
"13860303418198054644271827809984867757526756615344099647083475463061491185143",
521+
"7750331146056656453454308267328134694500438800080743301030181391570997944788",
527522
]
528523
.iter()
529524
.map(|&p| BigUint::from_str(p).unwrap())

src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn to_element(value: Fq) -> Element {
4040

4141
/// Download zkey from artifacts: https://snark-artifacts.pse.dev/
4242
pub fn download_zkey(depth: u16) -> Result<String, Box<dyn Error>> {
43-
let version = "4.0.0";
43+
let version = "4.13.0";
4444
let base_url = format!("https://snark-artifacts.pse.dev/semaphore/{version}/");
4545
let filename = format!("semaphore-{depth}.zkey");
4646
let dest_filename = format!("semaphore-{version}-{depth}.zkey");

witness_graph/semaphore-1.bin

45 Bytes
Binary file not shown.

witness_graph/semaphore-10.bin

347 Bytes
Binary file not shown.

witness_graph/semaphore-11.bin

382 Bytes
Binary file not shown.

witness_graph/semaphore-12.bin

404 Bytes
Binary file not shown.

witness_graph/semaphore-13.bin

448 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)