@openzeppelin/compact-contracts 0.4.0 → 0.5.0-alpha.2
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 +9 -4
- package/access/AccessControl.compact +8 -9
- package/access/Ownable.compact +21 -20
- package/access/ShieldedAccessControl.compact +20 -19
- package/access/ZOwnablePK.compact +5 -3
- package/crypto/Ecdh.compact +153 -0
- package/crypto/EcdhMask.compact +146 -84
- package/crypto/Ecdsa.compact +1 -1
- package/crypto/Eip712.compact +1 -1
- package/crypto/ElGamal.compact +13 -13
- package/math/UintN.compact +82 -0
- package/multisig/ForwarderPrivate.compact +6 -17
- package/multisig/ForwarderShielded.compact +1 -1
- package/multisig/ForwarderUnshielded.compact +1 -1
- package/multisig/ProposalManager.compact +127 -65
- package/multisig/Secp256k1EcdsaMultisig.compact +1 -1
- package/multisig/ShieldedTreasury.compact +8 -20
- package/multisig/ShieldedTreasuryStateless.compact +9 -21
- package/multisig/Signer.compact +1 -1
- package/multisig/UnshieldedTreasury.compact +11 -24
- package/multisig/examples/ForwarderPrivateExample.compact +2 -3
- package/multisig/examples/ForwarderShieldedExample.compact +1 -1
- package/multisig/examples/ForwarderUnshieldedExample.compact +1 -1
- package/multisig/examples/{ShieldedMultiSigV2Example.compact → NativeShieldedStatelessTreasuryExample.compact} +23 -23
- package/multisig/examples/NativeShieldedTokenIssuerExample.compact +1 -1
- package/multisig/presets/NativeShieldedStatelessTreasury.compact +443 -0
- package/multisig/presets/NativeShieldedTokenIssuer.compact +2 -5
- package/package.json +11 -11
- package/security/Allowlist.compact +1 -1
- package/security/Blocklist.compact +1 -1
- package/security/Initializable.compact +3 -1
- package/security/Pausable.compact +1 -1
- package/token/ConfidentialFungibleToken.compact +22 -70
- package/token/ConfidentialNoteFungibleToken.compact +741 -0
- package/token/FungibleToken.compact +36 -30
- package/token/MultiToken.compact +27 -21
- package/token/NativeShieldedToken.compact +4 -12
- package/token/NativeShieldedTokenCore.compact +1 -1
- package/token/NativeShieldedTokenFamily.compact +4 -4
- package/token/NonFungibleToken.compact +28 -22
- package/token/examples/ZOwnableNativeShieldedTokenExample.compact +1 -1
- package/token/extensions/ConfidentialFungibleTokenPublicSupply.compact +1 -1
- package/token/extensions/ConfidentialNoteFungibleTokenDelivery.compact +274 -0
- package/token/extensions/NativeShieldedTokenDerivedNonce.compact +1 -1
- package/token/extensions/NativeShieldedTokenFamilyPublicSupply.compact +1 -1
- package/token/extensions/NativeShieldedTokenPublicSupply.compact +1 -1
- package/token/extensions/NativeShieldedTokenPublicSupplyCore.compact +1 -1
- package/token/presets/ZOwnableNativeShieldedToken.compact +1 -1
- package/utils/EvmAbi.compact +1 -1
- package/utils/Utils.compact +1 -1
- package/multisig/RecipientTypes.compact +0 -48
- package/multisig/presets/ShieldedMultiSigV2.compact +0 -295
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
|
-
// OpenZeppelin Compact Contracts v0.
|
|
2
|
+
// OpenZeppelin Compact Contracts v0.5.0-alpha.2 (token/ConfidentialFungibleToken.compact)
|
|
3
3
|
|
|
4
4
|
pragma language_version >= 0.26.0;
|
|
5
5
|
|
|
@@ -28,16 +28,6 @@ pragma language_version >= 0.26.0;
|
|
|
28
28
|
* (`extensions/ConfidentialFungibleTokenPublicSupply`) a composing contract pairs
|
|
29
29
|
* with them if it wants a tracked supply.
|
|
30
30
|
*
|
|
31
|
-
* @notice Allowances. `approve` funds the allowance at approve time: `value`
|
|
32
|
-
* moves out of the caller's spendable balance into the escrow, where it stays
|
|
33
|
-
* until spent or re-approved. Funding is required, not a choice: the spender
|
|
34
|
-
* holds no owner encryption key, so at spend time it can only prove against
|
|
35
|
-
* its own escrow copy, never that the owner's balance covers the allowance.
|
|
36
|
-
* An approve conserves the owner's holdings (spendable plus every outstanding
|
|
37
|
-
* escrow), so allowances across spenders can sum to the whole holding but
|
|
38
|
-
* never exceed it, and a re-approve replaces the prior one rather than
|
|
39
|
-
* stacking.
|
|
40
|
-
*
|
|
41
31
|
* @notice Single-receiver. Auditor support, freeze, and admin-style seize are
|
|
42
32
|
* deliberately left to companion modules or a future multi-receiver variant.
|
|
43
33
|
* The escrow-spend primitive here (`_spendEscrow`) enables user-consenting
|
|
@@ -45,9 +35,6 @@ pragma language_version >= 0.26.0;
|
|
|
45
35
|
* requires authority visibility into balances and is therefore out of scope
|
|
46
36
|
* for the single-receiver base.
|
|
47
37
|
*
|
|
48
|
-
* @dev Initialization. Every exported circuit except `initialize` asserts the
|
|
49
|
-
* contract is initialized.
|
|
50
|
-
*
|
|
51
38
|
* @dev Trust model for witnesses.
|
|
52
39
|
*
|
|
53
40
|
* Witness implementations live in the user's wallet (TypeScript frontend) and
|
|
@@ -403,9 +390,7 @@ module ConfidentialFungibleToken {
|
|
|
403
390
|
/**
|
|
404
391
|
* @description Escrowed allowances, keyed by owner then spender. Membership is
|
|
405
392
|
* checked independently of the entry, so an allowance that was never escrowed
|
|
406
|
-
* is unspendable.
|
|
407
|
-
* registered, so an entry written here for an unregistered account (for
|
|
408
|
-
* example by a composing contract) is unspendable as well.
|
|
393
|
+
* is unspendable.
|
|
409
394
|
* @type {Bytes<32>} owner - The account that escrowed the allowance.
|
|
410
395
|
* @type {Bytes<32>} spender - The account allowed to spend it.
|
|
411
396
|
* @type {EscrowEntry} entry - The escrowed allowance.
|
|
@@ -633,37 +618,25 @@ module ConfidentialFungibleToken {
|
|
|
633
618
|
|
|
634
619
|
/**
|
|
635
620
|
* @description Returns the escrow entry (the encrypted allowance) that `owner`
|
|
636
|
-
* granted `spender`. When no allowance exists, returns a
|
|
637
|
-
*
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
* @notice The placeholder's `spenderCt` and `ownerCt` are genuine encryptions
|
|
643
|
-
* of 0. Its `ownerMemo` is not: it is a sentinel for an absent allowance,
|
|
644
|
-
* recognised by `ephemeralPk == identity`, which `EcdhMask_encrypt` never
|
|
645
|
-
* produces and `EcdhMask_decrypt` rejects. A wallet must test for the
|
|
646
|
-
* sentinel rather than decrypt and narrow it.
|
|
647
|
-
*
|
|
648
|
-
* @notice "No allowance" and "an allowance of 0" both read as encrypted-zero in
|
|
649
|
-
* the amount fields; the memo sentinel tells them apart, since `approve` stores
|
|
650
|
-
* a real memo even for 0. This getter grants nothing, the spend path
|
|
651
|
-
* (`transferFrom`/`burnFrom`) gates on `_escrow` membership independently, so a
|
|
652
|
-
* non-existent allowance is unspendable.
|
|
653
|
-
*
|
|
654
|
-
* @constraints k=10, rows=938
|
|
621
|
+
* granted `spender`. When no allowance exists, returns a well-formed
|
|
622
|
+
* encrypted-zero entry (its encrypted amounts decrypt to 0, analogous to an
|
|
623
|
+
* ERC-20 zero allowance) rather than `default<EscrowEntry>`: the returned
|
|
624
|
+
* Jubjub points are on-curve, so the view is safe to prove (e.g. through a
|
|
625
|
+
* contract-to-contract call) and safe for a wallet to decrypt, whereas a zeroed
|
|
626
|
+
* default holds off-curve points. The cap is encrypted, not public.
|
|
655
627
|
*
|
|
656
|
-
*
|
|
628
|
+
* @notice "No allowance" and "an allowance of 0" both read as encrypted-zero;
|
|
629
|
+
* a caller that must distinguish them reads `_escrow` membership off-chain. This
|
|
630
|
+
* getter grants nothing, the spend path (`transferFrom`/`burnFrom`) gates on
|
|
631
|
+
* `_escrow` membership independently, so a non-existent allowance is unspendable.
|
|
657
632
|
*
|
|
658
|
-
*
|
|
633
|
+
* @constraints k=10, rows=936
|
|
659
634
|
*
|
|
660
635
|
* @param {Bytes<32>} owner - The account that granted the allowance.
|
|
661
636
|
* @param {Bytes<32>} spender - The approved spender.
|
|
662
|
-
* @return {EscrowEntry} - The encrypted escrow entry (
|
|
663
|
-
* absent-allowance sentinel if none).
|
|
637
|
+
* @return {EscrowEntry} - The encrypted escrow entry (encrypted-zero if none).
|
|
664
638
|
*/
|
|
665
639
|
export circuit allowance(owner: Bytes<32>, spender: Bytes<32>): EscrowEntry {
|
|
666
|
-
assertInitialized();
|
|
667
640
|
if (!_escrow.member(disclose(owner)) ||
|
|
668
641
|
!_escrow.lookup(disclose(owner)).member(disclose(spender))) {
|
|
669
642
|
const id = constructJubjubPoint(0 as Field, 1 as Field);
|
|
@@ -683,17 +656,12 @@ module ConfidentialFungibleToken {
|
|
|
683
656
|
/**
|
|
684
657
|
* @description Returns whether `account` has registered an encryption key.
|
|
685
658
|
*
|
|
686
|
-
* @constraints k=9, rows=
|
|
687
|
-
*
|
|
688
|
-
* Requirements:
|
|
689
|
-
*
|
|
690
|
-
* - Contract is initialized.
|
|
659
|
+
* @constraints k=9, rows=303
|
|
691
660
|
*
|
|
692
661
|
* @param {Bytes<32>} account - The account to query.
|
|
693
662
|
* @return {Boolean} - True if `account` is registered.
|
|
694
663
|
*/
|
|
695
664
|
export circuit isRegistered(account: Bytes<32>): Boolean {
|
|
696
|
-
assertInitialized();
|
|
697
665
|
return _encryptionKeys.member(disclose(account));
|
|
698
666
|
}
|
|
699
667
|
|
|
@@ -844,12 +812,6 @@ module ConfidentialFungibleToken {
|
|
|
844
812
|
* `sum(balances) == totalSupply` invariant. Pair it with a debit (as `transfer`
|
|
845
813
|
* does) or a supply increase (as a supply layer's `mint` does).
|
|
846
814
|
*
|
|
847
|
-
* Requirements:
|
|
848
|
-
*
|
|
849
|
-
* - Contract is initialized.
|
|
850
|
-
* - `value` is within `MAX_TRANSFER_VALUE()`.
|
|
851
|
-
* - `account` is non-zero and registered.
|
|
852
|
-
*
|
|
853
815
|
* @param account - The recipient account id.
|
|
854
816
|
* @param value - The amount to credit.
|
|
855
817
|
*/
|
|
@@ -966,7 +928,7 @@ module ConfidentialFungibleToken {
|
|
|
966
928
|
* credits `to`, and pushes an encrypted memo to `to`. The amount is hidden;
|
|
967
929
|
* the (sender, recipient) pair is public.
|
|
968
930
|
*
|
|
969
|
-
* @constraints k=16, rows=
|
|
931
|
+
* @constraints k=16, rows=41623
|
|
970
932
|
*
|
|
971
933
|
* @notice Returns the caller's (sender's) `accountId` for caller-side gating.
|
|
972
934
|
* The sender is derived from the same authentication `_debit` performs, so the
|
|
@@ -984,6 +946,7 @@ module ConfidentialFungibleToken {
|
|
|
984
946
|
* @return {Bytes<32>} - The caller's (sender's) accountId.
|
|
985
947
|
*/
|
|
986
948
|
export circuit transfer(to: Bytes<32>, value: Uint<128>): Bytes<32> {
|
|
949
|
+
assertInitialized();
|
|
987
950
|
// Derive the sender from the same authentication `_debit` uses, so the
|
|
988
951
|
// returned id is exactly the account whose funds moved.
|
|
989
952
|
const senderId = _debit(value);
|
|
@@ -1003,7 +966,7 @@ module ConfidentialFungibleToken {
|
|
|
1003
966
|
* operations (`mint`/`burn`) live in a separate layer outside this conserving
|
|
1004
967
|
* surface, and only they may break conservation.
|
|
1005
968
|
*
|
|
1006
|
-
* @constraints k=16, rows=
|
|
969
|
+
* @constraints k=16, rows=41612
|
|
1007
970
|
*
|
|
1008
971
|
* @notice Like `transfer`, the credit lands in the recipient's pending pool
|
|
1009
972
|
* (see the dual-balance note); the caller sweeps their own incoming value.
|
|
@@ -1029,6 +992,7 @@ module ConfidentialFungibleToken {
|
|
|
1029
992
|
* @return {Bytes<32>} - The caller's accountId (for caller-side gating).
|
|
1030
993
|
*/
|
|
1031
994
|
export circuit _move(to: Bytes<32>, value: Uint<128>): Bytes<32> {
|
|
995
|
+
assertInitialized();
|
|
1032
996
|
const senderId = _debit(value);
|
|
1033
997
|
_credit(to, value);
|
|
1034
998
|
return senderId;
|
|
@@ -1161,7 +1125,7 @@ module ConfidentialFungibleToken {
|
|
|
1161
1125
|
* caller via `approve`) and credits it to `to`, reducing both escrow copies by
|
|
1162
1126
|
* `value`. The amount is hidden.
|
|
1163
1127
|
*
|
|
1164
|
-
* @constraints k=17, rows=
|
|
1128
|
+
* ???? @constraints k=17, rows=68920
|
|
1165
1129
|
*
|
|
1166
1130
|
* @notice Returns the caller's (spender's) `accountId` for caller-side gating.
|
|
1167
1131
|
*
|
|
@@ -1171,7 +1135,6 @@ module ConfidentialFungibleToken {
|
|
|
1171
1135
|
* - `value` is within `MAX_TRANSFER_VALUE()`.
|
|
1172
1136
|
* - `to` is registered and is not the zero account.
|
|
1173
1137
|
* - An escrow from `fromAddress` to the caller exists with at least `value`.
|
|
1174
|
-
* - `fromAddress` and the caller are registered.
|
|
1175
1138
|
*
|
|
1176
1139
|
* @param {Bytes<32>} fromAddress - The owner whose escrow is drawn on.
|
|
1177
1140
|
* @param {Bytes<32>} to - The recipient account.
|
|
@@ -1183,6 +1146,7 @@ module ConfidentialFungibleToken {
|
|
|
1183
1146
|
to: Bytes<32>,
|
|
1184
1147
|
value: Uint<128>
|
|
1185
1148
|
): Bytes<32> {
|
|
1149
|
+
assertInitialized();
|
|
1186
1150
|
_assertValueInBound(value);
|
|
1187
1151
|
assert(to != default<Bytes<32>>,
|
|
1188
1152
|
"ConfidentialFungibleToken: invalid receiver");
|
|
@@ -1335,13 +1299,6 @@ module ConfidentialFungibleToken {
|
|
|
1335
1299
|
* not prove the post-refund balance on a later re-approve/revoke. See the
|
|
1336
1300
|
* `EscrowEntry` field doc.
|
|
1337
1301
|
*
|
|
1338
|
-
* Requirements:
|
|
1339
|
-
*
|
|
1340
|
-
* - Contract is initialized.
|
|
1341
|
-
* - `value` is within `MAX_TRANSFER_VALUE()`.
|
|
1342
|
-
* - An escrow from `fromAddress` to the caller exists with at least `value`.
|
|
1343
|
-
* - `fromAddress` and the caller are registered.
|
|
1344
|
-
*
|
|
1345
1302
|
* @param fromAddress - The owner whose escrow the caller (spender) draws on.
|
|
1346
1303
|
* @param value - The amount to consume from the allowance.
|
|
1347
1304
|
*/
|
|
@@ -1353,10 +1310,6 @@ module ConfidentialFungibleToken {
|
|
|
1353
1310
|
assert(_escrow.member(disclose(fromAddress)) &&
|
|
1354
1311
|
_escrow.lookup(disclose(fromAddress)).member(disclose(spenderId)),
|
|
1355
1312
|
"ConfidentialFungibleToken: no escrow");
|
|
1356
|
-
assert(_encryptionKeys.member(disclose(spenderId)),
|
|
1357
|
-
"ConfidentialFungibleToken: spender not registered");
|
|
1358
|
-
assert(_encryptionKeys.member(disclose(fromAddress)),
|
|
1359
|
-
"ConfidentialFungibleToken: owner not registered");
|
|
1360
1313
|
|
|
1361
1314
|
const entry = _escrow.lookup(disclose(fromAddress)).lookup(disclose(spenderId));
|
|
1362
1315
|
|
|
@@ -1421,14 +1374,13 @@ module ConfidentialFungibleToken {
|
|
|
1421
1374
|
* recipient credit. The building block for a composing contract's
|
|
1422
1375
|
* `burnFrom`; it performs no supply accounting (see `_burn`).
|
|
1423
1376
|
*
|
|
1424
|
-
* @constraints k=16, rows=
|
|
1377
|
+
* ???? @constraints k=16, rows=42201
|
|
1425
1378
|
*
|
|
1426
1379
|
* Requirements:
|
|
1427
1380
|
*
|
|
1428
1381
|
* - Contract is initialized.
|
|
1429
1382
|
* - `value` is within `MAX_TRANSFER_VALUE()`.
|
|
1430
1383
|
* - An escrow from `fromAddress` to the caller exists with at least `value`.
|
|
1431
|
-
* - `fromAddress` and the caller are registered.
|
|
1432
1384
|
*
|
|
1433
1385
|
* @param {Bytes<32>} fromAddress - The owner whose escrow is consumed.
|
|
1434
1386
|
* @param {Uint<128>} value - The amount to burn.
|