initial version of a Poseidon2 SNARK benchmark
This commit is contained in:
parent
c036c05e21
commit
b5afc94752
|
@ -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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
*.ptau
|
|
@ -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).
|
|
@ -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
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
Hash functions CPU benchmarks
|
||||
-----------------------------
|
||||
|
||||
- `bench` contains the benchmarking scripts
|
||||
- `src` contains the 3rd party dependencies as git submodules
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
Hash functions SNARK benchmarks
|
||||
--------------------------------
|
||||
|
||||
- `bench` contains the benchmarking scripts
|
||||
- `external` contains the 3rd party dependencies as git submodules
|
||||
|
|
@ -0,0 +1 @@
|
|||
build
|
|
@ -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
|
|
@ -0,0 +1,36 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void generate(int n) {
|
||||
|
||||
printf("{ \"inp\":\n" );
|
||||
for(int i=0;i<n;i++) {
|
||||
char c = (i==0)?'[':',';
|
||||
printf("%c%d",c,i+1);
|
||||
if ((i%10)==9) { printf("\n"); }
|
||||
}
|
||||
printf("]\n");
|
||||
printf("}\n");
|
||||
|
||||
}
|
||||
|
||||
int main( int argc, char *argv[] ) {
|
||||
|
||||
int nElements = 1;
|
||||
switch(argc) {
|
||||
|
||||
case 2:
|
||||
nElements = atoi(argv[1]);
|
||||
generate(nElements);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("usage:\n");
|
||||
printf("$ ./generate_input <number_of_field_elements>:\n");
|
||||
exit(-1);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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 );
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1 @@
|
|||
Subproject commit bf6cca380547ca905ca0615cfdb6c49660e441a2
|
Loading…
Reference in New Issue