@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,368 +15,63 @@
|
|
|
15
15
|
// limitations under the License.
|
|
16
16
|
pragma solidity ^0.8.27;
|
|
17
17
|
|
|
18
|
-
import {
|
|
19
|
-
import {Groth16Verifier_Deposit} from "./verifiers/verifier_deposit.sol";
|
|
20
|
-
import {Groth16Verifier_WithdrawNullifier} from "./verifiers/verifier_withdraw_nullifier.sol";
|
|
21
|
-
import {Groth16Verifier_WithdrawNullifierBatch} from "./verifiers/verifier_withdraw_nullifier_batch.sol";
|
|
22
|
-
import {Groth16Verifier_AnonNullifierKycTransfer} from "./verifiers/verifier_anon_nullifier_kyc_transfer.sol";
|
|
23
|
-
import {Groth16Verifier_AnonNullifierKycTransferBatch} from "./verifiers/verifier_anon_nullifier_kyc_transfer_batch.sol";
|
|
24
|
-
import {Groth16Verifier_AnonNullifierKycTransferLocked} from "./verifiers/verifier_anon_nullifier_kyc_transferLocked.sol";
|
|
25
|
-
import {Groth16Verifier_AnonNullifierKycTransferLockedBatch} from "./verifiers/verifier_anon_nullifier_kyc_transferLocked_batch.sol";
|
|
26
|
-
import {ZetoNullifier} from "./lib/zeto_nullifier.sol";
|
|
27
|
-
import {ZetoFungibleWithdrawWithNullifiers} from "./lib/zeto_fungible_withdraw_nullifier.sol";
|
|
18
|
+
import {Zeto_AnonNullifier} from "./zeto_anon_nullifier.sol";
|
|
28
19
|
import {Registry} from "./lib/registry.sol";
|
|
29
|
-
import {
|
|
30
|
-
import {IZetoInitializable} from "./lib/interfaces/izeto_initializable.sol";
|
|
31
|
-
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
|
|
32
|
-
import {console} from "hardhat/console.sol";
|
|
20
|
+
import {IZetoInitializable} from "./lib/interfaces/IZetoInitializable.sol";
|
|
33
21
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
uint256 constant INPUT_SIZE_LOCKED = 9;
|
|
37
|
-
uint256 constant BATCH_INPUT_SIZE_LOCKED = 33;
|
|
38
|
-
|
|
39
|
-
/// @title A sample implementation of a Zeto based fungible token with anonymity and history masking
|
|
22
|
+
/// @title A sample implementation of a Zeto based fungible token with
|
|
23
|
+
/// anonymity, history masking via nullifiers, and KYC enforcement.
|
|
40
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.
|
|
41
28
|
/// @dev The proof has the following statements:
|
|
42
29
|
/// - each value in the output commitments must be a positive number in the range 0 ~ (2\*\*40 - 1)
|
|
43
30
|
/// - the sum of the nullified values match the sum of output values
|
|
44
31
|
/// - the hashes in the input and output match the hash(value, salt, owner public key) formula
|
|
45
32
|
/// - the sender possesses the private BabyJubjub key, whose public key is part of the pre-image of the input commitment hashes, which match the corresponding nullifiers
|
|
46
33
|
/// - the nullifiers represent input commitments that are included in a Sparse Merkle Tree represented by the root hash
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
34
|
+
/// - the input/output owners are members of the {Registry}'s identities tree
|
|
35
|
+
///
|
|
36
|
+
/// The {extraInputs} / {extraInputsForDeposit} overrides surface the
|
|
37
|
+
/// identities tree's root as an additional public input to the
|
|
38
|
+
/// transfer / deposit circuits, which is what wires KYC enforcement
|
|
39
|
+
/// into the same proof system used for value conservation.
|
|
40
|
+
contract Zeto_AnonNullifierKyc is Zeto_AnonNullifier, Registry {
|
|
41
|
+
/// @dev Lock the implementation contract on construction. The parent
|
|
42
|
+
/// {Zeto_AnonNullifier} already does this via its own constructor
|
|
43
|
+
/// (which Solidity invokes as part of every leaf's deployment),
|
|
44
|
+
/// but we restate it here so the H-2 protection survives any
|
|
45
|
+
/// future refactor that changes the inheritance graph.
|
|
46
|
+
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
47
|
+
constructor() {
|
|
48
|
+
_disableInitializers();
|
|
49
|
+
}
|
|
60
50
|
|
|
61
51
|
function initialize(
|
|
62
|
-
string
|
|
63
|
-
string
|
|
52
|
+
string calldata name,
|
|
53
|
+
string calldata symbol,
|
|
64
54
|
address initialOwner,
|
|
65
55
|
IZetoInitializable.VerifiersInfo calldata verifiers
|
|
66
|
-
) public initializer {
|
|
56
|
+
) public override initializer {
|
|
57
|
+
__ZetoAnonNullifier_init(name, symbol, initialOwner, verifiers);
|
|
67
58
|
__Registry_init();
|
|
68
|
-
__ZetoNullifier_init(name, symbol, initialOwner);
|
|
69
|
-
__ZetoFungibleWithdrawWithNullifiers_init(
|
|
70
|
-
(Groth16Verifier_Deposit)(verifiers.depositVerifier),
|
|
71
|
-
(Groth16Verifier_WithdrawNullifier)(verifiers.withdrawVerifier),
|
|
72
|
-
(Groth16Verifier_WithdrawNullifierBatch)(
|
|
73
|
-
verifiers.batchWithdrawVerifier
|
|
74
|
-
)
|
|
75
|
-
);
|
|
76
|
-
_verifier = (Groth16Verifier_AnonNullifierKycTransfer)(
|
|
77
|
-
verifiers.verifier
|
|
78
|
-
);
|
|
79
|
-
_batchVerifier = (Groth16Verifier_AnonNullifierKycTransferBatch)(
|
|
80
|
-
verifiers.batchVerifier
|
|
81
|
-
);
|
|
82
|
-
_lockVerifier = (Groth16Verifier_AnonNullifierKycTransferLocked)(
|
|
83
|
-
verifiers.lockVerifier
|
|
84
|
-
);
|
|
85
|
-
_batchLockVerifier = (
|
|
86
|
-
Groth16Verifier_AnonNullifierKycTransferLockedBatch
|
|
87
|
-
)(verifiers.batchLockVerifier);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function _authorizeUpgrade(address) internal override onlyOwner {}
|
|
91
|
-
|
|
92
|
-
function constructPublicInputs(
|
|
93
|
-
uint256[] memory nullifiers,
|
|
94
|
-
uint256[] memory outputs,
|
|
95
|
-
uint256 root,
|
|
96
|
-
uint256 size,
|
|
97
|
-
bool locked
|
|
98
|
-
) internal view returns (uint256[] memory publicInputs) {
|
|
99
|
-
publicInputs = new uint256[](size);
|
|
100
|
-
uint256 piIndex = 0;
|
|
101
|
-
// copy input nullifiers
|
|
102
|
-
for (uint256 i = 0; i < nullifiers.length; i++) {
|
|
103
|
-
publicInputs[piIndex++] = nullifiers[i];
|
|
104
|
-
}
|
|
105
|
-
// when verifying locked transfers, additional public input
|
|
106
|
-
// for the lock delegate
|
|
107
|
-
if (locked) {
|
|
108
|
-
publicInputs[piIndex++] = uint256(uint160(msg.sender));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// copy root
|
|
112
|
-
publicInputs[piIndex++] = root;
|
|
113
|
-
|
|
114
|
-
// populate enables
|
|
115
|
-
for (uint256 i = 0; i < nullifiers.length; i++) {
|
|
116
|
-
publicInputs[piIndex++] = (nullifiers[i] == 0) ? 0 : 1;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// copy identities root
|
|
120
|
-
publicInputs[piIndex++] = getIdentitiesRoot();
|
|
121
|
-
|
|
122
|
-
// copy output commitments
|
|
123
|
-
for (uint256 i = 0; i < outputs.length; i++) {
|
|
124
|
-
publicInputs[piIndex++] = outputs[i];
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return publicInputs;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @dev the main function of the contract.
|
|
132
|
-
*
|
|
133
|
-
* @param nullifiers Array of nullifiers that are secretly bound to UTXOs to be spent by the transaction.
|
|
134
|
-
* @param outputs Array of new UTXOs to generate, for future transactions to spend.
|
|
135
|
-
* @param root The root hash of the Sparse Merkle Tree that contains the nullifiers.
|
|
136
|
-
* @param proof A zero knowledge proof that the submitter is authorized to spend the inputs, and
|
|
137
|
-
* that the outputs are valid in terms of obeying mass conservation rules.
|
|
138
|
-
*
|
|
139
|
-
* Emits a {UTXOTransfer} event.
|
|
140
|
-
*/
|
|
141
|
-
function transfer(
|
|
142
|
-
uint256[] memory nullifiers,
|
|
143
|
-
uint256[] memory outputs,
|
|
144
|
-
uint256 root,
|
|
145
|
-
Commonlib.Proof calldata proof,
|
|
146
|
-
bytes calldata data
|
|
147
|
-
) public returns (bool) {
|
|
148
|
-
// Check and pad inputs and outputs based on the max size
|
|
149
|
-
nullifiers = checkAndPadCommitments(nullifiers);
|
|
150
|
-
outputs = checkAndPadCommitments(outputs);
|
|
151
|
-
validateTransactionProposal(nullifiers, outputs, root, false);
|
|
152
|
-
verifyProof(nullifiers, outputs, root, proof);
|
|
153
|
-
uint256[] memory empty;
|
|
154
|
-
processInputsAndOutputs(nullifiers, outputs, empty, address(0));
|
|
155
|
-
|
|
156
|
-
uint256[] memory nullifierArray = new uint256[](nullifiers.length);
|
|
157
|
-
uint256[] memory outputArray = new uint256[](outputs.length);
|
|
158
|
-
for (uint256 i = 0; i < nullifiers.length; ++i) {
|
|
159
|
-
nullifierArray[i] = nullifiers[i];
|
|
160
|
-
outputArray[i] = outputs[i];
|
|
161
|
-
}
|
|
162
|
-
emit UTXOTransfer(nullifierArray, outputArray, msg.sender, data);
|
|
163
|
-
return true;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function transferLocked(
|
|
167
|
-
uint256[] memory nullifiers,
|
|
168
|
-
uint256[] memory outputs,
|
|
169
|
-
uint256 root,
|
|
170
|
-
Commonlib.Proof calldata proof,
|
|
171
|
-
bytes calldata data
|
|
172
|
-
) public returns (bool) {
|
|
173
|
-
nullifiers = checkAndPadCommitments(nullifiers);
|
|
174
|
-
outputs = checkAndPadCommitments(outputs);
|
|
175
|
-
validateTransactionProposal(nullifiers, outputs, root, true);
|
|
176
|
-
verifyProofLocked(nullifiers, outputs, root, proof);
|
|
177
|
-
uint256[] memory empty;
|
|
178
|
-
processInputsAndOutputs(nullifiers, outputs, empty, address(0));
|
|
179
|
-
|
|
180
|
-
uint256[] memory nullifierArray = new uint256[](nullifiers.length);
|
|
181
|
-
uint256[] memory outputArray = new uint256[](outputs.length);
|
|
182
|
-
for (uint256 i = 0; i < nullifiers.length; ++i) {
|
|
183
|
-
nullifierArray[i] = nullifiers[i];
|
|
184
|
-
outputArray[i] = outputs[i];
|
|
185
|
-
}
|
|
186
|
-
emit UTXOTransfer(nullifierArray, outputArray, msg.sender, data);
|
|
187
|
-
return true;
|
|
188
59
|
}
|
|
189
60
|
|
|
190
|
-
function
|
|
191
|
-
uint256
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
bytes calldata data
|
|
195
|
-
) public {
|
|
196
|
-
_deposit(amount, outputs, proof);
|
|
197
|
-
_mint(outputs, data);
|
|
61
|
+
function extraInputs() internal view override returns (uint256[] memory) {
|
|
62
|
+
uint256[] memory extras = new uint256[](1);
|
|
63
|
+
extras[0] = getIdentitiesRoot();
|
|
64
|
+
return extras;
|
|
198
65
|
}
|
|
199
66
|
|
|
200
|
-
function
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
uint256
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
outputs[0] = output;
|
|
210
|
-
// Check and pad inputs and outputs based on the max size
|
|
211
|
-
nullifiers = checkAndPadCommitments(nullifiers);
|
|
212
|
-
outputs = checkAndPadCommitments(outputs);
|
|
213
|
-
validateTransactionProposal(nullifiers, outputs, root, false);
|
|
214
|
-
|
|
215
|
-
_withdrawWithNullifiers(amount, nullifiers, output, root, proof);
|
|
216
|
-
uint256[] memory empty;
|
|
217
|
-
processInputsAndOutputs(nullifiers, outputs, empty, address(0));
|
|
218
|
-
emit UTXOWithdraw(amount, nullifiers, output, msg.sender, data);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function mint(
|
|
222
|
-
uint256[] memory utxos,
|
|
223
|
-
bytes calldata data
|
|
224
|
-
) public onlyOwner {
|
|
225
|
-
_mint(utxos, data);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function lock(
|
|
229
|
-
uint256[] memory nullifiers,
|
|
230
|
-
uint256[] memory outputs,
|
|
231
|
-
uint256[] memory lockedOutputs,
|
|
232
|
-
uint256 root,
|
|
233
|
-
Commonlib.Proof calldata proof,
|
|
234
|
-
address delegate,
|
|
235
|
-
bytes calldata data
|
|
236
|
-
) public {
|
|
237
|
-
// merge the outputs and lockedOutputs and do a regular transfer
|
|
238
|
-
uint256[] memory allOutputs = new uint256[](
|
|
239
|
-
outputs.length + lockedOutputs.length
|
|
240
|
-
);
|
|
241
|
-
for (uint256 i = 0; i < outputs.length; i++) {
|
|
242
|
-
allOutputs[i] = outputs[i];
|
|
243
|
-
}
|
|
244
|
-
for (uint256 i = 0; i < lockedOutputs.length; i++) {
|
|
245
|
-
allOutputs[outputs.length + i] = lockedOutputs[i];
|
|
246
|
-
}
|
|
247
|
-
nullifiers = checkAndPadCommitments(nullifiers);
|
|
248
|
-
allOutputs = checkAndPadCommitments(allOutputs);
|
|
249
|
-
validateTransactionProposal(nullifiers, allOutputs, root, false);
|
|
250
|
-
verifyProof(nullifiers, allOutputs, root, proof);
|
|
251
|
-
|
|
252
|
-
processNullifiers(nullifiers);
|
|
253
|
-
|
|
254
|
-
// lock the intended outputs
|
|
255
|
-
_lock(nullifiers, outputs, lockedOutputs, delegate, data);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function unlock(
|
|
259
|
-
uint256[] memory nullifiers,
|
|
260
|
-
uint256[] memory outputs,
|
|
261
|
-
uint256 root,
|
|
262
|
-
Commonlib.Proof calldata proof,
|
|
263
|
-
bytes calldata data
|
|
264
|
-
) public {
|
|
265
|
-
transferLocked(nullifiers, outputs, root, proof, data);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function verifyProof(
|
|
269
|
-
uint256[] memory nullifiers,
|
|
270
|
-
uint256[] memory outputs,
|
|
271
|
-
uint256 root,
|
|
272
|
-
Commonlib.Proof calldata proof
|
|
273
|
-
) public view returns (bool) {
|
|
274
|
-
// Check the proof
|
|
275
|
-
if (nullifiers.length > 2 || outputs.length > 2) {
|
|
276
|
-
uint256[] memory publicInputs = constructPublicInputs(
|
|
277
|
-
nullifiers,
|
|
278
|
-
outputs,
|
|
279
|
-
root,
|
|
280
|
-
BATCH_INPUT_SIZE,
|
|
281
|
-
false
|
|
282
|
-
);
|
|
283
|
-
// construct the public inputs for batchVerifier
|
|
284
|
-
uint256[BATCH_INPUT_SIZE] memory fixedSizeInputs;
|
|
285
|
-
for (uint256 i = 0; i < fixedSizeInputs.length; i++) {
|
|
286
|
-
fixedSizeInputs[i] = publicInputs[i];
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// Check the proof using batchVerifier
|
|
290
|
-
require(
|
|
291
|
-
_batchVerifier.verifyProof(
|
|
292
|
-
proof.pA,
|
|
293
|
-
proof.pB,
|
|
294
|
-
proof.pC,
|
|
295
|
-
fixedSizeInputs
|
|
296
|
-
),
|
|
297
|
-
"Invalid proof (batch)"
|
|
298
|
-
);
|
|
299
|
-
} else {
|
|
300
|
-
uint256[] memory publicInputs = constructPublicInputs(
|
|
301
|
-
nullifiers,
|
|
302
|
-
outputs,
|
|
303
|
-
root,
|
|
304
|
-
INPUT_SIZE,
|
|
305
|
-
false
|
|
306
|
-
);
|
|
307
|
-
// construct the public inputs for verifier
|
|
308
|
-
uint256[INPUT_SIZE] memory fixedSizeInputs;
|
|
309
|
-
for (uint256 i = 0; i < fixedSizeInputs.length; i++) {
|
|
310
|
-
fixedSizeInputs[i] = publicInputs[i];
|
|
311
|
-
}
|
|
312
|
-
// Check the proof
|
|
313
|
-
require(
|
|
314
|
-
_verifier.verifyProof(
|
|
315
|
-
proof.pA,
|
|
316
|
-
proof.pB,
|
|
317
|
-
proof.pC,
|
|
318
|
-
fixedSizeInputs
|
|
319
|
-
),
|
|
320
|
-
"Invalid proof"
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
return true;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
function verifyProofLocked(
|
|
327
|
-
uint256[] memory nullifiers,
|
|
328
|
-
uint256[] memory outputs,
|
|
329
|
-
uint256 root,
|
|
330
|
-
Commonlib.Proof calldata proof
|
|
331
|
-
) public view returns (bool) {
|
|
332
|
-
if (nullifiers.length > 2 || outputs.length > 2) {
|
|
333
|
-
uint256[] memory publicInputs = constructPublicInputs(
|
|
334
|
-
nullifiers,
|
|
335
|
-
outputs,
|
|
336
|
-
root,
|
|
337
|
-
BATCH_INPUT_SIZE_LOCKED,
|
|
338
|
-
true
|
|
339
|
-
);
|
|
340
|
-
// construct the public inputs for batchVerifier
|
|
341
|
-
uint256[BATCH_INPUT_SIZE_LOCKED] memory fixedSizeInputs;
|
|
342
|
-
for (uint256 i = 0; i < fixedSizeInputs.length; i++) {
|
|
343
|
-
fixedSizeInputs[i] = publicInputs[i];
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// Check the proof using batchVerifier
|
|
347
|
-
require(
|
|
348
|
-
_batchLockVerifier.verifyProof(
|
|
349
|
-
proof.pA,
|
|
350
|
-
proof.pB,
|
|
351
|
-
proof.pC,
|
|
352
|
-
fixedSizeInputs
|
|
353
|
-
),
|
|
354
|
-
"Invalid proof (batch)"
|
|
355
|
-
);
|
|
356
|
-
} else {
|
|
357
|
-
uint256[] memory publicInputs = constructPublicInputs(
|
|
358
|
-
nullifiers,
|
|
359
|
-
outputs,
|
|
360
|
-
root,
|
|
361
|
-
INPUT_SIZE_LOCKED,
|
|
362
|
-
true
|
|
363
|
-
);
|
|
364
|
-
// construct the public inputs for verifier
|
|
365
|
-
uint256[INPUT_SIZE_LOCKED] memory fixedSizeInputs;
|
|
366
|
-
for (uint256 i = 0; i < fixedSizeInputs.length; i++) {
|
|
367
|
-
fixedSizeInputs[i] = publicInputs[i];
|
|
368
|
-
}
|
|
369
|
-
// Check the proof
|
|
370
|
-
require(
|
|
371
|
-
_lockVerifier.verifyProof(
|
|
372
|
-
proof.pA,
|
|
373
|
-
proof.pB,
|
|
374
|
-
proof.pC,
|
|
375
|
-
fixedSizeInputs
|
|
376
|
-
),
|
|
377
|
-
"Invalid proof"
|
|
378
|
-
);
|
|
379
|
-
}
|
|
380
|
-
return true;
|
|
67
|
+
function extraInputsForDeposit()
|
|
68
|
+
internal
|
|
69
|
+
view
|
|
70
|
+
override
|
|
71
|
+
returns (uint256[] memory)
|
|
72
|
+
{
|
|
73
|
+
uint256[] memory extras = new uint256[](1);
|
|
74
|
+
extras[0] = getIdentitiesRoot();
|
|
75
|
+
return extras;
|
|
381
76
|
}
|
|
382
77
|
}
|