diff --git a/.gitignore b/.gitignore index 40bc0b5..0ac3447 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ /target /zkey .DS_Store + +# witness graph +semaphore/ +circom-witnesscalc/ \ No newline at end of file diff --git a/README.md b/README.md index 02ac789..efeb2c2 100644 --- a/README.md +++ b/README.md @@ -96,3 +96,9 @@ cargo clippy ```bash cargo test ``` + +### Update `witness_graph` with [`circom-witnesscalc`](https://github.com/iden3/circom-witnesscalc) + +```bash +./script build_witness_graph.sh +``` diff --git a/script/build_witness_graph.sh b/script/build_witness_graph.sh new file mode 100755 index 0000000..42da814 --- /dev/null +++ b/script/build_witness_graph.sh @@ -0,0 +1,40 @@ +#! /bin/bash + +CIRCOM_WITNESSCALC_DIR="circom-witnesscalc" +SEMAPHORE_DIR="semaphore" +WITNESS_GRAPH_DIR="witness_graph" +CURRENT_DIR=$(pwd) + +# download the circom-witnesscalc repository +if [ ! -d "$CIRCOM_WITNESSCALC_DIR" ]; then + git clone https://github.com/iden3/circom-witnesscalc.git +fi +# download the semaphore circuit repository +if [ ! -d "$SEMAPHORE_DIR" ]; then + git clone https://github.com/semaphore-protocol/semaphore.git +fi +# Function to generate Circom circuit code for a given depth +create_circuit_code() { + local depth=$1 + cat < $CURRENT_DIR/$SEMAPHORE_DIR/semaphore-${depth}.circom +done +# build the witness graph +cd $CURRENT_DIR/$CIRCOM_WITNESSCALC_DIR +for depth in {1..32}; do + 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 +done +# save the witness graph to the witness_graph directory diff --git a/src/proof.rs b/src/proof.rs index b6bfabf..1451fcb 100644 --- a/src/proof.rs +++ b/src/proof.rs @@ -124,13 +124,8 @@ impl Proof { let merkle_proof = group.merkle_proof(&to_element(*identity.commitment())); let merkle_proof_length = merkle_proof.siblings.len(); - // The index must be converted to a list of indices, 1 for each tree level. - // The missing siblings can be set to 0, as they won"t be used in the circuit. - let mut merkle_proof_indices = Vec::new(); let mut merkle_proof_siblings = Vec::::new(); for i in 0..merkle_tree_depth { - merkle_proof_indices.push((merkle_proof.index >> i) & 1); - if let Some(sibling) = merkle_proof.siblings.get(i as usize) { merkle_proof_siblings.push(*sibling); } else { @@ -150,8 +145,8 @@ impl Proof { vec![merkle_proof_length.to_string()], ), ( - "merkleProofIndices".to_string(), - merkle_proof_indices.iter().map(|i| i.to_string()).collect(), + "merkleProofIndex".to_string(), + vec![merkle_proof.index.to_string()], ), ( "merkleProofSiblings".to_string(), @@ -516,14 +511,14 @@ mod tests { fn test_semaphore_js_proof() { let points = [ // Proof generated from `Semaphore-js` - "12803714274658725282520630356048215594611199462892068647123162130999777821470", - "14790427909013880978103423555540996578520237818660256715698081866578524307407", - "3103638479093034897036418556462341694689838452017242207620861422678426008987", - "13727581952519649861097277152692845564872363841132502933894854130976607522628", - "9411534790044921634269896122419705846815252106674427620586249081562203834159", - "10009619289272081097084761045154085973406496068797344071367935854823051916935", - "19672409605818107675150930119466509196235828486217699330399295338263828234556", - "15472461797587690185190826432462453505284546376663377924961837387512711582919", + "2448901300518098096993075752654536134313649038239216706400667219963346227679", + "11383357624181217239434984412545229801919536849542936327488167664579097021171", + "4740704242184999702574958393302343834384154042177684026319208048433986938524", + "2103898499672759617084297744151588687300569178309824227315704845907524437637", + "18126651739688030584140960766793516019865850111238360168731489534891060767936", + "13293264290162772264887787723520088518667325866686508255341288441681546077334", + "13860303418198054644271827809984867757526756615344099647083475463061491185143", + "7750331146056656453454308267328134694500438800080743301030181391570997944788", ] .iter() .map(|&p| BigUint::from_str(p).unwrap()) diff --git a/src/utils.rs b/src/utils.rs index 7ccf8b4..912a77b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -40,7 +40,7 @@ pub fn to_element(value: Fq) -> Element { /// Download zkey from artifacts: https://snark-artifacts.pse.dev/ pub fn download_zkey(depth: u16) -> Result> { - let version = "4.0.0"; + let version = "4.13.0"; let base_url = format!("https://snark-artifacts.pse.dev/semaphore/{version}/"); let filename = format!("semaphore-{depth}.zkey"); let dest_filename = format!("semaphore-{version}-{depth}.zkey"); diff --git a/witness_graph/semaphore-1.bin b/witness_graph/semaphore-1.bin index 8e1f073..e6dd8f0 100644 Binary files a/witness_graph/semaphore-1.bin and b/witness_graph/semaphore-1.bin differ diff --git a/witness_graph/semaphore-10.bin b/witness_graph/semaphore-10.bin index b911607..1cba1c2 100644 Binary files a/witness_graph/semaphore-10.bin and b/witness_graph/semaphore-10.bin differ diff --git a/witness_graph/semaphore-11.bin b/witness_graph/semaphore-11.bin index b823445..47740eb 100644 Binary files a/witness_graph/semaphore-11.bin and b/witness_graph/semaphore-11.bin differ diff --git a/witness_graph/semaphore-12.bin b/witness_graph/semaphore-12.bin index 309c63c..16a517a 100644 Binary files a/witness_graph/semaphore-12.bin and b/witness_graph/semaphore-12.bin differ diff --git a/witness_graph/semaphore-13.bin b/witness_graph/semaphore-13.bin index fec84d8..44d0302 100644 Binary files a/witness_graph/semaphore-13.bin and b/witness_graph/semaphore-13.bin differ diff --git a/witness_graph/semaphore-14.bin b/witness_graph/semaphore-14.bin index bd1b04d..f4cd149 100644 Binary files a/witness_graph/semaphore-14.bin and b/witness_graph/semaphore-14.bin differ diff --git a/witness_graph/semaphore-15.bin b/witness_graph/semaphore-15.bin index e04fa5c..bf12e8c 100644 Binary files a/witness_graph/semaphore-15.bin and b/witness_graph/semaphore-15.bin differ diff --git a/witness_graph/semaphore-16.bin b/witness_graph/semaphore-16.bin index f288d9b..be915be 100644 Binary files a/witness_graph/semaphore-16.bin and b/witness_graph/semaphore-16.bin differ diff --git a/witness_graph/semaphore-17.bin b/witness_graph/semaphore-17.bin index ee18373..4548e72 100644 Binary files a/witness_graph/semaphore-17.bin and b/witness_graph/semaphore-17.bin differ diff --git a/witness_graph/semaphore-18.bin b/witness_graph/semaphore-18.bin index 8390fa7..1383ebc 100644 Binary files a/witness_graph/semaphore-18.bin and b/witness_graph/semaphore-18.bin differ diff --git a/witness_graph/semaphore-19.bin b/witness_graph/semaphore-19.bin index e563c0b..bc3ed26 100644 Binary files a/witness_graph/semaphore-19.bin and b/witness_graph/semaphore-19.bin differ diff --git a/witness_graph/semaphore-2.bin b/witness_graph/semaphore-2.bin index 2248ef9..86d5693 100644 Binary files a/witness_graph/semaphore-2.bin and b/witness_graph/semaphore-2.bin differ diff --git a/witness_graph/semaphore-20.bin b/witness_graph/semaphore-20.bin index 4e7530d..9840410 100644 Binary files a/witness_graph/semaphore-20.bin and b/witness_graph/semaphore-20.bin differ diff --git a/witness_graph/semaphore-21.bin b/witness_graph/semaphore-21.bin index 33f23a7..7a4553f 100644 Binary files a/witness_graph/semaphore-21.bin and b/witness_graph/semaphore-21.bin differ diff --git a/witness_graph/semaphore-22.bin b/witness_graph/semaphore-22.bin index 18c1e8d..c47e486 100644 Binary files a/witness_graph/semaphore-22.bin and b/witness_graph/semaphore-22.bin differ diff --git a/witness_graph/semaphore-23.bin b/witness_graph/semaphore-23.bin index e0389e3..4a6b877 100644 Binary files a/witness_graph/semaphore-23.bin and b/witness_graph/semaphore-23.bin differ diff --git a/witness_graph/semaphore-24.bin b/witness_graph/semaphore-24.bin index 2d1bc60..194c92f 100644 Binary files a/witness_graph/semaphore-24.bin and b/witness_graph/semaphore-24.bin differ diff --git a/witness_graph/semaphore-25.bin b/witness_graph/semaphore-25.bin index 220c58a..ed94ab4 100644 Binary files a/witness_graph/semaphore-25.bin and b/witness_graph/semaphore-25.bin differ diff --git a/witness_graph/semaphore-26.bin b/witness_graph/semaphore-26.bin index b609abe..54696b0 100644 Binary files a/witness_graph/semaphore-26.bin and b/witness_graph/semaphore-26.bin differ diff --git a/witness_graph/semaphore-27.bin b/witness_graph/semaphore-27.bin index 64ead0d..5713329 100644 Binary files a/witness_graph/semaphore-27.bin and b/witness_graph/semaphore-27.bin differ diff --git a/witness_graph/semaphore-28.bin b/witness_graph/semaphore-28.bin index 1d4d282..ed6af0c 100644 Binary files a/witness_graph/semaphore-28.bin and b/witness_graph/semaphore-28.bin differ diff --git a/witness_graph/semaphore-29.bin b/witness_graph/semaphore-29.bin index a3dbf65..efff5ee 100644 Binary files a/witness_graph/semaphore-29.bin and b/witness_graph/semaphore-29.bin differ diff --git a/witness_graph/semaphore-3.bin b/witness_graph/semaphore-3.bin index 4871b5c..66e8441 100644 Binary files a/witness_graph/semaphore-3.bin and b/witness_graph/semaphore-3.bin differ diff --git a/witness_graph/semaphore-30.bin b/witness_graph/semaphore-30.bin index 07f9bf8..1f1f9c8 100644 Binary files a/witness_graph/semaphore-30.bin and b/witness_graph/semaphore-30.bin differ diff --git a/witness_graph/semaphore-31.bin b/witness_graph/semaphore-31.bin index dcf52ae..b997415 100644 Binary files a/witness_graph/semaphore-31.bin and b/witness_graph/semaphore-31.bin differ diff --git a/witness_graph/semaphore-32.bin b/witness_graph/semaphore-32.bin index e87e68d..bf7ccc4 100644 Binary files a/witness_graph/semaphore-32.bin and b/witness_graph/semaphore-32.bin differ diff --git a/witness_graph/semaphore-4.bin b/witness_graph/semaphore-4.bin index 338fcd5..e0e2ae3 100644 Binary files a/witness_graph/semaphore-4.bin and b/witness_graph/semaphore-4.bin differ diff --git a/witness_graph/semaphore-5.bin b/witness_graph/semaphore-5.bin index 436ae5a..7ed8534 100644 Binary files a/witness_graph/semaphore-5.bin and b/witness_graph/semaphore-5.bin differ diff --git a/witness_graph/semaphore-6.bin b/witness_graph/semaphore-6.bin index 277e26e..823829d 100644 Binary files a/witness_graph/semaphore-6.bin and b/witness_graph/semaphore-6.bin differ diff --git a/witness_graph/semaphore-7.bin b/witness_graph/semaphore-7.bin index 5f75f05..d17e7ef 100644 Binary files a/witness_graph/semaphore-7.bin and b/witness_graph/semaphore-7.bin differ diff --git a/witness_graph/semaphore-8.bin b/witness_graph/semaphore-8.bin index f3d3109..da04e5e 100644 Binary files a/witness_graph/semaphore-8.bin and b/witness_graph/semaphore-8.bin differ diff --git a/witness_graph/semaphore-9.bin b/witness_graph/semaphore-9.bin index f814d97..9262449 100644 Binary files a/witness_graph/semaphore-9.bin and b/witness_graph/semaphore-9.bin differ