File tree Expand file tree Collapse file tree 7 files changed +164
-0
lines changed
Expand file tree Collapse file tree 7 files changed +164
-0
lines changed Original file line number Diff line number Diff line change 11.idea
22
3+ /node_modules
34/target
45
56* .dev. *
Original file line number Diff line number Diff line change 1+ # Auxiliaries scripts:
2+ - ``` compile-circuit.sh <circuit_name> ```
3+ - ``` trusted-setup.sh <powers> ```
4+ - ``` export-keys.sh <circuit_name> <powers> ```
5+ - ``` prove.sh <circuit_name> <path_to_input_file> ```
6+ - ``` verify.sh <circuit_name> ```
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -e
3+
4+ CIRCUIT_NAME=$1
5+ BUILD_DIR=" "
6+ CIRCUIT_FILE=" "
7+
8+ # Define the build directory where intermediate files will be stored
9+ if [ -d ./circuits ]; then
10+ BUILD_DIR=" ./$CIRCUIT_NAME .dev"
11+ CIRCUIT_FILE=" ./circuits/$CIRCUIT_NAME .circom"
12+ elif [ -d ../circuits ]; then
13+ BUILD_DIR=" ../$CIRCUIT_NAME .dev"
14+ CIRCUIT_FILE=" ../circuits/$CIRCUIT_NAME .circom"
15+ else
16+ echo " Error: can't find way to circuits folder: unknow directory."
17+ exit 1
18+ fi
19+
20+ if [ -z " $CIRCUIT_NAME " ]; then
21+ echo " Error: CIRCUIT_NAME is empty."
22+ exit 1
23+ elif [ ! -e " $CIRCUIT_FILE " ]; then
24+ echo " Error: circuit doesn't exist."
25+ exit 1
26+ fi
27+
28+ rm -rf ${BUILD_DIR}
29+ mkdir -p ${BUILD_DIR}
30+
31+ # Compiling circuit with .r1cs and .wasm files as result
32+ echo -e " \nCompiling the circuits..."
33+
34+ circom ${CIRCUIT_FILE} --r1cs --wasm --sym -o ${BUILD_DIR}
35+
36+ mv ${BUILD_DIR} /${CIRCUIT_NAME} _js/${CIRCUIT_NAME} .wasm ${BUILD_DIR} /mul.wasm
37+
38+ # snarkjs r1cs print ${BUILD_DIR}/${CIRCUIT_NAME}.r1cs ${BUILD_DIR}/${CIRCUIT_NAME}.sym
39+
40+ echo -e " \nCircuit compiled ${BUILD_DIR} "
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -e
3+
4+ CIRCUIT_NAME=$1
5+ SETUP_POWERS=$2
6+ POWERS_FILE=" "
7+ BUILD_DIR=" "
8+
9+ # Define the build directory where intermediate files will be stored
10+ if [ -d ./circuits ]; then
11+ BUILD_DIR=" ./$CIRCUIT_NAME .dev"
12+ POWERS_FILE=./powers.dev/$SETUP_POWERS .ptau
13+ elif [ -d ../circuits ]; then
14+ BUILD_DIR=" ../$CIRCUIT_NAME .dev"
15+ POWERS_FILE=../powers.dev/$SETUP_POWERS .ptau
16+ else
17+ echo " Error: can't find way to circuits folder: unknow directory."
18+ exit 1
19+ fi
20+
21+ rm -rf ${BUILD_DIR} /zkey
22+ mkdir -p ${BUILD_DIR} /zkey
23+
24+ # Exporting key with verification_key.json, verifier.sol and circtuis_final.zkey as a result
25+ echo -e " \nExporting keys..."
26+
27+ snarkjs groth16 setup ${BUILD_DIR} /${CIRCUIT_NAME} .r1cs ${POWERS_FILE} ${BUILD_DIR} /${CIRCUIT_NAME} _0000.zkey -v
28+ echo ` xxd -l 128 -p /dev/urandom` | snarkjs zkey contribute ${BUILD_DIR} /${CIRCUIT_NAME} _0000.zkey ${BUILD_DIR} /circuit_final.zkey --name=" Someone" -v
29+
30+ snarkjs zkey export verificationkey ${BUILD_DIR} /circuit_final.zkey ${BUILD_DIR} /verification_key.json
31+ snarkjs zkey export solidityverifier ${BUILD_DIR} /circuit_final.zkey ${BUILD_DIR} /verifier.sol
32+
33+ # Removing redudant files
34+ rm -rf ${BUILD_DIR} /zkey ${BUILD_DIR} /${CIRCUIT_NAME} _0000.zkey
35+
36+ echo -e " \nKeys exported $BUILD_DIR /circuit_final.zkey, $BUILD_DIR /verification_key.json, $BUILD_DIR /verifier.sol"
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -e
3+
4+ CIRCUIT_NAME=$1
5+ INPUT_FILE=$2
6+ BUILD_DIR=" $CIRCUIT_NAME .dev"
7+
8+ # Define the build directory where intermediate files will be stored
9+ if [ -d ./$BUILD_DIR ]; then
10+ BUILD_DIR=" ./$BUILD_DIR "
11+ elif [ -d ../$BUILD_DIR ]; then
12+ BUILD_DIR=" ../$BUILD_DIR "
13+ else
14+ echo " Error: can't find way to build folder '$BUILD_DIR ': unknow directory."
15+ exit 1
16+ fi
17+
18+ if [ ! -e " $INPUT_FILE " ]; then
19+ echo " Error: can't find the input file '$INPUT_FILE '"
20+ exit 1
21+ fi
22+
23+ echo -e " \nProving..."
24+
25+ node ${BUILD_DIR} /${CIRCUIT_NAME} _js/generate_witness.js ${BUILD_DIR} /${CIRCUIT_NAME} .wasm ${INPUT_FILE} ${BUILD_DIR} /witness.wtns
26+
27+ snarkjs groth16 prove ${BUILD_DIR} /circuit_final.zkey ${BUILD_DIR} /witness.wtns ${BUILD_DIR} /proof.json ${BUILD_DIR} /public.json
28+
29+ echo -e " Proof generated ${BUILD_DIR} /proof.json"
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -e
3+
4+ SETUP_POWERS=$1
5+ BUILD_DIR=powers.dev
6+
7+ # Define the build directory where intermediate files will be stored
8+ if [ -d ./circuits ]; then
9+ BUILD_DIR=" ./$BUILD_DIR "
10+ elif [ -d ../circuits ]; then
11+ BUILD_DIR=" ../$BUILD_DIR "
12+ else
13+ echo " Error: can't find way to circuits folder: unknow directory."
14+ exit 1
15+ fi
16+
17+ mkdir -p $BUILD_DIR /$SETUP_POWERS
18+
19+ # Generatin trusted setup as powers/SETUP_POWERS.ptau
20+ echo -e " \Generating trustep setup..."
21+
22+ snarkjs powersoftau new bn128 ${SETUP_POWERS} ${BUILD_DIR} /${SETUP_POWERS} /pot${SETUP_POWERS} _0000.ptau
23+ echo ` xxd -l 128 -p /dev/urandom` | snarkjs powersoftau contribute ${BUILD_DIR} /${SETUP_POWERS} /pot${SETUP_POWERS} _0000.ptau ${BUILD_DIR} /${SETUP_POWERS} /pot${SETUP_POWERS} _0001.ptau --name=" Someone" -v
24+
25+ snarkjs powersoftau prepare phase2 ${BUILD_DIR} /${SETUP_POWERS} /pot${SETUP_POWERS} _0001.ptau ${BUILD_DIR} /${SETUP_POWERS} .ptau -v
26+
27+ # Removing redudant files
28+ rm -rf $BUILD_DIR /$SETUP_POWERS
29+
30+ echo -e " \nTrusted setup generated $BUILD_DIR /$SETUP_POWERS .ptau"
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -e
3+
4+ CIRCUIT_NAME=$1
5+ BUILD_DIR=" $CIRCUIT_NAME .dev"
6+
7+ # Define the build directory where intermediate files will be stored
8+ if [ -d ./$BUILD_DIR ]; then
9+ BUILD_DIR=" ./$BUILD_DIR "
10+ elif [ -d ../$BUILD_DIR ]; then
11+ BUILD_DIR=" ../$BUILD_DIR "
12+ else
13+ echo " Error: can't find way to build folder '$BUILD_DIR ': unknow directory."
14+ exit 1
15+ fi
16+
17+ # Verifying proof
18+ echo -e " \nVerifying..."
19+
20+ snarkjs groth16 verify ${BUILD_DIR} /verification_key.json ${BUILD_DIR} /public.json ${BUILD_DIR} /proof.json
21+
22+ echo -e " Verified ${BUILD_DIR} /proof.json"
You can’t perform that action at this time.
0 commit comments