@lfdecentralizedtrust/zeto-contracts 0.2.2 → 0.5.1

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