mirror of
https://github.com/arnaucube/circom-compat.git
synced 2026-01-09 15:31:31 +01:00
feat: benchmarks (#3)
* add benchmark * chore: add complex circuit * feat: enable parallel / asm * bench: use pre-calculated matrices/constraints * chore: bump ethers-rs * chore: fmt * feat: add benches for differently sized circuits (#6) * feat: update bench circuit * feat: add benches for many sizes * fix: adjust bench parameters * fix: remove sym * chore: fmt * fix: point to correct commit of groth16 * fix: update function names to upstream * fix: update function names to upstream Co-authored-by: Kobi Gurkan <kobigurk@gmail.com>
This commit is contained in:
committed by
GitHub
parent
11e6d04f3b
commit
bb0f5429fc
8
test-vectors/complex-circuit/.gitignore
vendored
Normal file
8
test-vectors/complex-circuit/.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
*.swp
|
||||
complex-circuit-*-*.*
|
||||
powersOfTau*
|
||||
!complex-circuit-10000-10000.*
|
||||
proof.json
|
||||
public.json
|
||||
verification_key.json
|
||||
witness.wtns
|
||||
20
test-vectors/complex-circuit/bench_all.sh
Executable file
20
test-vectors/complex-circuit/bench_all.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
MIN_NUM_VARIABLES=$1
|
||||
MAX_NUM_VARIABLES=$2
|
||||
MAX_NUM_CONSTRAINTS=$3
|
||||
|
||||
for i in `seq 10 19`; do wget https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_$i.ptau; done
|
||||
|
||||
./prepare.sh $MIN_NUM_VARIABLES $MAX_NUM_VARIABLES $MAX_NUM_CONSTRAINTS
|
||||
|
||||
for i in `seq $MIN_NUM_VARIABLES $MAX_NUM_VARIABLES`
|
||||
do
|
||||
for j in `seq $i $MAX_NUM_CONSTRAINTS`
|
||||
do
|
||||
NUM_VARIABLES=$(echo 10^$i | bc)
|
||||
NUM_CONSTRAINTS=$(echo 10^$j | bc)
|
||||
echo "**** START benchmarking $NUM_VARIABLES $NUM_CONSTRAINTS ****"
|
||||
./prove.sh $NUM_VARIABLES $NUM_CONSTRAINTS
|
||||
perf stat -r5 rapidsnark complex-circuit-$NUM_VARIABLES-$NUM_CONSTRAINTS.zkey witness.wtns proof.json public.json
|
||||
echo "**** END benchmarking $NUM_VARIABLES $NUM_CONSTRAINTS ****"
|
||||
done
|
||||
done
|
||||
11
test-vectors/complex-circuit/build.sh
Executable file
11
test-vectors/complex-circuit/build.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
NUM_VARIABLES=$1
|
||||
NUM_CONSTRAINTS=$2
|
||||
PTAU_POWER=$(echo "l($NUM_CONSTRAINTS)/l(2)" | bc -l | xargs -I{} awk "BEGIN{printf(\"%.f\n\", {}+0.5)}")
|
||||
|
||||
export NODE_OPTIONS=--max-old-space-size=8192
|
||||
|
||||
echo "compiling"
|
||||
circom -f complex-circuit-$NUM_VARIABLES-$NUM_CONSTRAINTS.circom --r1cs --wasm
|
||||
|
||||
echo "zkey"
|
||||
snarkjs zkey new complex-circuit-$NUM_VARIABLES-$NUM_CONSTRAINTS.r1cs powersOfTau28_hez_final_$PTAU_POWER.ptau complex-circuit-$NUM_VARIABLES-$NUM_CONSTRAINTS.zkey
|
||||
@@ -0,0 +1,21 @@
|
||||
template ManyConstraints(NUM_VARIABLES, NUM_CONSTRAINTS) {
|
||||
signal private input a;
|
||||
signal output c;
|
||||
|
||||
assert(NUM_VARIABLES <= NUM_CONSTRAINTS)
|
||||
|
||||
signal b[NUM_VARIABLES];
|
||||
|
||||
b[0] <== a*a;
|
||||
var i;
|
||||
for (i = 1; i < NUM_VARIABLES; i++) {
|
||||
b[i] <== b[i-1]*b[i-1];
|
||||
}
|
||||
i = i-1;
|
||||
for (var j = NUM_VARIABLES; j < NUM_CONSTRAINTS; j++) {
|
||||
b[i] === b[i-1]*b[i-1];
|
||||
}
|
||||
c <== b[i];
|
||||
}
|
||||
|
||||
component main = ManyConstraints(10000, 10000);
|
||||
BIN
test-vectors/complex-circuit/complex-circuit-10000-10000.r1cs
Normal file
BIN
test-vectors/complex-circuit/complex-circuit-10000-10000.r1cs
Normal file
Binary file not shown.
BIN
test-vectors/complex-circuit/complex-circuit-10000-10000.wasm
Normal file
BIN
test-vectors/complex-circuit/complex-circuit-10000-10000.wasm
Normal file
Binary file not shown.
BIN
test-vectors/complex-circuit/complex-circuit-10000-10000.zkey
Normal file
BIN
test-vectors/complex-circuit/complex-circuit-10000-10000.zkey
Normal file
Binary file not shown.
21
test-vectors/complex-circuit/complex-circuit.circom.template
Normal file
21
test-vectors/complex-circuit/complex-circuit.circom.template
Normal file
@@ -0,0 +1,21 @@
|
||||
template ManyConstraints(NUM_VARIABLES, NUM_CONSTRAINTS) {
|
||||
signal private input a;
|
||||
signal output c;
|
||||
|
||||
assert(NUM_VARIABLES <= NUM_CONSTRAINTS)
|
||||
|
||||
signal b[NUM_VARIABLES];
|
||||
|
||||
b[0] <== a*a;
|
||||
var i;
|
||||
for (i = 1; i < NUM_VARIABLES; i++) {
|
||||
b[i] <== b[i-1]*b[i-1];
|
||||
}
|
||||
i = i-1;
|
||||
for (var j = NUM_VARIABLES; j < NUM_CONSTRAINTS; j++) {
|
||||
b[i] === b[i-1]*b[i-1];
|
||||
}
|
||||
c <== b[i];
|
||||
}
|
||||
|
||||
component main = ManyConstraints(NUM_VARIABLES_TEMPLATE, NUM_CONSTRAINTS_TEMPLATE);
|
||||
1
test-vectors/complex-circuit/input.json
Normal file
1
test-vectors/complex-circuit/input.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "a": "3" }
|
||||
10
test-vectors/complex-circuit/prepare.sh
Executable file
10
test-vectors/complex-circuit/prepare.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
for i in `seq 3 5`
|
||||
do
|
||||
for j in `seq $i 5`
|
||||
do
|
||||
NUM_VARIABLES=$(echo 10^$i | bc)
|
||||
NUM_CONSTRAINTS=$(echo 10^$j | bc)
|
||||
sed "s/NUM_VARIABLES_TEMPLATE/$NUM_VARIABLES/g;s/NUM_CONSTRAINTS_TEMPLATE/$NUM_CONSTRAINTS/g" complex-circuit.circom.template > complex-circuit-$NUM_VARIABLES-$NUM_CONSTRAINTS.circom
|
||||
./build.sh $NUM_VARIABLES $NUM_CONSTRAINTS
|
||||
done
|
||||
done
|
||||
8
test-vectors/complex-circuit/prove.sh
Executable file
8
test-vectors/complex-circuit/prove.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
NUM_VARIABLES=$1
|
||||
NUM_CONSTRAINTS=$2
|
||||
|
||||
snarkjs wtns calculate complex-circuit-$NUM_VARIABLES-$NUM_CONSTRAINTS.wasm input.json witness.wtns
|
||||
snarkjs groth16 prove complex-circuit-$NUM_VARIABLES-$NUM_CONSTRAINTS.zkey witness.wtns proof.json public.json
|
||||
snarkjs zkey export verificationkey complex-circuit-$NUM_VARIABLES-$NUM_CONSTRAINTS.zkey
|
||||
snarkjs groth16 verify verification_key.json proof.json public.json
|
||||
|
||||
Reference in New Issue
Block a user