diff --git a/.gitmodules b/.gitmodules index 762351f..e298690 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "hash/cpu/src/Blake3"] path = hash/cpu/src/Blake3 url = https://github.com/BLAKE3-team/BLAKE3 +[submodule "hash/snark/src/hash-circuits"] + path = hash/snark/external/hash-circuits + url = https://github.com/faulhornlabs/hash-circuits diff --git a/ceremony/.gitignore b/ceremony/.gitignore new file mode 100644 index 0000000..e7fbb28 --- /dev/null +++ b/ceremony/.gitignore @@ -0,0 +1 @@ +*.ptau diff --git a/ceremony/README.md b/ceremony/README.md new file mode 100644 index 0000000..dc273fe --- /dev/null +++ b/ceremony/README.md @@ -0,0 +1,8 @@ + +Location for the trusted setup ceremony file +-------------------------------------------- + +Copy or symlink the ceremony file here with the name `ceremony.ptau`. + +You can find links to the Hermez ceremony files (up to size `2^28`) +[in the `snarkjs` readme](https://github.com/iden3/snarkjs). diff --git a/ceremony/setup.sh b/ceremony/setup.sh new file mode 100755 index 0000000..d78905f --- /dev/null +++ b/ceremony/setup.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +if [ -z ${ZKBENCH_CEREMONY_SIZE} ]; then +ZKBENCH_CEREMONY_SIZE=16 +fi + +echo "ceremony size = ${ZKBENCH_CEREMONY_SIZE}" + +snarkjs powersoftau new bn128 ${ZKBENCH_CEREMONY_SIZE} pot_0000.ptau +echo foobar | snarkjs powersoftau contribute pot_0000.ptau pot_0001.ptau --name="First contribution" +snarkjs powersoftau prepare phase2 pot_0001.ptau ceremony.ptau + +rm pot20_0000.ptau +mv pot20_0001.ptau ceremony.ptau diff --git a/hash/cpu/README.md b/hash/cpu/README.md new file mode 100644 index 0000000..c4ad07a --- /dev/null +++ b/hash/cpu/README.md @@ -0,0 +1,7 @@ + +Hash functions CPU benchmarks +----------------------------- + +- `bench` contains the benchmarking scripts +- `src` contains the 3rd party dependencies as git submodules + diff --git a/hash/snark/README.md b/hash/snark/README.md new file mode 100644 index 0000000..841dc2d --- /dev/null +++ b/hash/snark/README.md @@ -0,0 +1,7 @@ + +Hash functions SNARK benchmarks +-------------------------------- + +- `bench` contains the benchmarking scripts +- `external` contains the 3rd party dependencies as git submodules + diff --git a/hash/snark/bench/Poseidon2/.gitignore b/hash/snark/bench/Poseidon2/.gitignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/hash/snark/bench/Poseidon2/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/hash/snark/bench/Poseidon2/build.sh b/hash/snark/bench/Poseidon2/build.sh new file mode 100755 index 0000000..60147eb --- /dev/null +++ b/hash/snark/bench/Poseidon2/build.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +ORIG=`pwd` + +mkdir -p build + +gcc -O3 generate_input.c -o build/generate_input || { echo "gcc failed"; exit 101; } + +sed "s/ZKBENCH_INPUT_SIZE/${ZKBENCH_INPUT_SIZE}/g" hash_sponge.circom.template >build/hash_sponge.circom + +cd build + +circom hash_sponge.circom --r1cs --wasm || { echo "circom failed"; exit 102; } + +cd $ORIG \ No newline at end of file diff --git a/hash/snark/bench/Poseidon2/generate_input.c b/hash/snark/bench/Poseidon2/generate_input.c new file mode 100644 index 0000000..430abb2 --- /dev/null +++ b/hash/snark/bench/Poseidon2/generate_input.c @@ -0,0 +1,36 @@ + +#include +#include + +void generate(int n) { + + printf("{ \"inp\":\n" ); + for(int i=0;i:\n"); + exit(-1); + break; + + } +} + diff --git a/hash/snark/bench/Poseidon2/hash_sponge.circom.template b/hash/snark/bench/Poseidon2/hash_sponge.circom.template new file mode 100644 index 0000000..f8e8b28 --- /dev/null +++ b/hash/snark/bench/Poseidon2/hash_sponge.circom.template @@ -0,0 +1,5 @@ +pragma circom 2.0.0; + +include "../../../external/hash-circuits/circuits/poseidon2/poseidon2_hash.circom"; + +component main {public [inp]} = Poseidon2_hash( ZKBENCH_INPUT_SIZE ); diff --git a/hash/snark/bench/Poseidon2/run.sh b/hash/snark/bench/Poseidon2/run.sh new file mode 100755 index 0000000..4df2999 --- /dev/null +++ b/hash/snark/bench/Poseidon2/run.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +ORIG=`pwd` + +cd build + +NAME="hash_sponge" +echo "generating proof with snarkjs" +snarkjs groth16 prove ${NAME}_prover.zkey ${NAME}_witness.wtns ${NAME}_proof.json ${NAME}_public.json + +cd $ORIG diff --git a/hash/snark/bench/Poseidon2/setup.sh b/hash/snark/bench/Poseidon2/setup.sh new file mode 100755 index 0000000..c23b51d --- /dev/null +++ b/hash/snark/bench/Poseidon2/setup.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +ORIG=`pwd` +ROOT="${ORIG}/../../../../" + +cd build + +echo "generating input..." +./generate_input $ZKBENCH_INPUT_SIZE >input.json + +echo "generating witness..." +NAME="hash_sponge" +cd ${NAME}_js +node generate_witness.js ${NAME}.wasm ../input.json ../${NAME}_witness.wtns || { echo "witness gen failed"; exit 101; } +cd .. + +echo "circuit-specific ceremony..." +snarkjs groth16 setup ${NAME}.r1cs ${ROOT}/ceremony/ceremony.ptau ${NAME}_0000.zkey +echo "some_entropy" | snarkjs zkey contribute ${NAME}_0000.zkey ${NAME}_0001.zkey --name="1st Contributor Name" +rm ${NAME}_0000.zkey +mv ${NAME}_0001.zkey ${NAME}_prover.zkey +snarkjs zkey export verificationkey ${NAME}_prover.zkey ${NAME}_verification_key.json + +cd $ORIG diff --git a/hash/snark/external/hash-circuits b/hash/snark/external/hash-circuits new file mode 160000 index 0000000..bf6cca3 --- /dev/null +++ b/hash/snark/external/hash-circuits @@ -0,0 +1 @@ +Subproject commit bf6cca380547ca905ca0615cfdb6c49660e441a2