-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
248 lines (227 loc) · 13 KB
/
main.go
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// Welcome to the gnark playground!
package main
import (
"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/backend/plonk"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/frontend/cs/scs"
"math/big"
//"github.com/consensys/gnark/frontend/cs/r1cs"
//"github.com/consensys/gnark/std/algebra/emulated/sw_emulated"
//"github.com/consensys/gnark/std/math/emulated"
//"github.com/consensys/gnark/std/signature/ecdsa"
"github.com/consensys/gnark/test/unsafekzg"
"log"
)
var proofStr = []string{
"6040391028313978484211918676551733116401234039853332758960850838474140786869",
"15612760000835235043453110809787611149616276822696058008437284650746546753838",
"2593983859790167560688455226600824560283977050067854161682760085713688904914",
"19260161560257482627638391837380316026975390175046913343057587688581596194442",
"16225573509797931746870336409747879104419627023625227304647178518584829459517",
"14226531483611469783206972174724101836580032561768345241433994849123679369142",
"1479214271177237730676454915080871426264897492874111704679509191707554880571",
"10080782452676502724559382050780651823052013977335966155467052481166781585405",
"15261498842040232713481830851164493316688408435956532511959020796999664394636",
"19880446135424881202486106520690630074144659885723987547677131080649232169678",
"17475196855835811390120889945237472117471693801009310801076642572225905791679",
"13312647968638447618113252216683132279003980890741234146386070867686738542666",
"7433766596583137417377617650591474270354273768840675598473004260361687100865",
"10024293084655592231193779008843893806884912822312719548163134296706573630108",
"11855617913108077700065997726254386156629985424978042552022939475916902370558",
"13762608509980560233522858360838811676872071063596567240018879533519538491119",
"21314571930753728069996259462558349864734427913997343661515590025788261911797",
"14258668454853727405001310265255908375051460786748532514851863434871414464803",
"2466367992866699090823658261800208690185607350019421236938622193171265249709",
"15873776480475612064218066697903625112745597980890616668918730154590376138341",
"6727127810336921503876031542575911496387840435654688322134538119080888760950",
"20207121356841680158953838149920762410209955501802626791692173410638199147482",
"14282944644663879939708451532093828434102233798693214762420232045111017073346",
"18060064953202862447032910036797192303852612202004665798819733246694751147274",
"3143814600423895785345350053383304291317659163979504849830991916998452324675",
"4488183103824059506598443030054573799659183120715016976311770747614571311922",
"3886049620103466460043302423909677619778509048074037608990490829213583626444",
"4201470497418089075450393078908035142958081095503247831102000525962868882529",
"8629136992814481483283256922002779510237656603329113874742268259848297042238",
"11644296830886650446053727864242866709485443712324193094621340997097580237882",
"7389713057347271122372672649987885986856069082538136203897408292638957877444",
"20645668004014221570128326861258485659875150859869415962659666297494150381699",
"4558833108881744286133554461794452593266829121926124456514591894425651254506",
"4433284357007348169917002637533593160003957918643634713351513165123485048654",
"7275978011901972838302777028002136222015406902103007200178179371461876683309",
"19659686260996023964030185993960460859762993501390533249903905675203657368463",
"9810863361166331135089174854725998465094008475937600460204164784914582018302",
"15039139532657606727096761676273474359922799104189928853184431864027586333848",
"6697365270651584230146889620765325648104115402434888301556246691985656425408",
"20578156100843321307368431208436496246435465822615780919879575996533651043265",
"14593744636334602108539828109586108350182388406166734966637069413924872241412",
"9764577158641633263914405347191677483681555504721305417999954341416197414772",
"3326237301608665392144310758737293531903420545082662858833297442606607805709",
"15802127124053763012690907740138641386331593207902778341576950349184925351364",
"11627988358264772416821006090936976549744237070403434227740229808755463064647",
"9877133485175927933938612376247688693480761626300037609579938618435268747874",
"11973852370000111761435842389116001704132618146935887206893640607297316327630",
"1714135521968216370636237704591970353774778248164788355996163982260912163570",
"20385327976907123143863204131801795554068349528559224453813706897259217283829",
"14221558282713042911518957790565634467268500706118397666551751031198748504485",
"20607675607489231513511710769020688523666992557004498233581832224653930059869",
"1264797420416028187718480344467255113977168173158136006391320574930364171371",
"1615610822570478684476777596357258194416882639985621050258136565066110027532",
"6397122757826984815150818265392973022816896330335595947036996160634306843669",
"7482181824312515337904597338970052264540703032321275403741606042146737586634",
"8899244347121972539261691670915170548087019994583018609369054944934051712500",
"17142146333671213192286276966375737599618565827140024268973303397750321837586",
"7824972485880665317101827774042219882470836800272553463610802341992263948395",
"7715311952938002057892293990494696898751544324897922077177450407834099274636",
"3926394583176793663922881675102618497128700177503141618248563644798276319104",
"15969444527981988547623243841629540941292644600110613817171574158927247545195",
"14675566901794912902596292846774744292715837192528823930956470568724584254725",
"6198915652184885713851210015976017066660496687381332452553421895135256771338",
"606792630976896049066653975782869121063090601511028253486141233454457180488",
"1690321503337909329600042798216859950563789331769470564985965167947814212800",
"17708681560274293828407089124553132946030375363089102253733014323153053825914",
"21830302564078281187235914417070178478137874104420034246701120394563015130567",
"20336739493709499956213815945717150467046684331663982709873830685180281363418",
"10047878899691576413953564538638488142981110873489999846130246063023482349120",
"7913473937720930046147964640842622009755527373042814855385459052917709486658",
"3147087827201607118632553829784006395518040212175048762958915354827474129499",
"1356300434246325142143424223462237061250741875786315450935516723323686324978",
"8565346228007623171493823020106758460629908019252235164612722643595948448603",
"16615814945312513942012476518909118971055048405106952904957931580044837592203",
"10609123029491894511998297971183398370912262114471459144938660741389249945154",
"13790089485243745643511344816397792429096291012376908724735656166404265517504",
"2342744421778742073960689995632871172212962611635802381147909080188458834096",
"3884653336689914820564705636170567481273474959674580945030567209891221705545",
"95616299319603112200398386313336911109313832817595315603575224531234888210",
"20194724493197697283143937022980457413292722256350452033147445566054896783163",
"18501177650790470633409381058647356646688384941473091240984531975459023383240",
"15340702514497912821861863443385702827437687216253724286015975052596925808307",
"13347844363137201966825660337621979252857914912748581900039139508996869216314",
"586781691473263200727162341384823623060266480775553796324320014569046878012",
"16859078550074630705933248290764089985768002419804900798689490470858690985251",
"15638765325627570233734307006842172292168851708560494817656107908488491324915",
"15209653781974740076362764816933244741937642276791218708070587388849761738388",
"20217823041301236749036681243021341169357095676096384183533047217315311864426",
"13820917595770977664599477864576563114209717333748427347360723626312167179360",
"18552350691191835170650249284586249779754144647212402550883410976636446254544",
"20804524742095914786759560268508799929803089715132884188095367406202405435136",
"10253341666461839857026709810776041012852961627362888464029943696714224274237",
"13131454594371540869288648571489039514979311348852510803244955480667364697730",
"13260766900087776986591861526301153096106873989704674369161996773139822874475",
"21883473671391627556838051382826690148113526743642816997929727267371553198886",
"1890976346321102405541166731746172271506421091909039451212991781577631014865",
"2671778843608790255186606579761370487916054721454134720439851783686192402643",
"5729614234946405024473791418752103912198434522338033719578111093686749665029",
"10683279605881053376759869940756383839237075250675429864563664080871455374544",
"7547611984388921087570879758552377295646968808329672180541831410920545518918",
"18311365213787647478549906226462500770751194154202138786058552438717223063628",
"7053082475024936089491731097418889269619379854714000028522816832189714146874",
"2920616387084030925907755037226454382846345550621956833249622258647667607078",
"16502678157049327323910877548707266122319935523346850792311342099791838736912",
}
var auxStr = []string{
"14682075548635262302074385051110702234086274396931195933546742286128764358125",
"5970944479539763667607302383227109670115664003990899249555645330207628539815",
"7206167323204012920172020694146572854462090003484838410151461900447044137492",
"18300725921111785381142905892564341189078252048168893413679182768065165458873",
"15917298392299511554639103362030165418432700396425135094142558856368179955802",
"3587516950727489841103499852692933899470112352247140930019021418510643036744",
"16151655324356327614760014858525704209887167769008678047573542023792762405117",
"5736587547482947607486390886731570878661196631407356296124662162783046090500",
"1419367324747928750740274367894771235288461851295498307475706487306261727016",
"5707748190585141439752460049259769355677576232325499685890888944905271149423",
"11689593922861133887200066459481418654607356864746905626000232770614216718433",
"19387783161554357341921940911084468327547176706575548905518836360106050064187",
"2476626289238578204609570993403947988008457085418248697797844941324301300009",
"18722683493784403176336951594313758589329400787912550261272888155103625800384",
"6496776828228921447657185819640921303649571797651136931499664504670514728878",
"7262967178269634502214584662631180779259460182124420719996114193736337341167",
"18236718830889372358620508748939082284258422158604894293924155411313894246989",
"8022579757513435116576328365390377243723859585422666855272672472206173978140",
"18424665392613454736987314109345836106668473963999153826397914692375159257895",
"13865663114325840105670077379866897844824504814993367488425531714369634517477",
"3463577479225820485259091635911438981879890436416880517300289494200649237722",
}
func main() {
var aggCircuit = AggregatorCircuit{
Proof: make([]frontend.Variable, len(proofStr)),
VerifyInst: make([]frontend.Variable, 1),
Aux: make([]frontend.Variable, len(auxStr)),
TargetInst: make([]frontend.Variable, 4),
}
{
for i := 0; i < len(proofStr); i++ {
aggCircuit.Proof[i] = big.NewInt(0)
}
aggCircuit.VerifyInst[0] = big.NewInt(0)
for i := 0; i < len(auxStr); i++ {
aggCircuit.Aux[i] = big.NewInt(0)
}
aggCircuit.TargetInst[0] = big.NewInt(0)
aggCircuit.TargetInst[1] = big.NewInt(0)
aggCircuit.TargetInst[2] = big.NewInt(0)
aggCircuit.TargetInst[3] = big.NewInt(0)
}
var witnessCircuit = AggregatorCircuit{
Proof: make([]frontend.Variable, len(proofStr)),
VerifyInst: make([]frontend.Variable, 1),
Aux: make([]frontend.Variable, len(auxStr)),
TargetInst: make([]frontend.Variable, 4),
}
r1cs, err := frontend.Compile(ecc.BN254.ScalarField(), scs.NewBuilder, &aggCircuit)
if err != nil {
panic(err)
}
log.Println("start setup")
srs, srsLagrange, err := unsafekzg.NewSRS(r1cs)
if err != nil {
panic(err)
}
pk, vk, err := plonk.Setup(r1cs, srs, srsLagrange)
if err != nil {
panic(err)
}
log.Println("end setup")
{
for i := 0; i < len(proofStr); i++ {
proof, _ := big.NewInt(0).SetString(proofStr[i], 10)
witnessCircuit.Proof[i] = proof
}
verifyIns, _ := big.NewInt(0).SetString("10573525131658455000365299935369648652552518565632155338390913030155084554858", 10)
witnessCircuit.VerifyInst[0] = verifyIns
for i := 0; i < len(auxStr); i++ {
aux, _ := big.NewInt(0).SetString(auxStr[i], 10)
witnessCircuit.Aux[i] = aux
}
target0, _ := big.NewInt(0).SetString("7059793422771910484", 10)
target1, _ := big.NewInt(0).SetString("2556686405730241944", 10)
target2, _ := big.NewInt(0).SetString("2133554817341762742", 10)
target3, _ := big.NewInt(0).SetString("8974371243071329347", 10)
witnessCircuit.TargetInst[0] = target0
witnessCircuit.TargetInst[1] = target1
witnessCircuit.TargetInst[2] = target2
witnessCircuit.TargetInst[3] = target3
}
witness, err := frontend.NewWitness(&witnessCircuit, ecc.BN254.ScalarField())
if err != nil {
panic(err)
}
log.Println("start proof")
// 2. Proof creation
proof, err := plonk.Prove(r1cs, pk, witness)
if err != nil {
panic(err)
}
log.Println("end proof")
log.Println("start verify")
// 3. Proof verification
publicWitness, err := witness.Public()
if err != nil {
panic(err)
}
err = plonk.Verify(proof, vk, publicWitness)
if err != nil {
panic(err)
}
log.Println("end verify")
}