@openzeppelin/compact-contracts 0.2.0 → 0.3.0-alpha.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.
Files changed (40) hide show
  1. package/README.md +10 -10
  2. package/access/AccessControl.compact +3 -35
  3. package/access/Ownable.compact +5 -51
  4. package/access/ShieldedAccessControl.compact +2 -2
  5. package/access/ZOwnablePK.compact +2 -2
  6. package/crypto/EcdhMask.compact +177 -0
  7. package/crypto/ElGamal.compact +473 -0
  8. package/multisig/ForwarderPrivate.compact +233 -0
  9. package/multisig/ForwarderShielded.compact +149 -0
  10. package/multisig/ForwarderUnshielded.compact +152 -0
  11. package/multisig/ProposalManager.compact +328 -0
  12. package/multisig/ShieldedTreasury.compact +204 -0
  13. package/multisig/ShieldedTreasuryStateless.compact +80 -0
  14. package/multisig/Signer.compact +312 -0
  15. package/multisig/SignerManager.compact +205 -0
  16. package/multisig/UnshieldedTreasury.compact +114 -0
  17. package/multisig/presets/ShieldedMultiSig.compact +227 -0
  18. package/multisig/presets/ShieldedMultiSigV2.compact +280 -0
  19. package/multisig/presets/ShieldedMultiSigV3.compact +368 -0
  20. package/multisig/presets/forwarder/ForwarderPrivate.compact +125 -0
  21. package/multisig/presets/forwarder/ForwarderShielded.compact +62 -0
  22. package/multisig/presets/forwarder/ForwarderUnshielded.compact +64 -0
  23. package/package.json +32 -16
  24. package/security/Allowlist.compact +101 -0
  25. package/security/Blocklist.compact +99 -0
  26. package/security/Initializable.compact +2 -2
  27. package/security/Pausable.compact +2 -2
  28. package/token/ConfidentialFungibleToken.compact +1180 -0
  29. package/token/FungibleToken.compact +24 -82
  30. package/token/MultiToken.compact +21 -80
  31. package/token/NativeShieldedToken.compact +285 -0
  32. package/token/NativeShieldedTokenCore.compact +343 -0
  33. package/token/NativeShieldedTokenFamily.compact +287 -0
  34. package/token/NonFungibleToken.compact +25 -83
  35. package/token/extensions/ConfidentialFungibleTokenPublicSupply.compact +90 -0
  36. package/token/extensions/NativeShieldedTokenDerivedNonce.compact +70 -0
  37. package/token/extensions/NativeShieldedTokenFamilySupply.compact +145 -0
  38. package/token/extensions/NativeShieldedTokenSupply.compact +142 -0
  39. package/token/extensions/NativeShieldedTokenSupplyCore.compact +163 -0
  40. package/utils/Utils.compact +86 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openzeppelin/compact-contracts",
3
- "version": "0.2.0",
3
+ "version": "0.3.0-alpha.1",
4
4
  "description": "OpenZeppelin Compact contract library",
