@openzeppelin/compact-contracts 0.4.0-alpha.5 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +1 -1
  2. package/access/AccessControl.compact +1 -1
  3. package/access/Ownable.compact +1 -3
  4. package/access/ShieldedAccessControl.compact +44 -41
  5. package/access/ZOwnablePK.compact +12 -5
  6. package/crypto/EcdhMask.compact +11 -1
  7. package/crypto/Ecdsa.compact +1 -1
  8. package/crypto/Eip712.compact +1 -1
  9. package/crypto/ElGamal.compact +1 -1
  10. package/multisig/ForwarderPrivate.compact +17 -6
  11. package/multisig/ForwarderShielded.compact +1 -1
  12. package/multisig/ForwarderUnshielded.compact +1 -1
  13. package/multisig/ProposalManager.compact +65 -127
  14. package/multisig/RecipientTypes.compact +48 -0
  15. package/multisig/Secp256k1EcdsaMultisig.compact +275 -0
  16. package/multisig/ShieldedTreasury.compact +20 -8
  17. package/multisig/ShieldedTreasuryStateless.compact +11 -5
  18. package/multisig/Signer.compact +1 -1
  19. package/multisig/UnshieldedTreasury.compact +24 -11
  20. package/multisig/examples/ForwarderPrivateExample.compact +3 -2
  21. package/multisig/examples/ForwarderShieldedExample.compact +1 -1
  22. package/multisig/examples/ForwarderUnshieldedExample.compact +1 -1
  23. package/multisig/examples/NativeShieldedTokenIssuerExample.compact +4 -4
  24. package/multisig/examples/ShieldedMultiSigV2Example.compact +7 -9
  25. package/multisig/presets/NativeShieldedTokenIssuer.compact +88 -84
  26. package/multisig/presets/ShieldedMultiSigV2.compact +50 -52
  27. package/package.json +1 -1
  28. package/security/Allowlist.compact +1 -1
  29. package/security/Blocklist.compact +1 -1
  30. package/security/Initializable.compact +1 -3
  31. package/security/Pausable.compact +1 -1
  32. package/token/ConfidentialFungibleToken.compact +70 -22
  33. package/token/FungibleToken.compact +1 -3
  34. package/token/MultiToken.compact +1 -3
  35. package/token/NativeShieldedToken.compact +11 -3
  36. package/token/NativeShieldedTokenCore.compact +1 -1
  37. package/token/NativeShieldedTokenFamily.compact +1 -1
  38. package/token/NonFungibleToken.compact +1 -3
  39. package/token/examples/ZOwnableNativeShieldedTokenExample.compact +109 -0
  40. package/token/extensions/ConfidentialFungibleTokenPublicSupply.compact +1 -1
  41. package/token/extensions/NativeShieldedTokenDerivedNonce.compact +1 -1
  42. package/token/presets/ZOwnableNativeShieldedToken.compact +314 -0
  43. package/utils/EvmAbi.compact +1 -1
  44. package/utils/Utils.compact +1 -1
  45. package/multisig/EcdsaSignerManager.compact +0 -248
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Compact Contracts v0.4.0-alpha.5 (multisig/ShieldedTreasury.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0 (multisig/ShieldedTreasury.compact)
3
3
 
4
4
  pragma language_version >= 0.26.0;
5
5
 
@@ -82,13 +82,13 @@ module ShieldedTreasury {
82
82
  * The coin is then merged with any existing coin of the same color,
83
83
  * or inserted as a new entry if no coin of that color exists.
84
84
  *
85
- * Zero-value deposits are permitted and are not always a no-op. On a color the
86
- * treasury does not yet hold, a zero-value coin is inserted and occupies that
87
- * color's single slot until a later deposit merges into it; if a coin of that
88
- * color already exists, the zero merges into it via `mergeCoinImmediate` and
89
- * the stored value is unchanged. They may serve as signaling mechanisms when
90
- * events are supported. They are not useful as privacy decoys, this
91
- * treasury's holdings are public (see the module header).
85
+ * @warning Every deposit of a color replaces the coin that `_send` reads for
86
+ * that color, so a deposit that lands first invalidates every `_send` of the
87
+ * same color still waiting to be applied. A consumer that exposes `_deposit`
88
+ * without access control lets any depositor delay authorized sends for as
89
+ * long as they keep depositing; the sends must then be re-proven. No funds are
90
+ * lost. A zero-value coin is rejected, so each deposit costs at least one unit
91
+ * of the token plus the transaction fee.
92
92
  *
93
93
  * @notice Access control is NOT enforced here.
94
94
  * The consuming contract must gate this behind its own
@@ -96,6 +96,7 @@ module ShieldedTreasury {
96
96
  *
97
97
  * Requirements:
98
98
  *
99
+ * - The coin's value must be non-zero.
99
100
  * - Deposit must not cause received total overflow.
100
101
  *
101
102
  * @param {ShieldedCoinInfo} coin - The incoming shielded coin descriptor.
@@ -103,6 +104,8 @@ module ShieldedTreasury {
103
104
  * @returns {[]} Empty tuple.
104
105
  */
105
106
  export circuit _deposit(coin: ShieldedCoinInfo): [] {
107
+ assert(coin.value != 0, "ShieldedTreasury: zero value");
108
+
106
109
  const currentReceived = getReceivedTotal(coin.color);
107
110
  assert(currentReceived <= Utils_UINT128_MAX() - coin.value, "ShieldedTreasury: overflow");
108
111
 
@@ -142,12 +145,16 @@ module ShieldedTreasury {
142
145
  * the retained change coin, and nothing at all when the send leaves no change,
143
146
  * so the sent coin's plaintext is disclosed beyond anything in public state.
144
147
  *
148
+ * @dev A self-addressed coin is auto-received by `sendShielded` but never recorded
149
+ * in _coins so it would be stranded. Therefore, this circuit rejects sends to self.
150
+ *
145
151
  * @notice Access control is NOT enforced here.
146
152
  * The consuming contract must gate this behind its own
147
153
  * authorization policy.
148
154
  *
149
155
  * Requirements:
150
156
  *
157
+ * - `recipient` must not be this contract's own address.
151
158
  * - A coin of the given `color` must exist in the treasury.
152
159
  * - The coin's value must be >= `amount`.
153
160
  * - Send must not cause sent total overflow.
@@ -163,6 +170,11 @@ module ShieldedTreasury {
163
170
  color: Bytes<32>,
164
171
  amount: Uint<128>
165
172
  ): ShieldedSendResult {
173
+ // `kernel.self()` stays outside the `||`: the compiler treats a ledger
174
+ // read behind a witness-conditioned branch as an undeclared disclosure
175
+ const self = kernel.self();
176
+ assert(recipient.is_left || recipient.right != self,
177
+ "ShieldedTreasury: self-send");
166
178
  assert(_coins.member(disclose(color)), "ShieldedTreasury: no balance");
167
179
 
168
180
  const coin = _coins.lookup(disclose(color));
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Compact Contracts v0.4.0-alpha.5 (multisig/ShieldedTreasuryStateless.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0 (multisig/ShieldedTreasuryStateless.compact)
3
3
 
4
4
  pragma language_version >= 0.26.0;
5
5
 
@@ -22,10 +22,16 @@ pragma language_version >= 0.26.0;
22
22
  * application time. Sufficiency is likewise enforced by `sendShielded` rather
23
23
  * than by an assert here.
24
24
  *
25
- * @notice "No ledger state" is not the same as "unobservable". A coin
26
- * commitment is a hash of the coin's data, so `sendShielded` can link a coin
27
- * receive to its later spend; `_send` declares that disclosure on the
28
- * consumer's behalf. Consumers that need to make the trade-off themselves
25
+ * @notice "No ledger state" is not the same as "unobservable". A coin's
26
+ * nullifier is a hash of the coin and this contract's address, and
27
+ * `sendShielded` derives the nonces of the sent coin and of the change from a
28
+ * public hash of the spent coin's nonce. Whoever knows a deposited coin can
29
+ * therefore find the spend that consumes it, recover the amount sent (on a
30
+ * partial spend the change commitment has the value as its only unknown),
31
+ * test candidate recipients against the sent coin's commitment, and repeat
32
+ * from the change coin for every later spend descending from it. `_send`
33
+ * declares the spent coin's disclosure on the consumer's behalf. Consumers
34
+ * that need to make the trade-off themselves
29
35
  * should note it is only declared here for convenience — it could be moved to
30
36
  * the caller. Separately, see `_send`'s warning about its return value, which
31
37
  * carries coin plaintext.
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Compact Contracts v0.4.0-alpha.5 (multisig/Signer.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0 (multisig/Signer.compact)
3
3
 
4
4
  pragma language_version >= 0.26.0;
5
5
 
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Compact Contracts v0.4.0-alpha.5 (multisig/UnshieldedTreasury.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0 (multisig/UnshieldedTreasury.compact)
3
3
 
4
4
  pragma language_version >= 0.26.0;
5
5
 
@@ -61,6 +61,14 @@ module UnshieldedTreasury {
61
61
  * operation creates a zero-valued `_balances` entry, which
62
62
  * `getTokenBalance` reports the same as absence.
63
63
  *
64
+ * @warning Every non-zero deposit of a color rewrites the `_balances` entry
65
+ * that `_send` reads for that color, so a deposit that lands first
66
+ * invalidates every `_send` of the same color still waiting to be applied.
67
+ * A consumer that exposes `_deposit` without access control lets any
68
+ * depositor delay authorized sends for as long as they keep depositing; the
69
+ * sends must then be re-proven. No funds are lost. A zero-value deposit
70
+ * rewrites the entry with the same value and does not have this effect.
71
+ *
64
72
  * @notice Access control is NOT enforced here.
65
73
  * The consuming contract must gate this behind its own
66
74
  * authorization policy.
@@ -92,17 +100,16 @@ module UnshieldedTreasury {
92
100
  /**
93
101
  * @description Sends unshielded tokens from the treasury.
94
102
  *
95
- * @warning Recipients are not validated. An unspendable recipient (such as a
96
- * zero address) is accepted and permanently removes the funds from the
97
- * contract. This is not a sanctioned burn — no unshielded equivalent of
98
- * `shieldedBurnAddress` is exposed to contracts — so treat recipient
99
- * validation as the consuming contract's responsibility.
103
+ * @warning Recipients other than this contract are not validated. An
104
+ * unspendable recipient (such as a zero address) is accepted and
105
+ * permanently removes the funds from the contract. This is not a
106
+ * sanctioned burn (no unshielded equivalent of `shieldedBurnAddress` is
107
+ * exposed to contracts), so treat recipient validation as the consuming
108
+ * contract's responsibility.
100
109
  *
101
- * @warning Sending to this contract's own address zeroes the tracked balance
102
- * while the funds stay held and spendable at the protocol level, after which
103
- * `_send` will refuse to touch them. Recovery is only possible outside this
104
- * module: a consumer may reconcile the exported `_balances`, or spend the
105
- * funds through its own `sendUnshielded` call.
110
+ * @dev A self-addressed send is auto-received by `sendUnshielded` but
111
+ * still debited from `_balances`, so the funds would be stranded.
112
+ * Therefore, this circuit rejects sends to self.
106
113
  *
107
114
  * @notice Access control is NOT enforced here.
108
115
  * The consuming contract must gate this behind its own
@@ -110,6 +117,7 @@ module UnshieldedTreasury {
110
117
  *
111
118
  * Requirements:
112
119
  *
120
+ * - `recipient` must not be this contract's own address.
113
121
  * - The amount must be non-zero. The ledger rejects zero-value outputs.
114
122
  * - The treasury must hold sufficient balance for the given token color.
115
123
  *
@@ -124,6 +132,11 @@ module UnshieldedTreasury {
124
132
  color: Bytes<32>,
125
133
  amount: Uint<128>
126
134
  ): [] {
135
+ // `kernel.self()` stays outside the `||`: the compiler treats a ledger
136
+ // read behind a witness-conditioned branch as an undeclared disclosure
137
+ const self = kernel.self();
138
+ assert(!recipient.is_left || recipient.left != self,
139
+ "UnshieldedTreasury: self-send");
127
140
  assert(amount != 0, "UnshieldedTreasury: zero amount");
128
141
 
129
142
  const bal = getTokenBalance(color);
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Compact Contracts v0.4.0-alpha.5 (multisig/examples/ForwarderPrivateExample.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0 (multisig/examples/ForwarderPrivateExample.compact)
3
3
 
4
4
  pragma language_version >= 0.26.0;
5
5
 
@@ -54,7 +54,8 @@ export circuit deposit(coin: ShieldedCoinInfo): [] {
54
54
  * @description Spends a previously-deposited shielded coin to the parent,
55
55
  * a coin public key. The caller proves knowledge of `(parent, opSecret)`
56
56
  * matching the stored commitment; the coin is sent as a shielded note, so the
57
- * parent stays hidden on-chain. If the input coin's value exceeds `value`,
57
+ * parent stays hidden from anyone who holds no deposited coin (see the
58
+ * `ForwarderPrivate` module notice). If the input coin's value exceeds `value`,
58
59
  * change is re-emitted back to the contract for future drains.
59
60
  *
60
61
  * The parent is a `ZswapCoinPublicKey`, never a `ContractAddress`: a shielded
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Compact Contracts v0.4.0-alpha.5 (multisig/examples/ForwarderShieldedExample.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0 (multisig/examples/ForwarderShieldedExample.compact)
3
3
 
4
4
  pragma language_version >= 0.26.0;
5
5
 
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Compact Contracts v0.4.0-alpha.5 (multisig/examples/ForwarderUnshieldedExample.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0 (multisig/examples/ForwarderUnshieldedExample.compact)
3
3
 
4
4
  pragma language_version >= 0.26.0;
5
5
 
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Compact Contracts v0.4.0-alpha.5 (multisig/examples/NativeShieldedTokenIssuerExample.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0 (multisig/examples/NativeShieldedTokenIssuerExample.compact)
3
3
 
4
4
  pragma language_version >= 0.26.0;
5
5
 
@@ -19,7 +19,7 @@ pragma language_version >= 0.26.0;
19
19
 
20
20
  import CompactStandardLibrary;
21
21
 
22
- import "../presets/NativeShieldedTokenIssuer" prefix NativeShieldedTokenIssuer_;
22
+ import "../presets/NativeShieldedTokenIssuer"<2> prefix NativeShieldedTokenIssuer_;
23
23
 
24
24
  export { ZswapCoinPublicKey, ContractAddress, Either, Maybe };
25
25
  export { ShieldedCoinInfo, QualifiedShieldedCoinInfo };
@@ -39,7 +39,7 @@ import {
39
39
  _symbol,
40
40
  _decimals,
41
41
  _isInitialized,
42
- } from "../presets/NativeShieldedTokenIssuer";
42
+ } from "../presets/NativeShieldedTokenIssuer"<2>;
43
43
  export {
44
44
  _counter,
45
45
  _domainSeparator,
@@ -79,7 +79,7 @@ constructor(
79
79
  decimals_: Uint<8>,
80
80
  signerCommitments: Vector<3, Bytes<32>>,
81
81
  ) {
82
- NativeShieldedTokenIssuer_initialize(
82
+ NativeShieldedTokenIssuer_initialize<3>(
83
83
  instanceSalt,
84
84
  tokenDomain,
85
85
  name_,
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Compact Contracts v0.4.0-alpha.5 (multisig/examples/ShieldedMultiSigV2Example.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0 (multisig/examples/ShieldedMultiSigV2Example.compact)
3
3
 
4
4
  pragma language_version >= 0.26.0;
5
5
 
@@ -15,28 +15,26 @@ pragma language_version >= 0.26.0;
15
15
 
16
16
  import CompactStandardLibrary;
17
17
 
18
- import "../presets/ShieldedMultiSigV2" prefix ShieldedMultiSigV2_;
18
+ import "../presets/ShieldedMultiSigV2"<2> prefix ShieldedMultiSigV2_;
19
19
 
20
20
  export { ShieldedCoinInfo, QualifiedShieldedCoinInfo, ShieldedSendResult };
21
21
 
22
22
  // Surface the preset's domain separator unprefixed so `ledger()` readers see
23
23
  // the key name the preset published.
24
- import { _domainSeparator } from "../presets/ShieldedMultiSigV2";
24
+ import { _domainSeparator } from "../presets/ShieldedMultiSigV2"<2>;
25
25
  export { _domainSeparator };
26
26
 
27
27
  /**
28
- * @description Deploys the wallet with 3 signer commitments and a threshold.
28
+ * @description Deploys the wallet with 3 signer commitments.
29
29
  *
30
30
  * @param {Bytes<32>} instanceSalt - Random salt for commitment derivation.
31
31
  * @param {Vector<3, Bytes<32>>} signerCommitments - Hashed signer identities.
32
- * @param {Uint<8>} thresh - Approvals required. Must be 2.
33
32
  */
34
33
  constructor(
35
34
  instanceSalt: Bytes<32>,
36
- signerCommitments: Vector<3, Bytes<32>>,
37
- thresh: Uint<8>,
35
+ signerCommitments: Vector<3, Bytes<32>>
38
36
  ) {
39
- ShieldedMultiSigV2_initialize(instanceSalt, signerCommitments, thresh);
37
+ ShieldedMultiSigV2_initialize<3>(instanceSalt, signerCommitments);
40
38
  }
41
39
 
42
40
  export circuit deposit(coin: ShieldedCoinInfo): [] {
@@ -44,7 +42,7 @@ export circuit deposit(coin: ShieldedCoinInfo): [] {
44
42
  }
45
43
 
46
44
  export circuit execute(
47
- to: ShieldedMultiSigV2_Proposal_Recipient,
45
+ to: ShieldedMultiSigV2_Recipient,
48
46
  amount: Uint<128>,
49
47
  coin: QualifiedShieldedCoinInfo,
50
48
  pubkeys: Vector<2, Secp256k1Point>,