@agenticprimitives/contracts 1.0.0-alpha.47 → 1.0.0-alpha.49
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/AUDIT.md +36 -4
- package/deployments-faithchain.json +94 -68
- package/deployments-hopechain.json +71 -52
- package/dist/abi/AccountBootstrap.json +99 -0
- package/dist/abi/AgentAccount.json +95 -56
- package/dist/abi/AgentAccountFactory.json +189 -0
- package/dist/abi/AgentNameAttributeResolver.json +188 -0
- package/dist/abi/AgentNameRegistry.json +170 -0
- package/dist/abi/AgentNameUniversalResolver.json +188 -0
- package/dist/abi/AgentProfileResolver.json +188 -0
- package/dist/abi/AgentRegistryBase.json +193 -0
- package/dist/abi/AgentRelationship.json +193 -0
- package/dist/abi/AgenticGovernance.json +123 -0
- package/dist/abi/AgreementRegistry.json +193 -0
- package/dist/abi/AllowedMethodsEnforcer.json +193 -0
- package/dist/abi/AllowedTargetsEnforcer.json +193 -0
- package/dist/abi/ApprovedHashRegistry.json +220 -0
- package/dist/abi/AttestationRegistry.json +193 -0
- package/dist/abi/CallDataHashEnforcer.json +193 -0
- package/dist/abi/CustodyPolicy.json +195 -80
- package/dist/abi/DelegationManager.json +185 -0
- package/dist/abi/DigestBindingEnforcer.json +188 -0
- package/dist/abi/Eip7702.json +13 -0
- package/dist/abi/EstateProjectionRegistry.json +193 -0
- package/dist/abi/Generation5Bridge.json +355 -0
- package/dist/abi/GeoFeatureRegistry.json +193 -0
- package/dist/abi/ICustodyEpochView.json +28 -0
- package/dist/abi/IDelegationManager.json +18 -0
- package/dist/abi/IGeneration4Reads.json +143 -0
- package/dist/abi/IGeneration5Account.json +33 -0
- package/dist/abi/IGeneration5Voucher.json +26 -0
- package/dist/abi/IMoveAccountView.json +57 -0
- package/dist/abi/IMoveCustodyView.json +169 -0
- package/dist/abi/IMoveFactoryView.json +41 -0
- package/dist/abi/ITimelockVeto.json +93 -0
- package/dist/abi/OntologyTermRegistry.json +211 -0
- package/dist/abi/PayloadClassesEnforcer.json +193 -0
- package/dist/abi/PaymentEnforcer.json +188 -0
- package/dist/abi/PaymentEscrow.json +177 -0
- package/dist/abi/PaymentReceiptRegistry.json +206 -0
- package/dist/abi/PermissionlessSubregistry.json +188 -0
- package/dist/abi/PricedSubregistry.json +215 -0
- package/dist/abi/QuorumEnforcer.json +193 -0
- package/dist/abi/ReceiptAnchorRegistry.json +193 -0
- package/dist/abi/RelationshipTypeRegistry.json +211 -0
- package/dist/abi/ShapeRegistry.json +211 -0
- package/dist/abi/SignatureVerifier.json +196 -0
- package/dist/abi/SkillDefinitionRegistry.json +193 -0
- package/dist/abi/SmartAgentPaymaster.json +236 -1
- package/dist/abi/StableProxyGoverned.json +190 -0
- package/dist/abi/StableProxyGovernedOneShot.json +172 -0
- package/dist/abi/TimestampEnforcer.json +193 -0
- package/dist/abi/TreasurySpendPolicy.json +193 -0
- package/dist/abi/UpgradeVoucher.json +156 -4
- package/dist/abi/ValueEnforcer.json +193 -0
- package/dist/abi/index.d.ts +14 -0
- package/dist/abi/index.js +14 -0
- package/dist/deployments/faithchain.d.ts +34 -14
- package/dist/deployments/faithchain.js +93 -69
- package/dist/deployments/hopechain.d.ts +20 -7
- package/dist/deployments/hopechain.js +72 -55
- package/package.json +1 -1
- package/src/AccountBootstrap.sol +38 -0
- package/src/AgentAccount.sol +149 -41
- package/src/AgentAccountFactory.sol +52 -13
- package/src/ApprovedHashRegistry.sol +98 -9
- package/src/SmartAgentPaymaster.sol +96 -12
- package/src/UniversalSignatureValidator.sol +7 -0
- package/src/UpgradeVoucher.sol +16 -3
- package/src/agency/DelegationManager.sol +106 -32
- package/src/agency/IDelegationManager.sol +28 -0
- package/src/agreement/AgreementRegistry.sol +16 -15
- package/src/attestation/AttestationRegistry.sol +39 -16
- package/src/custody/CustodyPolicy.sol +36 -35
- package/src/custody/TreasurySpendPolicy.sol +10 -1
- package/src/enforcers/AllowedMethodsEnforcer.sol +7 -1
- package/src/enforcers/AllowedTargetsEnforcer.sol +7 -1
- package/src/enforcers/CallDataHashEnforcer.sol +7 -1
- package/src/enforcers/DigestBindingEnforcer.sol +5 -2
- package/src/enforcers/PayloadClassesEnforcer.sol +7 -1
- package/src/enforcers/PaymentEnforcer.sol +5 -2
- package/src/enforcers/QuorumEnforcer.sol +7 -1
- package/src/enforcers/TimestampEnforcer.sol +7 -1
- package/src/enforcers/ValueEnforcer.sol +7 -1
- package/src/geo/GeoFeatureRegistry.sol +15 -1
- package/src/governance/AgenticGovernance.sol +145 -0
- package/src/governance/GovernanceManaged.sol +2 -0
- package/src/governance/StableProxyGoverned.sol +79 -0
- package/src/governance/StableProxyGovernedOneShot.sol +93 -0
- package/src/identity/AgentProfileResolver.sol +11 -2
- package/src/libraries/Eip7702.sol +36 -0
- package/src/libraries/SignatureSlotRecovery.sol +4 -0
- package/src/libraries/SignatureVerifier.sol +52 -0
- package/src/libraries/WebAuthnLib.sol +3 -0
- package/src/migration/Generation5Bridge.sol +364 -0
- package/src/naming/AgentNameAttributeResolver.sol +12 -2
- package/src/naming/AgentNameRegistry.sol +84 -10
- package/src/naming/AgentNameUniversalResolver.sol +9 -2
- package/src/naming/PermissionlessSubregistry.sol +13 -2
- package/src/naming/PricedSubregistry.sol +59 -3
- package/src/ontology/OntologyTermRegistry.sol +30 -2
- package/src/ontology/ShapeRegistry.sol +30 -2
- package/src/payments/PaymentEscrow.sol +16 -1
- package/src/payments/PaymentReceiptRegistry.sol +28 -3
- package/src/provenance/ReceiptAnchorRegistry.sol +13 -1
- package/src/registry/AgentRegistryBase.sol +21 -1
- package/src/registry/EstateProjectionRegistry.sol +15 -1
- package/src/relationships/AgentRelationship.sol +17 -1
- package/src/relationships/RelationshipTypeRegistry.sol +30 -2
- package/src/skills/SkillDefinitionRegistry.sol +15 -1
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
5
|
+
import {Eip7702} from "../libraries/Eip7702.sol";
|
|
5
6
|
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
|
|
6
7
|
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
|
7
8
|
import "@openzeppelin/contracts/interfaces/IERC1271.sol";
|
|
9
|
+
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
|
|
10
|
+
import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
|
|
8
11
|
import "./IDelegationManager.sol";
|
|
9
12
|
import "./ICaveatEnforcer.sol";
|
|
10
13
|
import "../governance/IGovernance.sol";
|
|
@@ -34,7 +37,7 @@ import "../governance/IGovernance.sol";
|
|
|
34
37
|
* - Execute through delegator account, not direct target.call
|
|
35
38
|
* - Open delegations: delegate = address(0xa11) allows any redeemer
|
|
36
39
|
*/
|
|
37
|
-
contract DelegationManager is IDelegationManager, ReentrancyGuard {
|
|
40
|
+
contract DelegationManager is IDelegationManager, ReentrancyGuard, Initializable, UUPSUpgradeable {
|
|
38
41
|
using ECDSA for bytes32;
|
|
39
42
|
using MessageHashUtils for bytes32;
|
|
40
43
|
|
|
@@ -71,13 +74,22 @@ contract DelegationManager is IDelegationManager, ReentrancyGuard {
|
|
|
71
74
|
// contract that breaks freezes redemptions until a new DelegationManager is
|
|
72
75
|
// deployed (this contract is a re-deploy-on-bug singleton, SC4 § 4.3.4) — the
|
|
73
76
|
// same posture `SmartAgentPaymaster._governanceIsPaused` already takes (L1).
|
|
74
|
-
|
|
77
|
+
//
|
|
78
|
+
// Spec 447 (generation 5): no longer immutable. The manager is deployed behind a UUPS proxy at an address
|
|
79
|
+
// that never changes, so the EIP-712 domain (`verifyingContract` = the proxy), every signed delegation and the
|
|
80
|
+
// revocation set survive a fix; `governance` is storage, set once by the constructor (a direct deployment) or
|
|
81
|
+
// by `initialize` (behind a proxy), and is also the only upgrade authority ({_authorizeUpgrade}).
|
|
82
|
+
function governance() public view returns (address) {
|
|
83
|
+
return _governance;
|
|
84
|
+
}
|
|
75
85
|
|
|
76
86
|
error SystemPaused();
|
|
77
87
|
/// @dev DLG-7: constructor refused a non-zero governance address with no code.
|
|
78
88
|
error GovernanceHasNoCode(address governance);
|
|
79
89
|
/// @dev DLG-7: the configured governance did not answer `isPaused()` with one boolean word.
|
|
80
90
|
error GovernanceReadFailed();
|
|
91
|
+
/// @dev Spec 450 §6: {redemptionDepth} read while no caveat hook of a redemption is running.
|
|
92
|
+
error NotInCaveatHook();
|
|
81
93
|
/// @dev Spec 445 / audit DLG-2: a redemption whose `target` is the account that executes it
|
|
82
94
|
/// (the root delegator). See {redeemDelegation}.
|
|
83
95
|
error SelfTargetedRedemption();
|
|
@@ -88,11 +100,10 @@ contract DelegationManager is IDelegationManager, ReentrancyGuard {
|
|
|
88
100
|
/// @dev Open delegation sentinel — any address can redeem
|
|
89
101
|
address public constant OPEN_DELEGATION = address(0xa11);
|
|
90
102
|
|
|
91
|
-
/// @dev
|
|
92
|
-
|
|
93
|
-
///
|
|
94
|
-
|
|
95
|
-
uint256 private immutable _CACHED_CHAIN_ID;
|
|
103
|
+
/// @dev Spec 447: an upgrade by anything but this manager's governance.
|
|
104
|
+
error NotGovernance();
|
|
105
|
+
/// @dev Spec 447: a manager with no governance cannot be upgraded (it is frozen at its implementation).
|
|
106
|
+
error UpgradeWithoutGovernance();
|
|
96
107
|
|
|
97
108
|
/// @dev The root delegator of the redemption in flight (zero outside one). Transient
|
|
98
109
|
/// (EIP-1153): set and cleared inside the non-reentrant {redeemDelegation}. Lets a
|
|
@@ -101,6 +112,13 @@ contract DelegationManager is IDelegationManager, ReentrancyGuard {
|
|
|
101
112
|
/// which for a derived mandate is an intermediary, not the payer (audit DLG-8c).
|
|
102
113
|
address private transient _redemptionRoot;
|
|
103
114
|
|
|
115
|
+
/// @dev Spec 450 §6 — the chain context behind {redemptionDepth}. Transient (EIP-1153), never authority.
|
|
116
|
+
/// `_redemptionLinks` is the length of the chain being redeemed (0 outside a redemption);
|
|
117
|
+
/// `_redemptionLinkPlusOne` is the root-first index of the link whose caveat hooks are running, plus
|
|
118
|
+
/// one (0 while no hook runs: during validation, execution, and outside a redemption).
|
|
119
|
+
uint256 private transient _redemptionLinks;
|
|
120
|
+
uint256 private transient _redemptionLinkPlusOne;
|
|
121
|
+
|
|
104
122
|
/// @dev Delegation type hash for EIP-712.
|
|
105
123
|
///
|
|
106
124
|
/// **R1 / CROSS-STACK-001 closure (2026-05-31):** converged to
|
|
@@ -155,27 +173,48 @@ contract DelegationManager is IDelegationManager, ReentrancyGuard {
|
|
|
155
173
|
/// path. Migrate callers to `revokeDelegationByOwner(Delegation)`.
|
|
156
174
|
error LegacyRevocationDisabled();
|
|
157
175
|
|
|
158
|
-
/// @dev
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
///
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
///
|
|
166
|
-
///
|
|
167
|
-
/// `AgenticGovernance` address
|
|
168
|
-
|
|
176
|
+
/// @dev The pause source and upgrade authority (see {governance}). Spec 447: storage, not an immutable.
|
|
177
|
+
address private _governance;
|
|
178
|
+
|
|
179
|
+
/// @dev Storage gap. Spec 447: the manager is upgradeable behind a proxy from generation 5, so this layout is
|
|
180
|
+
/// gated by `check:storage-layouts`; a new field takes a slot from here and the gap shrinks by one.
|
|
181
|
+
uint256[49] private __gap;
|
|
182
|
+
|
|
183
|
+
/// @notice A DIRECT deployment (tests, a one-off instance): initialized here, so the instance works on its own
|
|
184
|
+
/// and nobody can initialize it later. Pass `address(0)` for `governance_` to opt out of the H7-C.10
|
|
185
|
+
/// pause gate (legacy / test deploys). Production deploys pass an `AgenticGovernance` address and put
|
|
186
|
+
/// the manager behind an ERC-1967 proxy, initialized with {initialize} (spec 447).
|
|
187
|
+
constructor(address governance_) initializer {
|
|
188
|
+
_initializeManager(governance_);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/// @notice The proxy's initializer (spec 447). Runs once per proxy.
|
|
192
|
+
function initialize(address governance_) external initializer {
|
|
193
|
+
_initializeManager(governance_);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function _initializeManager(address governance_) private {
|
|
169
197
|
// DLG-7 rule 1: zero is the explicit opt-out; anything else must already be a contract.
|
|
170
198
|
if (governance_ != address(0) && governance_.code.length == 0) revert GovernanceHasNoCode(governance_);
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator();
|
|
199
|
+
Eip7702.refuseDelegatedEOA(governance_); // "has code" is not "is a contract" (spec 448 §0)
|
|
200
|
+
_governance = governance_;
|
|
174
201
|
}
|
|
175
202
|
|
|
176
|
-
/// @
|
|
203
|
+
/// @dev Spec 447: only this manager's governance (the `AgenticGovernance` contract, acting through its
|
|
204
|
+
/// timelock) upgrades it. A manager with no governance is never upgraded. UUPS's `onlyProxy` already
|
|
205
|
+
/// refuses an upgrade of a direct deployment.
|
|
206
|
+
function _authorizeUpgrade(address) internal view override {
|
|
207
|
+
address gov = _governance;
|
|
208
|
+
if (gov == address(0)) revert UpgradeWithoutGovernance();
|
|
209
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
210
|
+
if (msg.sender != gov) revert NotGovernance();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/// @notice EIP-712 domain separator for the CURRENT chain id (audit DLG-10), with `verifyingContract` the
|
|
214
|
+
/// address callers use — the proxy's when behind one. Computed per call, never cached in an immutable:
|
|
215
|
+
/// an immutable would carry the implementation's address, not the proxy's (spec 447).
|
|
177
216
|
function DOMAIN_SEPARATOR() public view returns (bytes32) {
|
|
178
|
-
return
|
|
217
|
+
return _buildDomainSeparator();
|
|
179
218
|
}
|
|
180
219
|
|
|
181
220
|
function _buildDomainSeparator() private view returns (bytes32) {
|
|
@@ -198,9 +237,16 @@ contract DelegationManager is IDelegationManager, ReentrancyGuard {
|
|
|
198
237
|
return _redemptionRoot;
|
|
199
238
|
}
|
|
200
239
|
|
|
240
|
+
/// @inheritdoc IDelegationManager
|
|
241
|
+
function redemptionDepth() external view returns (uint256 links, uint256 position) {
|
|
242
|
+
uint256 p = _redemptionLinkPlusOne;
|
|
243
|
+
if (p == 0) revert NotInCaveatHook();
|
|
244
|
+
return (_redemptionLinks, p - 1);
|
|
245
|
+
}
|
|
246
|
+
|
|
201
247
|
/// @dev DLG-7 — the pause gate. See the rule at `governance`.
|
|
202
248
|
function _requireNotPaused() internal view {
|
|
203
|
-
address gov =
|
|
249
|
+
address gov = _governance;
|
|
204
250
|
if (gov == address(0) || gov.code.length == 0) return;
|
|
205
251
|
(bool ok, bytes memory ret) = gov.staticcall(abi.encodeWithSelector(IGovernanceView.isPaused.selector));
|
|
206
252
|
if (!ok || ret.length != 32) revert GovernanceReadFailed();
|
|
@@ -245,20 +291,34 @@ contract DelegationManager is IDelegationManager, ReentrancyGuard {
|
|
|
245
291
|
if (target == rootDelegator) revert SelfTargetedRedemption();
|
|
246
292
|
_redemptionRoot = rootDelegator;
|
|
247
293
|
|
|
248
|
-
//
|
|
249
|
-
|
|
294
|
+
// Spec 450 §6: the chain context {redemptionDepth} reports. `nonReentrant` makes a nested redemption
|
|
295
|
+
// unreachable today; the context is still saved and restored (not cleared) so an inner redemption could
|
|
296
|
+
// never leave the outer one reading the inner chain's numbers.
|
|
297
|
+
uint256 n = delegations.length;
|
|
298
|
+
uint256 savedLinks = _redemptionLinks;
|
|
299
|
+
uint256 savedLink = _redemptionLinkPlusOne;
|
|
300
|
+
_redemptionLinks = n;
|
|
301
|
+
|
|
302
|
+
// Phase 1: Validate chain + run beforeHooks (leaf to root). Leaf-first index i is root-first n-1-i.
|
|
303
|
+
for (uint256 i = 0; i < n; i++) {
|
|
250
304
|
_validateDelegation(delegations, i);
|
|
305
|
+
_redemptionLinkPlusOne = n - i;
|
|
251
306
|
_runBeforeHooks(delegations[i], target, value, data);
|
|
307
|
+
_redemptionLinkPlusOne = 0;
|
|
252
308
|
}
|
|
253
309
|
|
|
254
310
|
// Phase 2: Execute through the root delegator's smart account
|
|
255
311
|
_executeFromDelegator(rootDelegator, target, value, data);
|
|
256
312
|
|
|
257
313
|
// Phase 3: After-hooks (root to leaf, per DeleGator convention)
|
|
258
|
-
for (uint256 i =
|
|
314
|
+
for (uint256 i = n; i > 0; i--) {
|
|
315
|
+
_redemptionLinkPlusOne = n - i + 1;
|
|
259
316
|
_runAfterHooks(delegations[i - 1], target, value, data);
|
|
317
|
+
_redemptionLinkPlusOne = 0;
|
|
260
318
|
}
|
|
261
319
|
_redemptionRoot = address(0);
|
|
320
|
+
_redemptionLinks = savedLinks;
|
|
321
|
+
_redemptionLinkPlusOne = savedLink;
|
|
262
322
|
}
|
|
263
323
|
|
|
264
324
|
/// @inheritdoc IDelegationManager
|
|
@@ -393,6 +453,8 @@ contract DelegationManager is IDelegationManager, ReentrancyGuard {
|
|
|
393
453
|
Delegation[] calldata delegations,
|
|
394
454
|
address sender
|
|
395
455
|
) external view returns (bool ok, string memory reason) {
|
|
456
|
+
// Spec 450 §6: never answered from inside a caveat hook (see {verifyAuthorizationForCall}).
|
|
457
|
+
if (_redemptionLinkPlusOne != 0) return (false, "in-redemption");
|
|
396
458
|
if (delegations.length == 0) return (false, "empty-chain");
|
|
397
459
|
|
|
398
460
|
for (uint256 i = 0; i < delegations.length; i++) {
|
|
@@ -432,6 +494,9 @@ contract DelegationManager is IDelegationManager, ReentrancyGuard {
|
|
|
432
494
|
uint256 value,
|
|
433
495
|
bytes calldata data
|
|
434
496
|
) external view returns (bool ok, string memory reason) {
|
|
497
|
+
// Spec 450 §6: while a caveat hook of a redemption is running, {redemptionDepth} reports THAT chain's
|
|
498
|
+
// context, so an enforcer evaluated here would judge this chain by the outer one's numbers. Refused.
|
|
499
|
+
if (_redemptionLinkPlusOne != 0) return (false, "in-redemption");
|
|
435
500
|
if (delegations.length == 0) return (false, "empty-chain");
|
|
436
501
|
// DLG-2: identical to redemption — the executing account is never the target.
|
|
437
502
|
if (target == delegations[delegations.length - 1].delegator) return (false, "self-target");
|
|
@@ -488,6 +553,9 @@ contract DelegationManager is IDelegationManager, ReentrancyGuard {
|
|
|
488
553
|
if (d.delegate != OPEN_DELEGATION && d.delegate != sender) {
|
|
489
554
|
return (false, "invalid-delegate");
|
|
490
555
|
}
|
|
556
|
+
if (d.delegate != OPEN_DELEGATION && Eip7702.isDelegatedEOA(sender)) {
|
|
557
|
+
return (false, "delegated-eoa-redeemer");
|
|
558
|
+
}
|
|
491
559
|
} else {
|
|
492
560
|
if (d.delegate != OPEN_DELEGATION && d.delegate != delegations[i - 1].delegator) {
|
|
493
561
|
return (false, "invalid-delegate-chain");
|
|
@@ -520,8 +588,8 @@ contract DelegationManager is IDelegationManager, ReentrancyGuard {
|
|
|
520
588
|
bytes32 digest,
|
|
521
589
|
bytes calldata signature
|
|
522
590
|
) internal view returns (bool) {
|
|
523
|
-
// ERC-1271 path for smart accounts
|
|
524
|
-
if (signer.code.length > 0) {
|
|
591
|
+
// ERC-1271 path for smart accounts; a 7702-delegated EOA signs by ECDSA only (spec 448 §0)
|
|
592
|
+
if (signer.code.length > 0 && !Eip7702.isDelegatedEOA(signer)) {
|
|
525
593
|
try IERC1271(signer).isValidSignature(digest, signature) returns (bytes4 result) {
|
|
526
594
|
return result == IERC1271.isValidSignature.selector;
|
|
527
595
|
} catch {
|
|
@@ -552,7 +620,12 @@ contract DelegationManager is IDelegationManager, ReentrancyGuard {
|
|
|
552
620
|
|
|
553
621
|
// Validate delegate
|
|
554
622
|
if (i == 0) {
|
|
555
|
-
if (d.delegate != OPEN_DELEGATION
|
|
623
|
+
if (d.delegate != OPEN_DELEGATION) {
|
|
624
|
+
if (d.delegate != msg.sender) revert InvalidDelegate();
|
|
625
|
+
// Spec 448 §0 (EIP-7702): a named delegate that is a delegated EOA is refused as the redeemer —
|
|
626
|
+
// anyone can make its attached code call, so its `msg.sender` proves nothing about its key.
|
|
627
|
+
Eip7702.refuseDelegatedEOA(msg.sender);
|
|
628
|
+
}
|
|
556
629
|
} else {
|
|
557
630
|
if (d.delegate != OPEN_DELEGATION && d.delegate != delegations[i - 1].delegator) revert InvalidDelegate();
|
|
558
631
|
}
|
|
@@ -652,8 +725,9 @@ contract DelegationManager is IDelegationManager, ReentrancyGuard {
|
|
|
652
725
|
bytes32 digest,
|
|
653
726
|
bytes calldata signature
|
|
654
727
|
) internal view {
|
|
655
|
-
// ERC-1271 for smart accounts
|
|
656
|
-
|
|
728
|
+
// ERC-1271 for smart accounts. Spec 448 §0 (EIP-7702): a delegated EOA's attached code is never asked
|
|
729
|
+
// "is this signature yours?" — it signs by ECDSA below, like any EOA.
|
|
730
|
+
if (signer.code.length > 0 && !Eip7702.isDelegatedEOA(signer)) {
|
|
657
731
|
bytes4 result = IERC1271(signer).isValidSignature(digest, signature);
|
|
658
732
|
if (result != IERC1271.isValidSignature.selector) revert DelegationManager_InvalidSignature();
|
|
659
733
|
return;
|
|
@@ -65,6 +65,31 @@ interface IDelegationManager {
|
|
|
65
65
|
/// present a struct whose signature verifies, so it cannot revoke a forged hash.
|
|
66
66
|
function revokeDelegationByOwner(Delegation calldata delegation) external;
|
|
67
67
|
|
|
68
|
+
/// @notice The chain context of the caveat hook now running (spec 450 §6): `links` is the number of
|
|
69
|
+
/// delegations in the chain being redeemed, `position` the root-first index of the delegation whose
|
|
70
|
+
/// caveat is being checked (0 = the root grant, `links - 1` = the leaf the redeemer holds). With both,
|
|
71
|
+
/// an enforcer can bound a chain's length (`links`) or the re-delegations made below its own link
|
|
72
|
+
/// (`links - 1 - position`).
|
|
73
|
+
/// @dev An OBSERVATION for caveat enforcers, valid only while one of THIS manager's `beforeHook` /
|
|
74
|
+
/// `afterHook` calls is running inside {redeemDelegation}. It is not an authority and grants nothing,
|
|
75
|
+
/// and it is not a count of redemptions. Outside a hook — no redemption in flight, during chain
|
|
76
|
+
/// validation or the executed call — it REVERTS `NotInCaveatHook()`; there is no sentinel that could
|
|
77
|
+
/// be mistaken for "depth 0". The view verifiers hold no context of their own: called outside a hook,
|
|
78
|
+
/// a caveat that reads this reverts and {verifyAuthorizationForCall} returns `(false,
|
|
79
|
+
/// "caveat-failed")`; called while a hook is running, both verifiers return `(false,
|
|
80
|
+
/// "in-redemption")` without evaluating anything, so they never judge a chain by another chain's
|
|
81
|
+
/// numbers. An enforcer must let the revert propagate (fail closed) and read this only from
|
|
82
|
+
/// `msg.sender`, the manager that called its hook; a manager without this function reverts too.
|
|
83
|
+
///
|
|
84
|
+
/// The rule for a depth enforcer (`links` alone is NOT it — it counts ancestors the link does not
|
|
85
|
+
/// control): in `beforeHook`, take `maxBelow` from the signed `terms`, never from the
|
|
86
|
+
/// redeemer-supplied `args`; read `(links, position)` from `msg.sender` and let a revert propagate;
|
|
87
|
+
/// revert unless `links - 1 - position <= maxBelow` (the re-delegations made below this link — the
|
|
88
|
+
/// chain is hash-linked, so an intermediary can neither change that count nor drop the caveat). Every
|
|
89
|
+
/// link carrying the caveat is checked, so the strictest ancestor wins; `maxBelow = 0` forbids any
|
|
90
|
+
/// re-delegation.
|
|
91
|
+
function redemptionDepth() external view returns (uint256 links, uint256 position);
|
|
92
|
+
|
|
68
93
|
/// @notice Check if a delegation has been revoked.
|
|
69
94
|
function isRevoked(bytes32 delegationHash) external view returns (bool);
|
|
70
95
|
|
|
@@ -76,6 +101,7 @@ interface IDelegationManager {
|
|
|
76
101
|
/// @dev ⚠️ DANGER — chain-only; does NOT evaluate caveats. `true` is NOT permission for any
|
|
77
102
|
/// specific call. Use {verifyAuthorizationForCall} (fail-closed, evaluates caveats) or live
|
|
78
103
|
/// redemption to authorize a concrete (target, value, calldata).
|
|
104
|
+
/// Returns `(false, "in-redemption")` while a caveat hook of a redemption on this manager is running.
|
|
79
105
|
/// @param delegations Delegation chain, leaf first
|
|
80
106
|
/// @param sender The address that would be the redeemer
|
|
81
107
|
/// @return ok True if the chain verifies
|
|
@@ -91,6 +117,8 @@ interface IDelegationManager {
|
|
|
91
117
|
/// and every caveat passes under `staticcall`; a denied OR non-view-evaluable caveat
|
|
92
118
|
/// yields `false` ("use live redemption"). Lets a registry bind consent to the exact
|
|
93
119
|
/// call inside its own transaction. Caveat evaluation mirrors `redeemDelegation`.
|
|
120
|
+
/// Returns `(false, "in-redemption")` while a caveat hook of a redemption on this manager is
|
|
121
|
+
/// running (spec 450 §6, see {redemptionDepth}); callable from the executed call.
|
|
94
122
|
/// @param delegations Delegation chain, leaf first
|
|
95
123
|
/// @param sender The address that would be the redeemer
|
|
96
124
|
/// @param target The exact target of the delegated call
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import "@openzeppelin/contracts/interfaces/IERC1271.sol";
|
|
5
|
+
import {Eip7702} from "../libraries/Eip7702.sol";
|
|
5
6
|
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
7
|
+
import "../governance/StableProxyGoverned.sol";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* @title AgreementRegistry
|
|
@@ -35,7 +37,13 @@ import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
|
35
37
|
* commitment — one row per agreement, read API unchanged.
|
|
36
38
|
* AR-14 (REG-7) nullifiers are scoped to the agreement: an unrelated agreement cannot burn one.
|
|
37
39
|
*/
|
|
38
|
-
contract AgreementRegistry {
|
|
40
|
+
contract AgreementRegistry is StableProxyGoverned {
|
|
41
|
+
/// @notice Spec 447 — a DIRECT deployment, initialized here with no governance (its code is frozen, as
|
|
42
|
+
/// before). Behind a stable proxy, `initialize(governance_)` instead; the governance is then the only
|
|
43
|
+
/// upgrade authority. This contract has no admin of its own: governance can replace the code behind
|
|
44
|
+
/// the proxy and nothing else.
|
|
45
|
+
constructor() initializer {}
|
|
46
|
+
|
|
39
47
|
// ─── Constants ──────────────────────────────────────────────────────
|
|
40
48
|
|
|
41
49
|
uint64 public constant EPOCH_SECONDS = 3600;
|
|
@@ -333,20 +341,16 @@ contract AgreementRegistry {
|
|
|
333
341
|
|
|
334
342
|
// ─── Internal ───────────────────────────────────────────────────────
|
|
335
343
|
|
|
336
|
-
/// @dev ERC-1271 for contract signers, low-s ECDSA for EOAs. REG-16
|
|
337
|
-
///
|
|
338
|
-
///
|
|
339
|
-
///
|
|
344
|
+
/// @dev ERC-1271 for contract signers, low-s ECDSA for EOAs. REG-16 / spec 448 §0 (EIP-7702): a delegated
|
|
345
|
+
/// EOA (`0xef0100 ‖ delegate`) is an EOA here — ECDSA only. Its attached code is never asked, because
|
|
346
|
+
/// whoever obtained one authorization signature from the key chose that code. One mechanism per kind
|
|
347
|
+
/// of signer (ADR-0013).
|
|
340
348
|
function _isValidSignatureBool(
|
|
341
349
|
address signer,
|
|
342
350
|
bytes32 digest,
|
|
343
351
|
bytes memory signature
|
|
344
352
|
) internal view returns (bool) {
|
|
345
|
-
|
|
346
|
-
if (codeLen > 0) {
|
|
347
|
-
if (_erc1271Ok(signer, digest, signature)) return true;
|
|
348
|
-
if (!_isDelegatedEoa(signer, codeLen)) return false;
|
|
349
|
-
}
|
|
353
|
+
if (signer.code.length > 0 && !Eip7702.isDelegatedEOA(signer)) return _erc1271Ok(signer, digest, signature);
|
|
350
354
|
// P2-2 (audit 2026-06-10): OpenZeppelin ECDSA.tryRecover rejects high-s (malleable) signatures and
|
|
351
355
|
// malformed lengths. The error value is checked explicitly: on any error `recovered` is zero and
|
|
352
356
|
// is NOT compared (a zero `signer` can therefore never match).
|
|
@@ -367,9 +371,6 @@ contract AgreementRegistry {
|
|
|
367
371
|
return bytes32(ret) == bytes32(IERC1271.isValidSignature.selector);
|
|
368
372
|
}
|
|
369
373
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
bytes memory c = a.code;
|
|
373
|
-
return c[0] == 0xef && c[1] == 0x01 && c[2] == 0x00;
|
|
374
|
-
}
|
|
374
|
+
/// @dev Spec 447 — storage gap: the contract may sit behind a stable proxy; layout gated by `check:storage-layouts`.
|
|
375
|
+
uint256[48] private __gap;
|
|
375
376
|
}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import "@openzeppelin/contracts/interfaces/IERC1271.sol";
|
|
5
|
+
import {Eip7702} from "../libraries/Eip7702.sol";
|
|
5
6
|
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
7
|
+
import "../governance/StableProxyGoverned.sol";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* @title AttestationRegistry
|
|
@@ -35,7 +37,8 @@ import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
|
35
37
|
* AR-06 NO issuerRevoke(...) entrypoint — by static analysis
|
|
36
38
|
* AR-07 epoch-bucket timestamps; raw block.timestamp never stored
|
|
37
39
|
* AR-08 four indexed event topics (EAS-like)
|
|
38
|
-
* AR-09
|
|
40
|
+
* AR-09 no admin. A direct deployment is immutable; spec 447 — behind a stable proxy, governance may replace the
|
|
41
|
+
* code (and nothing else). Its digests bind `address(this)` per call, so they name the proxy and survive a fix.
|
|
39
42
|
* AR-10 (spec 445 / REG-3, ledger ATT-2) revocation follows the attestation's CONTENT, not its salt:
|
|
40
43
|
* the content id is the UID without the salt, plus the schema — (subject, party2, issuer, schemaId,
|
|
41
44
|
* credentialType, credentialHash, refUID). Revoking any row revokes that content: it cannot be
|
|
@@ -47,7 +50,13 @@ import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
|
47
50
|
*
|
|
48
51
|
* Spec 242 §9 + ADR-0023.
|
|
49
52
|
*/
|
|
50
|
-
contract AttestationRegistry {
|
|
53
|
+
contract AttestationRegistry is StableProxyGoverned {
|
|
54
|
+
/// @notice Spec 447 — a DIRECT deployment, initialized here with no governance (its code is frozen, as
|
|
55
|
+
/// before). Behind a stable proxy, `initialize(governance_)` instead; the governance is then the only
|
|
56
|
+
/// upgrade authority. This contract has no admin of its own: governance can replace the code behind
|
|
57
|
+
/// the proxy and nothing else.
|
|
58
|
+
constructor() initializer {}
|
|
59
|
+
|
|
51
60
|
// ─── Constants ──────────────────────────────────────────────────────
|
|
52
61
|
|
|
53
62
|
uint64 public constant EPOCH_SECONDS = 3600;
|
|
@@ -184,6 +193,7 @@ contract AttestationRegistry {
|
|
|
184
193
|
if (req.credentialHash == bytes32(0)) revert EmptyCredentialHash();
|
|
185
194
|
// AR-11 / REG-8: the holder anchors its own association. Anyone holding the issuer's signature
|
|
186
195
|
// could previously publish the subject↔issuer link (and pick the status-list pointer).
|
|
196
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
187
197
|
if (msg.sender != req.subject) revert NotSubject();
|
|
188
198
|
|
|
189
199
|
// SC-2: RECOMPUTE the issuer-attestation digest binding the SUBJECT (+ schema / type / chain /
|
|
@@ -305,6 +315,11 @@ contract AttestationRegistry {
|
|
|
305
315
|
{
|
|
306
316
|
bytes32 cid = _contentId(req.party1, req.party2, req.issuer, req.schemaId, req.credentialType, req.credentialHash, req.refUID);
|
|
307
317
|
if (_contentRevokedAt[cid] != 0) revert ContentRevoked(cid);
|
|
318
|
+
// Audit 2026-12-02 C4-4: the content id above includes the issuer, the schema and the credential type —
|
|
319
|
+
// three fields the consent signatures do NOT cover and a re-anchorer chooses. A party's revocation
|
|
320
|
+
// therefore also follows exactly what the two parties signed.
|
|
321
|
+
cid = _jointConsentKey(req.party1, req.party2, req.refUID, req.credentialHash);
|
|
322
|
+
if (_contentRevokedAt[cid] != 0) revert ContentRevoked(cid);
|
|
308
323
|
}
|
|
309
324
|
|
|
310
325
|
bytes32 uid = _computeUid(
|
|
@@ -402,6 +417,21 @@ contract AttestationRegistry {
|
|
|
402
417
|
if (bucket == 0) bucket = 1;
|
|
403
418
|
a.revocationEpochBucket = bucket;
|
|
404
419
|
_contentRevokedAt[cid] = bucket;
|
|
420
|
+
// C4-4: a joint agreement is revoked for what its parties consented to, whoever anchors it next.
|
|
421
|
+
if (a.party2 != address(0)) {
|
|
422
|
+
_contentRevokedAt[_jointConsentKey(a.subject, a.party2, a.refUID, a.credentialHash)] = bucket;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/// @dev Key of "the two parties' consent to (refUID, credentialHash) was withdrawn", kept in
|
|
427
|
+
/// `_contentRevokedAt` beside the content ids. The leading tag keeps the two key spaces apart (a content
|
|
428
|
+
/// id is the hash of seven words, this of five, the first of them the tag).
|
|
429
|
+
function _jointConsentKey(address party1, address party2, bytes32 refUID, bytes32 credentialHash)
|
|
430
|
+
internal
|
|
431
|
+
pure
|
|
432
|
+
returns (bytes32)
|
|
433
|
+
{
|
|
434
|
+
return keccak256(abi.encode(keccak256("agenticprimitives.joint-consent-revoked"), party1, party2, refUID, credentialHash));
|
|
405
435
|
}
|
|
406
436
|
|
|
407
437
|
function _contentIdOf(Attestation storage a) internal view returns (bytes32) {
|
|
@@ -435,20 +465,16 @@ contract AttestationRegistry {
|
|
|
435
465
|
);
|
|
436
466
|
}
|
|
437
467
|
|
|
438
|
-
/// @dev ERC-1271 for contract signers, low-s ECDSA for EOAs. REG-16
|
|
439
|
-
///
|
|
440
|
-
///
|
|
441
|
-
///
|
|
468
|
+
/// @dev ERC-1271 for contract signers, low-s ECDSA for EOAs. REG-16 / spec 448 §0 (EIP-7702): a delegated
|
|
469
|
+
/// EOA (`0xef0100 ‖ delegate`) is an EOA here — ECDSA only. Its attached code is never asked, because
|
|
470
|
+
/// whoever obtained one authorization signature from the key chose that code. One mechanism per kind
|
|
471
|
+
/// of signer (ADR-0013).
|
|
442
472
|
function _isValidSignatureBool(
|
|
443
473
|
address signer,
|
|
444
474
|
bytes32 digest,
|
|
445
475
|
bytes memory signature
|
|
446
476
|
) internal view returns (bool) {
|
|
447
|
-
|
|
448
|
-
if (codeLen > 0) {
|
|
449
|
-
if (_erc1271Ok(signer, digest, signature)) return true;
|
|
450
|
-
if (!_isDelegatedEoa(signer, codeLen)) return false;
|
|
451
|
-
}
|
|
477
|
+
if (signer.code.length > 0 && !Eip7702.isDelegatedEOA(signer)) return _erc1271Ok(signer, digest, signature);
|
|
452
478
|
// P2-2 (audit 2026-06-10): OpenZeppelin ECDSA.tryRecover rejects high-s (malleable) signatures and
|
|
453
479
|
// malformed lengths. The error value is checked explicitly: on any error `recovered` is zero and
|
|
454
480
|
// is NOT compared (a zero `signer` can therefore never match).
|
|
@@ -469,9 +495,6 @@ contract AttestationRegistry {
|
|
|
469
495
|
return bytes32(ret) == bytes32(IERC1271.isValidSignature.selector);
|
|
470
496
|
}
|
|
471
497
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
bytes memory c = a.code;
|
|
475
|
-
return c[0] == 0xef && c[1] == 0x01 && c[2] == 0x00;
|
|
476
|
-
}
|
|
498
|
+
/// @dev Spec 447 — storage gap: the contract may sit behind a stable proxy; layout gated by `check:storage-layouts`.
|
|
499
|
+
uint256[48] private __gap;
|
|
477
500
|
}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import {IAgentAccount, AgentAccountRecoveryArgs, AgentAccountRecoveryPasskeyAdd, AgentAccountRotateCredentialArgs} from "../IAgentAccount.sol";
|
|
5
|
-
import {
|
|
5
|
+
import {SignatureVerifier} from "../libraries/SignatureVerifier.sol";
|
|
6
|
+
import {StableProxyGoverned} from "../governance/StableProxyGoverned.sol";
|
|
6
7
|
|
|
7
8
|
/// @dev R6.6 — minimal interface for the `account → factory → governance.isPaused()`
|
|
8
9
|
/// staticcall chain. Mirrors the same patterns introduced by R6.5
|
|
@@ -67,7 +68,7 @@ interface ICustodyPolicyPasskeyView {
|
|
|
67
68
|
* timelock → safetyDelay, guardian → trustee, owner → custodian),
|
|
68
69
|
* and EIP-712 typehashes likewise.
|
|
69
70
|
*/
|
|
70
|
-
contract CustodyPolicy {
|
|
71
|
+
contract CustodyPolicy is StableProxyGoverned {
|
|
71
72
|
// ─── ERC-7579 marker constants (mirror of the account-side ids) ──
|
|
72
73
|
uint256 internal constant MODULE_TYPE_EXECUTOR = 2;
|
|
73
74
|
uint256 internal constant MODULE_TYPE_HOOK = 4;
|
|
@@ -138,6 +139,8 @@ contract CustodyPolicy {
|
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
mapping(address => Config) internal _configs;
|
|
142
|
+
/// @dev Storage gap (spec 447: behind a stable proxy; layout gated by `check:storage-layouts`).
|
|
143
|
+
uint256[49] private __gap;
|
|
141
144
|
|
|
142
145
|
// ─── Constants ────────────────────────────────────────────────────
|
|
143
146
|
|
|
@@ -159,15 +162,19 @@ contract CustodyPolicy {
|
|
|
159
162
|
"CancelScheduledChangeRequest(address account,uint8 action,bytes32 argsHash,uint256 changeId,uint64 eta)"
|
|
160
163
|
);
|
|
161
164
|
|
|
162
|
-
/// @
|
|
163
|
-
///
|
|
164
|
-
///
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
/// @notice A direct deployment, initialized here (no governance: never upgradeable). Behind a stable proxy
|
|
166
|
+
/// (spec 447), `initialize(governance_)` instead. The quorum signs over this contract's EIP-712 domain,
|
|
167
|
+
/// and every account holds its address as the factory's canonical custody policy, so a fix must keep
|
|
168
|
+
/// the address: scheduled changes and their signatures survive it.
|
|
169
|
+
/// @notice Spec 449: the stateless verifier that recovers each quorum signature slot
|
|
170
|
+
/// (`SignatureSlotRecovery.recoverFromSlot`, unchanged) — moved out of this bytecode for EIP-170 room.
|
|
171
|
+
/// Created by this implementation's constructor, so it is part of the code governance vouched; reached
|
|
172
|
+
/// by STATICCALL from `_verifyQuorum` only; no state, no authority (it returns a signer, this policy
|
|
173
|
+
/// decides whether that signer counts).
|
|
174
|
+
address public immutable signatureVerifier;
|
|
167
175
|
|
|
168
|
-
constructor() {
|
|
169
|
-
|
|
170
|
-
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator();
|
|
176
|
+
constructor() initializer {
|
|
177
|
+
signatureVerifier = address(new SignatureVerifier());
|
|
171
178
|
}
|
|
172
179
|
|
|
173
180
|
// ─── R6.6 / CON-CustodyPolicy-005 — system-pause modifier ──────
|
|
@@ -259,8 +266,9 @@ contract CustodyPolicy {
|
|
|
259
266
|
);
|
|
260
267
|
}
|
|
261
268
|
|
|
269
|
+
/// @dev Computed per call from `address(this)` — the proxy's address behind a proxy. Never cached in an
|
|
270
|
+
/// immutable: that would carry the implementation's address (spec 447). Recomputes on a chain split.
|
|
262
271
|
function _domainSeparator() internal view returns (bytes32) {
|
|
263
|
-
if (block.chainid == _CACHED_CHAIN_ID) return _CACHED_DOMAIN_SEPARATOR;
|
|
264
272
|
return _buildDomainSeparator();
|
|
265
273
|
}
|
|
266
274
|
|
|
@@ -1063,14 +1071,15 @@ contract CustodyPolicy {
|
|
|
1063
1071
|
if (signatures.length < uint256(vargs.reqThreshold) * 65) {
|
|
1064
1072
|
revert AdminInsufficientQuorum(signatures.length / 65, vargs.reqThreshold);
|
|
1065
1073
|
}
|
|
1066
|
-
bytes memory sigsMem = signatures;
|
|
1067
1074
|
address approvedHashReg = c.approvedHashRegistry;
|
|
1075
|
+
SignatureVerifier verifier = SignatureVerifier(signatureVerifier);
|
|
1068
1076
|
signers = new address[](vargs.reqThreshold);
|
|
1069
1077
|
address prev;
|
|
1070
1078
|
for (uint256 i; i < vargs.reqThreshold; i++) {
|
|
1071
|
-
|
|
1079
|
+
// Its errors (`SignatureSlotRecovery.*`) revert through this call unchanged.
|
|
1080
|
+
address signer = verifier.recoverFromSlot(
|
|
1072
1081
|
// Spec 302 W2 — v=2 passkey slots derive the per-ACCOUNT PIA.
|
|
1073
|
-
vargs.payloadHash,
|
|
1082
|
+
vargs.payloadHash, signatures, i, approvedHashReg, account
|
|
1074
1083
|
);
|
|
1075
1084
|
if (signer <= prev) revert AdminDuplicateOrUnsortedSigner(signer);
|
|
1076
1085
|
prev = signer;
|
|
@@ -1158,10 +1167,14 @@ contract CustodyPolicy {
|
|
|
1158
1167
|
_applyRotateCredential(account, c, r);
|
|
1159
1168
|
} else if (action == CustodyAction.ApplySystemUpdate) {
|
|
1160
1169
|
// Spec 445 §1.3 (i): the account refuses `newImpl` unless its implementation's UpgradeVoucher
|
|
1161
|
-
// vouches for (newImpl, keccak256(
|
|
1162
|
-
// code either.
|
|
1163
|
-
(
|
|
1164
|
-
|
|
1170
|
+
// vouches for (newImpl, keccak256(data)) at this moment — a quorum cannot delegatecall arbitrary
|
|
1171
|
+
// code either. Spec 447 §3.4: `args` is `abi.encode(newImpl)` (a plain upgrade) or
|
|
1172
|
+
// `abi.encode(newImpl, data)` (a vouched migration, e.g. the generation-5 factory move).
|
|
1173
|
+
address newImpl;
|
|
1174
|
+
bytes memory data;
|
|
1175
|
+
if (args.length == 32) newImpl = abi.decode(args, (address));
|
|
1176
|
+
else (newImpl, data) = abi.decode(args, (address, bytes));
|
|
1177
|
+
_execute(account, abi.encodeWithSignature("upgradeToAndCall(address,bytes)", newImpl, data));
|
|
1165
1178
|
} else if (action == CustodyAction.InstallModule) {
|
|
1166
1179
|
(uint256 moduleTypeId, address module, bytes memory initData) = abi.decode(args, (uint256, address, bytes));
|
|
1167
1180
|
_execute(account, abi.encodeWithSignature(
|
|
@@ -1257,24 +1270,12 @@ contract CustodyPolicy {
|
|
|
1257
1270
|
if (newMode > 3) revert InvalidMode(newMode);
|
|
1258
1271
|
uint8 oldMode = c.mode;
|
|
1259
1272
|
if (newMode == 0 && c.trusteeCount > 0) revert CannotDowngradeWithTrustees();
|
|
1260
|
-
// EXT-CHANGEMODE-1 (2026-07-05 audit): a runtime ChangeMode must re-run the factory's install-time
|
|
1261
|
-
// mode-3 feasibility so the account can't enter an un-executable / liveness-hostile org mode.
|
|
1262
|
-
// Org SoD needs ≥2 signers (distinct proposers + appliers) and T4/T5 thresholds within the
|
|
1263
|
-
// floor(N/2) cap (else 2×threshold > N → no disjoint quorum → the tier silently locks). Require the
|
|
1264
|
-
// signer floor; cap the SoD-constrained thresholds (mirrors the factory, avoids a locked mode).
|
|
1265
|
-
if (newMode == 3) {
|
|
1266
|
-
uint256 n = IAgentAccount(account).custodianCount();
|
|
1267
|
-
if (n < 2) revert InfeasibleOrgConfig(uint8(n));
|
|
1268
|
-
uint8 sodCap = uint8(n / 2); // ≥ 1 since n ≥ 2
|
|
1269
|
-
for (uint8 tier = 4; tier <= 5; tier++) {
|
|
1270
|
-
uint8 v = c.approvalsRequiredByTier[tier];
|
|
1271
|
-
if (v > sodCap) {
|
|
1272
|
-
c.approvalsRequiredByTier[tier] = sodCap;
|
|
1273
|
-
emit ThresholdChanged(account, tier, v, sodCap);
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
1273
|
c.mode = newMode;
|
|
1274
|
+
// EXT-CHANGEMODE-1 + audit 2026-12-02 C2-7: entering org mode needs >= 2 signers and T4 / T5 within the
|
|
1275
|
+
// floor(N/2) separation-of-duties cap. It is REFUSED when they are not, never capped: capping here lowered
|
|
1276
|
+
// T5 under a T4 quorum (and the lowered value stayed when the mode changed back). The quorum lowers the
|
|
1277
|
+
// thresholds first, as `ChangeApprovalsRequired` — a T5 action that names the numbers it signs.
|
|
1278
|
+
if (newMode == 3) _requireThresholdsReachable(c, IAgentAccount(account).custodianCount());
|
|
1278
1279
|
emit ModeChanged(account, oldMode, newMode);
|
|
1279
1280
|
}
|
|
1280
1281
|
|