@openzeppelin/compact-contracts 0.4.0-alpha.2 → 0.4.0-alpha.4

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 (42) hide show
  1. package/access/AccessControl.compact +1 -1
  2. package/access/Ownable.compact +1 -1
  3. package/access/ShieldedAccessControl.compact +1 -1
  4. package/access/ZOwnablePK.compact +1 -1
  5. package/crypto/EcdhMask.compact +1 -1
  6. package/crypto/Ecdsa.compact +1 -1
  7. package/crypto/Eip712.compact +1 -1
  8. package/crypto/ElGamal.compact +44 -3
  9. package/multisig/EcdsaSignerManager.compact +1 -1
  10. package/multisig/ForwarderPrivate.compact +1 -1
  11. package/multisig/ForwarderShielded.compact +1 -1
  12. package/multisig/ForwarderUnshielded.compact +1 -1
  13. package/multisig/ProposalManager.compact +1 -1
  14. package/multisig/ShieldedTreasury.compact +1 -1
  15. package/multisig/ShieldedTreasuryStateless.compact +1 -1
  16. package/multisig/Signer.compact +1 -1
  17. package/multisig/UnshieldedTreasury.compact +1 -1
  18. package/multisig/examples/ForwarderPrivateExample.compact +1 -1
  19. package/multisig/examples/ForwarderShieldedExample.compact +1 -1
  20. package/multisig/examples/ForwarderUnshieldedExample.compact +1 -1
  21. package/multisig/examples/NativeShieldedTokenIssuerExample.compact +25 -5
  22. package/multisig/examples/ShieldedMultiSigV2Example.compact +1 -1
  23. package/multisig/presets/NativeShieldedTokenIssuer.compact +253 -100
  24. package/multisig/presets/ShieldedMultiSigV2.compact +1 -1
  25. package/package.json +5 -3
  26. package/security/Allowlist.compact +1 -1
  27. package/security/Blocklist.compact +1 -1
  28. package/security/Initializable.compact +1 -1
  29. package/security/Pausable.compact +1 -1
  30. package/token/ConfidentialFungibleToken.compact +268 -69
  31. package/token/FungibleToken.compact +1 -1
  32. package/token/MultiToken.compact +1 -1
  33. package/token/NativeShieldedToken.compact +59 -10
  34. package/token/NativeShieldedTokenCore.compact +41 -9
  35. package/token/NativeShieldedTokenFamily.compact +60 -10
  36. package/token/NonFungibleToken.compact +56 -12
  37. package/token/extensions/ConfidentialFungibleTokenPublicSupply.compact +1 -1
  38. package/token/extensions/NativeShieldedTokenDerivedNonce.compact +1 -1
  39. package/token/extensions/NativeShieldedTokenFamilyPublicSupply.compact +2 -2
  40. package/token/extensions/NativeShieldedTokenPublicSupply.compact +2 -2
  41. package/utils/EvmAbi.compact +1 -1
  42. package/utils/Utils.compact +11 -1
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Compact Contracts v0.4.0-alpha.2 (access/AccessControl.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (access/AccessControl.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.2 (access/Ownable.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (access/Ownable.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.2 (access/ShieldedAccessControl.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (access/ShieldedAccessControl.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.2 (access/ZOwnablePK.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (access/ZOwnablePK.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.2 (crypto/EcdhMask.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (crypto/EcdhMask.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.2 (crypto/Ecdsa.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (crypto/Ecdsa.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.2 (crypto/Eip712.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (crypto/Eip712.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.2 (crypto/ElGamal.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (crypto/ElGamal.compact)
3
3
 
4
4
  pragma language_version >= 0.26.0;
5
5
 
@@ -38,6 +38,13 @@ pragma language_version >= 0.26.0;
38
38
  * cast reduces modulo the subgroup order, so casting at a call site would
39
39
  * silently accept an out-of-range scalar the typed parameter rejects.
40
40
  *
41
+ * @dev Domain separation. `persistentHash<Vector<N, Bytes<32>>>` is NOT
42
+ * domain-separating on its own. Two circuits hashing the same arity and
43
+ * element type share one hash domain, and the hash cannot tell which slot was
44
+ * "meant" as a tag. `secretToScalar` therefore prefixes a fixed constant, and
45
+ * that constant is placed FIRST so no call to `expandRandomness` (whose two
46
+ * slots are both caller-supplied) can reproduce the tuple by ordinary use.
47
+ *
41
48
  * @dev TRUST ASSUMPTION — subgroup membership. This is the module's most
42
49
  * load-bearing assumption. Every `JubjubPoint` reaching a curve operation is
43
50
  * assumed to be in the Jubjub prime-order subgroup, including points supplied by
@@ -105,11 +112,34 @@ module ElGamal {
105
112
  * @description Maps a 32-byte secret to a valid Jubjub scalar. See the
106
113
  * module-level hash-to-scalar note for why `degradeToTransient` is required.
107
114
  *
115
+ * @dev Domain separation here is load-bearing, not cosmetic. This output is
116
+ * the private key protecting every ciphertext held under an account. Public
117
+ * account identifiers derived from `Utils.computeAccountId`, for example,
118
+ * are computed as `persistentHash([secretKey])`, and that identifier
119
+ * is stored in the clear as a ledger map key. Untagged, this circuit
120
+ * would compute that same hash, so a secret used in both roles would
121
+ * have its encryption key recoverable from a published identifier by applying
122
+ * `degradeToTransient`. The tag makes the two derivations unrelated, so a
123
+ * wallet MAY safely derive its account secret and its encryption secret from
124
+ * common key material.
125
+ *
126
+ * @dev The tag is FIRST, deliberately. `expandRandomness` hashes
127
+ * `[seed, tag]` with both slots caller-supplied, so tagging this circuit as
128
+ * `[secret, tag]` would make `secretToScalar(x)` identical to
129
+ * `expandRandomness(x, <this tag>)` reachable by passing this domain string
130
+ * to the parameter that exists to receive domain strings. Leading with the
131
+ * tag means reproducing this output through `expandRandomness` would require
132
+ * passing the domain constant as the *seed*. Do not normalise the orderings.
133
+ *
108
134
  * @param secret - The 32-byte secret to map.
109
135
  * @return A valid Jubjub scalar.
110
136
  */
111
137
  export pure circuit secretToScalar(secret: Bytes<32>): JubjubScalar {
112
- return degradeToTransient(persistentHash<Vector<1, Bytes<32>>>([secret])) as JubjubScalar;
138
+ return degradeToTransient(
139
+ persistentHash<Vector<2, Bytes<32>>>(
140
+ [pad(32, "ElGamal:secretToScalar"), secret]
141
+ )
142
+ ) as JubjubScalar;
113
143
  }
114
144
 
115
145
  /**
@@ -419,6 +449,17 @@ module ElGamal {
419
449
  * wrong plaintext fails the decryption check. Lifted special case of
420
450
  * `assertDecryptsToPoint` with the message point `g^claimedValue`.
421
451
  *
452
+ * @notice `claimedValue` is the widest `Uint` Compact offers, so this parameter
453
+ * never bounds a caller. A narrower value costs proportionally fewer rows: the
454
+ * range constraint belongs to where the value is declared, not to this
455
+ * signature.
456
+ *
457
+ * @warning The claim domain must stay below the Jubjub subgroup order `l`:
458
+ * verification compares `g^claimedValue`, so two claims congruent mod `l` are
459
+ * indistinguishable. `Uint<248>` clears `l` (~2^251.86) by under 4 bits, and
460
+ * that width is set by Compact's cap rather than by this bound. 251 is the
461
+ * widest sound `Uint` if the cap ever rises.
462
+ *
422
463
  * Requirements:
423
464
  *
424
465
  * - `ek` is the secret for `pk`.
@@ -433,7 +474,7 @@ module ElGamal {
433
474
  ct: Ciphertext,
434
475
  pk: JubjubPoint,
435
476
  ek: Bytes<32>,
436
- claimedValue: Uint<128>
477
+ claimedValue: Uint<248>
437
478
  ): [] {
438
479
  assertDecryptsToPoint(ct, pk, ek, ecMulGenerator(claimedValue as JubjubScalar));
439
480
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Compact Contracts v0.4.0-alpha.2 (multisig/EcdsaSignerManager.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (multisig/EcdsaSignerManager.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.2 (multisig/ForwarderPrivate.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (multisig/ForwarderPrivate.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.2 (multisig/ForwarderShielded.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (multisig/ForwarderShielded.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.2 (multisig/ForwarderUnshielded.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (multisig/ForwarderUnshielded.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.2 (multisig/ProposalManager.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (multisig/ProposalManager.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.2 (multisig/ShieldedTreasury.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (multisig/ShieldedTreasury.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.2 (multisig/ShieldedTreasuryStateless.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (multisig/ShieldedTreasuryStateless.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.2 (multisig/Signer.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (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.2 (multisig/UnshieldedTreasury.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (multisig/UnshieldedTreasury.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.2 (multisig/examples/ForwarderPrivateExample.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (multisig/examples/ForwarderPrivateExample.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.2 (multisig/examples/ForwarderShieldedExample.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (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.2 (multisig/examples/ForwarderUnshieldedExample.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (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.2 (multisig/examples/NativeShieldedTokenIssuerExample.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (multisig/examples/NativeShieldedTokenIssuerExample.compact)
3
3
 
4
4
  pragma language_version >= 0.26.0;
5
5
 
@@ -7,10 +7,12 @@ pragma language_version >= 0.26.0;
7
7
  * @title NativeShieldedTokenIssuerExample
8
8
  * @description Deployable reference contract for the `NativeShieldedTokenIssuer`
9
9
  * preset: a native shielded token whose supply enters only through an
10
- * ECDSA-authorized mint and leaves only through an ECDSA-authorized burn.
10
+ * ECDSA-authorized mint, to a holder (`mint`) or to the contract itself
11
+ * (`mintToSelf`), and leaves only through an ECDSA-authorized burn, of a
12
+ * holder's coin (`burn`) or of one the contract holds (`burnFromSelf`).
11
13
  *
12
14
  * The token is non-transferable by construction. There is no transfer circuit,
13
- * so a holder's only exit is to present the coin back for burn.
15
+ * so a holder's only exit is to pay the coin into a `burn` tx.
14
16
  */
15
17
 
16
18
  import CompactStandardLibrary;
@@ -94,20 +96,38 @@ export pure circuit _calculateSignerId(
94
96
 
95
97
  export circuit mint(
96
98
  amount: Uint<64>,
97
- recipient: Either<ZswapCoinPublicKey, ContractAddress>,
99
+ recipient: ZswapCoinPublicKey,
98
100
  pubkeys: Vector<2, Secp256k1Point>,
99
101
  signatures: Vector<2, Secp256k1EcdsaSignature>
100
102
  ): ShieldedCoinInfo {
101
103
  return NativeShieldedTokenIssuer_mint(amount, recipient, pubkeys, signatures);
102
104
  }
103
105
 
106
+ export circuit mintToSelf(
107
+ amount: Uint<64>,
108
+ pubkeys: Vector<2, Secp256k1Point>,
109
+ signatures: Vector<2, Secp256k1EcdsaSignature>
110
+ ): ShieldedCoinInfo {
111
+ return NativeShieldedTokenIssuer_mintToSelf(amount, pubkeys, signatures);
112
+ }
113
+
104
114
  export circuit burn(
115
+ coin: ShieldedCoinInfo,
116
+ amount: Uint<64>,
117
+ refundTo: ZswapCoinPublicKey,
118
+ pubkeys: Vector<2, Secp256k1Point>,
119
+ signatures: Vector<2, Secp256k1EcdsaSignature>
120
+ ): Maybe<ShieldedCoinInfo> {
121
+ return NativeShieldedTokenIssuer_burn(coin, amount, refundTo, pubkeys, signatures);
122
+ }
123
+
124
+ export circuit burnFromSelf(
105
125
  coin: QualifiedShieldedCoinInfo,
106
126
  amount: Uint<64>,
107
127
  pubkeys: Vector<2, Secp256k1Point>,
108
128
  signatures: Vector<2, Secp256k1EcdsaSignature>
109
129
  ): Maybe<ShieldedCoinInfo> {
110
- return NativeShieldedTokenIssuer_burn(coin, amount, pubkeys, signatures);
130
+ return NativeShieldedTokenIssuer_burnFromSelf(coin, amount, pubkeys, signatures);
111
131
  }
112
132
 
113
133
  export circuit getNonce(): Uint<64> {
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Compact Contracts v0.4.0-alpha.2 (multisig/examples/ShieldedMultiSigV2Example.compact)
2
+ // OpenZeppelin Compact Contracts v0.4.0-alpha.4 (multisig/examples/ShieldedMultiSigV2Example.compact)
3
3
 
4
4
  pragma language_version >= 0.26.0;
5
5