@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.
- package/README.md +10 -10
- package/access/AccessControl.compact +3 -35
- package/access/Ownable.compact +5 -51
- package/access/ShieldedAccessControl.compact +2 -2
- package/access/ZOwnablePK.compact +2 -2
- package/crypto/EcdhMask.compact +177 -0
- package/crypto/ElGamal.compact +473 -0
- package/multisig/ForwarderPrivate.compact +233 -0
- package/multisig/ForwarderShielded.compact +149 -0
- package/multisig/ForwarderUnshielded.compact +152 -0
- package/multisig/ProposalManager.compact +328 -0
- package/multisig/ShieldedTreasury.compact +204 -0
- package/multisig/ShieldedTreasuryStateless.compact +80 -0
- package/multisig/Signer.compact +312 -0
- package/multisig/SignerManager.compact +205 -0
- package/multisig/UnshieldedTreasury.compact +114 -0
- package/multisig/presets/ShieldedMultiSig.compact +227 -0
- package/multisig/presets/ShieldedMultiSigV2.compact +280 -0
- package/multisig/presets/ShieldedMultiSigV3.compact +368 -0
- package/multisig/presets/forwarder/ForwarderPrivate.compact +125 -0
- package/multisig/presets/forwarder/ForwarderShielded.compact +62 -0
- package/multisig/presets/forwarder/ForwarderUnshielded.compact +64 -0
- package/package.json +32 -16
- package/security/Allowlist.compact +101 -0
- package/security/Blocklist.compact +99 -0
- package/security/Initializable.compact +2 -2
- package/security/Pausable.compact +2 -2
- package/token/ConfidentialFungibleToken.compact +1180 -0
- package/token/FungibleToken.compact +24 -82
- package/token/MultiToken.compact +21 -80
- package/token/NativeShieldedToken.compact +285 -0
- package/token/NativeShieldedTokenCore.compact +343 -0
- package/token/NativeShieldedTokenFamily.compact +287 -0
- package/token/NonFungibleToken.compact +25 -83
- package/token/extensions/ConfidentialFungibleTokenPublicSupply.compact +90 -0
- package/token/extensions/NativeShieldedTokenDerivedNonce.compact +70 -0
- package/token/extensions/NativeShieldedTokenFamilySupply.compact +145 -0
- package/token/extensions/NativeShieldedTokenSupply.compact +142 -0
- package/token/extensions/NativeShieldedTokenSupplyCore.compact +163 -0
- 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.
|
|
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
|
|
24
|
+
"#test-utils/*": "./test-utils/*"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
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": "
|
|
35
|
-
"test:coverage": "
|
|
36
|
-
"
|
|
37
|
-
"test:
|
|
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
|
-
"@
|
|
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": "
|
|
51
|
-
"@vitest/coverage-v8": "^4.1.
|
|
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.
|
|
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
|
+
// OpenZeppelin Compact Contracts v0.3.0-alpha.1 (security/Initializable.compact)
|
|
3
3
|
|
|
4
|
-
pragma language_version >= 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
|
+
// OpenZeppelin Compact Contracts v0.3.0-alpha.1 (security/Pausable.compact)
|
|
3
3
|
|
|
4
|
-
pragma language_version >= 0.
|
|
4
|
+
pragma language_version >= 0.23.0;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @module Pausable
|