Refactor circuits, update prover & verifier tests

This commit is contained in:
arnaucube
2020-04-26 21:22:56 +02:00
parent 5b77df54b7
commit d3f43ce1a0
18 changed files with 133 additions and 141 deletions

View File

@@ -1 +0,0 @@
{ "in": 1}

View File

@@ -1,4 +1,4 @@
template A(n) {
template TestConstraints(n) {
signal input in;
signal output out;
@@ -11,4 +11,4 @@ template A(n) {
out <== intermediate[n-1];
}
component main = A(1000); // bigger takes too much time on generating trusted setup
component main = TestConstraints(10000);

1
testdata/circuit10k/inputs.json vendored Normal file
View File

@@ -0,0 +1 @@
{"in":"1"}

14
testdata/circuit1k/circuit.circom vendored Normal file
View File

@@ -0,0 +1,14 @@
template TestConstraints(n) {
signal input in;
signal output out;
signal intermediate[n];
intermediate[0] <== in;
for (var i=1; i<n; i++) {
intermediate[i] <== intermediate[i-1] * intermediate[i-1] + i;
}
out <== intermediate[n-1];
}
component main = TestConstraints(1000);

1
testdata/circuit1k/inputs.json vendored Normal file
View File

@@ -0,0 +1 @@
{"in":"1"}

14
testdata/circuit20k/circuit.circom vendored Normal file
View File

@@ -0,0 +1,14 @@
template TestConstraints(n) {
signal input in;
signal output out;
signal intermediate[n];
intermediate[0] <== in;
for (var i=1; i<n; i++) {
intermediate[i] <== intermediate[i-1] * intermediate[i-1] + i;
}
out <== intermediate[n-1];
}
component main = TestConstraints(20000);

1
testdata/circuit20k/inputs.json vendored Normal file
View File

@@ -0,0 +1 @@
{"in":"1"}

14
testdata/circuit5k/circuit.circom vendored Normal file
View File

@@ -0,0 +1,14 @@
template TestConstraints(n) {
signal input in;
signal output out;
signal intermediate[n];
intermediate[0] <== in;
for (var i=1; i<n; i++) {
intermediate[i] <== intermediate[i-1] * intermediate[i-1] + i;
}
out <== intermediate[n-1];
}
component main = TestConstraints(5000);

1
testdata/circuit5k/inputs.json vendored Normal file
View File

@@ -0,0 +1 @@
{"in":"1"}

9
testdata/clean-gereated-files.sh vendored Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/sh
# rm */*.json
find */*.json -type f -not -name 'inputs.json' -delete
rm */*.wasm
rm */*.cpp
rm */*.sym
rm */*.r1cs
rm */*.sol

42
testdata/compile-circuits.sh vendored Executable file
View File

@@ -0,0 +1,42 @@
#!/bin/sh
compile_and_ts_and_witness() {
echo $(date +"%T") "circom circuit.circom --r1cs --wasm --sym"
itime="$(date -u +%s)"
circom circuit.circom --r1cs --wasm --sym
ftime="$(date -u +%s)"
echo " ($(($(date -u +%s)-$itime))s)"
echo $(date +"%T") "snarkjs info -r circuit.r1cs"
snarkjs info -r circuit.r1cs
echo $(date +"%T") "snarkjs setup"
itime="$(date -u +%s)"
snarkjs setup
echo " ($(($(date -u +%s)-$itime))s)"
echo $(date +"%T") "trusted setup generated"
sed -i 's/null/["0","0","0"]/g' proving_key.json
echo "calculating witness"
snarkjs calculatewitness --wasm circuit.wasm --input inputs.json --witness witness.json
echo $(date +"%T") "snarkjs generateverifier"
itime="$(date -u +%s)"
snarkjs generateverifier
echo " ($(($(date -u +%s)-$itime))s)"
echo $(date +"%T") "generateverifier generated"
}
echo "compile & trustesetup for circuit1k"
cd circuit1k
compile_and_ts_and_witness
echo "compile & trustesetup for circuit5k"
cd ../circuit5k
compile_and_ts_and_witness
# echo "compile & trustesetup for circuit10k"
# cd ../circuit10k
# compile_and_ts_and_witness
# echo "compile & trustesetup for circuit20k"
# cd ../circuit20k
# compile_and_ts_and_witness

View File

@@ -1,9 +0,0 @@
template Multiplier() {
signal private input a;
signal private input b;
signal output c;
c <== a*b;
}
component main = Multiplier();

View File

@@ -1 +0,0 @@
{ "a":3, "b": 11}