@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
@@ -15,228 +15,131 @@
15
15
  // limitations under the License.
16
16
  pragma solidity ^0.8.27;
17
17
 
18
- import {IZeto} from "./lib/interfaces/izeto.sol";
19
- import {Groth16Verifier_Deposit} from "./verifiers/verifier_deposit.sol";
20
- import {Groth16Verifier_Withdraw} from "./verifiers/verifier_withdraw.sol";
21
- import {Groth16Verifier_WithdrawBatch} from "./verifiers/verifier_withdraw_batch.sol";
22
- import {Groth16Verifier_AnonEnc} from "./verifiers/verifier_anon_enc.sol";
23
- import {Groth16Verifier_AnonEncBatch} from "./verifiers/verifier_anon_enc_batch.sol";
24
- import {ZetoFungibleWithdraw} from "./lib/zeto_fungible_withdraw.sol";
25
- import {ZetoBase} from "./lib/zeto_base.sol";
26
- import {Commonlib} from "./lib/common.sol";
27
- import {IZetoInitializable} from "./lib/interfaces/izeto_initializable.sol";
28
- import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
18
+ import {Commonlib} from "./lib/common/common.sol";
19
+ import {IZetoInitializable} from "./lib/interfaces/IZetoInitializable.sol";
20
+ import {Zeto_Anon} from "./zeto_anon.sol";
29
21
 
30
- uint256 constant INPUT_SIZE = 15;
31
- uint256 constant BATCH_INPUT_SIZE = 63;
32
-
33
- /// @title A sample implementation of a Zeto based fungible token with anonymity, and encryption
22
+ /// @title A sample implementation of a Zeto based fungible token with
23
+ /// anonymity and encryption (no nullifier history masking).
34
24
  /// @author Kaleido, Inc.
25
+ /// @notice Decimals: this token uses **4** decimals, inherited from
26
+ /// {ZetoCommon.decimals}. Indexers and UIs reading this contract
27
+ /// directly should treat balances accordingly.
35
28
  /// @dev The proof has the following statements:
36
29
  /// - each value in the output commitments must be a positive number in the range 0 ~ (2\*\*40 - 1)
37
30
  /// - the sum of the input values match the sum of output values
38
31
  /// - the hashes in the input and output match the hash(value, salt, owner public key) formula
39
32
  /// - the sender possesses the private BabyJubjub key, whose public key is part of the pre-image of the input commitment hashes
40
- /// - the encrypted value in the input is derived from the receiver's UTXO value and encrypted with a shared secret using
33
+ /// - the encrypted value in the output is derived from the receiver's UTXO value and encrypted with a shared secret using
41
34
  /// the ECDH protocol between the sender and receiver (this guarantees data availability for the receiver)
