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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/target
/zkey
.DS_Store

# witness graph
semaphore/
circom-witnesscalc/
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
40 changes: 40 additions & 0 deletions script/build_witness_graph.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
pragma circom 2.1.5;

include "semaphore.circom";

component main {public [message, scope]} = Semaphore(${depth});
EOF
}

# install the dependencies
cd $CURRENT_DIR/$SEMAPHORE_DIR
yarn install
# build all semaphore circuits
for depth in {1..32}; do
create_circuit_code $depth > $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
25 changes: 10 additions & 15 deletions src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Element>::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 {
Expand All @@ -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(),
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Box<dyn Error>> {
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");
Expand Down
Binary file modified witness_graph/semaphore-1.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-10.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-11.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-12.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-13.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-14.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-15.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-16.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-17.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-18.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-19.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-2.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-20.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-21.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-22.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-23.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-24.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-25.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-26.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-27.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-28.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-29.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-3.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-30.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-31.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-32.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-4.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-5.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-6.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-7.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-8.bin
Binary file not shown.
Binary file modified witness_graph/semaphore-9.bin
Binary file not shown.
Loading