@lfdecentralizedtrust/zeto-contracts 0.2.2 → 0.5.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.
- package/README.md +70 -162
- package/contracts/factory.sol +30 -34
- package/contracts/factory_upgradeable.sol +11 -7
- package/contracts/lib/common/util.sol +40 -0
- package/contracts/lib/interfaces/ILockableCapability.sol +318 -0
- package/contracts/lib/interfaces/{izeto.sol → IZeto.sol} +13 -1
- package/contracts/lib/interfaces/{izeto_initializable.sol → IZetoInitializable.sol} +14 -12
- package/contracts/lib/interfaces/{izeto_kyc.sol → IZetoKyc.sol} +3 -3
- package/contracts/lib/interfaces/IZetoLockableCapability.sol +237 -0
- package/contracts/lib/interfaces/IZetoStorage.sol +106 -0
- package/contracts/lib/interfaces/{izeto_lockable.sol → IZetoVerifier.sol} +8 -21
- package/contracts/lib/registry.sol +74 -26
- package/contracts/lib/storage/base.sol +210 -0
- package/contracts/lib/storage/nullifier.sol +166 -0
- package/contracts/lib/zeto_common.sol +277 -28
- package/contracts/lib/zeto_fungible.sol +451 -33
- package/contracts/lib/zeto_fungible_base.sol +69 -0
- package/contracts/lib/zeto_fungible_burn.sol +83 -53
- package/contracts/lib/zeto_fungible_burn_nullifier.sol +115 -72
- package/contracts/lib/zeto_fungible_nullifier.sol +167 -0
- package/contracts/lib/zeto_lockable.sol +613 -0
- package/contracts/lib/zeto_non_fungible.sol +236 -0
- package/contracts/lib/zeto_non_fungible_base.sol +61 -0
- package/contracts/lib/zeto_non_fungible_nullifier.sol +61 -0
- package/contracts/test/escrow1.sol +90 -34
- package/contracts/test/escrow2.sol +64 -29
- package/contracts/test/qurrency.sol +10 -2
- package/contracts/test/smt.sol +6 -1
- package/contracts/test/tendecimals.sol +14 -12
- package/contracts/verifiers/impl/anon.sol +189 -0
- package/contracts/verifiers/impl/anon_batch.sol +301 -0
- package/contracts/verifiers/impl/anon_enc.sol +266 -0
- package/contracts/verifiers/impl/anon_enc_batch.sol +602 -0
- package/contracts/verifiers/impl/anon_enc_nullifier.sol +287 -0
- package/contracts/verifiers/impl/anon_enc_nullifier_batch.sol +679 -0
- package/contracts/verifiers/impl/anon_enc_nullifier_kyc.sol +294 -0
- package/contracts/verifiers/impl/anon_enc_nullifier_kyc_batch.sol +686 -0
- package/contracts/verifiers/impl/anon_enc_nullifier_non_repudiation.sol +413 -0
- package/contracts/verifiers/impl/anon_enc_nullifier_non_repudiation_batch.sol +1141 -0
- package/contracts/verifiers/impl/anon_nullifier_kyc_transfer.sol +217 -0
- package/contracts/verifiers/impl/anon_nullifier_kyc_transferLocked.sol +196 -0
- package/contracts/verifiers/impl/anon_nullifier_kyc_transferLocked_batch.sol +308 -0
- package/contracts/verifiers/impl/anon_nullifier_kyc_transfer_batch.sol +385 -0
- package/contracts/verifiers/impl/anon_nullifier_qurrency_transfer.sol +497 -0
- package/contracts/verifiers/impl/anon_nullifier_qurrency_transfer_batch.sol +1001 -0
- package/contracts/verifiers/{verifier_anon_nullifier_transferLocked.sol → impl/anon_nullifier_transfer.sol} +12 -19
- package/contracts/verifiers/{verifier_anon_nullifier_transferLocked_batch.sol → impl/anon_nullifier_transfer_batch.sol} +44 -51
- package/contracts/verifiers/impl/burn.sol +182 -0
- package/contracts/verifiers/impl/burn_batch.sol +238 -0
- package/contracts/verifiers/impl/burn_nullifier.sol +203 -0
- package/contracts/verifiers/impl/burn_nullifier_batch.sol +315 -0
- package/contracts/verifiers/impl/deposit.sol +182 -0
- package/contracts/verifiers/impl/deposit_kyc.sol +189 -0
- package/contracts/verifiers/impl/nf_anon.sol +175 -0
- package/contracts/verifiers/{verifier_nf_anon_nullifier_transferLocked.sol → impl/nf_anon_nullifier_transfer.sol} +6 -13
- package/contracts/verifiers/impl/withdraw.sol +189 -0
- package/contracts/verifiers/impl/withdraw_batch.sol +245 -0
- package/contracts/verifiers/impl/withdraw_nullifier.sol +210 -0
- package/contracts/verifiers/impl/withdraw_nullifier_batch.sol +322 -0
- package/contracts/verifiers/verifier_anon.sol +31 -186
- package/contracts/verifiers/verifier_anon_batch.sol +31 -298
- package/contracts/verifiers/verifier_anon_enc.sol +31 -263
- package/contracts/verifiers/verifier_anon_enc_batch.sol +31 -599
- package/contracts/verifiers/verifier_anon_enc_nullifier.sol +31 -284
- package/contracts/verifiers/verifier_anon_enc_nullifier_batch.sol +33 -676
- package/contracts/verifiers/verifier_anon_enc_nullifier_kyc.sol +31 -291
- package/contracts/verifiers/verifier_anon_enc_nullifier_kyc_batch.sol +33 -683
- package/contracts/verifiers/verifier_anon_enc_nullifier_non_repudiation.sol +33 -410
- package/contracts/verifiers/verifier_anon_enc_nullifier_non_repudiation_batch.sol +33 -1138
- package/contracts/verifiers/verifier_anon_nullifier_kyc_transfer.sol +33 -214
- package/contracts/verifiers/verifier_anon_nullifier_kyc_transferLocked.sol +33 -221
- package/contracts/verifiers/verifier_anon_nullifier_kyc_transferLocked_batch.sol +33 -389
- package/contracts/verifiers/verifier_anon_nullifier_kyc_transfer_batch.sol +33 -382
- package/contracts/verifiers/verifier_anon_nullifier_qurrency_transfer.sol +33 -221
- package/contracts/verifiers/verifier_anon_nullifier_qurrency_transfer_batch.sol +33 -389
- package/contracts/verifiers/verifier_anon_nullifier_transfer.sol +33 -207
- package/contracts/verifiers/verifier_anon_nullifier_transfer_batch.sol +33 -375
- package/contracts/verifiers/verifier_burn.sol +31 -179
- package/contracts/verifiers/verifier_burn_batch.sol +31 -235
- package/contracts/verifiers/verifier_burn_nullifier.sol +31 -200
- package/contracts/verifiers/verifier_burn_nullifier_batch.sol +31 -312
- package/contracts/verifiers/verifier_deposit.sol +31 -179
- package/contracts/verifiers/verifier_deposit_kyc.sol +34 -0
- package/contracts/verifiers/verifier_nf_anon.sol +31 -172
- package/contracts/verifiers/verifier_nf_anon_nullifier_transfer.sol +33 -179
- package/contracts/verifiers/verifier_withdraw.sol +31 -186
- package/contracts/verifiers/verifier_withdraw_batch.sol +31 -242
- package/contracts/verifiers/verifier_withdraw_nullifier.sol +31 -207
- package/contracts/verifiers/verifier_withdraw_nullifier_batch.sol +33 -319
- package/contracts/zeto_anon.sol +77 -231
- package/contracts/zeto_anon_burnable.sol +56 -12
- package/contracts/zeto_anon_enc.sol +93 -190
- package/contracts/zeto_anon_enc_nullifier.sol +249 -195
- package/contracts/zeto_anon_enc_nullifier_kyc.sol +51 -232
- package/contracts/zeto_anon_enc_nullifier_non_repudiation.sol +231 -238
- package/contracts/zeto_anon_nullifier.sol +164 -298
- package/contracts/zeto_anon_nullifier_burnable.sol +68 -18
- package/contracts/zeto_anon_nullifier_kyc.sol +40 -345
- package/contracts/zeto_anon_nullifier_qurrency.sol +217 -361
- package/contracts/zeto_nf_anon.sol +55 -130
- package/contracts/zeto_nf_anon_nullifier.sol +90 -152
- package/hardhat.config.ts +9 -3
- package/ignition/modules/lib/deps.ts +8 -0
- package/ignition/modules/zeto_anon_burnable.ts +8 -7
- package/ignition/modules/zeto_anon_enc_nullifier.ts +31 -0
- package/ignition/modules/zeto_anon_enc_nullifier_kyc.ts +2 -2
- package/ignition/modules/zeto_anon_nullifier.ts +28 -4
- package/ignition/modules/zeto_anon_nullifier_burnable.ts +50 -16
- package/ignition/modules/zeto_anon_nullifier_kyc.ts +27 -12
- package/ignition/modules/zeto_nf_anon_nullifier.ts +14 -10
- package/package.json +4 -2
- package/scripts/deploy_cloneable.ts +19 -10
- package/scripts/deploy_upgradeable.ts +9 -5
- package/scripts/tokens/Zeto_Anon.ts +3 -3
- package/scripts/tokens/Zeto_AnonBurnable.ts +1 -1
- package/scripts/tokens/Zeto_AnonEnc.ts +12 -3
- package/scripts/tokens/Zeto_AnonEncNullifier.ts +5 -3
- package/scripts/tokens/Zeto_AnonEncNullifierKyc.ts +1 -1
- package/scripts/tokens/Zeto_AnonEncNullifierNonRepudiation.ts +1 -1
- package/scripts/tokens/Zeto_AnonNullifier.ts +1 -1
- package/scripts/tokens/Zeto_AnonNullifierBurnable.ts +1 -1
- package/scripts/tokens/Zeto_AnonNullifierKyc.ts +1 -1
- package/scripts/tokens/Zeto_AnonNullifierQurrency.ts +1 -1
- package/scripts/tokens/Zeto_NfAnon.ts +2 -2
- package/scripts/tokens/Zeto_NfAnonNullifier.ts +1 -1
- package/test/factory.ts +46 -73
- package/test/lib/anon_nullifier_helpers.ts +89 -0
- package/test/lib/anon_zeto_helpers.ts +76 -0
- package/test/lib/deploy.ts +3 -2
- package/test/lib/utils.ts +74 -35
- package/test/test/escrow1.ts +185 -58
- package/test/test/escrow2.ts +200 -107
- package/test/test/qurrency.ts +13 -33
- package/test/usdc-shielding.ts +39 -26
- package/test/utils.ts +144 -21
- package/test/zeto_anon.ts +956 -465
- package/test/zeto_anon_enc.ts +881 -142
- package/test/zeto_anon_enc_nullifier.ts +847 -38
- package/test/zeto_anon_enc_nullifier_kyc.ts +120 -181
- package/test/zeto_anon_enc_nullifier_non_repudiation.ts +77 -46
- package/test/zeto_anon_nullifier.ts +1212 -953
- package/test/zeto_anon_nullifier_kyc.ts +674 -655
- package/test/zeto_anon_nullifier_qurrency.ts +452 -306
- package/test/zeto_nf_anon.ts +737 -137
- package/test/zeto_nf_anon_nullifier.ts +876 -246
- package/contracts/lib/zeto_base.sol +0 -293
- package/contracts/lib/zeto_fungible_withdraw.sol +0 -132
- package/contracts/lib/zeto_fungible_withdraw_nullifier.sol +0 -144
- package/contracts/lib/zeto_nullifier.sol +0 -340
- package/contracts/zkDvP.sol_ +0 -273
- package/test/zkDvP.ts_ +0 -455
- /package/contracts/lib/{common.sol → common/common.sol} +0 -0
|
@@ -1,238 +1,34 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
*/
|
|
1
|
+
// Copyright © 2025 Kaleido, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
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.
|
|
20
16
|
|
|
21
17
|
pragma solidity >=0.7.0 <0.9.0;
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
|
|
40
|
-
uint256 constant deltax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
|
|
41
|
-
uint256 constant deltax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
|
|
42
|
-
uint256 constant deltay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
|
|
43
|
-
uint256 constant deltay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
uint256 constant IC0x = 7631257906107650252600145723888878222116317244029552711162468092756937492692;
|
|
47
|
-
uint256 constant IC0y = 21533439902964678059972645672295063253017913469233699615769382673890163442989;
|
|
48
|
-
|
|
49
|
-
uint256 constant IC1x = 1452116139955566603194478923716910101802496934152744867265527791250404038823;
|
|
50
|
-
uint256 constant IC1y = 6673542924818916509202846631770828428780632369731800323285779288715125663589;
|
|
51
|
-
|
|
52
|
-
uint256 constant IC2x = 7420056446893507736984550520579335657278263462589586131787103166599640463478;
|
|
53
|
-
uint256 constant IC2y = 15975062804917941696207231021230248919824358958350174816797234388427655512882;
|
|
54
|
-
|
|
55
|
-
uint256 constant IC3x = 3671066312224999073665280455061768923412039416115707772601043596926286431278;
|
|
56
|
-
uint256 constant IC3y = 2677952671086594665255013146125932150995484950543368552641379515907256501003;
|
|
57
|
-
|
|
58
|
-
uint256 constant IC4x = 20773542083028731773382992271757996563109613809271335566652212304600047070091;
|
|
59
|
-
uint256 constant IC4y = 4127534931003107599356004838413250277935814851296724893875709823794065306505;
|
|
60
|
-
|
|
61
|
-
uint256 constant IC5x = 10341004646478092931355681616660382693902678512482677938125005887124316152765;
|
|
62
|
-
uint256 constant IC5y = 7923464261944844839205065292580326683188404716466262258956809956184590021761;
|
|
63
|
-
|
|
64
|
-
uint256 constant IC6x = 6779471029284756918162956883720127063236000026616043850873659326220351759164;
|
|
65
|
-
uint256 constant IC6y = 3363099043577458891348004651430331031933902732546825484112862780494882706345;
|
|
66
|
-
|
|
67
|
-
uint256 constant IC7x = 3643583922845363299324866982994565910128232221293173155892149319988212291914;
|
|
68
|
-
uint256 constant IC7y = 19361444849011000229658521500930422347828327395570485178056706722338361925130;
|
|
69
|
-
|
|
70
|
-
uint256 constant IC8x = 13770709707251326390999117178934284613506760387725864815634125535930222646522;
|
|
71
|
-
uint256 constant IC8y = 21800266370933077493571039770074679032281564373672646405217493746190607957218;
|
|
72
|
-
|
|
73
|
-
uint256 constant IC9x = 5806904013223972450761771117316723363768298169000699993638559554524950945770;
|
|
74
|
-
uint256 constant IC9y = 18543558357419593215531073075248309048964681146029999482511740458059720449689;
|
|
75
|
-
|
|
76
|
-
uint256 constant IC10x = 18320219688608829968075030384893825876458562520853056684465492113328876872578;
|
|
77
|
-
uint256 constant IC10y = 13479039050249889368250244419835364693499574538369869489319903643150801464206;
|
|
78
|
-
|
|
79
|
-
uint256 constant IC11x = 851671849735031126345893979530598322453966429040751705913475255243208778752;
|
|
80
|
-
uint256 constant IC11y = 10153380221453105148515421084979735587724520574654009426957875693321035012414;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// Memory data
|
|
84
|
-
uint16 constant pVk = 0;
|
|
85
|
-
uint16 constant pPairing = 128;
|
|
86
|
-
|
|
87
|
-
uint16 constant pLastMem = 896;
|
|
88
|
-
|
|
89
|
-
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[11] calldata _pubSignals) public view returns (bool) {
|
|
90
|
-
assembly {
|
|
91
|
-
function checkField(v) {
|
|
92
|
-
if iszero(lt(v, r)) {
|
|
93
|
-
mstore(0, 0)
|
|
94
|
-
return(0, 0x20)
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// G1 function to multiply a G1 value(x,y) to value in an address
|
|
99
|
-
function g1_mulAccC(pR, x, y, s) {
|
|
100
|
-
let success
|
|
101
|
-
let mIn := mload(0x40)
|
|
102
|
-
mstore(mIn, x)
|
|
103
|
-
mstore(add(mIn, 32), y)
|
|
104
|
-
mstore(add(mIn, 64), s)
|
|
105
|
-
|
|
106
|
-
success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64)
|
|
107
|
-
|
|
108
|
-
if iszero(success) {
|
|
109
|
-
mstore(0, 0)
|
|
110
|
-
return(0, 0x20)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
mstore(add(mIn, 64), mload(pR))
|
|
114
|
-
mstore(add(mIn, 96), mload(add(pR, 32)))
|
|
115
|
-
|
|
116
|
-
success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
|
|
117
|
-
|
|
118
|
-
if iszero(success) {
|
|
119
|
-
mstore(0, 0)
|
|
120
|
-
return(0, 0x20)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk {
|
|
125
|
-
let _pPairing := add(pMem, pPairing)
|
|
126
|
-
let _pVk := add(pMem, pVk)
|
|
127
|
-
|
|
128
|
-
mstore(_pVk, IC0x)
|
|
129
|
-
mstore(add(_pVk, 32), IC0y)
|
|
130
|
-
|
|
131
|
-
// Compute the linear combination vk_x
|
|
132
|
-
|
|
133
|
-
g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
|
|
134
|
-
|
|
135
|
-
g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
|
|
136
|
-
|
|
137
|
-
g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64)))
|
|
138
|
-
|
|
139
|
-
g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96)))
|
|
140
|
-
|
|
141
|
-
g1_mulAccC(_pVk, IC5x, IC5y, calldataload(add(pubSignals, 128)))
|
|
142
|
-
|
|
143
|
-
g1_mulAccC(_pVk, IC6x, IC6y, calldataload(add(pubSignals, 160)))
|
|
144
|
-
|
|
145
|
-
g1_mulAccC(_pVk, IC7x, IC7y, calldataload(add(pubSignals, 192)))
|
|
146
|
-
|
|
147
|
-
g1_mulAccC(_pVk, IC8x, IC8y, calldataload(add(pubSignals, 224)))
|
|
148
|
-
|
|
149
|
-
g1_mulAccC(_pVk, IC9x, IC9y, calldataload(add(pubSignals, 256)))
|
|
150
|
-
|
|
151
|
-
g1_mulAccC(_pVk, IC10x, IC10y, calldataload(add(pubSignals, 288)))
|
|
152
|
-
|
|
153
|
-
g1_mulAccC(_pVk, IC11x, IC11y, calldataload(add(pubSignals, 320)))
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
// -A
|
|
157
|
-
mstore(_pPairing, calldataload(pA))
|
|
158
|
-
mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
|
|
159
|
-
|
|
160
|
-
// B
|
|
161
|
-
mstore(add(_pPairing, 64), calldataload(pB))
|
|
162
|
-
mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
|
|
163
|
-
mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
|
|
164
|
-
mstore(add(_pPairing, 160), calldataload(add(pB, 96)))
|
|
165
|
-
|
|
166
|
-
// alpha1
|
|
167
|
-
mstore(add(_pPairing, 192), alphax)
|
|
168
|
-
mstore(add(_pPairing, 224), alphay)
|
|
169
|
-
|
|
170
|
-
// beta2
|
|
171
|
-
mstore(add(_pPairing, 256), betax1)
|
|
172
|
-
mstore(add(_pPairing, 288), betax2)
|
|
173
|
-
mstore(add(_pPairing, 320), betay1)
|
|
174
|
-
mstore(add(_pPairing, 352), betay2)
|
|
175
|
-
|
|
176
|
-
// vk_x
|
|
177
|
-
mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
|
|
178
|
-
mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
// gamma2
|
|
182
|
-
mstore(add(_pPairing, 448), gammax1)
|
|
183
|
-
mstore(add(_pPairing, 480), gammax2)
|
|
184
|
-
mstore(add(_pPairing, 512), gammay1)
|
|
185
|
-
mstore(add(_pPairing, 544), gammay2)
|
|
186
|
-
|
|
187
|
-
// C
|
|
188
|
-
mstore(add(_pPairing, 576), calldataload(pC))
|
|
189
|
-
mstore(add(_pPairing, 608), calldataload(add(pC, 32)))
|
|
190
|
-
|
|
191
|
-
// delta2
|
|
192
|
-
mstore(add(_pPairing, 640), deltax1)
|
|
193
|
-
mstore(add(_pPairing, 672), deltax2)
|
|
194
|
-
mstore(add(_pPairing, 704), deltay1)
|
|
195
|
-
mstore(add(_pPairing, 736), deltay2)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
|
|
199
|
-
|
|
200
|
-
isOk := and(success, mload(_pPairing))
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
let pMem := mload(0x40)
|
|
204
|
-
mstore(0x40, add(pMem, pLastMem))
|
|
205
|
-
|
|
206
|
-
// Validate that all evaluations ∈ F
|
|
207
|
-
|
|
208
|
-
checkField(calldataload(add(_pubSignals, 0)))
|
|
209
|
-
|
|
210
|
-
checkField(calldataload(add(_pubSignals, 32)))
|
|
211
|
-
|
|
212
|
-
checkField(calldataload(add(_pubSignals, 64)))
|
|
213
|
-
|
|
214
|
-
checkField(calldataload(add(_pubSignals, 96)))
|
|
215
|
-
|
|
216
|
-
checkField(calldataload(add(_pubSignals, 128)))
|
|
217
|
-
|
|
218
|
-
checkField(calldataload(add(_pubSignals, 160)))
|
|
219
|
-
|
|
220
|
-
checkField(calldataload(add(_pubSignals, 192)))
|
|
221
|
-
|
|
222
|
-
checkField(calldataload(add(_pubSignals, 224)))
|
|
223
|
-
|
|
224
|
-
checkField(calldataload(add(_pubSignals, 256)))
|
|
225
|
-
|
|
226
|
-
checkField(calldataload(add(_pubSignals, 288)))
|
|
227
|
-
|
|
228
|
-
checkField(calldataload(add(_pubSignals, 320)))
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
// Validate all evaluations
|
|
232
|
-
let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
|
|
233
|
-
|
|
234
|
-
mstore(0, isValid)
|
|
235
|
-
return(0, 0x20)
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
19
|
+
import {Verifier_BurnBatch} from "./impl/burn_batch.sol";
|
|
20
|
+
|
|
21
|
+
contract Groth16Verifier_BurnBatch is Verifier_BurnBatch {
|
|
22
|
+
function verify(
|
|
23
|
+
uint[2] calldata _pA,
|
|
24
|
+
uint[2][2] calldata _pB,
|
|
25
|
+
uint[2] calldata _pC,
|
|
26
|
+
uint[] calldata _pubSignals
|
|
27
|
+
) public view returns (bool) {
|
|
28
|
+
uint256[11] memory fixedSizeInputs;
|
|
29
|
+
for (uint256 i = 0; i < fixedSizeInputs.length; i++) {
|
|
30
|
+
fixedSizeInputs[i] = _pubSignals[i];
|
|
31
|
+
}
|
|
32
|
+
return this.verifyProof(_pA, _pB, _pC, fixedSizeInputs);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,203 +1,34 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
*/
|
|
1
|
+
// Copyright © 2025 Kaleido, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
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.
|
|
20
16
|
|
|
21
17
|
pragma solidity >=0.7.0 <0.9.0;
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
|
|
40
|
-
uint256 constant deltax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634;
|
|
41
|
-
uint256 constant deltax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781;
|
|
42
|
-
uint256 constant deltay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531;
|
|
43
|
-
uint256 constant deltay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
uint256 constant IC0x = 6377235690443028896840504532581929995971904954652810718538234000616699427601;
|
|
47
|
-
uint256 constant IC0y = 5030738044882242586194846102159033322186429427953711545130849459477797885963;
|
|
48
|
-
|
|
49
|
-
uint256 constant IC1x = 14548775479962439286702264257623534821071180132293450318252615080467770313388;
|
|
50
|
-
uint256 constant IC1y = 6780862244910210455575251548483793578490724343597309236295752002913610902589;
|
|
51
|
-
|
|
52
|
-
uint256 constant IC2x = 9093278509018641818845779899210440534749601604268623796054086063776956765874;
|
|
53
|
-
uint256 constant IC2y = 13114198174121848791638491773271715167734502626894020703037579826798229777421;
|
|
54
|
-
|
|
55
|
-
uint256 constant IC3x = 14483847674451758601558409531965871769998544014331775462662403097859988620769;
|
|
56
|
-
uint256 constant IC3y = 20295994853773468699125232574237048558414126151217827123352257831634006334434;
|
|
57
|
-
|
|
58
|
-
uint256 constant IC4x = 17409291535847317872558601164878187925707900750585225056692158099319340316207;
|
|
59
|
-
uint256 constant IC4y = 4841260338820424554802873887094114639639762348217039425723482182782998060883;
|
|
60
|
-
|
|
61
|
-
uint256 constant IC5x = 2147337277406567513367522396606681146587596851229720265111344286306293382767;
|
|
62
|
-
uint256 constant IC5y = 20165702748314350953967854437006874240662504290993771238053003370147396279802;
|
|
63
|
-
|
|
64
|
-
uint256 constant IC6x = 5522384291547847276990719037049131256862185241045033972659501231876246004794;
|
|
65
|
-
uint256 constant IC6y = 20988550067066315168232765216331537940219755786876019136997990891675073378235;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// Memory data
|
|
69
|
-
uint16 constant pVk = 0;
|
|
70
|
-
uint16 constant pPairing = 128;
|
|
71
|
-
|
|
72
|
-
uint16 constant pLastMem = 896;
|
|
73
|
-
|
|
74
|
-
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[6] calldata _pubSignals) public view returns (bool) {
|
|
75
|
-
assembly {
|
|
76
|
-
function checkField(v) {
|
|
77
|
-
if iszero(lt(v, r)) {
|
|
78
|
-
mstore(0, 0)
|
|
79
|
-
return(0, 0x20)
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// G1 function to multiply a G1 value(x,y) to value in an address
|
|
84
|
-
function g1_mulAccC(pR, x, y, s) {
|
|
85
|
-
let success
|
|
86
|
-
let mIn := mload(0x40)
|
|
87
|
-
mstore(mIn, x)
|
|
88
|
-
mstore(add(mIn, 32), y)
|
|
89
|
-
mstore(add(mIn, 64), s)
|
|
90
|
-
|
|
91
|
-
success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64)
|
|
92
|
-
|
|
93
|
-
if iszero(success) {
|
|
94
|
-
mstore(0, 0)
|
|
95
|
-
return(0, 0x20)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
mstore(add(mIn, 64), mload(pR))
|
|
99
|
-
mstore(add(mIn, 96), mload(add(pR, 32)))
|
|
100
|
-
|
|
101
|
-
success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
|
|
102
|
-
|
|
103
|
-
if iszero(success) {
|
|
104
|
-
mstore(0, 0)
|
|
105
|
-
return(0, 0x20)
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk {
|
|
110
|
-
let _pPairing := add(pMem, pPairing)
|
|
111
|
-
let _pVk := add(pMem, pVk)
|
|
112
|
-
|
|
113
|
-
mstore(_pVk, IC0x)
|
|
114
|
-
mstore(add(_pVk, 32), IC0y)
|
|
115
|
-
|
|
116
|
-
// Compute the linear combination vk_x
|
|
117
|
-
|
|
118
|
-
g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
|
|
119
|
-
|
|
120
|
-
g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
|
|
121
|
-
|
|
122
|
-
g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64)))
|
|
123
|
-
|
|
124
|
-
g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96)))
|
|
125
|
-
|
|
126
|
-
g1_mulAccC(_pVk, IC5x, IC5y, calldataload(add(pubSignals, 128)))
|
|
127
|
-
|
|
128
|
-
g1_mulAccC(_pVk, IC6x, IC6y, calldataload(add(pubSignals, 160)))
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// -A
|
|
132
|
-
mstore(_pPairing, calldataload(pA))
|
|
133
|
-
mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
|
|
134
|
-
|
|
135
|
-
// B
|
|
136
|
-
mstore(add(_pPairing, 64), calldataload(pB))
|
|
137
|
-
mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
|
|
138
|
-
mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
|
|
139
|
-
mstore(add(_pPairing, 160), calldataload(add(pB, 96)))
|
|
140
|
-
|
|
141
|
-
// alpha1
|
|
142
|
-
mstore(add(_pPairing, 192), alphax)
|
|
143
|
-
mstore(add(_pPairing, 224), alphay)
|
|
144
|
-
|
|
145
|
-
// beta2
|
|
146
|
-
mstore(add(_pPairing, 256), betax1)
|
|
147
|
-
mstore(add(_pPairing, 288), betax2)
|
|
148
|
-
mstore(add(_pPairing, 320), betay1)
|
|
149
|
-
mstore(add(_pPairing, 352), betay2)
|
|
150
|
-
|
|
151
|
-
// vk_x
|
|
152
|
-
mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
|
|
153
|
-
mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
// gamma2
|
|
157
|
-
mstore(add(_pPairing, 448), gammax1)
|
|
158
|
-
mstore(add(_pPairing, 480), gammax2)
|
|
159
|
-
mstore(add(_pPairing, 512), gammay1)
|
|
160
|
-
mstore(add(_pPairing, 544), gammay2)
|
|
161
|
-
|
|
162
|
-
// C
|
|
163
|
-
mstore(add(_pPairing, 576), calldataload(pC))
|
|
164
|
-
mstore(add(_pPairing, 608), calldataload(add(pC, 32)))
|
|
165
|
-
|
|
166
|
-
// delta2
|
|
167
|
-
mstore(add(_pPairing, 640), deltax1)
|
|
168
|
-
mstore(add(_pPairing, 672), deltax2)
|
|
169
|
-
mstore(add(_pPairing, 704), deltay1)
|
|
170
|
-
mstore(add(_pPairing, 736), deltay2)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
|
|
174
|
-
|
|
175
|
-
isOk := and(success, mload(_pPairing))
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
let pMem := mload(0x40)
|
|
179
|
-
mstore(0x40, add(pMem, pLastMem))
|
|
180
|
-
|
|
181
|
-
// Validate that all evaluations ∈ F
|
|
182
|
-
|
|
183
|
-
checkField(calldataload(add(_pubSignals, 0)))
|
|
184
|
-
|
|
185
|
-
checkField(calldataload(add(_pubSignals, 32)))
|
|
186
|
-
|
|
187
|
-
checkField(calldataload(add(_pubSignals, 64)))
|
|
188
|
-
|
|
189
|
-
checkField(calldataload(add(_pubSignals, 96)))
|
|
190
|
-
|
|
191
|
-
checkField(calldataload(add(_pubSignals, 128)))
|
|
192
|
-
|
|
193
|
-
checkField(calldataload(add(_pubSignals, 160)))
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
// Validate all evaluations
|
|
197
|
-
let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
|
|
198
|
-
|
|
199
|
-
mstore(0, isValid)
|
|
200
|
-
return(0, 0x20)
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
19
|
+
import {Verifier_BurnNullifier} from "./impl/burn_nullifier.sol";
|
|
20
|
+
|
|
21
|
+
contract Groth16Verifier_BurnNullifier is Verifier_BurnNullifier {
|
|
22
|
+
function verify(
|
|
23
|
+
uint[2] calldata _pA,
|
|
24
|
+
uint[2][2] calldata _pB,
|
|
25
|
+
uint[2] calldata _pC,
|
|
26
|
+
uint[] calldata _pubSignals
|
|
27
|
+
) public view returns (bool) {
|
|
28
|
+
uint256[6] memory fixedSizeInputs;
|
|
29
|
+
for (uint256 i = 0; i < fixedSizeInputs.length; i++) {
|
|
30
|
+
fixedSizeInputs[i] = _pubSignals[i];
|
|
31
|
+
}
|
|
32
|
+
return this.verifyProof(_pA, _pB, _pC, fixedSizeInputs);
|
|
33
|
+
}
|
|
34
|
+
}
|