@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,408 +15,264 @@
|
|
|
15
15
|
// limitations under the License.
|
|
16
16
|
pragma solidity ^0.8.27;
|
|
17
17
|
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {Groth16Verifier_Deposit} from "./verifiers/verifier_deposit.sol";
|
|
22
|
-
import {Groth16Verifier_WithdrawNullifier} from "./verifiers/verifier_withdraw_nullifier.sol";
|
|
23
|
-
import {Groth16Verifier_WithdrawNullifierBatch} from "./verifiers/verifier_withdraw_nullifier_batch.sol";
|
|
24
|
-
import {Groth16Verifier_AnonNullifierQurrencyTransfer} from "./verifiers/verifier_anon_nullifier_qurrency_transfer.sol";
|
|
25
|
-
// import {Groth16Verifier_AnonNullifierTransferLocked} from "./verifiers/verifier_anon_nullifier_transferLocked.sol";
|
|
26
|
-
import {Groth16Verifier_AnonNullifierQurrencyTransferBatch} from "./verifiers/verifier_anon_nullifier_qurrency_transfer_batch.sol";
|
|
27
|
-
// import {Groth16Verifier_AnonNullifierTransferLockedBatch} from "./verifiers/verifier_anon_nullifier_transferLocked_batch.sol";
|
|
28
|
-
import {ZetoNullifier} from "./lib/zeto_nullifier.sol";
|
|
29
|
-
import {ZetoFungibleWithdrawWithNullifiers} from "./lib/zeto_fungible_withdraw_nullifier.sol";
|
|
30
|
-
import {Commonlib} from "./lib/common.sol";
|
|
31
|
-
import {IZetoInitializable} from "./lib/interfaces/izeto_initializable.sol";
|
|
32
|
-
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
|
|
33
|
-
import {console} from "hardhat/console.sol";
|
|
18
|
+
import {Commonlib} from "./lib/common/common.sol";
|
|
19
|
+
import {IZetoInitializable} from "./lib/interfaces/IZetoInitializable.sol";
|
|
20
|
+
import {Zeto_AnonNullifier} from "./zeto_anon_nullifier.sol";
|
|
34
21
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// uint256 constant BATCH_INPUT_SIZE_LOCKED = 32;
|
|
40
|
-
|
|
41
|
-
/// @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 post-quantum
|
|
24
|
+
/// ML-KEM encryption envelopes for transferred values.
|
|
42
25
|
/// @author Kaleido, Inc.
|
|
43
|
-
/// @
|
|
44
|
-
///
|
|
45
|
-
///
|
|
46
|
-
///
|
|
47
|
-
///
|
|
48
|
-
///
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
26
|
+
/// @notice Decimals: this token uses **4** decimals, inherited from
|
|
27
|
+
/// {ZetoCommon.decimals}. Indexers and UIs reading this contract
|
|
28
|
+
/// directly should treat balances accordingly.
|
|
29
|
+
/// @dev Replaces the BabyJubjub-based ECDH envelope used by
|
|
30
|
+
/// {Zeto_AnonEncNullifier} with an ML-KEM (post-quantum)
|
|
31
|
+
/// key-encapsulation envelope. The proof carries the
|
|
32
|
+
/// `encapsulatedSharedSecret` (25 field elements -- the encoded
|
|
33
|
+
/// KEM ciphertext) alongside the encrypted output values; the
|
|
34
|
+
/// circuit asserts that the encrypted values were produced under
|
|
35
|
+
/// the same shared secret derived from that ciphertext.
|
|
36
|
+
///
|
|
37
|
+
/// Locked-input circuit binding: this contract intentionally does
|
|
38
|
+
/// NOT include `msg.sender` in the public-input vector for the
|
|
39
|
+
/// locked-input flavour, even though `main` did. Lock-spender
|
|
40
|
+
/// authorization is now enforced at the Zeto contract layer (via
|
|
41
|
+
/// `ZetoFungible._locks[lockId].spender == msg.sender`) rather than
|
|
42
|
+
/// inside the circuit. This matches how {Zeto_AnonNullifier}
|
|
43
|
+
/// organises its locked-input proof; deployments that still want a
|
|
44
|
+
/// circuit-level binding to the spender can override
|
|
45
|
+
/// {constructPublicInputs} and append it.
|
|
46
|
+
contract Zeto_AnonNullifierQurrency is Zeto_AnonNullifier {
|
|
47
|
+
/// @dev Proof decode + public-input assembly scratch lives in
|
|
48
|
+
/// {ZetoAnonNullifierQurrencyStorage} (ERC-7201).
|
|
58
49
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
/// @dev Lock the implementation contract on construction. Restated at
|
|
51
|
+
/// every leaf in the inheritance graph for H-2 robustness.
|
|
52
|
+
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
53
|
+
constructor() {
|
|
54
|
+
_disableInitializers();
|
|
55
|
+
}
|
|
62
56
|
|
|
63
57
|
function initialize(
|
|
64
|
-
string
|
|
65
|
-
string
|
|
58
|
+
string calldata name,
|
|
59
|
+
string calldata symbol,
|
|
66
60
|
address initialOwner,
|
|
67
61
|
IZetoInitializable.VerifiersInfo calldata verifiers
|
|
68
|
-
) public initializer {
|
|
69
|
-
|
|
70
|
-
__ZetoFungibleWithdrawWithNullifiers_init(
|
|
71
|
-
(Groth16Verifier_Deposit)(verifiers.depositVerifier),
|
|
72
|
-
(Groth16Verifier_WithdrawNullifier)(verifiers.withdrawVerifier),
|
|
73
|
-
(Groth16Verifier_WithdrawNullifierBatch)(
|
|
74
|
-
verifiers.batchWithdrawVerifier
|
|
75
|
-
)
|
|
76
|
-
);
|
|
77
|
-
_verifier = (Groth16Verifier_AnonNullifierQurrencyTransfer)(
|
|
78
|
-
verifiers.verifier
|
|
79
|
-
);
|
|
80
|
-
// _lockVerifier = (Groth16Verifier_AnonNullifierTransferLocked)(
|
|
81
|
-
// verifiers.lockVerifier
|
|
82
|
-
// );
|
|
83
|
-
_batchVerifier = (Groth16Verifier_AnonNullifierQurrencyTransferBatch)(
|
|
84
|
-
verifiers.batchVerifier
|
|
85
|
-
);
|
|
86
|
-
// _batchLockVerifier = (Groth16Verifier_AnonNullifierTransferLockedBatch)(
|
|
87
|
-
// verifiers.batchLockVerifier
|
|
88
|
-
// );
|
|
62
|
+
) public override initializer {
|
|
63
|
+
__ZetoAnonNullifier_init(name, symbol, initialOwner, verifiers);
|
|
89
64
|
}
|
|
90
65
|
|
|
91
|
-
function
|
|
92
|
-
|
|
93
|
-
function constructPublicInputs(
|
|
94
|
-
uint[2] memory computed_hashes,
|
|
66
|
+
function emitTransferEvent(
|
|
95
67
|
uint256[] memory nullifiers,
|
|
96
68
|
uint256[] memory outputs,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// for the lock delegate
|
|
112
|
-
if (locked) {
|
|
113
|
-
publicInputs[piIndex++] = uint256(uint160(msg.sender));
|
|
114
|
-
}
|
|
115
|
-
// copy root
|
|
116
|
-
publicInputs[piIndex++] = root;
|
|
117
|
-
|
|
118
|
-
// populate enables
|
|
119
|
-
for (uint256 i = 0; i < nullifiers.length; i++) {
|
|
120
|
-
publicInputs[piIndex++] = (nullifiers[i] == 0) ? 0 : 1;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// copy output commitments
|
|
124
|
-
for (uint256 i = 0; i < outputs.length; i++) {
|
|
125
|
-
publicInputs[piIndex++] = outputs[i];
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return publicInputs;
|
|
69
|
+
bytes memory proof,
|
|
70
|
+
bytes memory data
|
|
71
|
+
) internal override {
|
|
72
|
+
ZetoAnonNullifierQurrencyStorage.DecodedProofQurrency memory dp;
|
|
73
|
+
(dp, ) = decodeProof_Qurrency(proof);
|
|
74
|
+
emit UTXOTransferWithMlkemEncryptedValues(
|
|
75
|
+
nullifiers,
|
|
76
|
+
outputs,
|
|
77
|
+
dp.encryptionNonce,
|
|
78
|
+
dp.encapsulatedSharedSecret,
|
|
79
|
+
dp.encryptedValues,
|
|
80
|
+
msg.sender,
|
|
81
|
+
data
|
|
82
|
+
);
|
|
129
83
|
}
|
|
130
84
|
|
|
131
85
|
/**
|
|
132
|
-
* @dev
|
|
86
|
+
* @dev Layout of `proof` (ABI-encoded tuple):
|
|
87
|
+
* (uint256 root,
|
|
88
|
+
* uint256 encryptionNonce,
|
|
89
|
+
* uint256[] encryptedValues,
|
|
90
|
+
* uint256[25] encapsulatedSharedSecret,
|
|
91
|
+
* Commonlib.Proof groth16Proof)
|
|
92
|
+
*
|
|
93
|
+
* Public-inputs layout (unlocked):
|
|
94
|
+
* encapsulatedSharedSecret[25]
|
|
95
|
+
* ++ encryptedValues
|
|
96
|
+
* ++ nullifiers
|
|
97
|
+
* ++ root
|
|
98
|
+
* ++ enabled-flags
|
|
99
|
+
* ++ outputs
|
|
133
100
|
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* that the outputs are valid in terms of obeying mass conservation rules.
|
|
101
|
+
* Locked variant drops the `root`/`enabled-flags` block (locked
|
|
102
|
+
* inputs are raw UTXOs, not nullifiers, so the SMT-membership
|
|
103
|
+
* block is not part of the witness) but keeps the encryption
|
|
104
|
+
* commitments so the receiver can still decrypt the new outputs.
|
|
139
105
|
*
|
|
140
|
-
*
|
|
106
|
+
* Root validation is performed here for the unlocked path so the
|
|
107
|
+
* proof bytes are decoded exactly once per transition.
|
|
141
108
|
*/
|
|
142
|
-
function
|
|
109
|
+
function constructPublicInputs(
|
|
143
110
|
uint256[] memory nullifiers,
|
|
144
111
|
uint256[] memory outputs,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
112
|
+
bytes memory proof,
|
|
113
|
+
bool inputsLocked
|
|
114
|
+
)
|
|
115
|
+
internal
|
|
116
|
+
virtual
|
|
117
|
+
override
|
|
118
|
+
returns (uint256[] memory, Commonlib.Proof memory)
|
|
119
|
+
{
|
|
120
|
+
(
|
|
121
|
+
ZetoAnonNullifierQurrencyStorage.DecodedProofQurrency memory dp,
|
|
122
|
+
Commonlib.Proof memory proofStruct
|
|
123
|
+
) = decodeProof_Qurrency(proof);
|
|
157
124
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
for (uint256 i = 0; i < nullifiers.length; ++i) {
|
|
161
|
-
nullifierArray[i] = nullifiers[i];
|
|
162
|
-
outputArray[i] = outputs[i];
|
|
125
|
+
if (!inputsLocked) {
|
|
126
|
+
validateRoot(dp.root);
|
|
163
127
|
}
|
|
164
|
-
emit UTXOTransfer(nullifierArray, outputArray, msg.sender, data);
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
128
|
|
|
168
|
-
|
|
169
|
-
// uint256[] memory nullifiers,
|
|
170
|
-
// uint256[] memory outputs,
|
|
171
|
-
// uint256 root,
|
|
172
|
-
// Commonlib.Proof calldata proof,
|
|
173
|
-
// bytes calldata data
|
|
174
|
-
// ) public returns (bool) {
|
|
175
|
-
// nullifiers = checkAndPadCommitments(nullifiers);
|
|
176
|
-
// outputs = checkAndPadCommitments(outputs);
|
|
177
|
-
// validateTransactionProposal(nullifiers, outputs, root, true);
|
|
178
|
-
// verifyProofLocked(nullifiers, outputs, root, proof);
|
|
179
|
-
// uint256[] memory empty;
|
|
180
|
-
// processInputsAndOutputs(nullifiers, outputs, empty, address(0));
|
|
129
|
+
ZetoAnonNullifierQurrencyStorage.layout().dpq = dp;
|
|
181
130
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
// for (uint256 i = 0; i < nullifiers.length; ++i) {
|
|
185
|
-
// nullifierArray[i] = nullifiers[i];
|
|
186
|
-
// outputArray[i] = outputs[i];
|
|
187
|
-
// }
|
|
188
|
-
// emit UTXOTransfer(nullifierArray, outputArray, msg.sender, data);
|
|
189
|
-
// return true;
|
|
190
|
-
// }
|
|
131
|
+
uint256 size = _calcSize_Qurrency(nullifiers, outputs, inputsLocked);
|
|
132
|
+
_fillPublicInputs_Qurrency(size, nullifiers, outputs, inputsLocked);
|
|
191
133
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
uint256[] memory
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
_mint(outputs, data);
|
|
134
|
+
ZetoAnonNullifierQurrencyStorage.Layout storage $ = ZetoAnonNullifierQurrencyStorage
|
|
135
|
+
.layout();
|
|
136
|
+
uint256[] memory out = new uint256[]($.publicInputsBuf.length);
|
|
137
|
+
for (uint256 i = 0; i < out.length; ++i) {
|
|
138
|
+
out[i] = $.publicInputsBuf[i];
|
|
139
|
+
}
|
|
140
|
+
return (out, proofStruct);
|
|
200
141
|
}
|
|
201
142
|
|
|
202
|
-
function
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
143
|
+
function decodeProof_Qurrency(
|
|
144
|
+
bytes memory proof
|
|
145
|
+
)
|
|
146
|
+
internal
|
|
147
|
+
pure
|
|
148
|
+
returns (
|
|
149
|
+
ZetoAnonNullifierQurrencyStorage.DecodedProofQurrency memory dp,
|
|
150
|
+
Commonlib.Proof memory proofStruct
|
|
151
|
+
)
|
|
152
|
+
{
|
|
153
|
+
(
|
|
154
|
+
dp.root,
|
|
155
|
+
dp.encryptionNonce,
|
|
156
|
+
dp.encryptedValues,
|
|
157
|
+
dp.encapsulatedSharedSecret,
|
|
158
|
+
proofStruct
|
|
159
|
+
) = abi.decode(
|
|
160
|
+
proof,
|
|
161
|
+
(uint256, uint256, uint256[], uint256[25], Commonlib.Proof)
|
|
162
|
+
);
|
|
163
|
+
return (dp, proofStruct);
|
|
220
164
|
}
|
|
221
165
|
|
|
222
|
-
function
|
|
223
|
-
uint256[] memory
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
166
|
+
function _calcSize_Qurrency(
|
|
167
|
+
uint256[] memory nullifiers,
|
|
168
|
+
uint256[] memory outputs,
|
|
169
|
+
bool inputsLocked
|
|
170
|
+
) internal view returns (uint256) {
|
|
171
|
+
ZetoAnonNullifierQurrencyStorage.DecodedProofQurrency storage dq = ZetoAnonNullifierQurrencyStorage
|
|
172
|
+
.layout()
|
|
173
|
+
.dpq;
|
|
174
|
+
if (inputsLocked) {
|
|
175
|
+
return
|
|
176
|
+
dq.encapsulatedSharedSecret.length +
|
|
177
|
+
dq.encryptedValues.length +
|
|
178
|
+
nullifiers.length +
|
|
179
|
+
outputs.length;
|
|
180
|
+
}
|
|
181
|
+
return
|
|
182
|
+
dq.encapsulatedSharedSecret.length +
|
|
183
|
+
dq.encryptedValues.length +
|
|
184
|
+
(nullifiers.length * 2) + // nullifiers + enabled flags
|
|
185
|
+
1 + // root
|
|
186
|
+
outputs.length;
|
|
227
187
|
}
|
|
228
188
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
// uint256[] memory outputs,
|
|
232
|
-
// uint256[] memory lockedOutputs,
|
|
233
|
-
// uint256 root,
|
|
234
|
-
// Commonlib.Proof calldata proof,
|
|
235
|
-
// address delegate,
|
|
236
|
-
// bytes calldata data
|
|
237
|
-
// ) public {
|
|
238
|
-
// // merge the outputs and lockedOutputs and do a regular transfer
|
|
239
|
-
// uint256[] memory allOutputs = new uint256[](
|
|
240
|
-
// outputs.length + lockedOutputs.length
|
|
241
|
-
// );
|
|
242
|
-
// for (uint256 i = 0; i < outputs.length; i++) {
|
|
243
|
-
// allOutputs[i] = outputs[i];
|
|
244
|
-
// }
|
|
245
|
-
// for (uint256 i = 0; i < lockedOutputs.length; i++) {
|
|
246
|
-
// allOutputs[outputs.length + i] = lockedOutputs[i];
|
|
247
|
-
// }
|
|
248
|
-
// nullifiers = checkAndPadCommitments(nullifiers);
|
|
249
|
-
// allOutputs = checkAndPadCommitments(allOutputs);
|
|
250
|
-
// validateTransactionProposal(nullifiers, allOutputs, root, false);
|
|
251
|
-
// verifyProof(nullifiers, allOutputs, root, proof);
|
|
252
|
-
|
|
253
|
-
// spendNullifiers(nullifiers);
|
|
254
|
-
|
|
255
|
-
// // lock the intended outputs
|
|
256
|
-
// _lock(nullifiers, outputs, lockedOutputs, delegate, data);
|
|
257
|
-
// }
|
|
258
|
-
|
|
259
|
-
// function unlock(
|
|
260
|
-
// uint256[] memory nullifiers,
|
|
261
|
-
// uint256[] memory outputs,
|
|
262
|
-
// uint256 root,
|
|
263
|
-
// Commonlib.Proof calldata proof,
|
|
264
|
-
// bytes calldata data
|
|
265
|
-
// ) public {
|
|
266
|
-
// transferLocked(nullifiers, outputs, root, proof, data);
|
|
267
|
-
// }
|
|
268
|
-
|
|
269
|
-
function verifyProof(
|
|
270
|
-
uint[2] memory computed_hashes,
|
|
189
|
+
function _fillPublicInputs_Qurrency(
|
|
190
|
+
uint256 size,
|
|
271
191
|
uint256[] memory nullifiers,
|
|
272
192
|
uint256[] memory outputs,
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
);
|
|
285
|
-
// construct the public inputs for verifier
|
|
286
|
-
uint256[BATCH_INPUT_SIZE] memory fixedSizeInputs;
|
|
287
|
-
for (uint256 i = 0; i < fixedSizeInputs.length; i++) {
|
|
288
|
-
fixedSizeInputs[i] = publicInputs[i];
|
|
289
|
-
}
|
|
290
|
-
// Check the proof using batchVerifier
|
|
291
|
-
require(
|
|
292
|
-
_batchVerifier.verifyProof(
|
|
293
|
-
proof.pA,
|
|
294
|
-
proof.pB,
|
|
295
|
-
proof.pC,
|
|
296
|
-
fixedSizeInputs
|
|
297
|
-
),
|
|
298
|
-
"Invalid proof (batch)"
|
|
299
|
-
);
|
|
300
|
-
} else {
|
|
301
|
-
uint256[] memory publicInputs = constructPublicInputs(
|
|
302
|
-
computed_hashes,
|
|
303
|
-
nullifiers,
|
|
304
|
-
outputs,
|
|
305
|
-
root,
|
|
306
|
-
INPUT_SIZE,
|
|
307
|
-
false
|
|
308
|
-
);
|
|
309
|
-
// construct the public inputs for verifier
|
|
310
|
-
uint256[INPUT_SIZE] memory fixedSizeInputs;
|
|
311
|
-
for (uint256 i = 0; i < fixedSizeInputs.length; i++) {
|
|
312
|
-
fixedSizeInputs[i] = publicInputs[i];
|
|
313
|
-
}
|
|
314
|
-
// Check the proof
|
|
315
|
-
require(
|
|
316
|
-
_verifier.verifyProof(
|
|
317
|
-
proof.pA,
|
|
318
|
-
proof.pB,
|
|
319
|
-
proof.pC,
|
|
320
|
-
fixedSizeInputs
|
|
321
|
-
),
|
|
322
|
-
"Invalid proof"
|
|
323
|
-
);
|
|
193
|
+
bool inputsLocked
|
|
194
|
+
) internal {
|
|
195
|
+
ZetoAnonNullifierQurrencyStorage.Layout storage $ = ZetoAnonNullifierQurrencyStorage
|
|
196
|
+
.layout();
|
|
197
|
+
$.publicInputsBuf = new uint256[](size);
|
|
198
|
+
$.piIndex = 0;
|
|
199
|
+
|
|
200
|
+
_fillEncapsulatedSharedSecret_Q();
|
|
201
|
+
_fillEncryptedValues_Q();
|
|
202
|
+
_fillInputs_Q(nullifiers);
|
|
203
|
+
if (!inputsLocked) {
|
|
204
|
+
_fillRootAndEnables_Q(nullifiers);
|
|
324
205
|
}
|
|
325
|
-
|
|
206
|
+
_fillOutputs_Q(outputs);
|
|
326
207
|
}
|
|
327
208
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
// BATCH_INPUT_SIZE_LOCKED,
|
|
340
|
-
// true
|
|
341
|
-
// );
|
|
342
|
-
// // construct the public inputs for batchVerifier
|
|
343
|
-
// uint256[BATCH_INPUT_SIZE_LOCKED] memory fixedSizeInputs;
|
|
344
|
-
// for (uint256 i = 0; i < fixedSizeInputs.length; i++) {
|
|
345
|
-
// fixedSizeInputs[i] = publicInputs[i];
|
|
346
|
-
// }
|
|
209
|
+
function _fillEncapsulatedSharedSecret_Q() internal {
|
|
210
|
+
ZetoAnonNullifierQurrencyStorage.Layout storage $ = ZetoAnonNullifierQurrencyStorage
|
|
211
|
+
.layout();
|
|
212
|
+
for (
|
|
213
|
+
uint256 i = 0;
|
|
214
|
+
i < $.dpq.encapsulatedSharedSecret.length;
|
|
215
|
+
++i
|
|
216
|
+
) {
|
|
217
|
+
$.publicInputsBuf[$.piIndex++] = $.dpq.encapsulatedSharedSecret[i];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
347
220
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
// ),
|
|
356
|
-
// "Invalid proof"
|
|
357
|
-
// );
|
|
358
|
-
// } else {
|
|
359
|
-
// uint256[] memory publicInputs = constructPublicInputs(
|
|
360
|
-
// nullifiers,
|
|
361
|
-
// outputs,
|
|
362
|
-
// root,
|
|
363
|
-
// INPUT_SIZE_LOCKED,
|
|
364
|
-
// true
|
|
365
|
-
// );
|
|
366
|
-
// // construct the public inputs for verifier
|
|
367
|
-
// uint256[INPUT_SIZE_LOCKED] memory fixedSizeInputs;
|
|
368
|
-
// for (uint256 i = 0; i < fixedSizeInputs.length; i++) {
|
|
369
|
-
// fixedSizeInputs[i] = publicInputs[i];
|
|
370
|
-
// }
|
|
371
|
-
// // Check the proof
|
|
372
|
-
// require(
|
|
373
|
-
// _lockVerifier.verifyProof(
|
|
374
|
-
// proof.pA,
|
|
375
|
-
// proof.pB,
|
|
376
|
-
// proof.pC,
|
|
377
|
-
// fixedSizeInputs
|
|
378
|
-
// ),
|
|
379
|
-
// "Invalid proof"
|
|
380
|
-
// );
|
|
381
|
-
// }
|
|
382
|
-
// return true;
|
|
383
|
-
// }
|
|
221
|
+
function _fillEncryptedValues_Q() internal {
|
|
222
|
+
ZetoAnonNullifierQurrencyStorage.Layout storage $ = ZetoAnonNullifierQurrencyStorage
|
|
223
|
+
.layout();
|
|
224
|
+
for (uint256 i = 0; i < $.dpq.encryptedValues.length; ++i) {
|
|
225
|
+
$.publicInputsBuf[$.piIndex++] = $.dpq.encryptedValues[i];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
384
228
|
|
|
385
|
-
function
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
uint256 result;
|
|
391
|
-
bytes memory ct = new bytes(768);
|
|
392
|
-
for (uint i = 0; i < ct.length; i++) {
|
|
393
|
-
ct[i] = ciphertext[i];
|
|
229
|
+
function _fillInputs_Q(uint256[] memory nullifiers) internal {
|
|
230
|
+
ZetoAnonNullifierQurrencyStorage.Layout storage $ = ZetoAnonNullifierQurrencyStorage
|
|
231
|
+
.layout();
|
|
232
|
+
for (uint256 i = 0; i < nullifiers.length; i++) {
|
|
233
|
+
$.publicInputsBuf[$.piIndex++] = nullifiers[i];
|
|
394
234
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
)
|
|
404
|
-
result := mload(add(ret, 0x20))
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function _fillRootAndEnables_Q(uint256[] memory nullifiers) internal {
|
|
238
|
+
ZetoAnonNullifierQurrencyStorage.Layout storage $ = ZetoAnonNullifierQurrencyStorage
|
|
239
|
+
.layout();
|
|
240
|
+
$.publicInputsBuf[$.piIndex++] = $.dpq.root;
|
|
241
|
+
for (uint256 i = 0; i < nullifiers.length; i++) {
|
|
242
|
+
$.publicInputsBuf[$.piIndex++] = (nullifiers[i] == 0) ? 0 : 1;
|
|
405
243
|
}
|
|
406
|
-
|
|
244
|
+
}
|
|
407
245
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
for (
|
|
412
|
-
|
|
246
|
+
function _fillOutputs_Q(uint256[] memory outputs) internal {
|
|
247
|
+
ZetoAnonNullifierQurrencyStorage.Layout storage $ = ZetoAnonNullifierQurrencyStorage
|
|
248
|
+
.layout();
|
|
249
|
+
for (uint256 i = 0; i < outputs.length; i++) {
|
|
250
|
+
$.publicInputsBuf[$.piIndex++] = outputs[i];
|
|
413
251
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/// @dev ERC-7201 (`erc7201:zeto.storage.Zeto_AnonNullifierQurrency`).
|
|
256
|
+
library ZetoAnonNullifierQurrencyStorage {
|
|
257
|
+
struct DecodedProofQurrency {
|
|
258
|
+
uint256 root;
|
|
259
|
+
uint256 encryptionNonce;
|
|
260
|
+
uint256[] encryptedValues;
|
|
261
|
+
uint256[25] encapsulatedSharedSecret;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
struct Layout {
|
|
265
|
+
DecodedProofQurrency dpq;
|
|
266
|
+
uint256[] publicInputsBuf;
|
|
267
|
+
uint256 piIndex;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
bytes32 private constant STORAGE_LOCATION =
|
|
271
|
+
0x61ea13f87e8d672de1c36df013aa52a47bae99190f6e222ce275d312c118d800;
|
|
272
|
+
|
|
273
|
+
function layout() internal pure returns (Layout storage $) {
|
|
274
|
+
assembly {
|
|
275
|
+
$.slot := STORAGE_LOCATION
|
|
419
276
|
}
|
|
420
|
-
return computed_pubSignals;
|
|
421
277
|
}
|
|
422
278
|
}
|