@clearproof/contracts 0.3.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/README.md +33 -5
  2. package/artifacts/contracts/ComplianceRegistry.sol/ComplianceRegistry.json +356 -5
  3. package/artifacts/contracts/Groth16Verifier.sol/Groth16Verifier.json +7 -2
  4. package/artifacts/contracts/MockVerifier.sol/MockVerifier.json +45 -0
  5. package/artifacts/contracts/Pairing.sol/Pairing.json +10 -0
  6. package/artifacts/contracts/PairingHarness.sol/PairingHarness.json +252 -0
  7. package/artifacts/contracts/PilotCurrentRegistry.sol/PilotCurrentRegistry.json +1063 -0
  8. package/artifacts/contracts/PilotGroth16Verifier.sol/PilotGroth16Verifier.json +155 -0
  9. package/artifacts/contracts/PilotRootCheckpoint.sol/PilotRootCheckpoint.json +476 -0
  10. package/artifacts/contracts/SanctionsOracle.sol/SanctionsOracle.json +27 -2
  11. package/artifacts/contracts/SanctionsRootRelay.sol/SanctionsRootRelay.json +12 -2
  12. package/artifacts/contracts/VASPRegistry.sol/VASPRegistry.json +27 -2
  13. package/artifacts/contracts/{ComplianceRegistry.sol → VerifierRouter.sol}/IGroth16Verifier.json +1 -1
  14. package/artifacts/contracts/VerifierRouter.sol/VerifierRouter.json +741 -0
  15. package/artifacts/contracts/bench/Groth16VerifierBLS.sol/Groth16VerifierBLS.json +35 -0
  16. package/contracts/ComplianceRegistry.sol +186 -35
  17. package/contracts/Groth16Verifier.sol +135 -267
  18. package/contracts/MockVerifier.sol +14 -0
  19. package/contracts/Pairing.sol +147 -0
  20. package/contracts/PairingHarness.sol +27 -0
  21. package/contracts/PilotCurrentRegistry.sol +216 -0
  22. package/contracts/PilotGroth16Verifier.sol +95 -0
  23. package/contracts/PilotRootCheckpoint.sol +68 -0
  24. package/contracts/SanctionsOracle.sol +12 -5
  25. package/contracts/SanctionsRootRelay.sol +6 -2
  26. package/contracts/VASPRegistry.sol +13 -6
  27. package/contracts/VerifierRouter.sol +207 -0
  28. package/contracts/bench/Groth16VerifierBLS.sol +127 -0
  29. package/package.json +6 -2
@@ -1,273 +1,141 @@
1
- // SPDX-License-Identifier: GPL-3.0
2
- /*
3
- Copyright 2021 0KIMS association.
4
-
5
- This file is generated with [snarkJS](https://github.com/iden3/snarkjs).
6
-
7
- snarkJS is a free software: you can redistribute it and/or modify it
8
- under the terms of the GNU General Public License as published by
9
- the Free Software Foundation, either version 3 of the License, or
10
- (at your option) any later version.
11
-
12
- snarkJS is distributed in the hope that it will be useful, but WITHOUT
13
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15
- License for more details.
16
-
17
- You should have received a copy of the GNU General Public License
18
- along with snarkJS. If not, see <https://www.gnu.org/licenses/>.
19
- */
20
-
21
- pragma solidity >=0.7.0 <0.9.0;
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ //
3
+ // Copyright 2026 clearproof contributors
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 (the "License");
6
+ // you may not use this file except in compliance with the License.
7
+ // You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing, software
12
+ // distributed under the License is distributed on an "AS IS" BASIS,
13
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ // See the License for the specific language governing permissions and
15
+ // limitations under the License.
16
+ //
17
+ // -----------------------------------------------------------------------------
18
+ // GENERATED FILE — do not edit constants by hand.
19
+ // Regenerate: node scripts/generate_verifier.mjs <verification_key.json> <output>
20
+ //
21
+ // Independent Groth16 (BN128) verifier, implemented from the protocol
22
+ // specification on the MIT-licensed Pairing library. This is NOT the
23
+ // snarkjs-generated verifier (GPL-3.0); see
24
+ // docs/adr/0001-groth16-verifier-licensing.md.
25
+ //
26
+ // Security properties (clearproof implementation):
27
+ // - Public-signal count is enforced at the ABI level: the fixed-size
28
+ // uint256[16] parameter makes mismatched signal counts inexpressible.
29
+ // - Every public signal is range-checked to be a canonical scalar-field
30
+ // element (< SNARK_SCALAR_FIELD) before use.
31
+ // - Malformed curve points are rejected by the pairing precompiles
32
+ // (staticcall success checks in Pairing.sol).
33
+ // -----------------------------------------------------------------------------
34
+
35
+ pragma solidity ^0.8.24;
36
+
37
+ import {Pairing} from "./Pairing.sol";
22
38
 
