@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.
- package/README.md +76 -162
- package/config/eip170.ts +30 -0
- 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/IZetoLockHooks.sol +42 -0
- 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 +443 -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 +219 -0
- package/contracts/lib/zeto_lockable_lib.sol +460 -0
- package/contracts/lib/zeto_lockable_storage.sol +43 -0
- package/contracts/lib/zeto_non_fungible.sol +228 -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 +18 -3
- package/ignition/modules/lib/deps.ts +13 -0
- package/ignition/modules/test/tendecimals.ts +7 -1
- package/ignition/modules/zeto_anon.ts +3 -0
- package/ignition/modules/zeto_anon_burnable.ts +11 -7
- package/ignition/modules/zeto_anon_enc.ts +3 -0
- package/ignition/modules/zeto_anon_enc_nullifier.ts +34 -0
- package/ignition/modules/zeto_anon_enc_nullifier_kyc.ts +5 -2
- package/ignition/modules/zeto_anon_enc_nullifier_non_repudiation.ts +3 -0
- package/ignition/modules/zeto_anon_nullifier.ts +31 -4
- package/ignition/modules/zeto_anon_nullifier_burnable.ts +53 -16
- package/ignition/modules/zeto_anon_nullifier_kyc.ts +30 -12
- package/ignition/modules/zeto_anon_nullifier_qurrency.ts +3 -0
- package/ignition/modules/zeto_nf_anon.ts +3 -1
- package/ignition/modules/zeto_nf_anon_nullifier.ts +17 -12
- package/package.json +7 -3
- package/scripts/deploy_cloneable.ts +19 -10
- package/scripts/deploy_upgradeable.ts +9 -5
- package/scripts/lib/zeto_libraries.ts +47 -0
- package/scripts/tokens/Zeto_Anon.ts +6 -3
- package/scripts/tokens/Zeto_AnonBurnable.ts +4 -1
- package/scripts/tokens/Zeto_AnonEnc.ts +15 -3
- package/scripts/tokens/Zeto_AnonEncNullifier.ts +11 -8
- package/scripts/tokens/Zeto_AnonEncNullifierKyc.ts +7 -6
- package/scripts/tokens/Zeto_AnonEncNullifierNonRepudiation.ts +7 -6
- package/scripts/tokens/Zeto_AnonNullifier.ts +7 -6
- package/scripts/tokens/Zeto_AnonNullifierBurnable.ts +7 -6
- package/scripts/tokens/Zeto_AnonNullifierKyc.ts +7 -6
- package/scripts/tokens/Zeto_AnonNullifierQurrency.ts +7 -8
- package/scripts/tokens/Zeto_NfAnon.ts +5 -3
- package/scripts/tokens/Zeto_NfAnonNullifier.ts +7 -7
- package/test/factory.ts +55 -73
- package/test/lib/anon_nullifier_helpers.ts +89 -0
- package/test/lib/anon_zeto_helpers.ts +76 -0
- package/test/lib/deploy.ts +5 -2
- package/test/lib/eip170.ts +23 -0
- 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 -27
- package/test/utils.ts +144 -21
- package/test/zeto_anon.ts +956 -465
- package/test/zeto_anon_enc.ts +881 -143
- package/test/zeto_anon_enc_nullifier.ts +850 -39
- package/test/zeto_anon_enc_nullifier_kyc.ts +123 -182
- package/test/zeto_anon_enc_nullifier_non_repudiation.ts +80 -47
- package/test/zeto_anon_nullifier.ts +1212 -954
- package/test/zeto_anon_nullifier_kyc.ts +677 -656
- package/test/zeto_anon_nullifier_qurrency.ts +455 -307
- package/test/zeto_nf_anon.ts +737 -138
- package/test/zeto_nf_anon_nullifier.ts +876 -247
- 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
|
@@ -15,228 +15,131 @@
|
|
|
15
15
|
// limitations under the License.
|
|
16
16
|
pragma solidity ^0.8.27;
|
|
17
17
|
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
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
|
-
|
|
31
|
-
|
|
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
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
|
54
|
-
string
|
|
55
|
+
string calldata name,
|
|
56
|
+
string calldata symbol,
|
|
55
57
|
address initialOwner,
|
|
56
58
|
IZetoInitializable.VerifiersInfo calldata verifiers
|
|
57
|
-
) public initializer {
|
|
58
|
-
|
|
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
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
}
|