@agenticprimitives/contracts 1.0.0-alpha.5 → 1.0.0-alpha.50

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.
Files changed (145) hide show
  1. package/AUDIT.md +119 -27
  2. package/README.md +47 -12
  3. package/deployments-base-sepolia.json +52 -1
  4. package/deployments-faithchain.json +103 -0
  5. package/deployments-hopechain.json +78 -0
  6. package/deployments-paymaster-anvil.json +1 -0
  7. package/deployments-registries-base-sepolia.json +1 -0
  8. package/deployments-registries-hopechain.json +1 -0
  9. package/dist/abi/AccountBootstrap.json +99 -0
  10. package/dist/abi/AgentAccount.json +461 -67
  11. package/dist/abi/AgentAccountFactory.json +309 -0
  12. package/dist/abi/AgentNameAttributeResolver.json +212 -0
  13. package/dist/abi/AgentNameRegistry.json +544 -0
  14. package/dist/abi/AgentNameUniversalResolver.json +222 -0
  15. package/dist/abi/AgentProfileResolver.json +236 -0
  16. package/dist/abi/AgentRegistryBase.json +1003 -0
  17. package/dist/abi/AgentRelationship.json +405 -0
  18. package/dist/abi/AgenticGovernance.json +155 -0
  19. package/dist/abi/AgreementRegistry.json +203 -5
  20. package/dist/abi/AllowedMethodsEnforcer.json +193 -0
  21. package/dist/abi/AllowedTargetsEnforcer.json +193 -0
  22. package/dist/abi/ApprovedHashRegistry.json +267 -2
  23. package/dist/abi/AttestationRegistry.json +242 -0
  24. package/dist/abi/AttributeStorage.json +24 -0
  25. package/dist/abi/CallDataHashEnforcer.json +193 -0
  26. package/dist/abi/CustodyPolicy.json +422 -55
  27. package/dist/abi/DelegationManager.json +292 -0
  28. package/dist/abi/DigestBindingEnforcer.json +541 -0
  29. package/dist/abi/Eip7702.json +13 -0
  30. package/dist/abi/EstateProjectionRegistry.json +599 -0
  31. package/dist/abi/Generation5Bridge.json +355 -0
  32. package/dist/abi/GeoFeatureRegistry.json +235 -0
  33. package/dist/abi/IAgentAccountFactoryView.json +26 -0
  34. package/dist/abi/IAgentAccountGovernanceTimelockView.json +15 -0
  35. package/dist/abi/IApprovedHashRegistryWrite.json +35 -0
  36. package/dist/abi/ICustodyEpochView.json +28 -0
  37. package/dist/abi/ICustodyPolicyAccountModuleView.json +31 -0
  38. package/dist/abi/ICustodyPolicyFactoryView.json +13 -0
  39. package/dist/abi/ICustodyPolicyPasskeyView.json +50 -0
  40. package/dist/abi/IDelegationManager.json +18 -0
  41. package/dist/abi/IGeneration4Reads.json +143 -0
  42. package/dist/abi/IGeneration5Account.json +33 -0
  43. package/dist/abi/IGeneration5Voucher.json +26 -0
  44. package/dist/abi/IMoveAccountView.json +57 -0
  45. package/dist/abi/IMoveCustodyView.json +169 -0
  46. package/dist/abi/IMoveFactoryView.json +41 -0
  47. package/dist/abi/IPaymentReceiptRegistry.json +50 -0
  48. package/dist/abi/IRedemptionContext.json +15 -0
  49. package/dist/abi/IRegistryMembershipPolicy.json +70 -0
  50. package/dist/abi/ITimelockVeto.json +93 -0
  51. package/dist/abi/ITreasurySpendPolicyAccountView.json +44 -0
  52. package/dist/abi/IUpgradeVoucherView.json +26 -0
  53. package/dist/abi/MockUSDC.json +621 -0
  54. package/dist/abi/OntologyTermRegistry.json +268 -0
  55. package/dist/abi/PayloadClassesEnforcer.json +310 -0
  56. package/dist/abi/PaymentEnforcer.json +639 -0
  57. package/dist/abi/PaymentEscrow.json +501 -0
  58. package/dist/abi/PaymentReceiptRegistry.json +388 -0
  59. package/dist/abi/PermissionlessSubregistry.json +353 -0
  60. package/dist/abi/PricedSubregistry.json +1141 -0
  61. package/dist/abi/QuorumEnforcer.json +209 -0
  62. package/dist/abi/ReceiptAnchorRegistry.json +346 -0
  63. package/dist/abi/RelationshipTypeRegistry.json +268 -0
  64. package/dist/abi/ShapeRegistry.json +268 -0
  65. package/dist/abi/SignatureVerifier.json +196 -0
  66. package/dist/abi/SkillDefinitionRegistry.json +235 -0
  67. package/dist/abi/SmartAgentPaymaster.json +445 -1
  68. package/dist/abi/StableProxyGoverned.json +190 -0
  69. package/dist/abi/StableProxyGovernedOneShot.json +172 -0
  70. package/dist/abi/TimestampEnforcer.json +193 -0
  71. package/dist/abi/TreasurySpendPolicy.json +667 -0
  72. package/dist/abi/UpgradeVoucher.json +328 -0
  73. package/dist/abi/ValueEnforcer.json +193 -0
  74. package/dist/abi/index.d.ts +35 -0
  75. package/dist/abi/index.js +35 -0
  76. package/dist/deployments/base-sepolia.d.ts +11 -0
  77. package/dist/deployments/base-sepolia.js +51 -28
  78. package/dist/deployments/faithchain.d.ts +77 -0
  79. package/dist/deployments/faithchain.js +107 -0
  80. package/dist/deployments/hopechain.d.ts +68 -0
  81. package/dist/deployments/hopechain.js +82 -0
  82. package/dist/deployments/index.d.ts +7 -2
  83. package/dist/deployments/index.js +15 -0
  84. package/dist/deployments/paymaster-anvil.d.ts +11 -0
  85. package/dist/deployments/paymaster-anvil.js +9 -0
  86. package/dist/deployments/registries-base-sepolia.d.ts +10 -0
  87. package/dist/deployments/registries-base-sepolia.js +8 -0
  88. package/dist/deployments/registries-hopechain.d.ts +10 -0
  89. package/dist/deployments/registries-hopechain.js +8 -0
  90. package/package.json +37 -7
  91. package/src/AccountBootstrap.sol +38 -0
  92. package/src/AgentAccount.sol +1091 -134
  93. package/src/AgentAccountFactory.sol +198 -21
  94. package/src/ApprovedHashRegistry.sol +134 -10
  95. package/src/IAgentAccount.sol +37 -0
  96. package/src/SmartAgentPaymaster.sol +275 -22
  97. package/src/UniversalSignatureValidator.sol +7 -0
  98. package/src/UpgradeVoucher.sol +87 -0
  99. package/src/agency/DelegationManager.sol +299 -76
  100. package/src/agency/ICaveatEnforcer.sol +10 -0
  101. package/src/agency/IDelegationManager.sol +37 -5
  102. package/src/agreement/AgreementRegistry.sol +105 -35
  103. package/src/attestation/AttestationRegistry.sol +220 -40
  104. package/src/custody/CustodyPolicy.sol +588 -70
  105. package/src/custody/TreasurySpendPolicy.sol +338 -0
  106. package/src/enforcers/AllowedMethodsEnforcer.sol +13 -2
  107. package/src/enforcers/AllowedTargetsEnforcer.sol +13 -2
  108. package/src/enforcers/CallDataHashEnforcer.sol +7 -1
  109. package/src/enforcers/DigestBindingEnforcer.sol +182 -0
  110. package/src/enforcers/PayloadClassesEnforcer.sol +36 -0
  111. package/src/enforcers/PaymentEnforcer.sol +291 -0
  112. package/src/enforcers/QuorumEnforcer.sol +24 -3
  113. package/src/enforcers/TimestampEnforcer.sol +7 -1
  114. package/src/enforcers/ValueEnforcer.sol +13 -2
  115. package/src/geo/GeoFeatureRegistry.sol +67 -22
  116. package/src/governance/AgenticGovernance.sol +187 -4
  117. package/src/governance/GovernanceManaged.sol +2 -0
  118. package/src/governance/StableProxyGoverned.sol +79 -0
  119. package/src/governance/StableProxyGovernedOneShot.sol +93 -0
  120. package/src/identity/AgentProfilePredicates.sol +23 -0
  121. package/src/identity/AgentProfileResolver.sol +22 -2
  122. package/src/libraries/Eip7702.sol +36 -0
  123. package/src/libraries/SignatureSlotRecovery.sol +28 -7
  124. package/src/libraries/SignatureVerifier.sol +52 -0
  125. package/src/libraries/WebAuthnLib.sol +16 -0
  126. package/src/migration/Generation5Bridge.sol +364 -0
  127. package/src/mocks/MockUSDC.sol +152 -0
  128. package/src/naming/AgentNameAttributeResolver.sol +29 -4
  129. package/src/naming/AgentNamePredicates.sol +89 -0
  130. package/src/naming/AgentNameRegistry.sol +324 -20
  131. package/src/naming/AgentNameUniversalResolver.sol +35 -2
  132. package/src/naming/PermissionlessSubregistry.sol +82 -25
  133. package/src/naming/PricedSubregistry.sol +293 -0
  134. package/src/ontology/AttributeStorage.sol +93 -80
  135. package/src/ontology/OntologyTermRegistry.sol +58 -2
  136. package/src/ontology/ShapeRegistry.sol +58 -2
  137. package/src/payments/PaymentEscrow.sol +187 -0
  138. package/src/payments/PaymentReceiptRegistry.sol +100 -0
  139. package/src/provenance/ReceiptAnchorRegistry.sol +67 -0
  140. package/src/registry/AgentRegistryBase.sol +372 -0
  141. package/src/registry/EstateProjectionRegistry.sol +177 -0
  142. package/src/registry/IRegistryMembershipPolicy.sol +30 -0
  143. package/src/relationships/AgentRelationship.sol +129 -8
  144. package/src/relationships/RelationshipTypeRegistry.sol +58 -2
  145. package/src/skills/SkillDefinitionRegistry.sol +61 -17
