@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,175 +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_NfAnon {
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 = 13873740177715802755385732077366977622618043548586667644931510412045732345211;
47
- uint256 constant IC0y = 7822603196038058903946191150335625452288855271795991044394515523726630086823;
48
-
49
- uint256 constant IC1x = 20387114900165564444764599841003695882681843564123010509570888345037810796233;
50
- uint256 constant IC1y = 716107887690255579382932830143841687883619764720110130104332293089743616318;
51
-
52
- uint256 constant IC2x = 19953561954684321143934408477761743321734499762610383055455222208328857184181;
53
- uint256 constant IC2y = 21474413230170442926828652492881481675080019689587204357649131313116699670567;
54
-
55
-
56
- // Memory data
57
- uint16 constant pVk = 0;
58
- uint16 constant pPairing = 128;
59
-
60
- uint16 constant pLastMem = 896;
61
-
62
- function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[2] calldata _pubSignals) public view returns (bool) {
63
- assembly {
64
- function checkField(v) {
65
- if iszero(lt(v, r)) {
66
- mstore(0, 0)
67
- return(0, 0x20)
68
- }
69
- }
70
-
71
- // G1 function to multiply a G1 value(x,y) to value in an address
72
- function g1_mulAccC(pR, x, y, s) {
73
- let success
74
- let mIn := mload(0x40)
75
- mstore(mIn, x)
76
- mstore(add(mIn, 32), y)
77
- mstore(add(mIn, 64), s)
78
-
79
- success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64)
80
-
81
- if iszero(success) {
82
- mstore(0, 0)
83
- return(0, 0x20)
84
- }
85
-
86
- mstore(add(mIn, 64), mload(pR))
87
- mstore(add(mIn, 96), mload(add(pR, 32)))
88
-
89
- success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
90
-
91
- if iszero(success) {
92
- mstore(0, 0)
93
- return(0, 0x20)
94
- }
95
- }
96
-
97
- function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk {
98
- let _pPairing := add(pMem, pPairing)
99
- let _pVk := add(pMem, pVk)
100
-
101
- mstore(_pVk, IC0x)
102
- mstore(add(_pVk, 32), IC0y)
103
-
104
- // Compute the linear combination vk_x
105
-
106
- g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
107
-
108
- g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
109
-
110
-
111
- // -A
112
- mstore(_pPairing, calldataload(pA))
113
- mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
114
-
115
- // B
116
- mstore(add(_pPairing, 64), calldataload(pB))
117
- mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
118
- mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
119
- mstore(add(_pPairing, 160), calldataload(add(pB, 96)))
120
-
121
- // alpha1
122
- mstore(add(_pPairing, 192), alphax)
123
- mstore(add(_pPairing, 224), alphay)
124
-
125
- // beta2
126
- mstore(add(_pPairing, 256), betax1)
127
- mstore(add(_pPairing, 288), betax2)
128
- mstore(add(_pPairing, 320), betay1)
129
- mstore(add(_pPairing, 352), betay2)
130
-
131
- // vk_x
132
- mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
133
- mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
134
-
135
-
136
- // gamma2
137
- mstore(add(_pPairing, 448), gammax1)
138
- mstore(add(_pPairing, 480), gammax2)
139
- mstore(add(_pPairing, 512), gammay1)
140
- mstore(add(_pPairing, 544), gammay2)
141
-
142
- // C
143
- mstore(add(_pPairing, 576), calldataload(pC))
144
- mstore(add(_pPairing, 608), calldataload(add(pC, 32)))
145
-
146
- // delta2
147
- mstore(add(_pPairing, 640), deltax1)
148
- mstore(add(_pPairing, 672), deltax2)
149
- mstore(add(_pPairing, 704), deltay1)
150
- mstore(add(_pPairing, 736), deltay2)
151
-
152
-
153
- let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
154
-
155
- isOk := and(success, mload(_pPairing))
156
- }
157
-
158
- let pMem := mload(0x40)
159
- mstore(0x40, add(pMem, pLastMem))
160
-
161
- // Validate that all evaluations ∈ F
162
-
163
- checkField(calldataload(add(_pubSignals, 0)))
164
-
165
- checkField(calldataload(add(_pubSignals, 32)))
166
-
167
-
168
- // Validate all evaluations
169
- let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
170
-
171
- mstore(0, isValid)
172
- return(0, 0x20)
173
- }
174
- }
175
- }
19
+ import {Verifier_NfAnon} from "./impl/nf_anon.sol";
20
+
21
+ contract Groth16Verifier_NfAnon is Verifier_NfAnon {
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[2] 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,182 +1,36 @@
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_NfAnonNullifierTransfer {
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 = 13058539721432268764503714828619663141375444649879587444307036004161584042698;
47
- uint256 constant IC0y = 13231166779218028213678924006298697901762633361997917108298474235370208643631;
48
-
49
- uint256 constant IC1x = 849607412105127908955236592676452928309067622614671328242877911559171816381;
50
- uint256 constant IC1y = 9222683832419210809057694616641998563004311751553037755021147738067550736734;
51
-
52
- uint256 constant IC2x = 16469335622955445337328593001184226898027550673288315478807844082367562992169;
53
- uint256 constant IC2y = 14305423454287146943700407542874078083717688140560973373015596129936527323894;
54
-
55
- uint256 constant IC3x = 2173970074146945515801333097040165190744481352606396129963339167047945407546;
56
- uint256 constant IC3y = 4213666044264827852959682467546159931844165433052708261298581182042946212721;
57
-
58
-
59
- // Memory data
60
- uint16 constant pVk = 0;
61
- uint16 constant pPairing = 128;
62
-
63
- uint16 constant pLastMem = 896;
64
-
65
- function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[3] calldata _pubSignals) public view returns (bool) {
66
- assembly {
67
- function checkField(v) {
68
- if iszero(lt(v, r)) {
69
- mstore(0, 0)
70
- return(0, 0x20)
71
- }
72
- }
73
-
74
- // G1 function to multiply a G1 value(x,y) to value in an address
75
- function g1_mulAccC(pR, x, y, s) {
76
- let success
77
- let mIn := mload(0x40)
78
- mstore(mIn, x)
79
- mstore(add(mIn, 32), y)
80
- mstore(add(mIn, 64), s)
81
-
82
- success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64)
83
-
84
- if iszero(success) {
85
- mstore(0, 0)
86
- return(0, 0x20)
87
- }
88
-
89
- mstore(add(mIn, 64), mload(pR))
90
- mstore(add(mIn, 96), mload(add(pR, 32)))
91
-
92
- success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
93
-
94
- if iszero(success) {
95
- mstore(0, 0)
96
- return(0, 0x20)
97
- }
98
- }
99
-
100
- function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk {
101
- let _pPairing := add(pMem, pPairing)
102
- let _pVk := add(pMem, pVk)
103
-
104
- mstore(_pVk, IC0x)
105
- mstore(add(_pVk, 32), IC0y)
106
-
107
- // Compute the linear combination vk_x
108
-
109
- g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
110
-
111
- g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
112
-
113
- g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64)))
114
-
115
-
116
- // -A
117
- mstore(_pPairing, calldataload(pA))
118
- mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
119
-
120
- // B
121
- mstore(add(_pPairing, 64), calldataload(pB))
122
- mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
123
- mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
124
- mstore(add(_pPairing, 160), calldataload(add(pB, 96)))
125
-
126
- // alpha1
127
- mstore(add(_pPairing, 192), alphax)
128
- mstore(add(_pPairing, 224), alphay)
129
-
130
- // beta2
131
- mstore(add(_pPairing, 256), betax1)
132
- mstore(add(_pPairing, 288), betax2)
133
- mstore(add(_pPairing, 320), betay1)
134
- mstore(add(_pPairing, 352), betay2)
135
-
136
- // vk_x
137
- mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
138
- mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
139
-
140
-
141
- // gamma2
142
- mstore(add(_pPairing, 448), gammax1)
143
- mstore(add(_pPairing, 480), gammax2)
144
- mstore(add(_pPairing, 512), gammay1)
145
- mstore(add(_pPairing, 544), gammay2)
146
-
147
- // C
148
- mstore(add(_pPairing, 576), calldataload(pC))
149
- mstore(add(_pPairing, 608), calldataload(add(pC, 32)))
150
-
151
- // delta2
152
- mstore(add(_pPairing, 640), deltax1)
153
- mstore(add(_pPairing, 672), deltax2)
154
- mstore(add(_pPairing, 704), deltay1)
155
- mstore(add(_pPairing, 736), deltay2)
156
-
157
-
158
- let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
159
-
160
- isOk := and(success, mload(_pPairing))
161
- }
162
-
163
- let pMem := mload(0x40)
164
- mstore(0x40, add(pMem, pLastMem))
165
-
166
- // Validate that all evaluations ∈ F
167
-
168
- checkField(calldataload(add(_pubSignals, 0)))
169
-
170
- checkField(calldataload(add(_pubSignals, 32)))
171
-
172
- checkField(calldataload(add(_pubSignals, 64)))
173
-
174
-
175
- // Validate all evaluations
176
- let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
177
-
178
- mstore(0, isValid)
179
- return(0, 0x20)
180
- }
181
- }
182
- }
19
+ import {Verifier_NfAnonNullifierTransfer} from "./impl/nf_anon_nullifier_transfer.sol";
20
+
21
+ contract Groth16Verifier_NfAnonNullifierTransfer is
22
+ Verifier_NfAnonNullifierTransfer
23
+ {
24
+ function verify(
25
+ uint[2] calldata _pA,
26
+ uint[2][2] calldata _pB,
27
+ uint[2] calldata _pC,
28
+ uint[] calldata _pubSignals
29
+ ) public view returns (bool) {
30
+ uint256[3] memory fixedSizeInputs;
31
+ for (uint256 i = 0; i < fixedSizeInputs.length; i++) {
32
+ fixedSizeInputs[i] = _pubSignals[i];
33
+ }
34
+ return this.verifyProof(_pA, _pB, _pC, fixedSizeInputs);
35
+ }
36
+ }
@@ -1,189 +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_Withdraw {
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 = 6106103413938023487307204874536788037350276764606519282648243197514897278952;
47
- uint256 constant IC0y = 3528187465382696386595286033004082674373512005440682910298735608454252181690;
48
-
49
- uint256 constant IC1x = 4662932240032905513938339639979591690434004356592875276946986182417970341271;
50
- uint256 constant IC1y = 16733286924379241595351916588598405705645947681316067102766860496137808868265;
51
-
52
- uint256 constant IC2x = 10731888986847002440999584697187001873037906507381142562896634269462375949754;
53
- uint256 constant IC2y = 7917515192822230362458167996322490026140465057424702702781234959276845779224;
54
-
55
- uint256 constant IC3x = 19424719198946717269480314101461187486570565226402374347852842533345082752012;
56
- uint256 constant IC3y = 19329130570177469096377324066801922870880468297295439065859835039161258421175;
57
-
58
- uint256 constant IC4x = 8276041867071851396034700029402999489477040766526970805162551250935226101017;
59
- uint256 constant IC4y = 7668294809888478252940099646148799858250794898051062508098740609391502413691;
60
-
61
-
62
- // Memory data
63
- uint16 constant pVk = 0;
64
- uint16 constant pPairing = 128;
65
-
66
- uint16 constant pLastMem = 896;
67
-
68
- function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[4] calldata _pubSignals) public view returns (bool) {
69
- assembly {
70
- function checkField(v) {
71
- if iszero(lt(v, r)) {
72
- mstore(0, 0)
73
- return(0, 0x20)
74
- }
75
- }
76
-
77
- // G1 function to multiply a G1 value(x,y) to value in an address
78
- function g1_mulAccC(pR, x, y, s) {
79
- let success
80
- let mIn := mload(0x40)
81
- mstore(mIn, x)
82
- mstore(add(mIn, 32), y)
83
- mstore(add(mIn, 64), s)
84
-
85
- success := staticcall(sub(gas(), 2000), 7, mIn, 96, mIn, 64)
86
-
87
- if iszero(success) {
88
- mstore(0, 0)
89
- return(0, 0x20)
90
- }
91
-
92
- mstore(add(mIn, 64), mload(pR))
93
- mstore(add(mIn, 96), mload(add(pR, 32)))
94
-
95
- success := staticcall(sub(gas(), 2000), 6, mIn, 128, pR, 64)
96
-
97
- if iszero(success) {
98
- mstore(0, 0)
99
- return(0, 0x20)
100
- }
101
- }
102
-
103
- function checkPairing(pA, pB, pC, pubSignals, pMem) -> isOk {
104
- let _pPairing := add(pMem, pPairing)
105
- let _pVk := add(pMem, pVk)
106
-
107
- mstore(_pVk, IC0x)
108
- mstore(add(_pVk, 32), IC0y)
109
-
110
- // Compute the linear combination vk_x
111
-
112
- g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
113
-
114
- g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
115
-
116
- g1_mulAccC(_pVk, IC3x, IC3y, calldataload(add(pubSignals, 64)))
117
-
118
- g1_mulAccC(_pVk, IC4x, IC4y, calldataload(add(pubSignals, 96)))
119
-
120
-
121
- // -A
122
- mstore(_pPairing, calldataload(pA))
123
- mstore(add(_pPairing, 32), mod(sub(q, calldataload(add(pA, 32))), q))
124
-
125
- // B
126
- mstore(add(_pPairing, 64), calldataload(pB))
127
- mstore(add(_pPairing, 96), calldataload(add(pB, 32)))
128
- mstore(add(_pPairing, 128), calldataload(add(pB, 64)))
129
- mstore(add(_pPairing, 160), calldataload(add(pB, 96)))
130
-
131
- // alpha1
132
- mstore(add(_pPairing, 192), alphax)
133
- mstore(add(_pPairing, 224), alphay)
134
-
135
- // beta2
136
- mstore(add(_pPairing, 256), betax1)
137
- mstore(add(_pPairing, 288), betax2)
138
- mstore(add(_pPairing, 320), betay1)
139
- mstore(add(_pPairing, 352), betay2)
140
-
141
- // vk_x
142
- mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
143
- mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
144
-
145
-
146
- // gamma2
147
- mstore(add(_pPairing, 448), gammax1)
148
- mstore(add(_pPairing, 480), gammax2)
149
- mstore(add(_pPairing, 512), gammay1)
150
- mstore(add(_pPairing, 544), gammay2)
151
-
152
- // C
153
- mstore(add(_pPairing, 576), calldataload(pC))
154
- mstore(add(_pPairing, 608), calldataload(add(pC, 32)))
155
-
156
- // delta2
157
- mstore(add(_pPairing, 640), deltax1)
158
- mstore(add(_pPairing, 672), deltax2)
159
- mstore(add(_pPairing, 704), deltay1)
160
- mstore(add(_pPairing, 736), deltay2)
161
-
162
-
163
- let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
164
-
165
- isOk := and(success, mload(_pPairing))
166
- }
167
-
168
- let pMem := mload(0x40)
169
- mstore(0x40, add(pMem, pLastMem))
170
-
171
- // Validate that all evaluations ∈ F
172
-
173
- checkField(calldataload(add(_pubSignals, 0)))
174
-
175
- checkField(calldataload(add(_pubSignals, 32)))
176
-
177
- checkField(calldataload(add(_pubSignals, 64)))
178
-
179
- checkField(calldataload(add(_pubSignals, 96)))
180
-
181
-
182
- // Validate all evaluations
183
- let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
184
-
185
- mstore(0, isValid)
186
- return(0, 0x20)
187
- }
188
- }
189
- }
19
+ import {Verifier_Withdraw} from "./impl/withdraw.sol";
20
+
21
+ contract Groth16Verifier_Withdraw is Verifier_Withdraw {
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[4] 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
+ }