5
5
  "keywords": [
6
6
  "openzeppelin",
@@ -21,20 +21,24 @@
21
21
  "homepage": "https://docs.openzeppelin.com/contracts-compact/",
22
22
  "type": "module",
23
23
  "imports": {
24
- "#test-utils/address.js": "./test-utils/address.js"
24
+ "#test-utils/*": "./test-utils/*"
25
25
  },
26
26
  "scripts": {
27
- "compact": "compact-compiler --exclude '*/archive/*'",
28
- "compact:access": "compact-compiler --dir access",
29
- "compact:archive": "compact-compiler --dir archive",
30
- "compact:security": "compact-compiler --dir security",
31
- "compact:token": "compact-compiler --dir token",
32
- "compact:utils": "compact-compiler --dir utils",
27
+ "compile": "compact-compiler --exclude '*/archive/*'",
28
+ "compile:access": "compact-compiler --dir access",
29
+ "compile:archive": "compact-compiler --dir archive",
30
+ "compile:crypto": "compact-compiler --dir crypto",
31
+ "compile:multisig": "compact-compiler --dir multisig",
32
+ "compile:security": "compact-compiler --dir security",
33
+ "compile:token": "compact-compiler --dir token",
34
+ "compile:utils": "compact-compiler --dir utils",
35
+ "compile:integration": "SKIP_ZK=true compact-compiler --src test/integration/_mocks",
33
36
  "build": "compact-builder --hierarchical --out dist --clean-dist --exclude '*/archive/*' --exclude 'Mock*' --exclude '*.mock.compact' --copy package.json --copy ../README.md && find dist -type d -empty -delete",
34
- "test": "SKIP_ZK=true yarn run compact && vitest run",
35
- "test:coverage": "SKIP_ZK=true yarn run compact && vitest run --coverage",
36
- "compact:integration": "SKIP_ZK=true compact compile test/integration/_mocks/SharedInitCollision.compact artifacts/SharedInitCollision && SKIP_ZK=true compact compile test/integration/_mocks/ComposedTokens.compact artifacts/ComposedTokens",
37
- "test:integration": "yarn run compact:integration && vitest run --config vitest.integration.config.ts",
37
+ "test": "vitest run --project unit",
38
+ "test:coverage": "vitest run --project unit --coverage",
39
+ "test:integration": "vitest run --project integration",
40
+ "test:harness": "vitest run --project harness",
41
+ "test:harness:live": "MIDNIGHT_BACKEND=live vitest run --project harness-live",
38
42
  "types": "tsc -p tsconfig.json --noEmit",
39
43
  "clean": "git clean -fXd"
40
44
  },
@@ -45,12 +49,24 @@
45
49
  "@openzeppelin/compact-cli": "^0.0.2"
46
50
  },
47
51
  "devDependencies": {
48
- "@openzeppelin/compact-simulator": "^0.0.1",
52
+ "@midnight-ntwrk/compact-js": "2.5.1",
53
+ "@midnight-ntwrk/compact-runtime": "0.16.0",
54
+ "@midnight-ntwrk/ledger-v8": "8.1.0",
55
+ "@midnight-ntwrk/midnight-js-contracts": "4.1.1",
56
+ "@midnight-ntwrk/midnight-js-http-client-proof-provider": "4.1.1",
57
+ "@midnight-ntwrk/midnight-js-indexer-public-data-provider": "4.1.1",
58
+ "@midnight-ntwrk/midnight-js-network-id": "4.1.1",
59
+ "@midnight-ntwrk/midnight-js-node-zk-config-provider": "4.1.1",
60
+ "@midnight-ntwrk/midnight-js-protocol": "4.1.1",
61
+ "@midnight-ntwrk/midnight-js-types": "4.1.1",
62
+ "@midnight-ntwrk/testkit-js": "4.1.1",
63
+ "@openzeppelin/compact-simulator": "^0.2.0",
49
64
  "@tsconfig/node24": "^24.0.4",
50
- "@types/node": "25.9.1",
51
- "@vitest/coverage-v8": "^4.1.8",
65
+ "@types/node": "26.1.1",
66
+ "@vitest/coverage-v8": "^4.1.10",
67
+ "fast-check": "^4.9.0",
52
68
  "ts-node": "^10.9.2",
53
69
  "typescript": "^6.0.3",
54
- "vitest": "^4.1.8"
70
+ "vitest": "^4.1.10"
55
71
  }
56
72
  }