@@ -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,13 +73,47 @@ 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.
83
+ * 3. PM-2 — hand the Ownable owner to the governance TimelockController via
84
+ * `Ownable2Step` (`transferOwnership(governance)` then a timelocked
85
+ * `acceptOwnership`) once deploy-time staking/funding is done. The owner
86
+ * controls the INHERITED instant `withdrawTo`/stake drains; in production
87
+ * it MUST be the timelock, not the bootstrap deployer EOA. The
88
+ * governance-native, TIMELOCKED `scheduleDepositWithdrawal` /
89
+ * `executeDepositWithdrawal` path below is the sanctioned drain that stays
90
+ * coupled to governance + delayed regardless of the owner handoff state.
91
+ * The deployer-owned window is bootstrap-only (tracked under the
92
+ * governance-key custody item).
93
+ * 4. PM-1 — after governance pauses, call `syncPauseFromGovernance()` (or
94
+ * `setPauseMirror(true)` from governance) so the validation-time mirror
95
+ * halts sponsorship. Validation never reads governance storage directly
96
+ * (ERC-7562), so the mirror must be pushed/synced.
74
97
  *
75
98
  * @dev Inherits `addStake`, `unlockStake`, `withdrawStake`, `deposit`,
76
99
  * and `withdrawTo` from `BasePaymaster`. Ownable owner is set in
