forked from 0xEigenLabs/eigen-zkvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stark_aggregation.sh
executable file
·151 lines (121 loc) · 5.97 KB
/
stark_aggregation.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
set -ex
## build
cargo build --release
export NODE_OPTIONS="--max-old-space-size=81920"
source ~/.bashrc
BIG_POWER=26
NUM_PROOF=2
NUM_INPUT=2
CUR_DIR=$(cd $(dirname $0);pwd)
ZKIT="${CUR_DIR}/../target/release/eigen-zkit"
CIRCUIT="fibonacci"
PILEXECJS="fibonacci/fibonacci.js"
RUNDIR="${CUR_DIR}/../starkjs"
WORKSPACE=/tmp/aggregation_$CIRCUIT
first_run=${1-no}
CURVE=${2-bn128}
if [ $first_run = "yes" ]; then
rm -rf $WORKSPACE && mkdir -p $WORKSPACE
fi
RECURSIVE_CIRCUIT=$CIRCUIT.recursive1
RECURSIVE2_CIRCUIT=$CIRCUIT.recursive2
FINAL_CIRCUIT=$CIRCUIT.final
input0=$CUR_DIR/aggregation/0/${RECURSIVE_CIRCUIT} && mkdir -p $input0
input1=$CUR_DIR/aggregation/1/${RECURSIVE_CIRCUIT} && mkdir -p $input1
mkdir -p ./aggregation/$RECURSIVE2_CIRCUIT
mkdir -p ./aggregation/$FINAL_CIRCUIT
# test poseidon
#CIRCUIT="poseidon"
#PILEXECJS="poseidon/main_poseidon.js"
c12_start=$(date +%s)
cd ${CUR_DIR} && npm i
for (( i=0; i<$NUM_PROOF; i++ ))
do
./recursive_proof_to_snark.sh $i $WORKSPACE $CIRCUIT $PILEXECJS "stark"
done
c12_end=$(date +%s)
aggregation_start=$(date +%s)
echo " ==> aggregation stage <== "
if [ ! -f "$WORKSPACE/$RECURSIVE_CIRCUIT.r1cs" ]; then
echo "1. compile circuit, use task 0 by default"
${ZKIT} compile -p goldilocks -i $CUR_DIR/../starkjs/circuits/0/$RECURSIVE_CIRCUIT.circom -l "../starkjs/node_modules/pil-stark/circuits.gl" -l "../starkjs/node_modules/circomlib/circuits" --O2=full -o $WORKSPACE
else
echo "1.no need compile circom : "$WORKSPACE/$RECURSIVE_CIRCUIT.r1cs" already generated"
fi
echo "2. combine input1.zkin.json with input2.zkin.json "
node $RUNDIR/src/recursive/main_joinzkin.js --starksetup ../starky/data/c12.starkStruct.json --zkin1 $input0/input.zkin.json --zkin2 $input1/input.zkin.json --zkinout $input0/r1_input.zkin.json
echo "3. generate the pil files and const polynomicals files "
# generate the pil files and const polynomicals files
# input files : $C12_VERIFIER.r1cs
# output files : $C12_VERIFIER.const $C12_VERIFIER.pil $C12_VERIFIER.exec
if [ ! -f "$WORKSPACE/$RECURSIVE_CIRCUIT.pil" ]; then
node $RUNDIR/src/compressor12/main_compressor12_setup.js \
-r $WORKSPACE/$RECURSIVE_CIRCUIT.r1cs \
-c $WORKSPACE/$RECURSIVE_CIRCUIT.const \
-p $WORKSPACE/$RECURSIVE_CIRCUIT.pil \
-e $WORKSPACE/$RECURSIVE_CIRCUIT.exec
fi
echo "4. generate the commit polynomicals files "
# generate the commit polynomicals files
# input files : $CIRCUIT.c12.wasm $C12_VERIFIER.zkin.json $C12_VERIFIER.pil /$C12_VERIFIER.exec
# output files : $C12_VERIFIER.cm
node $RUNDIR/src/compressor12/main_compressor12_exec.js \
-w $WORKSPACE/$RECURSIVE_CIRCUIT"_js"/$RECURSIVE_CIRCUIT.wasm \
-i $input0/r1_input.zkin.json \
-p $WORKSPACE/$RECURSIVE_CIRCUIT.pil \
-e $WORKSPACE/$RECURSIVE_CIRCUIT.exec \
-m $WORKSPACE/$RECURSIVE_CIRCUIT.cm
echo "5. generate recursive2 proof"
# generate the stark proof and the circom circuits to verify stark proof.
# input files : $C12_VERIFIER.pil.json(stark proof) $C12_VERIFIER.const(const polynomials) $C12_VERIFIER.cm (commit polynomials)
# output files : $RECURSIVE2_CIRCUIT.circom $RECURSIVE2_CIRCUIT/r2_input.json
# Remark: the N of r2.starkStruct must be 2^20 , because the degree of $RECURSIVE_CIRCUIT.pil is 2^20 which determined by the proocess of converting $RECURSIVE_CIRCUIT.circom to $RECURSIVE_CIRCUIT.pil
$ZKIT stark_prove -s ../starky/data/r2.starkStruct.json \
-p $WORKSPACE/$RECURSIVE_CIRCUIT.pil.json \
--o $WORKSPACE/$RECURSIVE_CIRCUIT.const \
--m $WORKSPACE/$RECURSIVE_CIRCUIT.cm -c $RUNDIR/circuits/$RECURSIVE2_CIRCUIT.circom --i ./aggregation/$RECURSIVE2_CIRCUIT/r2_input.zkin.json --norm_stage
aggregation_end=$(date +%s)
final_start=$(date +%s)
# final recursive stage
echo " ==> final recursive stage <== "
if [ ! -f "$WORKSPACE/$RECURSIVE2_CIRCUIT.r1cs" ]; then
echo "1. compile circuit and generate r1cs and wasm"
${ZKIT} compile -p goldilocks -i $RUNDIR/circuits/$RECURSIVE2_CIRCUIT.circom -l "../starkjs/node_modules/pil-stark/circuits.gl" -l "../starkjs/node_modules/circomlib/circuits" --O2=full -o $WORKSPACE
else
echo "1.no need compile circom : "$WORKSPACE/$RECURSIVE2_CIRCUIT.r1cs" already generated"
fi
echo "2. generate the pil files and const polynomicals files "
if [ ! -f "$WORKSPACE/$RECURSIVE2_CIRCUIT.pil" ]; then
node $RUNDIR/src/compressor12/main_compressor12_setup.js \
-r $WORKSPACE/$RECURSIVE2_CIRCUIT.r1cs \
-c $WORKSPACE/$RECURSIVE2_CIRCUIT.const \
-p $WORKSPACE/$RECURSIVE2_CIRCUIT.pil \
-e $WORKSPACE/$RECURSIVE2_CIRCUIT.exec
fi
echo "3. generate the commit polynomicals files "
node $RUNDIR/src/compressor12/main_compressor12_exec.js \
-w $WORKSPACE/$RECURSIVE2_CIRCUIT"_js"/$RECURSIVE2_CIRCUIT.wasm \
-i ./aggregation/$RECURSIVE2_CIRCUIT/r2_input.zkin.json \
-p $WORKSPACE/$RECURSIVE2_CIRCUIT.pil \
-e $WORKSPACE/$RECURSIVE2_CIRCUIT.exec \
-m $WORKSPACE/$RECURSIVE2_CIRCUIT.cm
echo "4. generate final proof "
# Remark: the N of final.starkStruct must be 2^20 , because the degree of $RECURSIVE2_CIRCUIT.pil is 2^20 which determined by the proocess of converting $RECURSIVE_CIRCUIT2.circom to $RECURSIVE_CIRCUIT2.pil
$ZKIT stark_prove -s ../starky/data/final.starkStruct.bn128.json \
-p $WORKSPACE/$RECURSIVE2_CIRCUIT.pil.json \
--o $WORKSPACE/$RECURSIVE2_CIRCUIT.const \
--m $WORKSPACE/$RECURSIVE2_CIRCUIT.cm -c $RUNDIR/circuits/$FINAL_CIRCUIT.circom --i ./aggregation/$FINAL_CIRCUIT/final_input.zkin.json --norm_stage
final_end=$(date +%s)
snark_start=$(date +%s)
if [ $first_run = "yes" ]; then
$CUR_DIR/snark_verifier.sh groth16 true $CURVE
else
$CUR_DIR/snark_verifier.sh groth16 false $CURVE
fi
snark_end=$(date +%s)
echo "C12 Stage Time Cost ($((c12_end - c12_start))s)"
echo "Aggregation Stage Time Cost ($((aggregation_end - aggregation_start))s)"
echo "Final Stage Time Cost ($((final_end - final_start))s)"
echo "Recursive Snark Stage Time Cost ($((snark_end - snark_start))s)"
echo "Full Process Time Cost ($((snark_end - c12_start))s)"