-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_plonk_proof.sh
executable file
·143 lines (106 loc) · 5.93 KB
/
generate_plonk_proof.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
#!/bin/sh
compile_and_ts_and_witness() {
echo "compile & trustesetup for circuit"
rm -r build/
# get inputs by js
echo "get contract logs and gen input"
mkdir -p build/inputs
node js/maci.test.js build/inputs
#compile circuits
mkdir -p zkeys/r1cs
echo $(date +"%T") "compile the circuit into r1cs, wasm and sym"
itime="$(date -u +%s)"
circom circuits/prod/msg.circom --r1cs --wasm --sym -o zkeys/r1cs
circom circuits/prod/tally.circom --r1cs --wasm --sym -o zkeys/r1cs
ftime="$(date -u +%s)"
echo " ($(($(date -u +%s)-$itime))s)"
# generate witness
echo $(date +"%T") "start generate witness"
mkdir -p build/wtns
folder_path="./build/inputs"
mkdir -p build/public
mkdir -p zkeys/verification_key/msg
plonkit export-verification-key --srs_monomial_form ./ptau/setup_2\^23.key --circuit zkeys/r1cs/msg.r1cs --vk_json zkeys/verification_key/msg/msg_vk.json --vk msg_vk.bin
for file in "$folder_path"/msg-input_*.json; do
if [ -f "$file" ]; then
filename=$(basename "$file")
number=$(echo "$filename" | cut -d '_' -f 2 | cut -d '.' -f 1)
# generate public and proof
echo $(date +"%T") "start generate proof"
mkdir -p build/proof/msg_$number
node "zkeys/r1cs/msg_js/generate_witness.js" "zkeys/r1cs/msg_js/msg.wasm" $file "build/wtns/msg_$number.wtns"
plonkit prove --srs_monomial_form "./ptau/setup_2^23.key" --circuit "zkeys/r1cs/msg.r1cs" --witness "build/wtns/msg_$number.wtns" --publicjson "build/public/msg-public_$number.json" --proofjson "build/proof/msg_$number/proof.json" --proof "build/proof/msg_$number/proof.bin"
fi
done
mkdir -p zkeys/verification_key/tally
plonkit export-verification-key --srs_monomial_form ./ptau/setup_2\^23.key --circuit zkeys/r1cs/tally.r1cs --vk_json zkeys/verification_key/tally/tally_vk.json --vk tally_vk.bin
for file in "$folder_path"/tally-input_*.json; do
if [ -f "$file" ]; then
filename=$(basename "$file")
number=$(echo "$filename" | cut -d '_' -f 2 | cut -d '.' -f 1)
# generate public and proof
echo $(date +"%T") "start generate proof"
mkdir -p build/proof/tally_$number
node "zkeys/r1cs/tally_js/generate_witness.js" "zkeys/r1cs/tally_js/tally.wasm" $file "build/wtns/tally_$number.wtns"
plonkit prove --srs_monomial_form "./ptau/setup_2^23.key" --circuit "zkeys/r1cs/tally.r1cs" --witness "build/wtns/tally_$number.wtns" --publicjson "build/public/tally-public_$number.json" --proofjson "build/proof/tally_$number/proof.json" --proof "build/proof/tally_$number/proof.bin"
fi
done
# # create zkey
# echo $(date +"%T") "start create zkey"
# mkdir -p zkeys/zkey
# snarkjs g16s zkeys/r1cs/msg.r1cs ptau/powersOfTau28_hez_final_22.ptau zkeys/zkey/msg_0.zkey
# snarkjs g16s zkeys/r1cs/tally.r1cs ptau/powersOfTau28_hez_final_22.ptau zkeys/zkey/tally_0.zkey
# # output verification key
# echo $(date +"%T") "output verification key"
# mkdir -p zkeys/verification_key/msg
# mkdir -p zkeys/verification_key/tally
# snarkjs zkc zkeys/zkey/msg_0.zkey zkeys/zkey/msg_1.zkey --name="DoraHacks" -v
# snarkjs zkev zkeys/zkey/msg_1.zkey zkeys/verification_key/msg/verification_key.json
# snarkjs zkc zkeys/zkey/tally_0.zkey zkeys/zkey/tally_1.zkey --name="DoraHacks" -v
# snarkjs zkev zkeys/zkey/tally_1.zkey zkeys/verification_key/tally/verification_key.json
# # generate witness
# echo $(date +"%T") "start generate witness"
# mkdir -p build/wtns
# folder_path="./build/inputs"
# mkdir -p build/public
# for file in "$folder_path"/msg-input_*.json; do
# if [ -f "$file" ]; then
# filename=$(basename "$file")
# number=$(echo "$filename" | cut -d '_' -f 2 | cut -d '.' -f 1)
# node "zkeys/r1cs/msg_js/generate_witness.js" "zkeys/r1cs/msg_js/msg.wasm" $file "build/wtns/msg_$number.wtns"
# # generate public and proof
# echo $(date +"%T") "start generate proof"
# mkdir -p build/proof/msg_$number
# node node_modules/snarkjs/cli.js g16p "zkeys/zkey/msg_1.zkey" "build/wtns/msg_$number.wtns" "build/proof/msg_$number/proof.json" build/public/msg-public_$number.json
# # verify proof by snarkjs
# echo $(date +"%T") "start verify the msg proof"
# node node_modules/snarkjs/cli.js groth16 verify zkeys/verification_key/msg/verification_key.json build/public/msg-public_$number.json build/proof/msg_$number/proof.json
# # start generate final proof
# echo $(date +"%T") "start transform the proof data format"
# mkdir -p build/final_proof/msg_$number
# mkdir -p build/final_verification_key/msg_$number
# node ./prove/src/adapt_maci.js msg $number
# fi
# done
# for file in "$folder_path"/tally-input_*.json; do
# if [ -f "$file" ]; then
# filename=$(basename "$file")
# number=$(echo "$filename" | cut -d '_' -f 2 | cut -d '.' -f 1)
# node "zkeys/r1cs/tally_js/generate_witness.js" "zkeys/r1cs/tally_js/tally.wasm" $file "build/wtns/tally_$number.wtns"
# # generate public and proof
# echo $(date +"%T") "start generate proof"
# mkdir -p build/proof/tally_$number
# node node_modules/snarkjs/cli.js g16p "zkeys/zkey/tally_1.zkey" "build/wtns/tally_$number.wtns" "build/proof/tally_$number/proof.json" build/public/tally-public_$number.json
# # verify proof by snarkjs
# echo $(date +"%T") "start verify the tally proof"
# node node_modules/snarkjs/cli.js groth16 verify zkeys/verification_key/tally/verification_key.json build/public/tally-public_$number.json build/proof/tally_$number/proof.json
# # start generate final proof
# echo $(date +"%T") "start transform the proof data format"
# mkdir -p build/final_proof/tally_$number
# mkdir -p build/final_verification_key/tally_$number
# node ./prove/src/adapt_maci.js tally $number
# fi
# done
echo "everything is ok"
}
compile_and_ts_and_witness