@openzeppelin/compact-contracts 0.3.0-alpha → 0.3.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 +7 -7
- package/access/AccessControl.compact +1 -1
- package/access/Ownable.compact +1 -1
- package/access/ShieldedAccessControl.compact +1 -1
- package/access/ZOwnablePK.compact +1 -1
- package/crypto/EcdhMask.compact +177 -0
- package/crypto/ElGamal.compact +1 -1
- package/multisig/ForwarderPrivate.compact +16 -12
- package/multisig/ForwarderShielded.compact +2 -2
- package/multisig/ForwarderUnshielded.compact +2 -2
- package/multisig/ProposalManager.compact +35 -1
- package/multisig/ShieldedTreasury.compact +46 -13
- package/multisig/ShieldedTreasuryStateless.compact +56 -23
- package/multisig/Signer.compact +45 -41
- package/multisig/UnshieldedTreasury.compact +44 -17
- package/multisig/presets/ShieldedMultiSig.compact +10 -19
- package/multisig/presets/ShieldedMultiSigV2.compact +2 -2
- package/multisig/presets/ShieldedMultiSigV3.compact +2 -2
- package/multisig/presets/forwarder/ForwarderPrivate.compact +1 -1
- package/multisig/presets/forwarder/ForwarderShielded.compact +1 -1
- package/multisig/presets/forwarder/ForwarderUnshielded.compact +1 -1
- package/package.json +32 -20
- package/security/Allowlist.compact +1 -1
- package/security/Blocklist.compact +1 -1
- package/security/Initializable.compact +1 -1
- package/security/Pausable.compact +1 -1
- package/token/ConfidentialFungibleToken.compact +1208 -0
- package/token/FungibleToken.compact +1 -1
- package/token/MultiToken.compact +1 -1
- package/token/NativeShieldedToken.compact +2 -2
- package/token/NativeShieldedTokenCore.compact +1 -1
- package/token/NativeShieldedTokenFamily.compact +2 -2
- package/token/NonFungibleToken.compact +1 -1
- package/token/extensions/ConfidentialFungibleTokenPublicSupply.compact +90 -0
- package/token/extensions/NativeShieldedTokenDerivedNonce.compact +70 -0
- package/token/extensions/NativeShieldedTokenFamilyPublicSupply.compact +145 -0
- package/token/extensions/NativeShieldedTokenPublicSupply.compact +142 -0
- package/token/extensions/NativeShieldedTokenPublicSupplyCore.compact +163 -0
- package/utils/Utils.compact +1 -1
- package/multisig/SignerManager.compact +0 -205
package/utils/Utils.compact
CHANGED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
// OpenZeppelin Compact Contracts v0.3.0-alpha (multisig/SignerManager.compact)
|
|
3
|
-
|
|
4
|
-
pragma language_version >= 0.23.0;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @module SignerManager<T>
|
|
8
|
-
* @description Manages signer registry, threshold enforcement, and signer
|
|
9
|
-
* validation for multisig governance contracts.
|
|
10
|
-
*
|
|
11
|
-
* Parameterized over the signer identity type `T`, allowing the consuming
|
|
12
|
-
* contract to choose the identity mechanism at import time. Common
|
|
13
|
-
* instantiations include:
|
|
14
|
-
*
|
|
15
|
-
* - `Either<ZswapCoinPublicKey, ContractAddress>` for ownPublicKey()-based identity
|
|
16
|
-
* - `Bytes<32>` for commitment-based identity (e.g., hash of ECDSA public key)
|
|
17
|
-
* - `NativePoint` for Schnorr/MuSig aggregated key
|
|
18
|
-
*
|
|
19
|
-
* SignerManager does not resolve caller identity. It receives a validated
|
|
20
|
-
* caller from the contract layer and checks it against the registry.
|
|
21
|
-
* This separation allows the identity mechanism to change without
|
|
22
|
-
* modifying the module.
|
|
23
|
-
*
|
|
24
|
-
* Underscore-prefixed circuits (_addSigner, _removeSigner,
|
|
25
|
-
* _changeThreshold) have no access control enforcement. The consuming
|
|
26
|
-
* contract must gate these behind its own authorization policy.
|
|
27
|
-
*/
|
|
28
|
-
module SignerManager<T> {
|
|
29
|
-
import CompactStandardLibrary;
|
|
30
|
-
|
|
31
|
-
// ─── State ──────────────────────────────────────────────────────────────────
|
|
32
|
-
|
|
33
|
-
export ledger _signers: Set<T>;
|
|
34
|
-
export ledger _signerCount: Uint<8>;
|
|
35
|
-
export ledger _threshold: Uint<8>;
|
|
36
|
-
|
|
37
|
-
// ─── Initialization ─────────────────────────────────────────────────────────
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @description Initializes the signer manager with the given threshold
|
|
41
|
-
* and an initial set of signers.
|
|
42
|
-
* Must be called in the contract's constructor.
|
|
43
|
-
*
|
|
44
|
-
* Requirements:
|
|
45
|
-
*
|
|
46
|
-
* - `thresh` must be greater than 0.
|
|
47
|
-
* - `signers` must not contain duplicates.
|
|
48
|
-
*
|
|
49
|
-
* @param {Vector<n, T>} signers - The initial signer set.
|
|
50
|
-
* @param {Uint<8>} thresh - The minimum number of approvals required.
|
|
51
|
-
*
|
|
52
|
-
* @returns {[]} Empty tuple.
|
|
53
|
-
*/
|
|
54
|
-
export circuit initialize<#n>(
|
|
55
|
-
signers: Vector<n, T>,
|
|
56
|
-
thresh: Uint<8>
|
|
57
|
-
): [] {
|
|
58
|
-
assert(thresh > 0, "SignerManager: threshold must be > 0");
|
|
59
|
-
_threshold = disclose(thresh);
|
|
60
|
-
|
|
61
|
-
for (const signer of signers) {
|
|
62
|
-
_addSigner(signer);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
assert(_signerCount >= thresh, "SignerManager: threshold exceeds signer count");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// ─── Guards ─────────────────────────────────────────────────────────────
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @description Asserts that the given caller is an active signer.
|
|
72
|
-
*
|
|
73
|
-
* Requirements:
|
|
74
|
-
*
|
|
75
|
-
* - `caller` must be a member of the signers registry.
|
|
76
|
-
*
|
|
77
|
-
* @param {T} caller - The identity to validate.
|
|
78
|
-
*
|
|
79
|
-
* @returns {[]} Empty tuple.
|
|
80
|
-
*/
|
|
81
|
-
export circuit assertSigner(caller: T): [] {
|
|
82
|
-
assert(isSigner(caller), "SignerManager: not a signer");
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* @description Asserts that the given approval count meets the threshold.
|
|
87
|
-
*
|
|
88
|
-
* Requirements:
|
|
89
|
-
*
|
|
90
|
-
* - `approvalCount` must be >= threshold.
|
|
91
|
-
*
|
|
92
|
-
* @param {Uint<8>} approvalCount - The current number of approvals.
|
|
93
|
-
*
|
|
94
|
-
* @returns {[]} Empty tuple.
|
|
95
|
-
*/
|
|
96
|
-
export circuit assertThresholdMet(approvalCount: Uint<8>): [] {
|
|
97
|
-
assert(approvalCount >= _threshold, "SignerManager: threshold not met");
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// ─── View ──────────────────────────────────────────────────────────
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* @description Returns the current signer count.
|
|
104
|
-
*
|
|
105
|
-
* @returns {Uint<8>} The number of active signers.
|
|
106
|
-
*/
|
|
107
|
-
export circuit getSignerCount(): Uint<8> {
|
|
108
|
-
return _signerCount;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* @description Returns the approval threshold.
|
|
113
|
-
*
|
|
114
|
-
* @returns {Uint<8>} The threshold.
|
|
115
|
-
*/
|
|
116
|
-
export circuit getThreshold(): Uint<8> {
|
|
117
|
-
return _threshold;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* @description Returns whether the given account is an active signer.
|
|
122
|
-
*
|
|
123
|
-
* @param {T} account - The account to check.
|
|
124
|
-
*
|
|
125
|
-
* @returns {Boolean} True if the account is an active signer.
|
|
126
|
-
*/
|
|
127
|
-
export circuit isSigner(account: T): Boolean {
|
|
128
|
-
return _signers.member(disclose(account));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// ─── Signer Management ─────────────────────────────────────────────────────
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* @description Adds a new signer to the registry.
|
|
135
|
-
*
|
|
136
|
-
* @notice Access control is NOT enforced here.
|
|
137
|
-
* The consuming contract must gate this behind its own
|
|
138
|
-
* authorization policy.
|
|
139
|
-
*
|
|
140
|
-
* Requirements:
|
|
141
|
-
*
|
|
142
|
-
* - `signer` must not already be an active signer.
|
|
143
|
-
*
|
|
144
|
-
* @param {T} signer - The signer to add.
|
|
145
|
-
*
|
|
146
|
-
* @returns {[]} Empty tuple.
|
|
147
|
-
*/
|
|
148
|
-
export circuit _addSigner(signer: T): [] {
|
|
149
|
-
assert(
|
|
150
|
-
!isSigner(signer),
|
|
151
|
-
"SignerManager: signer already active"
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
_signers.insert(disclose(signer));
|
|
155
|
-
_signerCount = _signerCount + 1 as Uint<8>;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* @description Removes a signer from the registry.
|
|
160
|
-
*
|
|
161
|
-
* @notice Access control is NOT enforced here.
|
|
162
|
-
* The consuming contract must gate this behind its own
|
|
163
|
-
* authorization policy.
|
|
164
|
-
*
|
|
165
|
-
* Requirements:
|
|
166
|
-
*
|
|
167
|
-
* - `signer` must be an active signer.
|
|
168
|
-
* - Removal must not drop signer count below threshold.
|
|
169
|
-
*
|
|
170
|
-
* @param {T} signer - The signer to remove.
|
|
171
|
-
*
|
|
172
|
-
* @returns {[]} Empty tuple.
|
|
173
|
-
*/
|
|
174
|
-
export circuit _removeSigner(signer: T): [] {
|
|
175
|
-
assert(isSigner(signer), "SignerManager: not a signer");
|
|
176
|
-
|
|
177
|
-
const newCount = _signerCount - 1 as Uint<8>;
|
|
178
|
-
assert(newCount >= _threshold, "SignerManager: removal would breach threshold");
|
|
179
|
-
|
|
180
|
-
_signers.remove(disclose(signer));
|
|
181
|
-
_signerCount = newCount;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* @description Updates the approval threshold.
|
|
186
|
-
*
|
|
187
|
-
* @notice Access control is NOT enforced here.
|
|
188
|
-
* The consuming contract must gate this behind its own
|
|
189
|
-
* authorization policy.
|
|
190
|
-
*
|
|
191
|
-
* Requirements:
|
|
192
|
-
*
|
|
193
|
-
* - `newThreshold` must be greater than 0.
|
|
194
|
-
* - `newThreshold` must not exceed the current signer count.
|
|
195
|
-
*
|
|
196
|
-
* @param {Uint<8>} newThreshold - The new minimum number of approvals required.
|
|
197
|
-
*
|
|
198
|
-
* @returns {[]} Empty tuple.
|
|
199
|
-
*/
|
|
200
|
-
export circuit _changeThreshold(newThreshold: Uint<8>): [] {
|
|
201
|
-
assert(newThreshold > 0, "SignerManager: threshold must be > 0");
|
|
202
|
-
assert(newThreshold <= _signerCount, "SignerManager: threshold exceeds signer count");
|
|
203
|
-
_threshold = disclose(newThreshold);
|
|
204
|
-
}
|
|
205
|
-
}
|