@@ -0,0 +1,101 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Compact Contracts v0.3.0-alpha.1 (security/Allowlist.compact)
3
+
4
+ pragma language_version >= 0.23.0;
5
+
6
+ /**
7
+ * @module Allowlist
8
+ * @description A minimal, reusable permit-list keyed by an abstract `Bytes<32>`
9
+ * account identifier. It answers a single question: is this account a member?
10
+ *
11
+ * This module is a pure membership MECHANISM, not a policy. It holds no notion
12
+ * of "when" the list is enforced and no access control. The mutators (`_allow`,
13
+ * `_disallow`) are deliberately UNGATED composable primitives: a composing
14
+ * contract gates them behind its access-control module (the same way a token
15
+ * gates `_mint` / `_burn`), and decides when to call `assertAllowed` (for
16
+ * example, only while an "eligibility required" flag is set). Keeping the
17
+ * enforce-or-not decision in the composing layer leaves this module general
18
+ * enough to back KYC allowlists, permissioned mints, membership gates, and the
19
+ * like.
20
+ *
21
+ * @notice This is the PUBLIC (transparent) allowlist: membership status is
22
+ * publicly readable and the approved set is publicly enumerable. That is the
23
+ * right posture for transparent or public-graph assets. A graph-private asset
24
+ * should instead use a shielded allowlist (a public allowlist would re-expose
25
+ * the candidate set and bound the anonymity set).
26
+ */
27
+ module Allowlist {
28
+ import CompactStandardLibrary;
29
+
30
+ // ---------------------------------------------------------------------------
31
+ // State
32
+ // ---------------------------------------------------------------------------
33
+
34
+ /** @description Approved accounts. Absent means not allowed. */
35
+ export ledger _allowed: Set<Bytes<32>>;
36
+
37
+ // ---------------------------------------------------------------------------
38
+ // Views
39
+ // ---------------------------------------------------------------------------
40
+
41
+ /**
42
+ * @description Returns whether `account` is currently allowed.
43
+ *
44
+ * @circuitInfo k=9, rows=305
45
+ *
46
+ * @param {Bytes<32>} account - The account to query.
47
+ * @return {Boolean} - True if `account` is a member of the allowlist.
48
+ */
49
+ export circuit isAllowed(account: Bytes<32>): Boolean {
50
+ return _allowed.member(disclose(account));
51
+ }
52
+
53
+ // ---------------------------------------------------------------------------
54
+ // Check (the eligibility seam)
55
+ // ---------------------------------------------------------------------------
56
+
57
+ /**
58
+ * @description Asserts that `account` is allowed. The composing contract
59
+ * decides when this gate applies.
60
+ *
61
+ * @circuitInfo k=9, rows=305
62
+ *
63
+ * Requirements:
64
+ *
65
+ * - `account` is a member of the allowlist.
66
+ *
67
+ * @param {Bytes<32>} account - The account that must be allowed.
68
+ * @return {[]} - Empty tuple.
69
+ */
70
+ export circuit assertAllowed(account: Bytes<32>): [] {
71
+ assert(isAllowed(account), "Allowlist: account not allowed");
72
+ }
73
+
74
+ // ---------------------------------------------------------------------------
75
+ // Mutators (UNGATED - the composing contract is responsible for gating these)
76
+ // ---------------------------------------------------------------------------
77
+
78
+ /**
79
+ * @description Adds `account` to the allowlist.
80
+ *
81
+ * @circuitInfo k=9, rows=303
82
+ *
83
+ * @param {Bytes<32>} account - The account to allow.
84
+ * @return {[]} - Empty tuple.
85
+ */
86
+ export circuit _allow(account: Bytes<32>): [] {
87
+ _allowed.insert(disclose(account));
88
+ }
89
+
90
+ /**
91
+ * @description Removes `account` from the allowlist.
92
+ *
93
+ * @circuitInfo k=9, rows=303
94
+ *
95
+ * @param {Bytes<32>} account - The account to disallow.
96
+ * @return {[]} - Empty tuple.
97
+ */
98
+ export circuit _disallow(account: Bytes<32>): [] {
99
+ _allowed.remove(disclose(account));
100
+ }
101
+ }
@@ -0,0 +1,99 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // OpenZeppelin Compact Contracts v0.3.0-alpha.1 (security/Blocklist.compact)
3
+
4
+ pragma language_version >= 0.23.0;
5
+
6
+ /**
7
+ * @module Blocklist
8
+ * @description A minimal, reusable deny-list keyed by an abstract `Bytes<32>`
9
+ * account identifier. It answers a single question: is this account blocked?
10
+ *
11
+ * This module is a pure membership MECHANISM, not a policy. It holds no notion
12
+ * of "when" the list is enforced and no access control. The mutators (`_block`,
13
+ * `_unblock`) are deliberately UNGATED composable primitives: a composing
14
+ * contract gates them behind its access-control module (the same way a token
15
+ * gates `_mint` / `_burn`), and decides when to call `assertNotBlocked`. Keeping
16
+ * the enforce-or-not decision in the composing layer leaves this module general
17
+ * enough to back sanctions lists, account freezes, abuse denials, and the like.
18
+ *
19
+ * @notice This is the PUBLIC (transparent) blocklist: membership status is
20
+ * publicly readable and the blocked set is publicly enumerable. That is the
21
+ * right posture for transparent or public-graph assets. A graph-private asset
22
+ * should instead use a shielded blocklist (a public blocklist would re-expose
23
+ * the candidate set and bound the anonymity set).
24
+ */
25
+ module Blocklist {
26
+ import CompactStandardLibrary;
27
+
28
+ // ---------------------------------------------------------------------------
29
+ // State
30
+ // ---------------------------------------------------------------------------
31
+
32
+ /** @description Blocked accounts. Absent means not blocked. */
33
+ export ledger _blocked: Set<Bytes<32>>;
34
+
35
+ // ---------------------------------------------------------------------------
36
+ // Views
37
+ // ---------------------------------------------------------------------------
38
+
39
+ /**
40
+ * @description Returns whether `account` is currently blocked.
41
+ *
42
+ * @circuitInfo k=9, rows=305
43
+ *
44
+ * @param {Bytes<32>} account - The account to query.
45
+ * @return {Boolean} - True if `account` is a member of the blocklist.
46
+ */
47
+ export circuit isBlocked(account: Bytes<32>): Boolean {
48
+ return _blocked.member(disclose(account));
49
+ }
50
+
51
+ // ---------------------------------------------------------------------------
52
+ // Check (the eligibility seam)
53
+ // ---------------------------------------------------------------------------
54
+
55
+ /**
56
+ * @description Asserts that `account` is not blocked. The composing contract
57
+ * decides when this gate applies.
58
+ *
59
+ * @circuitInfo k=9, rows=308
60
+ *
61
+ * Requirements:
62
+ *
63
+ * - `account` is not a member of the blocklist.
64
+ *
65
+ * @param {Bytes<32>} account - The account that must not be blocked.
66
+ * @return {[]} - Empty tuple.
67
+ */
68
+ export circuit assertNotBlocked(account: Bytes<32>): [] {
69
+ assert(!isBlocked(account), "Blocklist: account blocked");
70
+ }
71
+
72
+ // ---------------------------------------------------------------------------
73
+ // Mutators (UNGATED - the composing contract is responsible for gating these)
74
+ // ---------------------------------------------------------------------------
75
+
76
+ /**
77
+ * @description Adds `account` to the blocklist.
78
+ *
79
+ * @circuitInfo k=9, rows=303
80
+ *
81
+ * @param {Bytes<32>} account - The account to block.
82
+ * @return {[]} - Empty tuple.
83
+ */
84
+ export circuit _block(account: Bytes<32>): [] {
85
+ _blocked.insert(disclose(account));
86
+ }
87
+
88
+ /**
89
+ * @description Removes `account` from the blocklist.
90
+ *
91
+ * @circuitInfo k=9, rows=303
92
+ *
93
+ * @param {Bytes<32>} account - The account to unblock.
94
+ * @return {[]} - Empty tuple.
95
+ */
96
+ export circuit _unblock(account: Bytes<32>): [] {
97
+ _blocked.remove(disclose(account));
98
+ }
99
+ }
@@ -1,7 +1,7 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Compact Contracts v0.2.0 (security/Initializable.compact)
2
+ // OpenZeppelin Compact Contracts v0.3.0-alpha.1 (security/Initializable.compact)
3
3
 
4
- pragma language_version >= 0.21.0;
4
+ pragma language_version >= 0.23.0;
5
5
 
6
6
  /**
7
7
  * @module Initializable
@@ -1,7 +1,7 @@
1
1
  // SPDX-License-Identifier: MIT
2
- // OpenZeppelin Compact Contracts v0.2.0 (security/Pausable.compact)
2
+ // OpenZeppelin Compact Contracts v0.3.0-alpha.1 (security/Pausable.compact)
3
3
 
4
- pragma language_version >= 0.21.0;
4
+ pragma language_version >= 0.23.0;
5
5
 
6
6
  /**
7
7
  * @module Pausable