77
100
  * the constructor (Ownable2Step pattern).
78
101
  */
79
- contract SmartAgentPaymaster is BasePaymaster {
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 {
80
117
  using ECDSA for bytes32;
81
118
  using MessageHashUtils for bytes32;
82
119
 
@@ -91,23 +128,86 @@ contract SmartAgentPaymaster is BasePaymaster {
91
128
  /// the production check). Set via governance.
92
129
  address public verifyingSigner;
93
130
 
94
- /// @notice The Governance contract whose pause flag halts paymaster
95
- /// validation. Stored immutable.
96
- address public immutable governance;
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;
136
+
137
+ /// @notice PM-1 — local mirror of the governance pause flag. This is the
138
+ /// ONLY pause signal read during ERC-4337 validation. Reading the
139
+ /// external governance contract's storage inside
140
+ /// `_validatePaymasterUserOp` violates the ERC-7562 validation-scope
141
+ /// rules (a paymaster may touch only its own / associated storage),
142
+ /// so reputable bundlers (Pimlico/Stackup/Alchemy) drop the sponsored
143
+ /// op during simulation. We read this own-storage mirror instead;
144
+ /// `syncPauseFromGovernance()` — a normal call OUTSIDE validation —
145
+ /// refreshes it from the canonical governance flag. The mirror is a
146
+ /// validation-time cache of governance's pause bit, never a second
147
+ /// independent source (ADR-0013: cache-of-canonical, no fallback).
148
+ bool private _pausedMirror;
149
+
150
+ /// @notice Audit DLG-13 — governance's own EXPLICIT pause push (`setPauseMirror`), kept apart
151
+ /// from the mirrored flag so the permissionless `syncPauseFromGovernance()` cannot
152
+ /// undo it. Before generation 4 anyone could call sync while governance's global flag
153
+ /// was clear and overwrite a pushed `true` with `false`, re-opening sponsorship that
154
+ /// governance had deliberately halted for this paymaster alone. The validation-time
155
+ /// read is still the single own-storage `_pausedMirror` (ERC-7562); this flag only
156
+ /// feeds what sync writes into it. Packs into the same slot as `_pausedMirror`.
157
+ bool private _pausePushed;
158
+
159
+ /// @notice PM-2 — a scheduled, governance-authorized EntryPoint-deposit
160
+ /// withdrawal. The inherited owner `withdrawTo` is an INSTANT drain
161
+ /// gated only by the Ownable owner; this path couples a withdrawal to
162
+ /// governance (`onlyGovernance`) AND a fixed timelock, so the
163
+ /// sponsorship treasury cannot be emptied in a single transaction.
164
+ struct PendingWithdrawal {
165
+ address payable to;
166
+ uint64 eta;
167
+ uint256 amount;
168
+ }
169
+ PendingWithdrawal private _pendingWithdrawal;
170
+
171
+ /// @notice PM-2 — delay between scheduling and executing a governance
172
+ /// deposit withdrawal. Gives the guardian a window to pause if a
173
+ /// withdrawal is unexpected (incident response).
174
+ uint64 public constant DEPOSIT_WITHDRAWAL_TIMELOCK = 48 hours;
97
175
 
98
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);
99
179
  error SystemPaused();
100
180
  error ZeroGovernance();
101
181
  error NotGovernance();
102
182
  error PaymasterDataMalformed();
103
183
  error PaymasterSignatureInvalid();
184
+ /// @dev PM-2 withdrawal-lifecycle errors.
185
+ error NoPendingWithdrawal();
186
+ error WithdrawalNotReady(uint64 eta);
187
+ error WithdrawalAmountZero();
188
+ error WithdrawalToZero();
104
189
 
190
+ event GovernanceSet(address indexed governance);
105
191
  event DevModeSet(bool dev);
106
192
  event SenderAcceptedSet(address indexed sender, bool accepted);
193
+ event AllowlistMaxCostPerOpSet(uint256 ceilingWei);
107
194
  event VerifyingSignerSet(address indexed oldSigner, address indexed newSigner);
195
+ /// @notice PM-1 — emitted whenever the local pause mirror is updated.
196
+ event PauseMirrorSynced(bool paused, address indexed by);
197
+ /// @notice PM-2 — deposit-withdrawal lifecycle.
198
+ event DepositWithdrawalScheduled(address indexed to, uint256 amount, uint64 eta);
199
+ event DepositWithdrawalExecuted(address indexed to, uint256 amount);
200
+ event DepositWithdrawalCancelled(address indexed to, uint256 amount);
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;
108
206
 
109
207
  /// @dev Storage gap reserves slots for future state. Phase A.5 §3.1.
110
- uint256[49] private __gap;
208
+ /// PM-1/PM-2 consumed 3 slots (`_pausedMirror` packs into 1;
209
+ /// `PendingWithdrawal` is 2) — gap reduced 49 → 46; `allowlistMaxCostPerOp` took the first gap slot → 45.
210
+ uint256[45] private __gap;
111
211
 
112
212
  /// @dev Length of the paymaster-data tail when in verifying mode:
113
213
  /// 6 (validUntil) + 6 (validAfter) + 65 (sig) = 77 bytes.
@@ -115,6 +215,8 @@ contract SmartAgentPaymaster is BasePaymaster {
115
215
  /// @dev Offset in `paymasterAndData` where the post-prefix payload
116
216
  /// begins: 20 (paymaster addr) + 16 (verifGas) + 16 (postOpGas).
117
217
  uint256 private constant PM_DATA_OFFSET = 52;
218
+ /// @dev Offset of the two packed uint128 paymaster gas limits (after the paymaster address).
219
+ uint256 private constant PM_GAS_LIMITS_OFFSET = 20;
118
220
 
119
221
  /// @param devMode_ true → accept-all (dev/anvil); false → require
120
222
  /// verifying-signer or allowlist. R5.7 removed
@@ -129,9 +231,46 @@ contract SmartAgentPaymaster is BasePaymaster {
129
231
  address governance_,
130
232
  bool devMode_,
131
233
  address verifyingSigner_
132
- ) 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 {
133
261
  if (governance_ == address(0)) revert ZeroGovernance();
134
- governance = governance_;
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_);
135
274
  _dev = devMode_;
136
275
  emit DevModeSet(devMode_);
137
276
  if (verifyingSigner_ != address(0)) {
@@ -143,7 +282,8 @@ contract SmartAgentPaymaster is BasePaymaster {
143
282
  // ─── Admin (governance-only) ────────────────────────────────────────
144
283
 
145
284
  modifier onlyGovernance() {
146
- if (msg.sender != governance) revert NotGovernance();
285
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
286
+ if (msg.sender != governance()) revert NotGovernance();
147
287
  _;
148
288
  }
149
289
 
@@ -157,6 +297,12 @@ contract SmartAgentPaymaster is BasePaymaster {
157
297
  emit SenderAcceptedSet(sender, accepted);
158
298
  }
159
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
+
160
306
  function setAcceptedBatch(address[] calldata senders, bool accepted) external onlyGovernance {
161
307
  for (uint256 i = 0; i < senders.length; i++) {
162
308
  _acceptList[senders[i]] = accepted;
@@ -173,6 +319,99 @@ contract SmartAgentPaymaster is BasePaymaster {
173
319
  emit VerifyingSignerSet(old, newSigner);
174
320
  }
175
321
 
322
+ // ─── PM-1: pause mirror (own-storage, ERC-7562-compliant) ──────────
323
+
324
+ /// @notice PM-1 — refresh the local pause mirror from the canonical
325
+ /// governance flag. Permissionless ON PURPOSE: validation may not
326
+ /// read governance storage, so the mirror must be refreshable by
327
+ /// anyone (a keeper, a bundler, the guardian's incident response)
328
+ /// the moment governance pauses. This call is a NORMAL transaction
329
+ /// (not paymaster validation), so the ERC-7562 scope rules don't
330
+ /// apply to its cross-contract read. The mirror only ever holds the
331
+ /// canonical governance value — no independent pause source.
332
+ /// DLG-13: a pause governance pushed with `setPauseMirror(true)` survives a
333
+ /// sync — the mirror is `pushed OR governance.isPaused()`; only governance clears its push.
334
+ function syncPauseFromGovernance() external {
335
+ bool p = _pausePushed || _governanceIsPaused();
336
+ _pausedMirror = p;
337
+ emit PauseMirrorSynced(p, msg.sender);
338
+ }
339
+
340
+ /// @notice PM-1 — direct governance push of the pause mirror, for when
341
+ /// governance wants to halt sponsorship without depending on a
342
+ /// third party to sync. `onlyGovernance` ⇒ inherits the 24h
343
+ /// timelock (or guardian-driven governance flow).
344
+ function setPauseMirror(bool paused_) external onlyGovernance {
345
+ _pausePushed = paused_;
346
+ _pausedMirror = paused_;
347
+ emit PauseMirrorSynced(paused_, msg.sender);
348
+ }
349
+
350
+ /// @notice The pause bit read during validation (the local mirror).
351
+ function paused() external view returns (bool) {
352
+ return _pausedMirror;
353
+ }
354
+
355
+ /// @dev Read the canonical governance pause flag. Used ONLY by the out-of-band sync path, never
356
+ /// during validation (ERC-7562 scope). L1 (seam audit): distinguish "no governance configured"
357
+ /// (legacy / test deploy — not paused, by design) from "governance IS configured but the read
358
+ /// faulted / returned malformed data" (a governance outage or non-conforming contract), which now
359
+ /// FAILS CLOSED — treat as paused so a sync during a governance fault halts sponsorship rather
360
+ /// than fail-open sponsoring. Only a clean, decodable `false` permits sponsorship.
361
+ function _governanceIsPaused() internal view returns (bool) {
362
+ // Unconfigured governance (unset, or an EOA with no code) → not paused (legacy/test path).
363
+ address gov = governance();
364
+ if (gov == address(0) || gov.code.length == 0) return false;
365
+ (bool ok, bytes memory data) = gov.staticcall(
366
+ abi.encodeWithSelector(IGovernanceView.isPaused.selector)
367
+ );
368
+ // Configured but faulted (call failed or undecodable) → fail closed (paused).
369
+ if (!ok || data.length < 32) return true;
370
+ return abi.decode(data, (bool));
371
+ }
372
+
373
+ // ─── PM-2: governance-timelocked deposit withdrawal ────────────────
374
+
375
+ /// @notice PM-2 — schedule a governance-authorized withdrawal of the
376
+ /// EntryPoint deposit. Coupled to governance AND delayed by
377
+ /// `DEPOSIT_WITHDRAWAL_TIMELOCK`, unlike the inherited owner
378
+ /// `withdrawTo` (instant, owner-only). Overwrites any prior pending
379
+ /// withdrawal (governance is the single scheduler).
380
+ function scheduleDepositWithdrawal(address payable to, uint256 amount) external onlyGovernance {
381
+ if (to == address(0)) revert WithdrawalToZero();
382
+ if (amount == 0) revert WithdrawalAmountZero();
383
+ uint64 eta = uint64(block.timestamp) + DEPOSIT_WITHDRAWAL_TIMELOCK;
384
+ _pendingWithdrawal = PendingWithdrawal({to: to, eta: eta, amount: amount});
385
+ emit DepositWithdrawalScheduled(to, amount, eta);
386
+ }
387
+
388
+ /// @notice PM-2 — execute a previously-scheduled withdrawal once its
389
+ /// timelock has elapsed. `onlyGovernance` so the same authority
390
+ /// that scheduled it confirms; the delay gives the guardian time to
391
+ /// pause if the withdrawal is unexpected.
392
+ function executeDepositWithdrawal() external onlyGovernance {
393
+ PendingWithdrawal memory w = _pendingWithdrawal;
394
+ if (w.eta == 0) revert NoPendingWithdrawal();
395
+ if (block.timestamp < w.eta) revert WithdrawalNotReady(w.eta);
396
+ delete _pendingWithdrawal;
397
+ entryPoint().withdrawTo(w.to, w.amount);
398
+ emit DepositWithdrawalExecuted(w.to, w.amount);
399
+ }
400
+
401
+ /// @notice PM-2 — cancel a pending withdrawal (governance de-escalation).
402
+ function cancelDepositWithdrawal() external onlyGovernance {
403
+ PendingWithdrawal memory w = _pendingWithdrawal;
404
+ if (w.eta == 0) revert NoPendingWithdrawal();
405
+ delete _pendingWithdrawal;
406
+ emit DepositWithdrawalCancelled(w.to, w.amount);
407
+ }
408
+
409
+ /// @notice PM-2 — view the pending withdrawal (zero `eta` ⇒ none).
410
+ function pendingWithdrawal() external view returns (address to, uint256 amount, uint64 eta) {
411
+ PendingWithdrawal memory w = _pendingWithdrawal;
412
+ return (w.to, w.amount, w.eta);
413
+ }
414
+
176
415
  // ─── Views ──────────────────────────────────────────────────────────
177
416
 
178
417
  function devMode() external view returns (bool) {
@@ -187,10 +426,19 @@ contract SmartAgentPaymaster is BasePaymaster {
187
426
  /// Off-chain callers compute the same hash + sign via
188
427
  /// EIP-191 ("\x19Ethereum Signed Message:\n32" prefix);
189
428
  /// on-chain validation recovers via that wrapper.
190
- /// @dev Deliberately omits paymasterAndData (the signature lives
191
- /// there) and the userOp.signature (the account signs
429
+ /// @dev Omits the paymaster-data TAIL (validity window is passed in; the
430
+ /// signature lives there) and the userOp.signature (the account signs
192
431
  /// independently). Includes chainId + paymaster address for
193
432
  /// replay protection across chains + deployments.
433
+ ///
434
+ /// Spec 445 / audit DLG-4: the hash BINDS the paymaster gas limits —
435
+ /// `paymasterAndData[20:52]` = `paymasterVerificationGasLimit (uint128) ‖
436
+ /// paymasterPostOpGasLimit (uint128)`, as the reference VerifyingPaymaster
437
+ /// does. Before generation 4 they were unsigned, so a sponsored sender could
438
+ /// raise both after the sponsor signed, inflating the prefund reserved
439
+ /// against the deposit (and the post-op unused-gas penalty the day this
440
+ /// paymaster returns a context). A `paymasterAndData` shorter than the
441
+ /// 52-byte static prefix reverts `PaymasterDataMalformed`.
194
442
  function getHash(
195
443
  PackedUserOperation calldata userOp,
196
444
  uint48 validUntil,
@@ -203,6 +451,9 @@ contract SmartAgentPaymaster is BasePaymaster {
203
451
  // current EntryPoint would have been verifiable against a NEW
204
452
  // EntryPoint deployed at a different address, allowing cross-deployment
205
453
  // replay until validUntil elapses.
454
+ if (userOp.paymasterAndData.length < PM_DATA_OFFSET) revert PaymasterDataMalformed();
455
+ // DLG-4: verificationGasLimit ‖ postOpGasLimit, exactly as they sit in the userOp.
456
+ bytes32 paymasterGasLimits = bytes32(userOp.paymasterAndData[PM_GAS_LIMITS_OFFSET:PM_DATA_OFFSET]);
206
457
  return keccak256(
207
458
  abi.encode(
208
459
  userOp.sender,
@@ -210,6 +461,7 @@ contract SmartAgentPaymaster is BasePaymaster {
210
461
  keccak256(userOp.initCode),
211
462
  keccak256(userOp.callData),
212
463
  userOp.accountGasLimits,
464
+ paymasterGasLimits, // DLG-4 binding
213
465
  userOp.preVerificationGas,
214
466
  userOp.gasFees,
215
467
  block.chainid,
@@ -227,19 +479,15 @@ contract SmartAgentPaymaster is BasePaymaster {
227
479
  function _validatePaymasterUserOp(
228
480
  PackedUserOperation calldata userOp,
229
481
  bytes32 /*userOpHash*/,
230
- uint256 /*maxCost*/
482
+ uint256 maxCost
231
483
  ) internal view override returns (bytes memory context, uint256 validationData) {
232
- // H7-C.10 / EXT3-010: gated behind system-wide governance pause.
233
- // Skipped when `governance` is an EOA or non-conforming contract
234
- // (legacy / test deploys); production deploys MUST pass an
235
- // AgenticGovernance address, which the production-deploy preflight
236
- // (`check:production-deploy`) enforces.
237
- if (governance.code.length > 0) {
238
- (bool ok, bytes memory data) = governance.staticcall(
239
- abi.encodeWithSelector(IGovernanceView.isPaused.selector)
240
- );
241
- if (ok && data.length >= 32 && abi.decode(data, (bool))) revert SystemPaused();
242
- }
484
+ // PM-1 / H7-C.10 / EXT3-010: gated behind the system-wide governance
485
+ // pause — but read from the LOCAL mirror (`_pausedMirror`), never the
486
+ // external governance contract's storage. A cross-contract staticcall
487
+ // here violates the ERC-7562 validation-scope rules and gets the op
488
+ // dropped by bundlers. The mirror is refreshed out-of-band via
489
+ // `syncPauseFromGovernance()` (a normal call) or `setPauseMirror()`.
490
+ if (_pausedMirror) revert SystemPaused();
243
491
 
244
492
  if (_dev) {
245
493
  // Dev mode: accept all. validationData = 0 → "valid sig,
@@ -278,6 +526,11 @@ contract SmartAgentPaymaster is BasePaymaster {
278
526
 
279
527
  // Fallback: allowlist mode.
280
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);
281
534
  return ("", 0);
282
535
  }
283
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;
@@ -0,0 +1,87 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+
4
+ import "./governance/StableProxyGoverned.sol";
5
+
6
+ /**
7
+ * @title UpgradeVoucher — which implementations, with which migration data, an AgentAccount may upgrade to
8
+ * @notice Spec 445 §1.3 (i), audit 2026-11-10 H-2 / ACCT-1. `upgradeToAndCall(newImplementation, data)` delegatecalls
9
+ * `data` on `newImplementation` in the account's own storage. On a self-governed (mode-0) account one
10
+ * credential could therefore run arbitrary code as the account — plant an approved hash for a future
11
+ * custody epoch, write a custodian with no event — and none of it can be detected or undone afterwards.
12
+ * The only way to prevent that is to constrain what may be upgraded to. An `AgentAccount`
13
+ * implementation carries the address of ONE voucher as an immutable and refuses every upgrade — a
14
+ * person's own, a custody quorum's `ApplySystemUpdate`, a matured queued upgrade — unless
15
+ * `isVouched(newImplementation, keccak256(data))` is true here at the moment the upgrade executes.
16
+ *
17
+ * WHO VOUCHES. Governance only (`onlyGovernance` — the `AgenticGovernance` contract, which forwards
18
+ * nothing but calls its timelock executed). No guardian fast path, no signer path, no setter for the
19
+ * governance pointer, no upgradeability: to change who vouches, a new voucher is deployed and a new
20
+ * account implementation is built around it — and reaching that implementation is itself an upgrade
21
+ * this voucher must vouch for.
22
+ *
23
+ * WHAT IS VOUCHED. The pair `(implementation, dataHash)`. `dataHash` is `keccak256(data)` of the exact
24
+ * migration calldata; a plain upgrade (no migration call) is `keccak256("")` =
25
+ * `0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470`. Vouching an implementation for
26
+ * a plain upgrade does not vouch it for any migration call, and the reverse.
27
+ *
28
+ * WHAT GOVERNANCE MUST NOT VOUCH. An implementation that does not itself carry a voucher (any
29
+ * generation ≤ 3 `AgentAccount`, or foreign code): an account that upgrades to it leaves this rule
30
+ * behind for good — its next upgrade is checked by nobody. And migration data is CODE RUN AS EVERY
31
+ * ACCOUNT THAT USES IT: vouch only for a call whose every effect on account storage was reviewed.
32
+ *
33
+ * WHAT IT IS NOT. An authorization to upgrade any particular account — every account-side gate
34
+ * (`onlySelf`, the per-account timelock, the custody quorum) still applies. A voucher answers "is this
35
+ * code one the estate's governance reviewed?", never "may this caller upgrade?".
36
+ *
37
+ * WHY IT TRAVELS WITH THE IMPLEMENTATION AND NOT THE FACTORY. An account's factory pointer is set once
38
+ * at initialization and has no setter; an account upgraded in place still names its original factory.
39
+ * A vouching view on a new factory would never be consulted by an existing account.
40
+ */
41
+ contract UpgradeVoucher is StableProxyGoverned {
42
+ /// @notice `keccak256("")` — the `dataHash` of a plain upgrade (no migration call).
43
+ bytes32 public constant PLAIN_UPGRADE = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
44
+
45
+ /// implementation => keccak256(migration data) => vouched
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;
49
+
50
+ event UpgradeVouched(address indexed implementation, bytes32 indexed dataHash);
51
+ event UpgradeUnvouched(address indexed implementation, bytes32 indexed dataHash);
52
+
53
+ /// @dev Vouching for an address with no code would vouch for whatever is later deployed there.
54
+ error ImplementationHasNoCode(address implementation);
55
+
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
+ }
68
+
69
+ /// @notice Vouch for upgrading to `implementation` with migration data hashing to `dataHash`.
70
+ function vouch(address implementation, bytes32 dataHash) external onlyGovernance {
71
+ if (implementation.code.length == 0) revert ImplementationHasNoCode(implementation);
72
+ _vouched[implementation][dataHash] = true;
73
+ emit UpgradeVouched(implementation, dataHash);
74
+ }
75
+
76
+ /// @notice Withdraw a vouch. An upgrade that has not executed yet (including a queued one) is refused
77
+ /// from this transaction on; an account already running `implementation` is not affected.
78
+ function unvouch(address implementation, bytes32 dataHash) external onlyGovernance {
79
+ _vouched[implementation][dataHash] = false;
80
+ emit UpgradeUnvouched(implementation, dataHash);
81
+ }
82
+
83
+ /// @notice The one read an account makes before it upgrades.
84
+ function isVouched(address implementation, bytes32 dataHash) external view returns (bool) {
85
+ return _vouched[implementation][dataHash];
86
+ }
87
+ }