Skip to content

Commit

Permalink
added code to chunk semaphore circuits
Browse files Browse the repository at this point in the history
  • Loading branch information
RiverRuby committed Sep 2, 2022
1 parent 02e713e commit 6515b3d
Show file tree
Hide file tree
Showing 11 changed files with 4,956 additions and 1,179 deletions.
3,570 changes: 3,570 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"circom_tester": "^0.0.14",
"mocha": "^10.0.0",
"path": "^0.12.7",
"snarkjs": "git+https://github.com/vb7401/snarkjs.git#fae4fe381bdad2da13eee71010dfe477fc694ac1"
"snarkjs": "git+https://github.com/vb7401/snarkjs.git#24981febe8826b6ab76ae4d76cf7f9142919d2b8"
},
"scripts": {
"test": "mocha"
Expand Down
18 changes: 18 additions & 0 deletions semaphore_scripts/1_compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

CIRCUIT_NAME=semaphore
BUILD_DIR="../build/$CIRCUIT_NAME"

if [ ! -d "$BUILD_DIR" ]; then
echo "No build directory found. Creating build directory..."
mkdir -p "$BUILD_DIR"
fi

echo '****COMPILING CIRCUIT****'
start=`date +%s`
set -x
circom "$CIRCUIT_NAME".circom --r1cs --wasm --sym --c --wat --output "$BUILD_DIR"
{ set +x; } 2>/dev/null
end=`date +%s`
echo "DONE ($((end-start))s)"
echo
13 changes: 13 additions & 0 deletions semaphore_scripts/2_gen_wtns.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

CIRCUIT_NAME=semaphore
BUILD_DIR="../build/$CIRCUIT_NAME"

echo "****GENERATING WITNESS FOR SAMPLE INPUT****"
start=`date +%s`
set -x
node "$BUILD_DIR"/"$CIRCUIT_NAME"_js/generate_witness.js "$BUILD_DIR"/"$CIRCUIT_NAME"_js/"$CIRCUIT_NAME".wasm sample_input.json "$BUILD_DIR"/witness.wtns
{ set +x; } 2>/dev/null
end=`date +%s`
echo "DONE ($((end-start))s)"
echo
49 changes: 49 additions & 0 deletions semaphore_scripts/3_gen_chunk_zkey.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

CIRCUIT_NAME=semaphore
BUILD_DIR="../build/$CIRCUIT_NAME"
R1CS_FILE="$BUILD_DIR/$CIRCUIT_NAME.r1cs"
PARTIAL_ZKEYS="$BUILD_DIR"/partial_zkeys
PHASE1=../circuits/pot21_final.ptau

if [ ! -d "$BUILD_DIR"/partial_zkeys ]; then
echo "No partial_zkeys directory found. Creating partial_zkeys directory..."
mkdir -p "$BUILD_DIR"/partial_zkeys
fi

echo "****GENERATING ZKEY 0****"
start=`date +%s`
set -x
../node_modules/.bin/snarkjs groth16 setup "$R1CS_FILE" "$PHASE1" "$PARTIAL_ZKEYS"/"$CIRCUIT_NAME"_0.zkey
{ set +x; } 2>/dev/null
end=`date +%s`
echo "DONE ($((end-start))s)"
echo

echo "****GENERATING ZKEY 1****"
start=`date +%s`
set -x
../node_modules/.bin/snarkjs zkey contribute "$PARTIAL_ZKEYS"/"$CIRCUIT_NAME"_0.zkey "$PARTIAL_ZKEYS"/"$CIRCUIT_NAME"_1.zkey --name="1st Contributor Name" -v
{ set +x; } 2>/dev/null
end=`date +%s`
echo "DONE ($((end-start))s)"
echo

echo "****GENERATING ZKEY 2****"
start=`date +%s`
set -x
../node_modules/.bin/snarkjs zkey contribute "$PARTIAL_ZKEYS"/"$CIRCUIT_NAME"_1.zkey "$PARTIAL_ZKEYS"/"$CIRCUIT_NAME"_2.zkey --name="2nd Contributor Name" -v
{ set +x; } 2>/dev/null
end=`date +%s`
echo "DONE ($((end-start))s)"
echo

# Use merkle root of Vivek + Lakshman MIMC merkle tree
echo "****GENERATING FINAL ZKEY****"
start=`date +%s`
set -x
../node_modules/.bin/snarkjs zkey beacon "$PARTIAL_ZKEYS"/"$CIRCUIT_NAME"_2.zkey "$BUILD_DIR"/"$CIRCUIT_NAME".zkey 12FE2EC467BD428DD0E966A6287DE2AF8DE09C2C5C0AD902B2C666B0895ABB75 10 -n="Final Beacon phase2"
{ set +x; } 2>/dev/null
end=`date +%s`
echo "DONE ($((end-start))s)"
echo
15 changes: 15 additions & 0 deletions semaphore_scripts/4_gen_vkey.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

CIRCUIT_NAME=semaphore
BUILD_DIR="../build/$CIRCUIT_NAME"
R1CS_FILE="$BUILD_DIR/$CIRCUIT_NAME.r1cs"
PHASE1=../circuits/pot21_final.ptau

echo "****EXPORTING VKEY****"
start=`date +%s`
set -x
../node_modules/.bin/snarkjs zkey export verificationkey "$BUILD_DIR"/"$CIRCUIT_NAME".zkey "$BUILD_DIR"/vkey.json
end=`date +%s`
{ set +x; } 2>/dev/null
echo "DONE ($((end-start))s)"
echo
22 changes: 22 additions & 0 deletions semaphore_scripts/5_gen_proof.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

CIRCUIT_NAME=semaphore
BUILD_DIR="../build/$CIRCUIT_NAME"

echo "****GENERATING PROOF FOR SAMPLE INPUT****"
start=`date +%s`
set -x
../node_modules/.bin/snarkjs groth16 prove "$BUILD_DIR"/"$CIRCUIT_NAME".zkey "$BUILD_DIR"/witness.wtns "$BUILD_DIR"/proof.json "$BUILD_DIR"/public.json
{ set +x; } 2>/dev/null
end=`date +%s`
echo "DONE ($((end-start))s)"
echo

echo "****VERIFYING PROOF FOR SAMPLE INPUT****"
start=`date +%s`
set -x
../node_modules/.bin/snarkjs groth16 verify "$BUILD_DIR"/vkey.json "$BUILD_DIR"/public.json "$BUILD_DIR"/proof.json
end=`date +%s`
{ set +x; } 2>/dev/null
echo "DONE ($((end-start))s)"
echo
31 changes: 31 additions & 0 deletions semaphore_scripts/6_gen_proof_rapidsnark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

CIRCUIT_NAME=semaphore
BUILD_DIR="../build/$CIRCUIT_NAME"

echo "****MAKE CPP FILE FOR WITNESS GENERATION****"
start=`date +%s`
set -x
make -C "$BUILD_DIR"/"$CIRCUIT_NAME"_cpp/
{ set +x; } 2>/dev/null
end=`date +%s`
echo "DONE ($((end-start))s)"
echo

# echo "****GENERATING WITNESS FOR SAMPLE INPUT****"
# start=`date +%s`
# set -x
# ./"$BUILD_DIR"/"$CIRCUIT_NAME"_cpp/"$CIRCUIT_NAME" input_"$CIRCUIT_NAME".json "$BUILD_DIR"/witness.wtns
# { set +x; } 2>/dev/null
# end=`date +%s`
# echo "DONE ($((end-start))s)"
# echo

echo "****GENERATING PROOF FOR SAMPLE INPUT****"
start=`date +%s`
set -x
./../rapidsnark/build/prover "$BUILD_DIR"/"$CIRCUIT_NAME".zkey "$BUILD_DIR"/witness.wtns "$BUILD_DIR"/rapidsnark_proof.json "$BUILD_DIR"/rapidsnark_public.json
{ set +x; } 2>/dev/null
end=`date +%s`
echo "DONE ($((end-start))s)"
echo
50 changes: 50 additions & 0 deletions semaphore_scripts/sample_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"identityTrapdoor": "82210452188161928598733550128625220534270549590309517414894288204044874952104",
"identityNullifier": "34446120299491790288744020307510475236236188468021654103658443703745559098738",
"treePathIndices": [
"0",
"1",
"0",
"0",
"1",
"1",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0"
],
"treeSiblings": [
"21859231388776549968909650767822735199915982922882062141526844531343157274941",
"14829471396349223418257052718072297725193656766323729753108046043941694614133",
"21565033459481620757728978230971813577483843043063926737824021645126402264433",
"13766135533406964322328512470216179800123849709262691771686679999898328382435",
"15906119989045105387724746447675479121755810923330612184214594638701177825202",
"21800921921756254131913838460836323600506339982825051047143207130243409008074",
"16213393278042399151325230261731727739833111769028509859621460793858318292741",
"3396914609616007258851405644437304192397291162432396347162513310381425243293",
"21551820661461729022865262380882070649935529853313286572328683688269863701601",
"6573136701248752079028194407151022595060682063033565181951145966236778420039",
"12413880268183407374852357075976609371175688755676981206018884971008854919922",
"14271763308400718165336499097156975241954733520325982997864342600795471836726",
"20066985985293572387227381049700832219069292839614107140851619262827735677018",
"9394776414966240069580838672673694685292165040808226440647796406499139370960",
"11331146992410411304059858900317123658895005918277453009197229807340014528524",
"15819538789928229930262697811477882737253464456578333862691129291651619515538",
"19217088683336594659449020493828377907203207941212636669271704950158751593251",
"21035245323335827719745544373081896983162834604456827698288649288827293579666",
"6939770416153240137322503476966641397417391950902474480970945462551409848591",
"10941962436777715901943463195175331263348098796018438960955633645115732864202"
],
"externalNullifier": "1",
"signalHash": "90212440971967858186782821117966844623767893510927315567635373206777892737"
}
3 changes: 3 additions & 0 deletions semaphore_scripts/semaphore.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pragma circom 2.0.2;

include "../../semaphore/circuits/semaphore.circom";
Loading

0 comments on commit 6515b3d

Please sign in to comment.