@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
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
|
+
import {StableProxyGoverned} from "../governance/StableProxyGoverned.sol";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @title TreasurySpendPolicy — an aggregate ceiling AT THE RESOURCE (spec 410 §7, THESIS-6)
|
|
6
8
|
* @notice Every caveat enforcer bounds ONE delegation: `ValueEnforcer` a call's value, `PaymentEnforcer` a
|
|
@@ -83,7 +85,12 @@ interface ITreasurySpendPolicyAccountView {
|
|
|
83
85
|
function entryPoint() external view returns (address);
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
contract TreasurySpendPolicy {
|
|
88
|
+
contract TreasurySpendPolicy is StableProxyGoverned {
|
|
89
|
+
/// @notice A direct deployment, initialized here (no governance: never upgradeable). Behind a stable proxy
|
|
90
|
+
/// (spec 447), `initialize(governance_)` instead — a treasury holds this hook's address in its module
|
|
91
|
+
/// list, so a fix must keep the address (and every installed budget with it).
|
|
92
|
+
constructor() initializer {}
|
|
93
|
+
|
|
87
94
|
struct Budget {
|
|
88
95
|
address asset; // address(0) = native value
|
|
89
96
|
uint256 ceiling; // per window, in the asset's base units
|
|
@@ -96,6 +103,8 @@ contract TreasurySpendPolicy {
|
|
|
96
103
|
|
|
97
104
|
/// account => budget
|
|
98
105
|
mapping(address => Budget) private _budgets;
|
|
106
|
+
/// @dev Storage gap (spec 447; layout gated by `check:storage-layouts`).
|
|
107
|
+
uint256[49] private __gap;
|
|
99
108
|
|
|
100
109
|
event BudgetInstalled(address indexed account, address indexed asset, uint256 ceiling, uint64 windowSeconds, uint64 windowStart);
|
|
101
110
|
event BudgetUninstalled(address indexed account);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import "../agency/ICaveatEnforcer.sol";
|
|
5
|
+
import "../governance/StableProxyGoverned.sol";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @title AllowedMethodsEnforcer
|
|
@@ -20,7 +21,12 @@ import "../agency/ICaveatEnforcer.sol";
|
|
|
20
21
|
* executing account itself (`SelfTargetedRedemption`) — the route by which a self-`executeBatch`
|
|
21
22
|
* once ran inner calls no enforcer saw. Do not reuse this enforcer under a manager without that rule.
|
|
22
23
|
*/
|
|
23
|
-
contract AllowedMethodsEnforcer is ICaveatEnforcer {
|
|
24
|
+
contract AllowedMethodsEnforcer is ICaveatEnforcer, StableProxyGoverned {
|
|
25
|
+
/// @notice A direct deployment, initialized here (no governance: never upgradeable). Behind a stable proxy
|
|
26
|
+
/// (spec 447), `initialize(governance_)` instead — an enforcer's address is in every delegation that
|
|
27
|
+
/// names it, so a fix must keep the address.
|
|
28
|
+
constructor() initializer {}
|
|
29
|
+
|
|
24
30
|
error MethodNotAllowed();
|
|
25
31
|
error CalldataTooShort();
|
|
26
32
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import "../agency/ICaveatEnforcer.sol";
|
|
5
|
+
import "../governance/StableProxyGoverned.sol";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @title AllowedTargetsEnforcer
|
|
@@ -20,7 +21,12 @@ import "../agency/ICaveatEnforcer.sol";
|
|
|
20
21
|
* executing account itself (`SelfTargetedRedemption`) — the route by which a self-`executeBatch`
|
|
21
22
|
* once ran inner calls no enforcer saw. Do not reuse this enforcer under a manager without that rule.
|
|
22
23
|
*/
|
|
23
|
-
contract AllowedTargetsEnforcer is ICaveatEnforcer {
|
|
24
|
+
contract AllowedTargetsEnforcer is ICaveatEnforcer, StableProxyGoverned {
|
|
25
|
+
/// @notice A direct deployment, initialized here (no governance: never upgradeable). Behind a stable proxy
|
|
26
|
+
/// (spec 447), `initialize(governance_)` instead — an enforcer's address is in every delegation that
|
|
27
|
+
/// names it, so a fix must keep the address.
|
|
28
|
+
constructor() initializer {}
|
|
29
|
+
|
|
24
30
|
error TargetNotAllowed();
|
|
25
31
|
|
|
26
32
|
function beforeHook(
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import "../agency/ICaveatEnforcer.sol";
|
|
5
|
+
import "../governance/StableProxyGoverned.sol";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @title CallDataHashEnforcer
|
|
@@ -26,7 +27,12 @@ import "../agency/ICaveatEnforcer.sol";
|
|
|
26
27
|
* dispatch, and the read-only `verifyAuthorizationForCall` evaluates it
|
|
27
28
|
* via `staticcall`.
|
|
28
29
|
*/
|
|
29
|
-
contract CallDataHashEnforcer is ICaveatEnforcer {
|
|
30
|
+
contract CallDataHashEnforcer is ICaveatEnforcer, StableProxyGoverned {
|
|
31
|
+
/// @notice A direct deployment, initialized here (no governance: never upgradeable). Behind a stable proxy
|
|
32
|
+
/// (spec 447), `initialize(governance_)` instead — an enforcer's address is in every delegation that
|
|
33
|
+
/// names it, so a fix must keep the address.
|
|
34
|
+
constructor() initializer {}
|
|
35
|
+
|
|
30
36
|
error BadTermsLength();
|
|
31
37
|
error CallDataMismatch(bytes32 expected, bytes32 actual);
|
|
32
38
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import "../agency/ICaveatEnforcer.sol";
|
|
5
|
+
import "../governance/StableProxyGoverned.sol";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @title DigestBindingEnforcer
|
|
@@ -71,7 +72,7 @@ import "../agency/ICaveatEnforcer.sol";
|
|
|
71
72
|
* The hooks mutate state and are `onlyDelegationManager` (EXT-PMT-1's rule for stateful
|
|
72
73
|
* enforcers): a stranger cannot spend a use or a nonce outside a valid redemption.
|
|
73
74
|
*/
|
|
74
|
-
contract DigestBindingEnforcer is ICaveatEnforcer {
|
|
75
|
+
contract DigestBindingEnforcer is ICaveatEnforcer, StableProxyGoverned {
|
|
75
76
|
error BadTermsLength();
|
|
76
77
|
error BadArgsLength();
|
|
77
78
|
error ZeroMaxUses();
|
|
@@ -88,6 +89,8 @@ contract DigestBindingEnforcer is ICaveatEnforcer {
|
|
|
88
89
|
mapping(address => mapping(bytes32 => mapping(bytes32 => uint256))) private _uses;
|
|
89
90
|
/// delegator => delegationHash => keccak256(kind, redeemer, stepNonce) => consumed
|
|
90
91
|
mapping(address => mapping(bytes32 => mapping(bytes32 => bool))) private _used;
|
|
92
|
+
/// @dev Storage gap (spec 447: behind a stable proxy; layout gated by `check:storage-layouts`).
|
|
93
|
+
uint256[48] private __gap;
|
|
91
94
|
|
|
92
95
|
event DigestBindingRedeemed(
|
|
93
96
|
address indexed delegator,
|
|
@@ -100,7 +103,7 @@ contract DigestBindingEnforcer is ICaveatEnforcer {
|
|
|
100
103
|
uint256 maxUses
|
|
101
104
|
);
|
|
102
105
|
|
|
103
|
-
constructor(address delegationManager_) {
|
|
106
|
+
constructor(address delegationManager_) initializer {
|
|
104
107
|
require(delegationManager_ != address(0), "DigestBindingEnforcer: zero DelegationManager");
|
|
105
108
|
delegationManager = delegationManager_;
|
|
106
109
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import "../agency/ICaveatEnforcer.sol";
|
|
5
|
+
import "../governance/StableProxyGoverned.sol";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @title PayloadClassesEnforcer — the INFORMATION-FLOW caveat (spec 410 §7)
|
|
@@ -19,7 +20,12 @@ import "../agency/ICaveatEnforcer.sol";
|
|
|
19
20
|
* What it is NOT: authority over the read (the read has its own mandate and scope), a content
|
|
20
21
|
* filter, or a substitute for the vault's per-record scope — those are enforced where the data is.
|
|
21
22
|
*/
|
|
22
|
-
contract PayloadClassesEnforcer is ICaveatEnforcer {
|
|
23
|
+
contract PayloadClassesEnforcer is ICaveatEnforcer, StableProxyGoverned {
|
|
24
|
+
/// @notice A direct deployment, initialized here (no governance: never upgradeable). Behind a stable proxy
|
|
25
|
+
/// (spec 447), `initialize(governance_)` instead — an enforcer's address is in every delegation that
|
|
26
|
+
/// names it, so a fix must keep the address.
|
|
27
|
+
constructor() initializer {}
|
|
28
|
+
|
|
23
29
|
function beforeHook(bytes calldata, bytes calldata, bytes32, address, address, address, uint256, bytes calldata) external pure override {}
|
|
24
30
|
function afterHook(bytes calldata, bytes calldata, bytes32, address, address, address, uint256, bytes calldata) external pure override {}
|
|
25
31
|
|
|
@@ -3,6 +3,7 @@ pragma solidity ^0.8.28;
|
|
|
3
3
|
|
|
4
4
|
import "../agency/ICaveatEnforcer.sol";
|
|
5
5
|
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
6
|
+
import "../governance/StableProxyGoverned.sol";
|
|
6
7
|
|
|
7
8
|
/// @dev The one thing this enforcer asks of its DelegationManager beyond calling the hooks: whose
|
|
8
9
|
/// account executes the redemption in flight (audit DLG-8c). Attribution only.
|
|
@@ -65,7 +66,7 @@ interface IPaymentReceiptRegistry {
|
|
|
65
66
|
* smuggling; `value == 0` rejects ETH; the DelegationManager's single (target,value,data)
|
|
66
67
|
* redemption shape rejects batch/delegatecall.
|
|
67
68
|
*/
|
|
68
|
-
contract PaymentEnforcer is ICaveatEnforcer {
|
|
69
|
+
contract PaymentEnforcer is ICaveatEnforcer, StableProxyGoverned {
|
|
69
70
|
bytes4 private constant TRANSFER_SELECTOR = IERC20.transfer.selector; // 0xa9059cbb
|
|
70
71
|
|
|
71
72
|
struct Budget {
|
|
@@ -85,6 +86,8 @@ contract PaymentEnforcer is ICaveatEnforcer {
|
|
|
85
86
|
/// entry is distinguishable from an unset slot even when the treasury balance is 0. Set and
|
|
86
87
|
/// deleted within a single non-reentrant `redeemDelegation`, so it never persists across txs.
|
|
87
88
|
mapping(bytes32 => uint256) private _settleSnap;
|
|
89
|
+
/// @dev Storage gap (spec 447: behind a stable proxy; layout gated by `check:storage-layouts`).
|
|
90
|
+
uint256[47] private __gap;
|
|
88
91
|
|
|
89
92
|
/// @notice The ONLY authorized caller of the hooks (EXT-PMT-1 / C-NEW-1). Unlike the stateless
|
|
90
93
|
/// enforcers (timestamp/value/targets/methods), this enforcer MUTATES state (budget, nonce)
|
|
@@ -140,7 +143,7 @@ contract PaymentEnforcer is ICaveatEnforcer {
|
|
|
140
143
|
_;
|
|
141
144
|
}
|
|
142
145
|
|
|
143
|
-
constructor(address delegationManager_, address receiptRegistry_) {
|
|
146
|
+
constructor(address delegationManager_, address receiptRegistry_) initializer {
|
|
144
147
|
require(delegationManager_ != address(0), "PaymentEnforcer: zero DelegationManager");
|
|
145
148
|
delegationManager = delegationManager_;
|
|
146
149
|
receiptRegistry = IPaymentReceiptRegistry(receiptRegistry_);
|
|
@@ -3,6 +3,7 @@ pragma solidity ^0.8.28;
|
|
|
3
3
|
|
|
4
4
|
import "../agency/ICaveatEnforcer.sol";
|
|
5
5
|
import "../libraries/SignatureSlotRecovery.sol";
|
|
6
|
+
import "../governance/StableProxyGoverned.sol";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @title QuorumEnforcer
|
|
@@ -77,7 +78,12 @@ import "../libraries/SignatureSlotRecovery.sol";
|
|
|
77
78
|
* dispatch. See `docs/audits/r6-contracts-recon-2026-05-31.md`
|
|
78
79
|
* § 4.4 + `test/EnforcerPauseInvariantR67.t.sol`.
|
|
79
80
|
*/
|
|
80
|
-
contract QuorumEnforcer is ICaveatEnforcer {
|
|
81
|
+
contract QuorumEnforcer is ICaveatEnforcer, StableProxyGoverned {
|
|
82
|
+
/// @notice A direct deployment, initialized here (no governance: never upgradeable). Behind a stable proxy
|
|
83
|
+
/// (spec 447), `initialize(governance_)` instead — an enforcer's address is in every delegation that
|
|
84
|
+
/// names it, so a fix must keep the address.
|
|
85
|
+
constructor() initializer {}
|
|
86
|
+
|
|
81
87
|
error InsufficientQuorum(uint256 supplied, uint8 threshold);
|
|
82
88
|
error UnauthorizedSigner(address signer);
|
|
83
89
|
error DuplicateOrUnsortedSigner(address signer);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import "../agency/ICaveatEnforcer.sol";
|
|
5
|
+
import "../governance/StableProxyGoverned.sol";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @title TimestampEnforcer
|
|
@@ -16,7 +17,12 @@ import "../agency/ICaveatEnforcer.sol";
|
|
|
16
17
|
* dispatch. See `docs/audits/r6-contracts-recon-2026-05-31.md`
|
|
17
18
|
* § 4.4 + `test/EnforcerPauseInvariantR67.t.sol`.
|
|
18
19
|
*/
|
|
19
|
-
contract TimestampEnforcer is ICaveatEnforcer {
|
|
20
|
+
contract TimestampEnforcer is ICaveatEnforcer, StableProxyGoverned {
|
|
21
|
+
/// @notice A direct deployment, initialized here (no governance: never upgradeable). Behind a stable proxy
|
|
22
|
+
/// (spec 447), `initialize(governance_)` instead — an enforcer's address is in every delegation that
|
|
23
|
+
/// names it, so a fix must keep the address.
|
|
24
|
+
constructor() initializer {}
|
|
25
|
+
|
|
20
26
|
error TimestampNotYetValid();
|
|
21
27
|
error TimestampExpired();
|
|
22
28
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import "../agency/ICaveatEnforcer.sol";
|
|
5
|
+
import "../governance/StableProxyGoverned.sol";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @title ValueEnforcer
|
|
@@ -20,7 +21,12 @@ import "../agency/ICaveatEnforcer.sol";
|
|
|
20
21
|
* executing account itself (`SelfTargetedRedemption`) — the route by which a self-`executeBatch`
|
|
21
22
|
* once ran inner calls no enforcer saw. Do not reuse this enforcer under a manager without that rule.
|
|
22
23
|
*/
|
|
23
|
-
contract ValueEnforcer is ICaveatEnforcer {
|
|
24
|
+
contract ValueEnforcer is ICaveatEnforcer, StableProxyGoverned {
|
|
25
|
+
/// @notice A direct deployment, initialized here (no governance: never upgradeable). Behind a stable proxy
|
|
26
|
+
/// (spec 447), `initialize(governance_)` instead — an enforcer's address is in every delegation that
|
|
27
|
+
/// names it, so a fix must keep the address.
|
|
28
|
+
constructor() initializer {}
|
|
29
|
+
|
|
24
30
|
error ValueExceedsLimit();
|
|
25
31
|
|
|
26
32
|
function beforeHook(
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
|
+
import "../governance/StableProxyGoverned.sol";
|
|
4
|
+
import {Eip7702} from "../libraries/Eip7702.sol";
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* @title GeoFeatureRegistry
|
|
@@ -34,7 +36,13 @@ pragma solidity ^0.8.28;
|
|
|
34
36
|
* Ported from smart-agent `GeoFeatureRegistry`; diverges per spec 251 (AP auth,
|
|
35
37
|
* C-box-anchored kinds, no name binding in v1).
|
|
36
38
|
*/
|
|
37
|
-
contract GeoFeatureRegistry {
|
|
39
|
+
contract GeoFeatureRegistry is StableProxyGoverned {
|
|
40
|
+
/// @notice Spec 447 — a DIRECT deployment, initialized here with no governance (its code is frozen, as
|
|
41
|
+
/// before). Behind a stable proxy, `initialize(governance_)` instead; the governance is then the only
|
|
42
|
+
/// upgrade authority. This contract has no admin of its own: governance can replace the code behind
|
|
43
|
+
/// the proxy and nothing else.
|
|
44
|
+
constructor() initializer {}
|
|
45
|
+
|
|
38
46
|
// ─── C-box feature-kind codelist (keccak of the cbox URIs) ──────────
|
|
39
47
|
// Concept URIs are declared in packages/ontology cbox/geo-vocabulary.ttl
|
|
40
48
|
// (scheme apg:geoKind); lockstep-gated against the ontology (ADR-0009).
|
|
@@ -115,6 +123,7 @@ contract GeoFeatureRegistry {
|
|
|
115
123
|
function publish(PublishInput calldata p) external returns (uint64 version) {
|
|
116
124
|
if (p.featureId == bytes32(0)) revert EmptyId();
|
|
117
125
|
if (bytes(p.metadataURI).length == 0) revert EmptyMetadata();
|
|
126
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
118
127
|
if (msg.sender != p.stewardAccount) revert NotSteward();
|
|
119
128
|
|
|
120
129
|
uint64 prevVer = latestVersion[p.featureId];
|
|
@@ -160,6 +169,7 @@ contract GeoFeatureRegistry {
|
|
|
160
169
|
uint64 v = latestVersion[featureId];
|
|
161
170
|
if (v == 0) revert FeatureNotFound();
|
|
162
171
|
FeatureRecord storage r = _records[featureId][v];
|
|
172
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
163
173
|
if (msg.sender != r.stewardAccount) revert NotSteward();
|
|
164
174
|
r.active = false;
|
|
165
175
|
emit FeatureDeactivated(featureId, v);
|
|
@@ -168,6 +178,7 @@ contract GeoFeatureRegistry {
|
|
|
168
178
|
function setValidity(bytes32 featureId, uint64 version, uint64 validAfter, uint64 validUntil) external {
|
|
169
179
|
FeatureRecord storage r = _records[featureId][version];
|
|
170
180
|
if (r.version == 0) revert FeatureNotFound();
|
|
181
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
171
182
|
if (msg.sender != r.stewardAccount) revert NotSteward();
|
|
172
183
|
// REG-15: a published version's window can be ENDED, never rewritten. `validAfter` is fixed at
|
|
173
184
|
// publish; `validUntil` may be set (0 → a time) or moved earlier, not extended or cleared — a
|
|
@@ -218,4 +229,7 @@ contract GeoFeatureRegistry {
|
|
|
218
229
|
page = new bytes32[](end - offset);
|
|
219
230
|
for (uint256 i = offset; i < end; i++) page[i - offset] = _allFeatures[i];
|
|
220
231
|
}
|
|
232
|
+
|
|
233
|
+
/// @dev Spec 447 — storage gap: the contract may sit behind a stable proxy; layout gated by `check:storage-layouts`.
|
|
234
|
+
uint256[47] private __gap;
|
|
221
235
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import "./IGovernance.sol";
|
|
5
|
+
import {Eip7702} from "../libraries/Eip7702.sol";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @title AgenticGovernance
|
|
@@ -49,7 +50,42 @@ import "./IGovernance.sol";
|
|
|
49
50
|
* an AgentAccount is exercised by any one of its credentials. `Deploy.s.sol` proves the lift for the
|
|
50
51
|
* roles it installs (`_assertPauseLiftable`); `test/governance/PauseIsLiftable445.t.sol` proves it
|
|
51
52
|
* for every account mode.
|
|
53
|
+
*
|
|
54
|
+
* SYSTEM UPGRADES (spec 448 rule 10, audit 2026-12-02 H-3). From generation 5 every system contract is a
|
|
55
|
+
* proxy whose only upgrade authority is this contract, so every system upgrade is
|
|
56
|
+
* `timelock → execute(proxy, upgradeToAndCall(...))` here. Two limits live at that single door:
|
|
57
|
+
* - NO UPGRADE UNDER A PAUSE. `execute` refuses an `upgradeToAndCall` — and an `UpgradeVoucher.vouch`,
|
|
58
|
+
which admits account code — while paused. A pause freezes
|
|
59
|
+
* accounts; it must not also be the window in which the code that holds them is replaced.
|
|
60
|
+
* (An unpause and an upgrade may still execute in one timelock batch — both were public for the
|
|
61
|
+
* whole delay, and both are open to the veto below.)
|
|
62
|
+
* - THE GUARDIAN'S VETO. `vetoOperation` / `vetoBatch` let the guardian cancel a scheduled timelock
|
|
63
|
+
* operation — so an upgrade can be stopped by someone other than its proposer — but ONLY one that
|
|
64
|
+
* contains a system upgrade, a vouch, or a call to the timelock itself (its roles, its delay). The limit is
|
|
65
|
+
* deliberate: a guardian that could cancel anything could cancel its own replacement
|
|
66
|
+
* (`setGuardian`) and every `unpause`, and a stolen guardian key would freeze the estate for good.
|
|
67
|
+
* With the limit a hostile guardian can stall upgrades and role changes until the timelock replaces
|
|
68
|
+
* it (one delay), nothing more. This contract must hold the timelock's CANCELLER role for the veto
|
|
69
|
+
* to work (`Deploy.s.sol` grants and asserts it).
|
|
70
|
+
* WHAT THE VETO DOES NOT GIVE: immunity. A proposer and executor acting together can replace the
|
|
71
|
+
* guardian (one delay, public) and then upgrade (a second delay, public).
|
|
52
72
|
*/
|
|
73
|
+
/// @dev The slice of OpenZeppelin's `TimelockController` the veto uses.
|
|
74
|
+
interface ITimelockVeto {
|
|
75
|
+
function hashOperation(address target, uint256 value, bytes calldata data, bytes32 predecessor, bytes32 salt)
|
|
76
|
+
external
|
|
77
|
+
pure
|
|
78
|
+
returns (bytes32);
|
|
79
|
+
function hashOperationBatch(
|
|
80
|
+
address[] calldata targets,
|
|
81
|
+
uint256[] calldata values,
|
|
82
|
+
bytes[] calldata payloads,
|
|
83
|
+
bytes32 predecessor,
|
|
84
|
+
bytes32 salt
|
|
85
|
+
) external pure returns (bytes32);
|
|
86
|
+
function cancel(bytes32 id) external;
|
|
87
|
+
}
|
|
88
|
+
|
|
53
89
|
contract AgenticGovernance is IGovernanceView {
|
|
54
90
|
// ─── Immutables ───────────────────────────────────────────────
|
|
55
91
|
|
|
@@ -79,6 +115,13 @@ contract AgenticGovernance is IGovernanceView {
|
|
|
79
115
|
error NotGuardian(address caller);
|
|
80
116
|
error ExecuteFailed(address target, bytes returndata);
|
|
81
117
|
error ZeroAddress();
|
|
118
|
+
/// @dev A system upgrade was executed while the system is paused (spec 448 rule 10).
|
|
119
|
+
error UpgradeWhilePaused(address target);
|
|
120
|
+
/// @dev A system upgrade left the proxy answering differently for its upgrade authority or for one of the
|
|
121
|
+
/// system addresses it hands to accounts (audit C5-6). The whole upgrade is reverted.
|
|
122
|
+
error UpgradeChangesSystemWiring(address target);
|
|
123
|
+
/// @dev The guardian's veto reaches only an operation that upgrades a system contract or calls the timelock.
|
|
124
|
+
error NotVetoable();
|
|
82
125
|
|
|
83
126
|
// ─── Events ───────────────────────────────────────────────────
|
|
84
127
|
|
|
@@ -88,6 +131,8 @@ contract AgenticGovernance is IGovernanceView {
|
|
|
88
131
|
event Executed(address indexed target, uint256 value, bytes data);
|
|
89
132
|
/// @notice GOV-1 — the guardian (fast-pause) role was rotated by the timelock.
|
|
90
133
|
event GuardianRotated(address indexed oldGuardian, address indexed newGuardian);
|
|
134
|
+
/// @notice The guardian cancelled timelock operation `id`.
|
|
135
|
+
event OperationVetoed(bytes32 indexed id, address indexed by);
|
|
91
136
|
|
|
92
137
|
// ─── Constructor ──────────────────────────────────────────────
|
|
93
138
|
|
|
@@ -119,6 +164,7 @@ contract AgenticGovernance is IGovernanceView {
|
|
|
119
164
|
|
|
120
165
|
/// @notice Emergency pause. Callable by the guardian without delay.
|
|
121
166
|
function pause() external {
|
|
167
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
122
168
|
if (msg.sender != guardian) revert NotGuardian(msg.sender);
|
|
123
169
|
_paused = true;
|
|
124
170
|
emit Paused(msg.sender);
|
|
@@ -127,6 +173,7 @@ contract AgenticGovernance is IGovernanceView {
|
|
|
127
173
|
/// @notice Unpause. Requires the timelock (a deliberate 24h
|
|
128
174
|
/// decision); guardian alone cannot unpause.
|
|
129
175
|
function unpause() external {
|
|
176
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
130
177
|
if (msg.sender != timelock) revert NotTimelock(msg.sender);
|
|
131
178
|
_paused = false;
|
|
132
179
|
emit Unpaused(msg.sender);
|
|
@@ -143,9 +190,15 @@ contract AgenticGovernance is IGovernanceView {
|
|
|
143
190
|
payable
|
|
144
191
|
returns (bytes memory)
|
|
145
192
|
{
|
|
193
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
146
194
|
if (msg.sender != timelock) revert NotTimelock(msg.sender);
|
|
195
|
+
bool upgrade = _isUpgradeCall(data);
|
|
196
|
+
// audit H-3; a vouch is an account upgrade's admission and is held to the same rule (audit 2026-12-02 H-3 (c))
|
|
197
|
+
if ((upgrade || _isVouchCall(data)) && _paused) revert UpgradeWhilePaused(target);
|
|
198
|
+
bytes32 wiringBefore = upgrade ? _systemWiring(target) : bytes32(0);
|
|
147
199
|
(bool ok, bytes memory result) = target.call{value: value}(data);
|
|
148
200
|
if (!ok) revert ExecuteFailed(target, result);
|
|
201
|
+
if (upgrade && _systemWiring(target) != wiringBefore) revert UpgradeChangesSystemWiring(target); // audit C5-6
|
|
149
202
|
emit Executed(target, value, data);
|
|
150
203
|
return result;
|
|
151
204
|
}
|
|
@@ -153,6 +206,7 @@ contract AgenticGovernance is IGovernanceView {
|
|
|
153
206
|
/// @notice Add / remove a signer (consumed by `isSigner` reads from
|
|
154
207
|
/// downstream `GovernanceManaged` contracts).
|
|
155
208
|
function setSigner(address who, bool sig) external {
|
|
209
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
156
210
|
if (msg.sender != timelock) revert NotTimelock(msg.sender);
|
|
157
211
|
_signers[who] = sig;
|
|
158
212
|
emit SignerSet(who, sig);
|
|
@@ -165,13 +219,104 @@ contract AgenticGovernance is IGovernanceView {
|
|
|
165
219
|
/// address. Cannot be the zero address (would make `pause()` an
|
|
166
220
|
/// accidental no-op while looking live).
|
|
167
221
|
function setGuardian(address newGuardian) external {
|
|
222
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
168
223
|
if (msg.sender != timelock) revert NotTimelock(msg.sender);
|
|
169
224
|
if (newGuardian == address(0)) revert ZeroAddress();
|
|
225
|
+
Eip7702.refuseDelegatedEOA(newGuardian); // a seat held by a delegated EOA is a seat its attached code holds
|
|
170
226
|
address old = guardian;
|
|
171
227
|
guardian = newGuardian;
|
|
172
228
|
emit GuardianRotated(old, newGuardian);
|
|
173
229
|
}
|
|
174
230
|
|
|
231
|
+
// ─── The guardian's veto (spec 448 rule 10) ───────────────────
|
|
232
|
+
|
|
233
|
+
/// @dev `upgradeToAndCall(address,bytes)` — the one upgrade entry point of every system proxy (UUPS).
|
|
234
|
+
bytes4 private constant UPGRADE_SELECTOR = 0x4f1ef286;
|
|
235
|
+
|
|
236
|
+
/// @dev `vouch(address,bytes32)` — `UpgradeVoucher`'s admission of an ACCOUNT implementation (and of a
|
|
237
|
+
/// per-account move configuration). It changes what code accounts may run, so it is a system change like
|
|
238
|
+
/// an upgrade: refused under a pause and open to the guardian's veto. `unvouch` is not: withdrawing a
|
|
239
|
+
/// vouch only ever narrows, and it must stay available under a pause and beyond the guardian's reach.
|
|
240
|
+
bytes4 private constant VOUCH_SELECTOR = 0x3a101744;
|
|
241
|
+
|
|
242
|
+
function _isUpgradeCall(bytes calldata data) private pure returns (bool) {
|
|
243
|
+
return data.length >= 4 && bytes4(data[0:4]) == UPGRADE_SELECTOR;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function _isVouchCall(bytes calldata data) private pure returns (bool) {
|
|
247
|
+
return data.length >= 4 && bytes4(data[0:4]) == VOUCH_SELECTOR;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/// @dev Audit C5-6. What a system proxy must answer IDENTICALLY before and after an upgrade: who may upgrade
|
|
251
|
+
/// it (`governance()`), and the system addresses accounts read through it (a factory's custody policy,
|
|
252
|
+
/// delegation manager, approved-hash registry and voucher; anything's EntryPoint). The new implementation
|
|
253
|
+
/// keeps these in storage, in a namespaced slot or as its own immutables, and OpenZeppelin's only check
|
|
254
|
+
/// (`proxiableUUID`) passes for any UUPS contract — so one wrong address in a scheduled upgrade could leave
|
|
255
|
+
/// a proxy with NO upgrade authority for good, or silently re-point every account's custody policy
|
|
256
|
+
/// (making each custody-governed account self-governed). A view the target does not have is compared as
|
|
257
|
+
/// "absent" on both sides. Since generation 5 these addresses never change (spec 447 §1); an upgrade
|
|
258
|
+
/// that would change one is refused whole.
|
|
259
|
+
function _systemWiring(address target) private view returns (bytes32 h) {
|
|
260
|
+
bytes4[6] memory views = [
|
|
261
|
+
bytes4(keccak256("governance()")),
|
|
262
|
+
bytes4(keccak256("custodyPolicy()")),
|
|
263
|
+
bytes4(keccak256("delegationManager()")),
|
|
264
|
+
bytes4(keccak256("approvedHashRegistry()")),
|
|
265
|
+
bytes4(keccak256("upgradeVoucher()")),
|
|
266
|
+
bytes4(keccak256("entryPoint()"))
|
|
267
|
+
];
|
|
268
|
+
for (uint256 i; i < views.length; i++) {
|
|
269
|
+
(bool ok, bytes memory ret) = target.staticcall(abi.encodeWithSelector(views[i]));
|
|
270
|
+
h = keccak256(abi.encode(h, ok, ok ? keccak256(ret) : bytes32(0)));
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/// @dev One timelock call is vetoable iff its target is the timelock itself (role and delay administration),
|
|
275
|
+
/// or it is `this.execute(proxy, upgradeToAndCall(...), value)` — the only shape a system upgrade can
|
|
276
|
+
/// take, since a proxy accepts an upgrade from this contract alone — or `this.execute(voucher,
|
|
277
|
+
/// vouch(...), value)`, the only shape an account implementation's admission can take.
|
|
278
|
+
function _isVetoable(address target, bytes calldata data) private view returns (bool) {
|
|
279
|
+
if (target == timelock) return true;
|
|
280
|
+
if (target != address(this) || data.length < 4 || bytes4(data[0:4]) != this.execute.selector) return false;
|
|
281
|
+
(, bytes memory inner,) = abi.decode(data[4:], (address, bytes, uint256));
|
|
282
|
+
return inner.length >= 4 && (bytes4(inner) == UPGRADE_SELECTOR || bytes4(inner) == VOUCH_SELECTOR);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/// @notice Cancel the scheduled timelock operation `(target, value, data, predecessor, salt)`. Guardian only,
|
|
286
|
+
/// and only an operation `_isVetoable` describes. The operation is named by its contents, never by
|
|
287
|
+
/// its id, so what is cancelled is what was checked.
|
|
288
|
+
function vetoOperation(address target, uint256 value, bytes calldata data, bytes32 predecessor, bytes32 salt)
|
|
289
|
+
external
|
|
290
|
+
{
|
|
291
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
292
|
+
if (msg.sender != guardian) revert NotGuardian(msg.sender);
|
|
293
|
+
if (!_isVetoable(target, data)) revert NotVetoable();
|
|
294
|
+
_cancel(ITimelockVeto(timelock).hashOperation(target, value, data, predecessor, salt));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/// @notice The same for a batch: vetoable when ANY call in it is.
|
|
298
|
+
function vetoBatch(
|
|
299
|
+
address[] calldata targets,
|
|
300
|
+
uint256[] calldata values,
|
|
301
|
+
bytes[] calldata payloads,
|
|
302
|
+
bytes32 predecessor,
|
|
303
|
+
bytes32 salt
|
|
304
|
+
) external {
|
|
305
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
306
|
+
if (msg.sender != guardian) revert NotGuardian(msg.sender);
|
|
307
|
+
bool vetoable;
|
|
308
|
+
for (uint256 i; i < targets.length && i < payloads.length && !vetoable; i++) {
|
|
309
|
+
vetoable = _isVetoable(targets[i], payloads[i]);
|
|
310
|
+
}
|
|
311
|
+
if (!vetoable) revert NotVetoable();
|
|
312
|
+
_cancel(ITimelockVeto(timelock).hashOperationBatch(targets, values, payloads, predecessor, salt));
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function _cancel(bytes32 id) private {
|
|
316
|
+
ITimelockVeto(timelock).cancel(id);
|
|
317
|
+
emit OperationVetoed(id, msg.sender);
|
|
318
|
+
}
|
|
319
|
+
|
|
175
320
|
// ─── Receive ETH ──────────────────────────────────────────────
|
|
176
321
|
|
|
177
322
|
receive() external payable {}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import "./IGovernance.sol";
|
|
5
|
+
import {Eip7702} from "../libraries/Eip7702.sol";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @title GovernanceManaged
|
|
@@ -37,6 +38,7 @@ abstract contract GovernanceManaged {
|
|
|
37
38
|
/// @dev Only the governance contract (executing a passed proposal)
|
|
38
39
|
/// can call functions protected by this modifier.
|
|
39
40
|
modifier onlyGovernance() {
|
|
41
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
40
42
|
if (msg.sender != governance) revert NotGovernance();
|
|
41
43
|
_;
|
|
42
44
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.28;
|
|
3
|
+
|
|
4
|
+
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
|
|
5
|
+
import {Eip7702} from "../libraries/Eip7702.sol";
|
|
6
|
+
import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @title StableProxyGoverned
|
|
10
|
+
* @notice Spec 447 (generation 5) — the base for a system contract that lives behind a UUPS proxy at an address that
|
|
11
|
+
* never changes. Anything signed over, or held as an immutable by, a contract's address (an enforcer named in
|
|
12
|
+
* a delegation's caveats, the voucher an account implementation holds, the custody policy an account calls)
|
|
13
|
+
* survives a fix: the fix is a new implementation behind the same address.
|
|
14
|
+
*
|
|
15
|
+
* - `governance` (the `AgenticGovernance` contract, acting through its timelock) is the only upgrade
|
|
16
|
+
* authority. It lives in an ERC-7201 namespace, so a contract built on this base keeps its own linear
|
|
17
|
+
* storage layout exactly as it was.
|
|
18
|
+
* - A DIRECT deployment (tests, a one-off instance) is initialized in its constructor (the inheriting
|
|
19
|
+
* constructor carries the `initializer` modifier). UUPS's `onlyProxy` refuses to upgrade it.
|
|
20
|
+
* - Behind a proxy, `initialize(governance_)` runs once. The implementation itself can never be initialized
|
|
21
|
+
* (its constructor already was).
|
|
22
|
+
* - A contract with no governance is never upgraded.
|
|
23
|
+
*/
|
|
24
|
+
abstract contract StableProxyGoverned is Initializable, UUPSUpgradeable {
|
|
25
|
+
/// @custom:storage-location erc7201:agenticprimitives.stable-proxy-governed.v1
|
|
26
|
+
struct StableProxyGovernedStorage {
|
|
27
|
+
address governance;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// keccak256(abi.encode(uint256(keccak256("agenticprimitives.stable-proxy-governed.v1")) - 1)) & ~bytes32(uint256(0xff))
|
|
31
|
+
bytes32 private constant STABLE_PROXY_GOVERNED_SLOT =
|
|
32
|
+
0x775756232dfd963ad243ed4c7335d3b32889ad6784e2c9e947c9804ba981fb00;
|
|
33
|
+
|
|
34
|
+
/// @dev The same names `GovernanceManaged` uses, so callers matching on the selector are unaffected.
|
|
35
|
+
error NotGovernance();
|
|
36
|
+
error UpgradeWithoutGovernance();
|
|
37
|
+
|
|
38
|
+
event GovernanceSet(address indexed governance);
|
|
39
|
+
|
|
40
|
+
function _stableProxyGovernedStorage() private pure returns (StableProxyGovernedStorage storage $) {
|
|
41
|
+
bytes32 slot = STABLE_PROXY_GOVERNED_SLOT;
|
|
42
|
+
assembly {
|
|
43
|
+
$.slot := slot
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// @notice The upgrade authority (zero = none: the code is frozen).
|
|
48
|
+
function governance() public view returns (address) {
|
|
49
|
+
return _stableProxyGovernedStorage().governance;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// @notice The proxy's initializer. Runs once per proxy; never on an implementation.
|
|
53
|
+
/// @dev `virtual` so a contract whose proxy needs more than a governance address (a registry with its own
|
|
54
|
+
/// governor, a paymaster with an owner) can refuse this path and make its own
|
|
55
|
+
/// `initialize(governance_, ...)` the only one — a proxy initialized here would leave that state unset.
|
|
56
|
+
function initialize(address governance_) external virtual initializer {
|
|
57
|
+
_initializeGovernance(governance_);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/// @dev Records `governance_`. An inheriting contract that needs a non-zero governance (the voucher) overrides
|
|
61
|
+
/// this to refuse zero, then calls `super`.
|
|
62
|
+
function _initializeGovernance(address governance_) internal virtual {
|
|
63
|
+
_stableProxyGovernedStorage().governance = governance_;
|
|
64
|
+
emit GovernanceSet(governance_);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
modifier onlyGovernance() {
|
|
68
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
69
|
+
if (msg.sender != governance()) revert NotGovernance();
|
|
70
|
+
_;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function _authorizeUpgrade(address) internal view override {
|
|
74
|
+
address gov = governance();
|
|
75
|
+
if (gov == address(0)) revert UpgradeWithoutGovernance();
|
|
76
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
77
|
+
if (msg.sender != gov) revert NotGovernance();
|
|
78
|
+
}
|
|
79
|
+
}
|