23
39
  contract Groth16Verifier {
24
- // Scalar field size
25
- uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
26
- // Base field size
27
- uint256 constant q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
28
-
29
- // Verification Key data
30
- uint256 constant alphax = 18684454301819562296747362103013247904909563675066733611848264601238709664346;
31
- uint256 constant alphay = 13382596269673849011460709490273826982834575881932794785488992240206958268988;
32
- uint256 constant betax1 = 9369927713959446369253112845140960817273069559889791172429790728904899918096;
33
- uint256 constant betax2 = 7018936339641547380564548801205962972325910679402088163891495006948592464872;
34
- uint256 constant betay1 = 18192680457896402009106056585736590829886416492642881064592060259639186262006;
35
- uint256 constant betay2 = 18772142389951268793765998116630185741982332811051964345375452390107064860773;
40
+ /// The prime q of the base field F_q for G1.
41
+ uint256 constant PRIME_Q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
42
+ /// The order r of the scalar field. Public signals must be < r.
43
+ uint256 constant SNARK_SCALAR_FIELD = 21888242871839275222246405745257275088548364400416034343698204186575808495617;
44
+
45
+ error PublicSignalExceedsScalarField();
46
+
47
+ // Verification key (16 public signals)
48
+ uint256 constant alphax = 20491192805390485299153009773594534940189261866228447918068658471970481763042;
49
+ uint256 constant alphay = 9383485363053290200918347156157836566562967994039712273449902621266178545958;
50
+ uint256 constant betax1 = 4252822878758300859123897981450591353533073413197771768651442665752259397132;
51
+ uint256 constant betax2 = 6375614351688725206403948262868962793625744043794305715222011528459656738731;
52
+ uint256 constant betay1 = 21847035105528745403288232691147584728191162732299865338377159692350059136679;
53
+ uint256 constant betay2 = 10505242626370262277552901082094356697409835680220590971873171140371331206856;
36
54
  uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
37
55
  uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
38
56
  uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
39
57
  uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
40
- uint256 constant deltax1 = 16066285121322798283816661155683648225017439991112020715347694895015493523206;
41
- uint256 constant deltax2 = 614037217300847490032117582288372304806365997874449473897067122389611050097;
42
- uint256 constant deltay1 = 999132498792814032884695754087775892189854734043853267260966253796598566326;
43
- uint256 constant deltay2 = 8766526840950424236933975030317606082570070701224728700739511563570212380686;
44
-
45
-
46
- uint256 constant IC0x = 19703754809632249201814027769049360897773771752440156313927961195680977255238;
47
- uint256 constant IC0y = 1863925490430054976148272770686055683655162519876480200776277689914207928337;
48
-
49
- uint256 constant IC1x = 6842328490232091184800254442267828217282426694586120268639604059623298759838;
50
- uint256 constant IC1y = 967714464342934108376368520755357809485356696728159664181729268436457657190;
51
-
52
- uint256 constant IC2x = 20168307450615104806507934761145093110988772994737581512365163335324124341082;
53
- uint256 constant IC2y = 10175921511662100555565831453583846748641455819904993446565619840555873483197;
54
-
55
- uint256 constant IC3x = 13130823847203923185744389743407601594952943279001962854157420583880242661911;
56
- uint256 constant IC3y = 1717961719253118057145771753432516947365256073230761126917637302458731210680;
57
-
58
- uint256 constant IC4x = 11570200420498329636975473116508042564110840984594598431680781479352690086989;
59
- uint256 constant IC4y = 2681790313628491490316309945974353922008319929950691351513001124290112440736;
60
-
61
- uint256 constant IC5x = 17383935142461497800455236241660532858882483738548995787211516208205825872633;
62
- uint256 constant IC5y = 21812547690832652944021035744811596124906251282698352572728088438967242927530;
63
-
64
- uint256 constant IC6x = 17927548420151504692167355438129654718691791355276257368295386474362061086291;
65
- uint256 constant IC6y = 20321310284767358151473081167596474276348875693336193985919659549761811512857;
66
-
67
- uint256 constant IC7x = 11490640138309946172119907896307159561754460075139288207159881809998896901104;
68
- uint256 constant IC7y = 21399015425377341114977066020036205236372213642636323424071239423311652240134;
69
-
70
- uint256 constant IC8x = 13073587098352777029611799287598219241090404838333415008565749123384053614197;
71
- uint256 constant IC8y = 6780096976642213192330292067106932985430455462072442264071195827463047236936;
72
-
73
- uint256 constant IC9x = 10304063069706060097949924002149390132151400007771167907675220468774489442419;
74
- uint256 constant IC9y = 3848734989942396280575580725247574077840617816983408962229650854147376789056;
75
-
76
- uint256 constant IC10x = 12670767716151712103223751322086902107378299370689672575360531050799429950688;
77
- uint256 constant IC10y = 3892214401665217432763449110039673837691522297147787147934049711723284107590;
78
-
79
- uint256 constant IC11x = 12052672264941792184464623369009224229428685304257677818833685093473604781859;
80
- uint256 constant IC11y = 194825330483639781015203119551849820798527497461262547171710476416288887343;
81
-
82
- uint256 constant IC12x = 8474513833967152402487822542522099684202492964316709697478913113017585715777;
83
- uint256 constant IC12y = 11180594191762522476791053549177803613388260607752128766664277934879987230209;
84
-
85
- uint256 constant IC13x = 2129674974467473223954430982973092343153467817398447047287805202064270480021;
86
- uint256 constant IC13y = 21694323122275709283006518607681778669855744651418931639024155273779308722027;
87
-
88
- uint256 constant IC14x = 3250568833007067433888350215497425008219853791906085127332832556581794453248;
89
- uint256 constant IC14y = 6399011481929268902517857078272758443475218531566888876695352617518549414569;
90
-
91
- uint256 constant IC15x = 21361875659190037444465592626338380323701081645088974263958258082733413038127;
92
- uint256 constant IC15y = 2277204784735610188074535623007303162278324355868808350267617647867247585840;
93
-
94
- uint256 constant IC16x = 3784932913228748653290327846200321674983791114501050843187248759346176565642;
95
- uint256 constant IC16y = 16161068570005881855813026196520856335621943638222458671868213423896093305442;
96
-
97
-
98
- // Memory data
99
- uint16 constant pVk = 0;
100
- uint16 constant pPairing = 128;
101
-
102
- uint16 constant pLastMem = 896;
103
-
104
- function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[16] calldata _pubSignals) public view returns (bool) {
105
- assembly {
106
- function checkField(v) {
107
- if iszero(lt(v, r)) {
108
- mstore(0, 0)
109
- return(0, 0x20)
110
- }
111
- }
112
-
113
- // G1 function to multiply a G1 value(x,y) to value in an address
114
- function g1_mulAccC(pR, x, y, s) {
115
- let success
116
- let mIn := mload(0x40)
117
- mstore(mIn, x)
118
- mstore(add(mIn, 32), y)
119
- mstore(add(mIn, 64), s)
120
-
121
- success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64)
122
-
123
- if iszero(success) {
124
- mstore(0, 0)
125
- return(0, 0x20)
126
- }
127
-
128
- mstore(add(mIn, 64), mload(pR))
129
- mstore(add(mIn, 96), mload(add(pR, 32)))
130
-
131
- success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
132
-
133
- if iszero(success) {
134
- mstore(0, 0)
135
- return(0, 0x20)
136
- }
137
- }
138
-
139
- function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk {
140
- let _pPairing := add(pMem, pPairing)
141
- let _pVk := add(pMem, pVk)
142
-
143
- mstore(_pVk, IC0x)
144
- mstore(add(_pVk, 32), IC0y)
145
-
146
- // Compute the linear combination vk_x
147
-
148
- g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
149
-
150
- g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
151
-
152
- g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64)))
153
-
154
- g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96)))
155
-
156
- g1_mulAccC(_pVk, IC5x, IC5y, calldataload(add(pubSignals, 128)))
157
-
158
- g1_mulAccC(_pVk, IC6x, IC6y, calldataload(add(pubSignals, 160)))
159
-
160
- g1_mulAccC(_pVk, IC7x, IC7y, calldataload(add(pubSignals, 192)))
161
-
162
- g1_mulAccC(_pVk, IC8x, IC8y, calldataload(add(pubSignals, 224)))
163
-
164
- g1_mulAccC(_pVk, IC9x, IC9y, calldataload(add(pubSignals, 256)))
165
-
166
- g1_mulAccC(_pVk, IC10x, IC10y, calldataload(add(pubSignals, 288)))
167
-
168
- g1_mulAccC(_pVk, IC11x, IC11y, calldataload(add(pubSignals, 320)))
169
-
170
- g1_mulAccC(_pVk, IC12x, IC12y, calldataload(add(pubSignals, 352)))
171
-
172
- g1_mulAccC(_pVk, IC13x, IC13y, calldataload(add(pubSignals, 384)))
173
-
174
- g1_mulAccC(_pVk, IC14x, IC14y, calldataload(add(pubSignals, 416)))
175
-
176
- g1_mulAccC(_pVk, IC15x, IC15y, calldataload(add(pubSignals, 448)))
177
-
178
- g1_mulAccC(_pVk, IC16x, IC16y, calldataload(add(pubSignals, 480)))
179
-
180
-
181
- // -A
182
- mstore(_pPairing, calldataload(pA))
183
- mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
184
-
185
- // B
186
- mstore(add(_pPairing, 64), calldataload(pB))
187
- mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
188
- mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
189
- mstore(add(_pPairing, 160), calldataload(add(pB, 96)))
190
-
191
- // alpha1
192
- mstore(add(_pPairing, 192), alphax)
193
- mstore(add(_pPairing, 224), alphay)
194
-
195
- // beta2
196
- mstore(add(_pPairing, 256), betax1)
197
- mstore(add(_pPairing, 288), betax2)
198
- mstore(add(_pPairing, 320), betay1)
199
- mstore(add(_pPairing, 352), betay2)
200
-
201
- // vk_x
202
- mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
203
- mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
204
-
205
-
206
- // gamma2
207
- mstore(add(_pPairing, 448), gammax1)
208
- mstore(add(_pPairing, 480), gammax2)
209
- mstore(add(_pPairing, 512), gammay1)
210
- mstore(add(_pPairing, 544), gammay2)
211
-
212
- // C
213
- mstore(add(_pPairing, 576), calldataload(pC))
214
- mstore(add(_pPairing, 608), calldataload(add(pC, 32)))
215
-
216
- // delta2
217
- mstore(add(_pPairing, 640), deltax1)
218
- mstore(add(_pPairing, 672), deltax2)
219
- mstore(add(_pPairing, 704), deltay1)
220
- mstore(add(_pPairing, 736), deltay2)
221
-
222
-
223
- let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
224
-
225
- isOk := and(success, mload(_pPairing))
226
- }
227
-
228
- let pMem := mload(0x40)
229
- mstore(0x40, add(pMem, pLastMem))
230
-
231
- // Validate that all evaluations ∈ F
232
-
233
- checkField(calldataload(add(_pubSignals, 0)))
234
-
235
- checkField(calldataload(add(_pubSignals, 32)))
236
-
237
- checkField(calldataload(add(_pubSignals, 64)))
238
-
239
- checkField(calldataload(add(_pubSignals, 96)))
240
-
241
- checkField(calldataload(add(_pubSignals, 128)))
242
-
243
- checkField(calldataload(add(_pubSignals, 160)))
244
-
245
- checkField(calldataload(add(_pubSignals, 192)))
246
-
247
- checkField(calldataload(add(_pubSignals, 224)))
248
-
249
- checkField(calldataload(add(_pubSignals, 256)))
250
-
251
- checkField(calldataload(add(_pubSignals, 288)))
252
-
253
- checkField(calldataload(add(_pubSignals, 320)))
254
-
255
- checkField(calldataload(add(_pubSignals, 352)))
256
-
257
- checkField(calldataload(add(_pubSignals, 384)))
258
-
259
- checkField(calldataload(add(_pubSignals, 416)))
260
-
261
- checkField(calldataload(add(_pubSignals, 448)))
262
-
263
- checkField(calldataload(add(_pubSignals, 480)))
264
-
265
-
266
- // Validate all evaluations
267
- let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
268
-
269
- mstore(0, isValid)
270
- return(0, 0x20)
271
- }
272
- }
273
- }
58
+ uint256 constant deltax1 = 2974186555623760423529748672821583607714957426956571055135612844089429893870;
59
+ uint256 constant deltax2 = 10588375097153901518979627187992625042736109069865402096572190734982036093711;
60
+ uint256 constant deltay1 = 19115075767386990942872361475791754451415243780542039672791181011695122963135;
61
+ uint256 constant deltay2 = 18453349290665075967093640302238344548421058363254922932792497598489616969577;
62
+
63
+ uint256 constant IC0x = 6320402867178631099034713396176179451169551424584359885242680780062854313975;
64
+ uint256 constant IC0y = 12016981516162831151117332517423047432593407400633746641027498150956858122565;
65
+ uint256 constant IC1x = 11612237236320519487896771099790526467887475109294186289524281630804072429406;
66
+ uint256 constant IC1y = 7999839460413247993360782590113275912584779806878799416462766939520137639535;
67
+ uint256 constant IC2x = 12280131130311826237142059690896611329869781654965583809961877760208273069403;
68
+ uint256 constant IC2y = 9399360826546113839157339166720212670529248622766662980114806038413885652858;
69
+ uint256 constant IC3x = 235935767589638843194484738243440001651123719488028140224836726857790519651;
70
+ uint256 constant IC3y = 2160074695756937055821624156818221966620846012533340843583511119564723227710;
71
+ uint256 constant IC4x = 12514246984824863364758552430836523508948000400805705561132660558269013329159;
72
+ uint256 constant IC4y = 8945897447706496697377206577330970302367473625029100631207071646435059801435;
73
+ uint256 constant IC5x = 1189399182198744218913760200992678095171745662013576670869990791892545436293;
74
+ uint256 constant IC5y = 6495546434115721275101647085365813133542869615625241945312901482264615433839;
75
+ uint256 constant IC6x = 10852884109112385564176798557474108019600651273901031232533851695900032864529;
76
+ uint256 constant IC6y = 20830004315685083046625079539648450488706248669953412069712423076825951549686;
77
+ uint256 constant IC7x = 10150767544867940420531954861024490000403260053457110444319334803025267336461;
78
+ uint256 constant IC7y = 15685868690474432476213057508226220120370964243711934272720816712590593060511;
79
+ uint256 constant IC8x = 6568431607906919604133178408719368061437873761574527145194457801753462867956;
80
+ uint256 constant IC8y = 14965819811456168747166295731527048661157583795095892966695425054879365318527;
81
+ uint256 constant IC9x = 8131547615539762335919635735768678633166277457617611262734969038548935034116;
82
+ uint256 constant IC9y = 3399714098683786366859385881819469574234036914629453607257089628144504182669;
83
+ uint256 constant IC10x = 15083630918786638323142689808247084816374306976825016157081370961887072467317;
84
+ uint256 constant IC10y = 4438386490422326385664846404774488749327696290779541432879151283661196090365;
85
+ uint256 constant IC11x = 309911936085896535057858717570325200365353133859764045799523133901255375510;
86
+ uint256 constant IC11y = 19785558823022412308387222151439800711675018385330293294550125182809042015308;
87
+ uint256 constant IC12x = 17543212907982774739311131046950606295948219458798572917256884642868723900762;
88
+ uint256 constant IC12y = 19838531576599264607634108702569591756612307345341381380769640013212898709452;
89
+ uint256 constant IC13x = 4790067396140997324588919591499385551328501244947053437187646201064870312065;
90
+ uint256 constant IC13y = 11219960598651965672927988423602403606193103659584051801608879290720510853399;
91
+ uint256 constant IC14x = 15029229329386664858469073229692196307020303139700296259611287945944374494349;
92
+ uint256 constant IC14y = 3011509882340193522254314032372601948391997411360066844129855731121346236444;
93
+ uint256 constant IC15x = 4354478154068368148539165334446003847224901342262632115463185234997584487774;
94
+ uint256 constant IC15y = 14795618889726955301866756601200732031875743112673123496281953558764626394980;
95
+ uint256 constant IC16x = 12701746237094998839908554589470563785756504432109953255149349188041401300810;
96
+ uint256 constant IC16y = 20987001795982597851013441126000106920440396942492066466689462984572210970139;
97
+
98
+ /// Verifies a Groth16 proof: e(-A, B) * e(alpha, beta) * e(vk_x, gamma) * e(C, delta) == 1
99
+ /// where vk_x = IC[0] + sum(pubSignals[i] * IC[i+1]).
100
+ function verifyProof(
101
+ uint256[2] calldata _pA,
102
+ uint256[2][2] calldata _pB,
103
+ uint256[2] calldata _pC,
104
+ uint256[16] calldata _pubSignals
105
+ ) public view returns (bool) {
106
+ // Every public signal must be a canonical scalar-field element.
107
+ for (uint256 i = 0; i < 16; i++) {
108
+ if (_pubSignals[i] >= SNARK_SCALAR_FIELD) revert PublicSignalExceedsScalarField();
109
+ }
110
+
111
+ // vk_x = IC[0] + sum(_pubSignals[i] * IC[i+1])
112
+ Pairing.G1Point memory vk_x = Pairing.G1Point(IC0x, IC0y);
113
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC1x, IC1y), _pubSignals[0]));
114
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC2x, IC2y), _pubSignals[1]));
115
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC3x, IC3y), _pubSignals[2]));
116
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC4x, IC4y), _pubSignals[3]));
117
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC5x, IC5y), _pubSignals[4]));
118
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC6x, IC6y), _pubSignals[5]));
119
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC7x, IC7y), _pubSignals[6]));
120
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC8x, IC8y), _pubSignals[7]));
121
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC9x, IC9y), _pubSignals[8]));
122
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC10x, IC10y), _pubSignals[9]));
123
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC11x, IC11y), _pubSignals[10]));
124
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC12x, IC12y), _pubSignals[11]));
125
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC13x, IC13y), _pubSignals[12]));
126
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC14x, IC14y), _pubSignals[13]));
127
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC15x, IC15y), _pubSignals[14]));
128
+ vk_x = Pairing.add(vk_x, Pairing.scalar_mul(Pairing.G1Point(IC16x, IC16y), _pubSignals[15]));
129
+
130
+ return Pairing.pairingProd4(
131
+ Pairing.negate(Pairing.G1Point(_pA[0], _pA[1])),
132
+ Pairing.G2Point([_pB[0][0], _pB[0][1]], [_pB[1][0], _pB[1][1]]),
133
+ Pairing.G1Point(alphax, alphay),
134
+ Pairing.G2Point([betax1, betax2], [betay1, betay2]),
135
+ vk_x,
136
+ Pairing.G2Point([gammax1, gammax2], [gammay1, gammay2]),
137
+ Pairing.G1Point(_pC[0], _pC[1]),
138
+ Pairing.G2Point([deltax1, deltax2], [deltay1, deltay2])
139
+ );
140
+ }
141
+ }
@@ -0,0 +1,14 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.24;
3
+
4
+ /// @dev Mock verifier that always returns true, for testing event emission.
5
+ contract MockVerifier {
6
+ function verifyProof(
7
+ uint[2] calldata,
8
+ uint[2][2] calldata,
9
+ uint[2] calldata,
10
+ uint[16] calldata
11
+ ) external pure returns (bool) {
12
+ return true;
13
+ }
14
+ }
@@ -0,0 +1,147 @@
1
+ // SPDX-License-Identifier: MIT
2
+ //
3
+ // Copyright 2017 Christian Reitwiessner
4
+ //
5
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ // of this software and associated documentation files (the "Software"), to deal
7
+ // in the Software without restriction, including without limitation the rights
8
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ // copies of the Software, and to permit persons to whom the Software is
10
+ // furnished to do so, subject to the following conditions:
11
+ //
12
+ // The above copyright notice and this permission notice shall be included in
13
+ // all copies or substantial portions of the Software.
14
+ //
15
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ // SOFTWARE.
22
+ //
23
+ // -----------------------------------------------------------------------------
24
+ // Provenance note (clearproof):
25
+ // This is the MIT-licensed alt_bn128 pairing library originally published by
26
+ // Christian Reitwiessner (2017). It was ported to Solidity ^0.8.24 by
27
+ // clearproof contributors (uint256 annotations, pure/view, gas() usage,
28
+ // structs namespaced inside the library). It is intentionally NOT derived
29
+ // from the snarkjs verifier template, which iden3 publishes under GPL-3.0
30
+ // (see docs/adr/0001-groth16-verifier-licensing.md).
31
+ // -----------------------------------------------------------------------------
32
+
33
+ pragma solidity ^0.8.24;
34
+
35
+ library Pairing {
36
+ struct G1Point {
37
+ uint256 X;
38
+ uint256 Y;
39
+ }
40
+ // Encoding of field elements is: X[0] * z + X[1]
41
+ struct G2Point {
42
+ uint256[2] X;
43
+ uint256[2] Y;
44
+ }
45
+
46
+ /// @return the generator of G1
47
+ function P1() internal pure returns (G1Point memory) {
48
+ return G1Point(1, 2);
49
+ }
50
+
51
+ /// @return the generator of G2
52
+ function P2() internal pure returns (G2Point memory) {
53
+ return G2Point(
54
+ [uint256(11559732032986387107991004021392285783925812861821192530917403151452391805634),
55
+ uint256(10857046999023057135944570762232829481370756359578518086990519993285655852781)],
56
+ [uint256(4082367875863433681332203403145435568316851327593401208105741076214120093531),
57
+ uint256(8495653923123431417604973247489272438418190587263600148770280649306958101930)]
58
+ );
59
+ }
60
+
61
+ /// @return the negation of p, i.e. p.add(p.negate()) should be zero.
62
+ function negate(G1Point memory p) internal pure returns (G1Point memory) {
63
+ // The prime q in the base field F_q for G1
64
+ uint256 q = 21888242871839275222246405745257275088696311157297823662689037894645226208583;
65
+ if (p.X == 0 && p.Y == 0) {
66
+ return G1Point(0, 0);
67
+ }
68
+ return G1Point(p.X, q - (p.Y % q));
69
+ }
70
+
71
+ /// @return r the sum of two points of G1
72
+ function add(G1Point memory p1, G1Point memory p2) internal view returns (G1Point memory r) {
73
+ uint256[4] memory input;
74
+ input[0] = p1.X;
75
+ input[1] = p1.Y;
76
+ input[2] = p2.X;
77
+ input[3] = p2.Y;
78
+ bool success;
79
+ assembly {
80
+ // ecadd precompile (address 0x06)
81
+ success := staticcall(gas(), 6, input, 0x80, r, 0x40)
82
+ }
83
+ require(success, "Pairing: ecadd failed");
84
+ }
85
+
86
+ /// @return r the product of a point on G1 and a scalar, i.e.
87
+ /// p == p.scalar_mul(1) and p.add(p) == p.scalar_mul(2) for all points p.
88
+ function scalar_mul(G1Point memory p, uint256 s) internal view returns (G1Point memory r) {
89
+ uint256[3] memory input;
90
+ input[0] = p.X;
91
+ input[1] = p.Y;
92
+ input[2] = s;
93
+ bool success;
94
+ assembly {
95
+ // ecmul precompile (address 0x07)
96
+ success := staticcall(gas(), 7, input, 0x60, r, 0x40)
97
+ }
98
+ require(success, "Pairing: ecmul failed");
99
+ }
100
+
101
+ /// @return the result of computing the pairing check
102
+ /// e(p1[0], p2[0]) * .... * e(p1[n], p2[n]) == 1
103
+ /// For example pairing([P1(), P1().negate()], [P2(), P2()]) should
104
+ /// return true.
105
+ function pairing(G1Point[] memory p1, G2Point[] memory p2) internal view returns (bool) {
106
+ require(p1.length == p2.length, "Pairing: mismatched input lengths");
107
+ uint256 elements = p1.length;
108
+ uint256 inputSize = elements * 6;
109
+ uint256[] memory input = new uint256[](inputSize);
110
+ for (uint256 i = 0; i < elements; i++) {
111
+ input[i * 6 + 0] = p1[i].X;
112
+ input[i * 6 + 1] = p1[i].Y;
113
+ input[i * 6 + 2] = p2[i].X[0];
114
+ input[i * 6 + 3] = p2[i].X[1];
115
+ input[i * 6 + 4] = p2[i].Y[0];
116
+ input[i * 6 + 5] = p2[i].Y[1];
117
+ }
118
+ uint256[1] memory out;
119
+ bool success;
120
+ assembly {
121
+ // ecpairing precompile (address 0x08)
122
+ success := staticcall(gas(), 8, add(input, 0x20), mul(inputSize, 0x20), out, 0x20)
123
+ }
124
+ require(success, "Pairing: ecpairing failed");
125
+ return out[0] != 0;
126
+ }
127
+
128
+ /// Convenience method for a pairing check for four pairs.
129
+ function pairingProd4(
130
+ G1Point memory a1, G2Point memory a2,
131
+ G1Point memory b1, G2Point memory b2,
132
+ G1Point memory c1, G2Point memory c2,
133
+ G1Point memory d1, G2Point memory d2
134
+ ) internal view returns (bool) {
135
+ G1Point[] memory p1 = new G1Point[](4);
136
+ G2Point[] memory p2 = new G2Point[](4);
137
+ p1[0] = a1;
138
+ p1[1] = b1;
139
+ p1[2] = c1;
140
+ p1[3] = d1;
141
+ p2[0] = a2;
142
+ p2[1] = b2;
143
+ p2[2] = c2;
144
+ p2[3] = d2;
145
+ return pairing(p1, p2);
146
+ }
147
+ }
@@ -0,0 +1,27 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.24;
3
+
4
+ import {Pairing} from "./Pairing.sol";
5
+
6
+ /// @dev Test-only access to internal library operations; not an authorization verifier.
7
+ contract PairingHarness {
8
+ function generators() external pure returns (Pairing.G1Point memory, Pairing.G2Point memory) {
9
+ return (Pairing.P1(), Pairing.P2());
10
+ }
11
+
12
+ function negate(Pairing.G1Point memory p) external pure returns (Pairing.G1Point memory) {
13
+ return Pairing.negate(p);
14
+ }
15
+
16
+ function add(Pairing.G1Point memory a, Pairing.G1Point memory b) external view returns (Pairing.G1Point memory) {
17
+ return Pairing.add(a, b);
18
+ }
19
+
20
+ function multiply(Pairing.G1Point memory p, uint256 scalar) external view returns (Pairing.G1Point memory) {
21
+ return Pairing.scalar_mul(p, scalar);
22
+ }
23
+
24
+ function pairing(Pairing.G1Point[] memory a, Pairing.G2Point[] memory b) external view returns (bool) {
25
+ return Pairing.pairing(a, b);
26
+ }
27
+ }