42
- contract Zeto_AnonEnc is
43
- IZeto,
44
- IZetoInitializable,
45
- ZetoBase,
46
- ZetoFungibleWithdraw,
47
- UUPSUpgradeable
48
- {
49
- Groth16Verifier_AnonEnc internal _verifier;
50
- Groth16Verifier_AnonEncBatch internal _batchVerifier;
35
+ ///
36
+ /// Composes {Zeto_Anon} (transfer + ILockableCapability lifecycle) with
37
+ /// an encryption-aware {emitTransferEvent}/{constructPublicInputs}
38
+ /// override. The proof bytes carry the additional encryption metadata
39
+ /// (ECDH public key, encryption nonce, encrypted values) and a
40
+ /// Groth16 proof; we decode them in the public-inputs builder so the
41
+ /// circuit verifies the encryption commitments alongside value
42
+ /// conservation.
43
+ contract Zeto_AnonEnc is Zeto_Anon {
44
+ /// @dev Lock the implementation contract on construction. The parent
45
+ /// {Zeto_Anon} already does this via its own constructor (which
46
+ /// Solidity invokes as part of every leaf's deployment), but we
47
+ /// restate it here so the H-2 protection survives any future
48
+ /// refactor that changes the inheritance graph.
49
+ /// @custom:oz-upgrades-unsafe-allow constructor
50
+ constructor() {
51
+ _disableInitializers();
52
+ }
51
53
 
52
54
  function initialize(
53
- string memory name,
54
- string memory symbol,
55
+ string calldata name,
56
+ string calldata symbol,
55
57
  address initialOwner,
56
58
  IZetoInitializable.VerifiersInfo calldata verifiers
57
- ) public initializer {
58
- __ZetoBase_init(name, symbol, initialOwner);
59
- __ZetoFungibleWithdraw_init(
60
- (Groth16Verifier_Deposit)(verifiers.depositVerifier),
61
- (Groth16Verifier_Withdraw)(verifiers.withdrawVerifier),
62
- (Groth16Verifier_WithdrawBatch)(verifiers.batchWithdrawVerifier)
63
- );
64
- _verifier = (Groth16Verifier_AnonEnc)(verifiers.verifier);
65
- _batchVerifier = (Groth16Verifier_AnonEncBatch)(
66
- verifiers.batchVerifier
67
- );
59
+ ) public virtual override initializer {
60
+ __ZetoAnon_init(name, symbol, initialOwner, verifiers);
68
61
  }
69
62
 
70
- function _authorizeUpgrade(address) internal override onlyOwner {}
63
+ function emitTransferEvent(
64
+ uint256[] memory inputs,
65
+ uint256[] memory outputs,
66
+ bytes memory proof,
67
+ bytes memory data
68
+ ) internal virtual override {
69
+ (
70
+ uint256 encryptionNonce,
71
+ uint256[2] memory ecdhPublicKey,
72
+ uint256[] memory encryptedValues,
73
+
74
+ ) = abi.decode(
75
+ proof,
76
+ (uint256, uint256[2], uint256[], Commonlib.Proof)
77
+ );
78
+ emit UTXOTransferWithEncryptedValues(
79
+ inputs,
80
+ outputs,
81
+ encryptionNonce,
82
+ ecdhPublicKey,
83
+ encryptedValues,
84
+ msg.sender,
85
+ data
86
+ );
87
+ }
71
88
 
89
+ /// @dev Layout of `proof` (ABI-encoded tuple):
90
+ /// (uint256 encryptionNonce,
91
+ /// uint256[2] ecdhPublicKey,
92
+ /// uint256[] encryptedValues,
93
+ /// Commonlib.Proof groth16Proof)
94
+ ///
95
+ /// `inputsLocked` is ignored: the encryption circuit's public-input
96
+ /// layout is identical regardless of whether the inputs were
97
+ /// previously locked, since the lock state is enforced at the
98
+ /// Zeto layer (via {ZetoFungible}) rather than inside the circuit.
72
99
  function constructPublicInputs(
73
100
  uint256[] memory inputs,
74
101
  uint256[] memory outputs,
75
- uint256 encryptionNonce,
76
- uint256[2] memory ecdhPublicKey,
77
- uint256[] memory encryptedValues,
78
- uint256 size
79
- ) internal pure returns (uint256[] memory publicInputs) {
80
- publicInputs = new uint256[](size);
102
+ bytes memory proof,
103
+ bool /* inputsLocked */
104
+ )
105
+ internal
106
+ view
107
+ virtual
108
+ override
109
+ returns (uint256[] memory, Commonlib.Proof memory)
110
+ {
111
+ (
112
+ uint256 encryptionNonce,
113
+ uint256[2] memory ecdhPublicKey,
114
+ uint256[] memory encryptedValues,
115
+ Commonlib.Proof memory proofStruct
116
+ ) = abi.decode(
117
+ proof,
118
+ (uint256, uint256[2], uint256[], Commonlib.Proof)
119
+ );
120
+
121
+ // Layout: ecdhPublicKey ++ encryptedValues ++ inputs ++ outputs ++ encryptionNonce
122
+ uint256 size = ecdhPublicKey.length +
123
+ encryptedValues.length +
124
+ inputs.length +
125
+ outputs.length +
126
+ 1;
127
+ uint256[] memory publicInputs = new uint256[](size);
81
128
  uint256 piIndex = 0;
82
- // copy the ecdh public key
83
129
  for (uint256 i = 0; i < ecdhPublicKey.length; ++i) {
84
130
  publicInputs[piIndex++] = ecdhPublicKey[i];
85
131
  }
86
-
87
- // copy the encrypted value, salt and parity bit
88
132
  for (uint256 i = 0; i < encryptedValues.length; ++i) {
89
133
  publicInputs[piIndex++] = encryptedValues[i];
90
134
  }
91
- // copy input commitments
92
135
  for (uint256 i = 0; i < inputs.length; i++) {
93
136
  publicInputs[piIndex++] = inputs[i];
94
137
  }
95
-
96
- // copy output commitments
97
138
  for (uint256 i = 0; i < outputs.length; i++) {
98
139
  publicInputs[piIndex++] = outputs[i];
99
140
  }
100
-
101
- // copy encryption nonce
102
141
  publicInputs[piIndex++] = encryptionNonce;
103
142
 
104
- return publicInputs;
105
- }
106
-
107
- /**
108
- * @dev the main function of the contract.
109
- *
110
- * @param inputs Array of UTXOs to be spent by the transaction.
111
- * @param outputs Array of new UTXOs to generate, for future transactions to spend.
112
- * @param proof A zero knowledge proof that the submitter is authorized to spend the inputs, and
113
- * that the outputs are valid in terms of obeying mass conservation rules.
114
- *
115
- * Emits a {UTXOTransferWithEncryptedValues} event.
116
- */
117
- function transfer(
118
- uint256[] memory inputs,
119
- uint256[] memory outputs,
120
- uint256 encryptionNonce,
121
- uint256[2] memory ecdhPublicKey,
122
- uint256[] memory encryptedValues,
123
- Commonlib.Proof calldata proof,
124
- bytes calldata data
125
- ) public returns (bool) {
126
- // Check and pad commitments
127
- inputs = checkAndPadCommitments(inputs);
128
- outputs = checkAndPadCommitments(outputs);
129
- uint256[] memory lockedOutputs;
130
- validateTransactionProposal(inputs, outputs, lockedOutputs, false);
131
-
132
- // Check the proof
133
- if (inputs.length > 2 || outputs.length > 2) {
134
- uint256[] memory publicInputs = constructPublicInputs(
135
- inputs,
136
- outputs,
137
- encryptionNonce,
138
- ecdhPublicKey,
139
- encryptedValues,
140
- BATCH_INPUT_SIZE
141
- );
142
- // construct the public inputs for batchVerifier
143
- uint256[BATCH_INPUT_SIZE] memory fixedSizeInputs;
144
- for (uint256 i = 0; i < fixedSizeInputs.length; i++) {
145
- fixedSizeInputs[i] = publicInputs[i];
146
- }
147
-
148
- // Check the proof using batchVerifier
149
- require(
150
- _batchVerifier.verifyProof(
151
- proof.pA,
152
- proof.pB,
153
- proof.pC,
154
- fixedSizeInputs
155
- ),
156
- "Invalid proof (batch)"
157
- );
158
- } else {
159
- uint256[] memory publicInputs = constructPublicInputs(
160
- inputs,
161
- outputs,
162
- encryptionNonce,
163
- ecdhPublicKey,
164
- encryptedValues,
165
- INPUT_SIZE
166
- );
167
- // construct the public inputs for verifier
168
- uint256[INPUT_SIZE] memory fixedSizeInputs;
169
- for (uint256 i = 0; i < fixedSizeInputs.length; i++) {
170
- fixedSizeInputs[i] = publicInputs[i];
171
- }
172
- // Check the proof
173
- require(
174
- _verifier.verifyProof(
175
- proof.pA,
176
- proof.pB,
177
- proof.pC,
178
- fixedSizeInputs
179
- ),
180
- "Invalid proof"
181
- );
182
- }
183
-
184
- processInputsAndOutputs(inputs, outputs, lockedOutputs, false);
185
-
186
- uint256[] memory encryptedValuesArray = new uint256[](
187
- encryptedValues.length
188
- );
189
- for (uint256 i = 0; i < encryptedValues.length; ++i) {
190
- encryptedValuesArray[i] = encryptedValues[i];
191
- }
192
-
193
- emit UTXOTransferWithEncryptedValues(
194
- inputs,
195
- outputs,
196
- encryptionNonce,
197
- ecdhPublicKey,
198
- encryptedValuesArray,
199
- msg.sender,
200
- data
201
- );
202
- return true;
203
- }
204
-
205
- function deposit(
206
- uint256 amount,
207
- uint256[] memory outputs,
208
- Commonlib.Proof calldata proof,
209
- bytes calldata data
210
- ) public {
211
- _deposit(amount, outputs, proof);
212
- _mint(outputs, data);
213
- }
214
-
215
- function withdraw(
216
- uint256 amount,
217
- uint256[] memory inputs,
218
- uint256 output,
219
- Commonlib.Proof calldata proof,
220
- bytes calldata data
221
- ) public {
222
- uint256[] memory outputs = new uint256[](inputs.length);
223
- outputs[0] = output;
224
- // Check and pad commitments
225
- inputs = checkAndPadCommitments(inputs);
226
- outputs = checkAndPadCommitments(outputs);
227
- uint256[] memory lockedOutputs;
228
- validateTransactionProposal(inputs, outputs, lockedOutputs, false);
229
-
230
- _withdraw(amount, inputs, output, proof);
231
-
232
- processInputsAndOutputs(inputs, outputs, lockedOutputs, false);
233
- emit UTXOWithdraw(amount, inputs, output, msg.sender, data);
234
- }
235
-
236
- function mint(
237
- uint256[] memory utxos,
238
- bytes calldata data
239
- ) public onlyOwner {
240
- _mint(utxos, data);
143
+ return (publicInputs, proofStruct);
241
144
  }
242
145
  }