@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,16 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
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
|
+
/// @dev The one read the registry makes of an account signer (audit 2026-12-02 H-2).
|
|
9
|
+
interface ICustodyEpochView {
|
|
10
|
+
function custodyEpoch() external view returns (uint64);
|
|
11
|
+
function approvalRefused() external view returns (bool);
|
|
12
|
+
}
|
|
13
|
+
|
|
4
14
|
/**
|
|
5
15
|
* @title ApprovedHashRegistry
|
|
6
16
|
* @notice On-chain pre-approved hashes — the `v == 1` path of Safe's
|
|
@@ -27,12 +37,27 @@ pragma solidity ^0.8.28;
|
|
|
27
37
|
* smart account can `approveHash` + perform the delegated action
|
|
28
38
|
* in one userOp.
|
|
29
39
|
*
|
|
30
|
-
* R917-C-2 (spec 408 §1.2): an `AgentAccount`'s `0x03` sentinel does NOT
|
|
31
|
-
* it
|
|
40
|
+
* R917-C-2 (spec 408 §1.2): an `AgentAccount`'s `0x03` sentinel does NOT consult the raw hash —
|
|
41
|
+
* it consults `AgentAccount.approvedHashKey(hash)` = `keccak256(abi.encode(hash, custodyEpoch))`,
|
|
32
42
|
* so an approval planted by a custodian who is later removed is void once the account's custody
|
|
33
|
-
* epoch moves.
|
|
43
|
+
* epoch moves.
|
|
44
|
+
*
|
|
45
|
+
* THE KEY IS DERIVED HERE, never taken from the caller (audit 2026-12-02 H-2, THESIS-1a). A signer
|
|
46
|
+
* with code is an account: `approveHash(h)` / `revokeHash(h)` act on
|
|
47
|
+
* `keccak256(abi.encode(h, msg.sender.custodyEpoch()))` — the epoch the account is in NOW, read from
|
|
48
|
+
* it. A caller cannot name a future epoch, whatever code it runs: generation-4 code (which may call
|
|
49
|
+
* this registry directly, before or in the same call frame as its move to generation 5) and the
|
|
50
|
+
* generation-5 `approveDigest` alike. A signer with no code (an EOA, the `QuorumEnforcer` `v == 1`
|
|
51
|
+
* slot's usual signer) approves the raw hash: its approval dies with its key. A contract that does not
|
|
52
|
+
* answer `custodyEpoch()` cannot approve or revoke a single hash here (fail closed, ADR-0013).
|
|
53
|
+
*
|
|
54
|
+
* Spec 447 (generation 5): deployed behind a UUPS proxy at an address that never changes. The registry is
|
|
55
|
+
* an IMMUTABLE of every `AgentAccount` implementation, so before this, fixing it meant a new instance, every
|
|
56
|
+
* account upgrading to reach it, and every approval made again (with a window in which a hash approved in the
|
|
57
|
+
* new registry ahead of time would count — GC's upgrade rehearsal, 2026-11-30). Behind a stable proxy a fix
|
|
58
|
+
* is a new implementation: the address the accounts hold, and every approval and epoch, stay.
|
|
34
59
|
*/
|
|
35
|
-
contract ApprovedHashRegistry {
|
|
60
|
+
contract ApprovedHashRegistry is Initializable, UUPSUpgradeable {
|
|
36
61
|
/// @dev R917-C-2 (spec 408 §1.2): an approval is recorded with the signer's epoch at the time
|
|
37
62
|
/// (`epoch + 1`, so a set slot is never zero); `revokeAll()` bumps the epoch and voids every
|
|
38
63
|
/// approval the signer ever made in one call. `isApproved` is the ONE read: the `0x03` sentinel
|
|
@@ -41,26 +66,90 @@ contract ApprovedHashRegistry {
|
|
|
41
66
|
mapping(address => mapping(bytes32 => uint64)) private _approvedAt;
|
|
42
67
|
/// signer => current epoch
|
|
43
68
|
mapping(address => uint64) private _epoch;
|
|
69
|
+
/// @dev Spec 447: the only upgrade authority (the `AgenticGovernance` contract, acting through its timelock).
|
|
70
|
+
/// Zero = never upgradeable.
|
|
71
|
+
address private _governance;
|
|
72
|
+
/// @dev Storage gap; this layout is gated by `check:storage-layouts`.
|
|
73
|
+
uint256[47] private __gap;
|
|
74
|
+
|
|
75
|
+
/// @dev Spec 447: an upgrade by anything but this registry's governance.
|
|
76
|
+
error NotGovernance();
|
|
77
|
+
/// @dev Spec 447: a registry with no governance cannot be upgraded.
|
|
78
|
+
error UpgradeWithoutGovernance();
|
|
79
|
+
/// @dev Spec 447: a non-zero governance with no code (an upgrade authority that can never act).
|
|
80
|
+
error GovernanceHasNoCode(address governance);
|
|
81
|
+
/// @dev The signing account answered `approvalRefused()` true: its custody changed, or it moved, earlier in this
|
|
82
|
+
/// transaction, so an approval now could outlive the custodian who sent it.
|
|
83
|
+
error ApprovalAfterCustodyChange();
|
|
44
84
|
|
|
45
85
|
event HashApproved(address indexed signer, bytes32 indexed hash);
|
|
46
86
|
event HashRevoked(address indexed signer, bytes32 indexed hash);
|
|
47
87
|
/// @dev R917-C-2 — every approval `signer` made before this event is void.
|
|
48
88
|
event AllHashesRevoked(address indexed signer, uint64 epoch);
|
|
49
89
|
|
|
90
|
+
/// @notice A DIRECT deployment (tests, a one-off instance): initialized here with no governance, so it works on
|
|
91
|
+
/// its own, can never be upgraded, and nobody can initialize it later.
|
|
92
|
+
constructor() initializer {}
|
|
93
|
+
|
|
94
|
+
/// @notice The proxy's initializer (spec 447). `governance_` is the upgrade authority; zero freezes the code.
|
|
95
|
+
function initialize(address governance_) external initializer {
|
|
96
|
+
if (governance_ != address(0) && governance_.code.length == 0) revert GovernanceHasNoCode(governance_);
|
|
97
|
+
Eip7702.refuseDelegatedEOA(governance_); // "has code" is not "is a contract" (spec 448 §0)
|
|
98
|
+
_governance = governance_;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/// @notice The upgrade authority (zero = none).
|
|
102
|
+
function governance() external view returns (address) {
|
|
103
|
+
return _governance;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/// @dev Spec 447: only governance upgrades; never a registry without one. UUPS's `onlyProxy` already refuses an
|
|
107
|
+
/// upgrade of a direct deployment.
|
|
108
|
+
function _authorizeUpgrade(address) internal view override {
|
|
109
|
+
address gov = _governance;
|
|
110
|
+
if (gov == address(0)) revert UpgradeWithoutGovernance();
|
|
111
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
112
|
+
if (msg.sender != gov) revert NotGovernance();
|
|
113
|
+
}
|
|
114
|
+
|
|
50
115
|
/**
|
|
51
116
|
* @notice Pre-approve a hash. `msg.sender` is the signer; only
|
|
52
117
|
* this address can later be counted by `QuorumEnforcer`
|
|
53
118
|
* for this hash.
|
|
54
119
|
*/
|
|
55
120
|
function approveHash(bytes32 hash) external {
|
|
56
|
-
|
|
57
|
-
|
|
121
|
+
bytes32 key = _keyOf(msg.sender, hash);
|
|
122
|
+
// An account in the same transaction as its custody change or its move approves nothing (audit 2026-12-02
|
|
123
|
+
// H-2, the move-transaction route); one that cannot answer is refused.
|
|
124
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
125
|
+
if (msg.sender.code.length != 0 && ICustodyEpochView(msg.sender).approvalRefused()) {
|
|
126
|
+
revert ApprovalAfterCustodyChange();
|
|
127
|
+
}
|
|
128
|
+
_approvedAt[msg.sender][key] = _epoch[msg.sender] + 1;
|
|
129
|
+
emit HashApproved(msg.sender, key);
|
|
58
130
|
}
|
|
59
131
|
|
|
60
|
-
/// @notice Revoke a previously-approved hash before redemption.
|
|
132
|
+
/// @notice Revoke a previously-approved hash before redemption (keyed as `approveHash` keys it).
|
|
61
133
|
function revokeHash(bytes32 hash) external {
|
|
62
|
-
|
|
63
|
-
|
|
134
|
+
bytes32 key = _keyOf(msg.sender, hash);
|
|
135
|
+
_approvedAt[msg.sender][key] = 0;
|
|
136
|
+
emit HashRevoked(msg.sender, key);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/// @notice The key `approveHash(hash)` from `signer` records NOW: the raw hash for a signer with no code;
|
|
140
|
+
/// `keccak256(abi.encode(hash, signer.custodyEpoch()))` for an account. Reverts for a contract
|
|
141
|
+
/// that does not answer `custodyEpoch()`.
|
|
142
|
+
function keyOf(address signer, bytes32 hash) external view returns (bytes32) {
|
|
143
|
+
return _keyOf(signer, hash);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/// @dev Audit 2026-12-02 H-2 / THESIS-1a: the epoch is the caller's own current one, read here — never an
|
|
147
|
+
/// argument. One mechanism per kind of signer; an account that cannot say its epoch is refused.
|
|
148
|
+
function _keyOf(address signer, bytes32 hash) private view returns (bytes32) {
|
|
149
|
+
// A delegated EOA is keyed as the EOA it is (spec 448 §0): it approves nothing (refused above) but can
|
|
150
|
+
// still revoke the raw approvals its key made before it delegated.
|
|
151
|
+
if (signer.code.length == 0 || Eip7702.isDelegatedEOA(signer)) return hash;
|
|
152
|
+
return keccak256(abi.encode(hash, ICustodyEpochView(signer).custodyEpoch()));
|
|
64
153
|
}
|
|
65
154
|
|
|
66
155
|
/// @notice R917-C-2 — revoke EVERY hash `msg.sender` ever approved, in one call. The per-hash
|
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
4
|
import "account-abstraction/core/BasePaymaster.sol";
|
|
5
|
+
import {Eip7702} from "./libraries/Eip7702.sol";
|
|
5
6
|
import "account-abstraction/interfaces/IEntryPoint.sol";
|
|
6
7
|
import "account-abstraction/interfaces/PackedUserOperation.sol";
|
|
7
8
|
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
8
9
|
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
|
|
9
10
|
import "./governance/IGovernance.sol";
|
|
11
|
+
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
|
|
12
|
+
import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* @title SmartAgentPaymaster
|
|
@@ -70,6 +73,12 @@ import "./governance/IGovernance.sol";
|
|
|
70
73
|
* to allowlist is fail-closed: every userOp reverts with
|
|
71
74
|
* `SenderNotAccepted` until governance explicitly opts a sender
|
|
72
75
|
* in. That is the documented safe state.
|
|
76
|
+
* WHAT ALLOWLIST MODE TRUSTS (audit 2026-12-02 C2-5): nobody signs an
|
|
77
|
+
* allowlisted operation's fees, so each accepted sender — any ONE of
|
|
78
|
+
* its credentials — can spend the deposit on itself, bounded only by
|
|
79
|
+
* `allowlistMaxCostPerOp` PER OPERATION (zero = nothing is sponsored;
|
|
80
|
+
* governance sets it with the first `setAccepted`). There is no
|
|
81
|
+
* per-sender budget: prefer verifying mode wherever the deposit matters.
|
|
73
82
|
* 2. Monitor `getDeposit()` and alert below a runway threshold.
|
|
74
83
|
* 3. PM-2 — hand the Ownable owner to the governance TimelockController via
|
|
75
84
|
* `Ownable2Step` (`transferOwnership(governance)` then a timelocked
|
|
@@ -90,7 +99,21 @@ import "./governance/IGovernance.sol";
|
|
|
90
99
|
* and `withdrawTo` from `BasePaymaster`. Ownable owner is set in
|
|
91
100
|
* the constructor (Ownable2Step pattern).
|
|
92
101
|
*/
|
|
93
|
-
|
|
102
|
+
/// @dev Spec 447 (generation 5) — deployable behind an ERC-1967 UUPS proxy at an address that never changes (the
|
|
103
|
+
/// address every sponsored user operation names in `paymasterAndData`, and the EntryPoint deposit's holder).
|
|
104
|
+
/// `governance` moved from an immutable to `StableProxyGoverned`'s ERC-7201 slot
|
|
105
|
+
/// (`agenticprimitives.stable-proxy-governed.v1`; same `governance()` getter, same `onlyGovernance` /
|
|
106
|
+
/// `NotGovernance`); it is the admin of the paymaster AND the only upgrade authority. The paymaster does not
|
|
107
|
+
/// inherit `StableProxyGoverned` itself only because it already declares `NotGovernance` (a published
|
|
108
|
+
/// selector its callers and tests name as `SmartAgentPaymaster.NotGovernance`); it implements the same rule
|
|
109
|
+
/// in the same slot.
|
|
110
|
+
/// The linear layout (and `__gap`) is unchanged. A DIRECT deployment is initialized in the constructor and can
|
|
111
|
+
/// never be upgraded (`onlyProxy`); behind a proxy, `initialize(governance_, initialOwner, devMode_,
|
|
112
|
+
/// verifyingSigner_)` sets everything the constructor sets, including the `Ownable` owner (slot 0).
|
|
113
|
+
/// `_entryPoint` (in `BasePaymaster`) stays an immutable: the EntryPoint is a fixed singleton address.
|
|
114
|
+
/// Validation reads only the proxy's own storage (`_dev`, `_acceptList`, `verifyingSigner`, `_pausedMirror`)
|
|
115
|
+
/// through a DELEGATECALL to a deployed implementation — ERC-7562's own-storage rule still holds.
|
|
116
|
+
contract SmartAgentPaymaster is BasePaymaster, Initializable, UUPSUpgradeable {
|
|
94
117
|
using ECDSA for bytes32;
|
|
95
118
|
using MessageHashUtils for bytes32;
|
|
96
119
|
|
|
@@ -105,9 +128,11 @@ contract SmartAgentPaymaster is BasePaymaster {
|
|
|
105
128
|
/// the production check). Set via governance.
|
|
106
129
|
address public verifyingSigner;
|
|
107
130
|
|
|
108
|
-
/// @
|
|
109
|
-
///
|
|
110
|
-
|
|
131
|
+
/// @dev Spec 447 — `governance` (the Governance contract whose pause flag halts paymaster validation, and the
|
|
132
|
+
/// upgrade authority) lives in `StableProxyGoverned`'s ERC-7201 slot; it was an immutable.
|
|
133
|
+
/// keccak256(abi.encode(uint256(keccak256("agenticprimitives.stable-proxy-governed.v1")) - 1)) & ~bytes32(uint256(0xff))
|
|
134
|
+
bytes32 private constant STABLE_PROXY_GOVERNED_SLOT =
|
|
135
|
+
0x775756232dfd963ad243ed4c7335d3b32889ad6784e2c9e947c9804ba981fb00;
|
|
111
136
|
|
|
112
137
|
/// @notice PM-1 — local mirror of the governance pause flag. This is the
|
|
113
138
|
/// ONLY pause signal read during ERC-4337 validation. Reading the
|
|
@@ -149,6 +174,8 @@ contract SmartAgentPaymaster is BasePaymaster {
|
|
|
149
174
|
uint64 public constant DEPOSIT_WITHDRAWAL_TIMELOCK = 48 hours;
|
|
150
175
|
|
|
151
176
|
error SenderNotAccepted(address sender);
|
|
177
|
+
/// @dev Allowlist mode: the operation's maximum cost exceeds the per-operation ceiling (C2-5).
|
|
178
|
+
error SponsoredCostAboveCeiling(uint256 maxCost, uint256 ceiling);
|
|
152
179
|
error SystemPaused();
|
|
153
180
|
error ZeroGovernance();
|
|
154
181
|
error NotGovernance();
|
|
@@ -160,8 +187,10 @@ contract SmartAgentPaymaster is BasePaymaster {
|
|
|
160
187
|
error WithdrawalAmountZero();
|
|
161
188
|
error WithdrawalToZero();
|
|
162
189
|
|
|
190
|
+
event GovernanceSet(address indexed governance);
|
|
163
191
|
event DevModeSet(bool dev);
|
|
164
192
|
event SenderAcceptedSet(address indexed sender, bool accepted);
|
|
193
|
+
event AllowlistMaxCostPerOpSet(uint256 ceilingWei);
|
|
165
194
|
event VerifyingSignerSet(address indexed oldSigner, address indexed newSigner);
|
|
166
195
|
/// @notice PM-1 — emitted whenever the local pause mirror is updated.
|
|
167
196
|
event PauseMirrorSynced(bool paused, address indexed by);
|
|
@@ -170,10 +199,15 @@ contract SmartAgentPaymaster is BasePaymaster {
|
|
|
170
199
|
event DepositWithdrawalExecuted(address indexed to, uint256 amount);
|
|
171
200
|
event DepositWithdrawalCancelled(address indexed to, uint256 amount);
|
|
172
201
|
|
|
202
|
+
/// @notice Audit 2026-12-02 C2-5 — the most one ALLOWLIST-mode operation may cost the deposit (wei; the
|
|
203
|
+
/// EntryPoint's `maxCost`). Zero until governance sets it: allowlist mode then sponsors nothing.
|
|
204
|
+
/// Not a per-sender budget: an accepted sender can still repeat operations, each within the ceiling.
|
|
205
|
+
uint256 public allowlistMaxCostPerOp;
|
|
206
|
+
|
|
173
207
|
/// @dev Storage gap reserves slots for future state. Phase A.5 §3.1.
|
|
174
208
|
/// PM-1/PM-2 consumed 3 slots (`_pausedMirror` packs into 1;
|
|
175
|
-
/// `PendingWithdrawal` is 2) — gap reduced 49 → 46
|
|
176
|
-
uint256[
|
|
209
|
+
/// `PendingWithdrawal` is 2) — gap reduced 49 → 46; `allowlistMaxCostPerOp` took the first gap slot → 45.
|
|
210
|
+
uint256[45] private __gap;
|
|
177
211
|
|
|
178
212
|
/// @dev Length of the paymaster-data tail when in verifying mode:
|
|
179
213
|
/// 6 (validUntil) + 6 (validAfter) + 65 (sig) = 77 bytes.
|
|
@@ -197,9 +231,46 @@ contract SmartAgentPaymaster is BasePaymaster {
|
|
|
197
231
|
address governance_,
|
|
198
232
|
bool devMode_,
|
|
199
233
|
address verifyingSigner_
|
|
200
|
-
) BasePaymaster(entryPointAddr, initialOwner) {
|
|
234
|
+
) BasePaymaster(entryPointAddr, initialOwner) initializer {
|
|
235
|
+
_initPaymaster(governance_, devMode_, verifyingSigner_);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/// @notice Spec 447 — the proxy's initializer: what the constructor sets, once per proxy. The implementation is
|
|
239
|
+
/// built with the same `entryPointAddr` (its immutable); the `Ownable` owner, which the constructor sets
|
|
240
|
+
/// through `BasePaymaster`, is set here for the proxy's storage.
|
|
241
|
+
function initialize(address governance_, address initialOwner, bool devMode_, address verifyingSigner_)
|
|
242
|
+
external
|
|
243
|
+
initializer
|
|
244
|
+
{
|
|
245
|
+
if (initialOwner == address(0)) revert OwnableInvalidOwner(address(0));
|
|
246
|
+
_transferOwnership(initialOwner);
|
|
247
|
+
_initPaymaster(governance_, devMode_, verifyingSigner_);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/// @notice The Governance contract: the paymaster's admin, its pause source and (spec 447) its only upgrade
|
|
251
|
+
/// authority.
|
|
252
|
+
function governance() public view returns (address gov) {
|
|
253
|
+
bytes32 slot = STABLE_PROXY_GOVERNED_SLOT;
|
|
254
|
+
assembly {
|
|
255
|
+
gov := sload(slot)
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/// @dev As before spec 447: a paymaster needs a governance.
|
|
260
|
+
function _initializeGovernance(address governance_) private {
|
|
201
261
|
if (governance_ == address(0)) revert ZeroGovernance();
|
|
202
|
-
|
|
262
|
+
bytes32 slot = STABLE_PROXY_GOVERNED_SLOT;
|
|
263
|
+
assembly {
|
|
264
|
+
sstore(slot, governance_)
|
|
265
|
+
}
|
|
266
|
+
emit GovernanceSet(governance_);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/// @dev Spec 447 — only governance replaces the code behind the proxy (a direct deployment: never, `onlyProxy`).
|
|
270
|
+
function _authorizeUpgrade(address) internal view override onlyGovernance {}
|
|
271
|
+
|
|
272
|
+
function _initPaymaster(address governance_, bool devMode_, address verifyingSigner_) private {
|
|
273
|
+
_initializeGovernance(governance_);
|
|
203
274
|
_dev = devMode_;
|
|
204
275
|
emit DevModeSet(devMode_);
|
|
205
276
|
if (verifyingSigner_ != address(0)) {
|
|
@@ -211,7 +282,8 @@ contract SmartAgentPaymaster is BasePaymaster {
|
|
|
211
282
|
// ─── Admin (governance-only) ────────────────────────────────────────
|
|
212
283
|
|
|
213
284
|
modifier onlyGovernance() {
|
|
214
|
-
|
|
285
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
286
|
+
if (msg.sender != governance()) revert NotGovernance();
|
|
215
287
|
_;
|
|
216
288
|
}
|
|
217
289
|
|
|
@@ -225,6 +297,12 @@ contract SmartAgentPaymaster is BasePaymaster {
|
|
|
225
297
|
emit SenderAcceptedSet(sender, accepted);
|
|
226
298
|
}
|
|
227
299
|
|
|
300
|
+
/// @notice Set the allowlist-mode per-operation cost ceiling (see `allowlistMaxCostPerOp`).
|
|
301
|
+
function setAllowlistMaxCostPerOp(uint256 ceilingWei) external onlyGovernance {
|
|
302
|
+
allowlistMaxCostPerOp = ceilingWei;
|
|
303
|
+
emit AllowlistMaxCostPerOpSet(ceilingWei);
|
|
304
|
+
}
|
|
305
|
+
|
|
228
306
|
function setAcceptedBatch(address[] calldata senders, bool accepted) external onlyGovernance {
|
|
229
307
|
for (uint256 i = 0; i < senders.length; i++) {
|
|
230
308
|
_acceptList[senders[i]] = accepted;
|
|
@@ -282,8 +360,9 @@ contract SmartAgentPaymaster is BasePaymaster {
|
|
|
282
360
|
/// than fail-open sponsoring. Only a clean, decodable `false` permits sponsorship.
|
|
283
361
|
function _governanceIsPaused() internal view returns (bool) {
|
|
284
362
|
// Unconfigured governance (unset, or an EOA with no code) → not paused (legacy/test path).
|
|
285
|
-
|
|
286
|
-
(
|
|
363
|
+
address gov = governance();
|
|
364
|
+
if (gov == address(0) || gov.code.length == 0) return false;
|
|
365
|
+
(bool ok, bytes memory data) = gov.staticcall(
|
|
287
366
|
abi.encodeWithSelector(IGovernanceView.isPaused.selector)
|
|
288
367
|
);
|
|
289
368
|
// Configured but faulted (call failed or undecodable) → fail closed (paused).
|
|
@@ -400,7 +479,7 @@ contract SmartAgentPaymaster is BasePaymaster {
|
|
|
400
479
|
function _validatePaymasterUserOp(
|
|
401
480
|
PackedUserOperation calldata userOp,
|
|
402
481
|
bytes32 /*userOpHash*/,
|
|
403
|
-
uint256
|
|
482
|
+
uint256 maxCost
|
|
404
483
|
) internal view override returns (bytes memory context, uint256 validationData) {
|
|
405
484
|
// PM-1 / H7-C.10 / EXT3-010: gated behind the system-wide governance
|
|
406
485
|
// pause — but read from the LOCAL mirror (`_pausedMirror`), never the
|
|
@@ -447,6 +526,11 @@ contract SmartAgentPaymaster is BasePaymaster {
|
|
|
447
526
|
|
|
448
527
|
// Fallback: allowlist mode.
|
|
449
528
|
if (!_acceptList[userOp.sender]) revert SenderNotAccepted(userOp.sender);
|
|
529
|
+
// Audit 2026-12-02 C2-5: nobody signs an allowlisted operation's fees or gas limits, so an accepted
|
|
530
|
+
// sender (any one of its credentials) could size them to the whole deposit and collect it as its own
|
|
531
|
+
// bundler. `maxCost` is the EntryPoint's own figure — every gas limit of the operation times its
|
|
532
|
+
// `maxFeePerGas` — and it must fit the ceiling governance set. Unset (0) sponsors nothing.
|
|
533
|
+
if (maxCost > allowlistMaxCostPerOp) revert SponsoredCostAboveCeiling(maxCost, allowlistMaxCostPerOp);
|
|
450
534
|
return ("", 0);
|
|
451
535
|
}
|
|
452
536
|
|
|
@@ -4,6 +4,7 @@ pragma solidity ^0.8.28;
|
|
|
4
4
|
import "@openzeppelin/contracts/interfaces/IERC1271.sol";
|
|
5
5
|
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
6
6
|
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
|
|
7
|
+
import {Eip7702} from "./libraries/Eip7702.sol";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @title UniversalSignatureValidator
|
|
@@ -56,6 +57,9 @@ contract UniversalSignatureValidator {
|
|
|
56
57
|
bytes32 hash,
|
|
57
58
|
bytes calldata sig
|
|
58
59
|
) external returns (bool) {
|
|
60
|
+
// Spec 448 §0 (EIP-7702): a delegated EOA is an EOA here — ECDSA only, never its attached code, and
|
|
61
|
+
// never through an ERC-6492 wrapper (which would reach the same code).
|
|
62
|
+
if (Eip7702.isDelegatedEOA(signer)) return _ecdsaRecover(signer, hash, sig);
|
|
59
63
|
if (_has6492Magic(sig)) {
|
|
60
64
|
(address factory, bytes memory factoryCalldata, bytes memory innerSig) =
|
|
61
65
|
_decode6492(sig[:sig.length - 32]);
|
|
@@ -79,6 +83,9 @@ contract UniversalSignatureValidator {
|
|
|
79
83
|
bytes32 hash,
|
|
80
84
|
bytes calldata sig
|
|
81
85
|
) external view returns (bool) {
|
|
86
|
+
// Spec 448 §0 (EIP-7702): a delegated EOA is an EOA here — ECDSA only, never its attached code, and
|
|
87
|
+
// never through an ERC-6492 wrapper (which would reach the same code).
|
|
88
|
+
if (Eip7702.isDelegatedEOA(signer)) return _ecdsaRecover(signer, hash, sig);
|
|
82
89
|
if (_has6492Magic(sig)) {
|
|
83
90
|
(, , bytes memory innerSig) = _decode6492(sig[:sig.length - 32]);
|
|
84
91
|
if (signer.code.length == 0) return false;
|
package/src/UpgradeVoucher.sol
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
3
|
|
|
4
|
-
import "./governance/
|
|
4
|
+
import "./governance/StableProxyGoverned.sol";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @title UpgradeVoucher — which implementations, with which migration data, an AgentAccount may upgrade to
|
|
@@ -38,12 +38,14 @@ import "./governance/GovernanceManaged.sol";
|
|
|
38
38
|
* at initialization and has no setter; an account upgraded in place still names its original factory.
|
|
39
39
|
* A vouching view on a new factory would never be consulted by an existing account.
|
|
40
40
|
*/
|
|
41
|
-
contract UpgradeVoucher is
|
|
41
|
+
contract UpgradeVoucher is StableProxyGoverned {
|
|
42
42
|
/// @notice `keccak256("")` — the `dataHash` of a plain upgrade (no migration call).
|
|
43
43
|
bytes32 public constant PLAIN_UPGRADE = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
|
|
44
44
|
|
|
45
45
|
/// implementation => keccak256(migration data) => vouched
|
|
46
46
|
mapping(address => mapping(bytes32 => bool)) private _vouched;
|
|
47
|
+
/// @dev Storage gap (spec 447: behind a proxy; layout gated by `check:storage-layouts`).
|
|
48
|
+
uint256[49] private __gap;
|
|
47
49
|
|
|
48
50
|
event UpgradeVouched(address indexed implementation, bytes32 indexed dataHash);
|
|
49
51
|
event UpgradeUnvouched(address indexed implementation, bytes32 indexed dataHash);
|
|
@@ -51,7 +53,18 @@ contract UpgradeVoucher is GovernanceManaged {
|
|
|
51
53
|
/// @dev Vouching for an address with no code would vouch for whatever is later deployed there.
|
|
52
54
|
error ImplementationHasNoCode(address implementation);
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
/// @dev A voucher with no governance could never vouch, so every account holding it could never upgrade.
|
|
57
|
+
error ZeroGovernance();
|
|
58
|
+
|
|
59
|
+
/// @notice A direct deployment, initialized here. Behind a proxy (spec 447), `initialize(governance_)` instead.
|
|
60
|
+
constructor(address governance_) initializer {
|
|
61
|
+
_initializeGovernance(governance_);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function _initializeGovernance(address governance_) internal override {
|
|
65
|
+
if (governance_ == address(0)) revert ZeroGovernance();
|
|
66
|
+
super._initializeGovernance(governance_);
|
|
67
|
+
}
|
|
55
68
|
|
|
56
69
|
/// @notice Vouch for upgrading to `implementation` with migration data hashing to `dataHash`.
|
|
57
70
|
function vouch(address implementation, bytes32 dataHash) external onlyGovernance {
|