Skip to content

Commit eb35cb5

Browse files
committed
feat: add script to build witness graph and update README
1 parent cab10e9 commit eb35cb5

36 files changed

+58
-8
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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,14 @@ mod tests {
511511
fn test_semaphore_js_proof() {
512512
let points = [
513513
// Proof generated from `Semaphore-js`
514-
"12803714274658725282520630356048215594611199462892068647123162130999777821470",
515-
"14790427909013880978103423555540996578520237818660256715698081866578524307407",
516-
"3103638479093034897036418556462341694689838452017242207620861422678426008987",
517-
"13727581952519649861097277152692845564872363841132502933894854130976607522628",
518-
"9411534790044921634269896122419705846815252106674427620586249081562203834159",
519-
"10009619289272081097084761045154085973406496068797344071367935854823051916935",
520-
"19672409605818107675150930119466509196235828486217699330399295338263828234556",
521-
"15472461797587690185190826432462453505284546376663377924961837387512711582919",
514+
"2448901300518098096993075752654536134313649038239216706400667219963346227679",
515+
"11383357624181217239434984412545229801919536849542936327488167664579097021171",
516+
"4740704242184999702574958393302343834384154042177684026319208048433986938524",
517+
"2103898499672759617084297744151588687300569178309824227315704845907524437637",
518+
"18126651739688030584140960766793516019865850111238360168731489534891060767936",
519+
"13293264290162772264887787723520088518667325866686508255341288441681546077334",
520+
"13860303418198054644271827809984867757526756615344099647083475463061491185143",
521+
"7750331146056656453454308267328134694500438800080743301030181391570997944788",
522522
]
523523
.iter()
524524
.map(|&p| BigUint::from_str(p).unwrap())

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.

witness_graph/semaphore-14.bin

485 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)