@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,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
@@ -33,7 +34,58 @@ import "./IGovernance.sol";
33
34
  * with a long-lived multisig (an `AgentAccount` deployed by
34
35
  * the factory whose `CustodyPolicy` requires M-of-N signers).
35
36
  * Deployer then renounces the timelock admin role and is gone.
37
+ *
38
+ * A PAUSE IS ALWAYS LIFTABLE BY THOSE ACCOUNTS (spec 445 §1.2, audit 2026-11-10 H-3 / CUST-1).
39
+ * `unpause()` needs the timelock; the timelock needs its proposer and executor to call it; and when
40
+ * those are `AgentAccount`s of the very factory this contract pauses, every outbound call they make
41
+ * is pause-gated. Generation 4 therefore exempts, in `AgentAccount.execute` (the single call only —
42
+ * not `executeBatch`, not `executeFromModule`), a validated user operation whose target is THIS
43
+ * contract or its `timelock`. Both addresses are read from the factory's immutable governance
44
+ * pointer and this contract's immutable `timelock`; nothing an account can write selects them. The
45
+ * exemption grants nothing here: `NotTimelock` / `NotGuardian` and the timelock's own roles still
46
+ * decide. Operational consequences to plan for: (1) the paymaster refuses to sponsor under a pause,
47
+ * so a role-holding account must be able to pay its own gas (an EntryPoint deposit or a native
48
+ * balance); (2) `AgentAccount.execute` validates ONE custodian signature on every custody mode — an
49
+ * account's M-of-N governs its custody changes, not its outbound calls — so a timelock role held by
50
+ * an AgentAccount is exercised by any one of its credentials. `Deploy.s.sol` proves the lift for the
51
+ * roles it installs (`_assertPauseLiftable`); `test/governance/PauseIsLiftable445.t.sol` proves it
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).
36
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
+
37
89
  contract AgenticGovernance is IGovernanceView {
38
90
  // ─── Immutables ───────────────────────────────────────────────
39
91
 
@@ -42,21 +94,34 @@ contract AgenticGovernance is IGovernanceView {
42
94
  /// construction; rotate by redeploying.
43
95
  address public immutable timelock;
44
96
 
45
- /// @notice Fast-path emergency-pauser role. Can pause without delay
46
- /// but CANNOT unpause (unpause requires the timelock).
47
- address public immutable guardian;
48
-
49
97
  // ─── State ────────────────────────────────────────────────────
50
98
 
51
99
  bool private _paused;
52
100
  mapping(address => bool) private _signers;
53
101
 
102
+ /// @notice Fast-path emergency-pauser role. Can pause without delay but
103
+ /// CANNOT unpause (unpause requires the timelock). GOV-1: this is a
104
+ /// STORAGE var (not immutable) so the timelock can ROTATE it — a
105
+ /// guardian whose key is compromised and grief-pauses the system can
106
+ /// be replaced WITHOUT a full governance redeploy, bounding the
107
+ /// re-pause DoS to one timelock window instead of "permanent". Set
108
+ /// (`setGuardian`) only by the timelock. Declared after the existing
109
+ /// storage vars so their slot assignments don't shift.
110
+ address public guardian;
111
+
54
112
  // ─── Errors ───────────────────────────────────────────────────
55
113
 
56
114
  error NotTimelock(address caller);
57
115
  error NotGuardian(address caller);
58
116
  error ExecuteFailed(address target, bytes returndata);
59
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();
60
125
 
61
126
  // ─── Events ───────────────────────────────────────────────────
62
127
 
@@ -64,6 +129,10 @@ contract AgenticGovernance is IGovernanceView {
64
129
  event Unpaused(address indexed by);
65
130
  event SignerSet(address indexed who, bool isSigner);
66
131
  event Executed(address indexed target, uint256 value, bytes data);
132
+ /// @notice GOV-1 — the guardian (fast-pause) role was rotated by the timelock.
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);
67
136
 
68
137
  // ─── Constructor ──────────────────────────────────────────────
69
138
 
@@ -95,6 +164,7 @@ contract AgenticGovernance is IGovernanceView {
95
164
 
96
165
  /// @notice Emergency pause. Callable by the guardian without delay.
97
166
  function pause() external {
167
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
98
168
  if (msg.sender != guardian) revert NotGuardian(msg.sender);
99
169
  _paused = true;
100
170
  emit Paused(msg.sender);
@@ -103,6 +173,7 @@ contract AgenticGovernance is IGovernanceView {
103
173
  /// @notice Unpause. Requires the timelock (a deliberate 24h
104
174
  /// decision); guardian alone cannot unpause.
105
175
  function unpause() external {
176
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
106
177
  if (msg.sender != timelock) revert NotTimelock(msg.sender);
107
178
  _paused = false;
108
179
  emit Unpaused(msg.sender);
@@ -119,9 +190,15 @@ contract AgenticGovernance is IGovernanceView {
119
190
  payable
120
191
  returns (bytes memory)
121
192
  {
193
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
122
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);
123
199
  (bool ok, bytes memory result) = target.call{value: value}(data);
124
200
  if (!ok) revert ExecuteFailed(target, result);
201
+ if (upgrade && _systemWiring(target) != wiringBefore) revert UpgradeChangesSystemWiring(target); // audit C5-6
125
202
  emit Executed(target, value, data);
126
203
  return result;
127
204
  }
@@ -129,11 +206,117 @@ contract AgenticGovernance is IGovernanceView {
129
206
  /// @notice Add / remove a signer (consumed by `isSigner` reads from
130
207
  /// downstream `GovernanceManaged` contracts).
131
208
  function setSigner(address who, bool sig) external {
209
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
132
210
  if (msg.sender != timelock) revert NotTimelock(msg.sender);
133
211
  _signers[who] = sig;
134
212
  emit SignerSet(who, sig);
135
213
  }
136
214
 
215
+ /// @notice GOV-1 — rotate the guardian (fast-pause) role. Timelock-only, so a
216
+ /// compromised guardian that is perpetually re-pausing the system can
217
+ /// be replaced after one timelock window WITHOUT a governance redeploy.
218
+ /// To retire the fast-pause capability entirely, rotate to a burn
219
+ /// address. Cannot be the zero address (would make `pause()` an
220
+ /// accidental no-op while looking live).
221
+ function setGuardian(address newGuardian) external {
222
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
223
+ if (msg.sender != timelock) revert NotTimelock(msg.sender);
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
226
+ address old = guardian;
227
+ guardian = newGuardian;
228
+ emit GuardianRotated(old, newGuardian);
229
+ }
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
+
137
320
  // ─── Receive ETH ──────────────────────────────────────────────
138
321
 
139
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
+ }
@@ -0,0 +1,93 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+
4
+ import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
5
+ import {Eip7702} from "../libraries/Eip7702.sol";
6
+
7
+ /**
8
+ * @title StableProxyGovernedOneShot
9
+ * @notice Spec 447 — {StableProxyGoverned} for a contract that cannot inherit OpenZeppelin's `Initializable`.
10
+ * `AgentNameRegistry` publishes an `initializer()` role getter (the root initializer, spec 445), and that
11
+ * name collides with `Initializable`'s `initializer` modifier; renaming the getter would break every
12
+ * client of the published ABI.
13
+ *
14
+ * Same upgrade authority as {StableProxyGoverned}, in the SAME ERC-7201 slot
15
+ * (`agenticprimitives.stable-proxy-governed.v1`), with the same error/event names. Initialization is a
16
+ * one-shot guard, `_initOnce()`, kept in `Initializable`'s own ERC-7201 slot with its `InvalidInitialization`
17
+ * error and `Initialized` event: it leaves that slot exactly as `Initializable.initializer` would, so a later
18
+ * implementation may still run a `reinitializer(2)`.
19
+ *
20
+ * - A DIRECT deployment calls `_initOnce()` in its constructor: the implementation can never be initialized
21
+ * afterwards, and UUPS's `onlyProxy` refuses to upgrade it.
22
+ * - Behind a proxy, the inheritor's own `initialize(governance_, ...)` calls `_initOnce()`, once.
23
+ * - A contract with no governance is never upgraded.
24
+ */
25
+ abstract contract StableProxyGovernedOneShot is UUPSUpgradeable {
26
+ /// @custom:storage-location erc7201:agenticprimitives.stable-proxy-governed.v1
27
+ struct StableProxyGovernedStorage {
28
+ address governance;
29
+ }
30
+
31
+ // keccak256(abi.encode(uint256(keccak256("agenticprimitives.stable-proxy-governed.v1")) - 1)) & ~bytes32(uint256(0xff))
32
+ bytes32 private constant STABLE_PROXY_GOVERNED_SLOT =
33
+ 0x775756232dfd963ad243ed4c7335d3b32889ad6784e2c9e947c9804ba981fb00;
34
+
35
+ // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
36
+ bytes32 private constant INITIALIZABLE_STORAGE =
37
+ 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
38
+
39
+ error NotGovernance();
40
+ error UpgradeWithoutGovernance();
41
+ /// @dev Same selector as OpenZeppelin `Initializable.InvalidInitialization`.
42
+ error InvalidInitialization();
43
+
44
+ event GovernanceSet(address indexed governance);
45
+ /// @dev Same signature as OpenZeppelin `Initializable.Initialized`.
46
+ event Initialized(uint64 version);
47
+
48
+ function _stableProxyGovernedStorage() private pure returns (StableProxyGovernedStorage storage $) {
49
+ bytes32 slot = STABLE_PROXY_GOVERNED_SLOT;
50
+ assembly {
51
+ $.slot := slot
52
+ }
53
+ }
54
+
55
+ /// @notice The upgrade authority (zero = none: the code is frozen).
56
+ function governance() public view returns (address) {
57
+ return _stableProxyGovernedStorage().governance;
58
+ }
59
+
60
+ /// @dev Runs once per storage (a direct deployment's constructor, or a proxy's initializer). Writes
61
+ /// `_initialized = 1, _initializing = false` into `Initializable`'s slot.
62
+ function _initOnce() internal {
63
+ bytes32 slot = INITIALIZABLE_STORAGE;
64
+ uint256 v;
65
+ assembly {
66
+ v := sload(slot)
67
+ }
68
+ if (v != 0) revert InvalidInitialization();
69
+ assembly {
70
+ sstore(slot, 1)
71
+ }
72
+ emit Initialized(1);
73
+ }
74
+
75
+ /// @dev Records `governance_`. An inheritor that needs a non-zero governance overrides this to refuse zero.
76
+ function _initializeGovernance(address governance_) internal virtual {
77
+ _stableProxyGovernedStorage().governance = governance_;
78
+ emit GovernanceSet(governance_);
79
+ }
80
+
81
+ modifier onlyGovernance() {
82
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
83
+ if (msg.sender != governance()) revert NotGovernance();
84
+ _;
85
+ }
86
+
87
+ function _authorizeUpgrade(address) internal view override {
88
+ address gov = governance();
89
+ if (gov == address(0)) revert UpgradeWithoutGovernance();
90
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
91
+ if (msg.sender != gov) revert NotGovernance();
92
+ }
93
+ }
@@ -28,7 +28,30 @@ library AgentProfilePredicates {
28
28
  // ─── Identity-only ──────────────────────────────────────────────
29
29
 
30
30
  bytes32 internal constant ATL_DESCRIPTION = keccak256("atl:description");
31
+ /// @dev LEGACY READ ONLY (ADR-0051). Publicly-asserted labels, written before the vocabulary settled
32
+ /// on "capability" for what an agent can do. New writes go to `ATL_CAPABILITIES`; readers consult
33
+ /// this only when that is empty, which is the documented migration state — not a second mechanism
34
+ /// (ADR-0013). Kept because agents named under it are still on chain.
35
+ bytes32 internal constant ATL_SKILLS = keccak256("atl:skills");
36
+ /// ADR-0051 — the ids of what this agent CAN DO, comma-joined, same rail as the legacy labels above.
37
+ /// The SAME ids appear in `profile.capabilities[].id`, in ARD `capabilities[]`, and in the A2A card's
38
+ /// `skills[]` (the wire's name for them). Ids only: names, descriptions and examples live in the
39
+ /// profile record, because the chain is the place to prove WHICH capabilities are claimed, not to
40
+ /// store their prose. The indexer projects to approf:capabilities.
41
+ bytes32 internal constant ATL_CAPABILITIES = keccak256("atl:capabilities");
42
+ /// spec 347 §8.5 — how to OBTAIN AND RUN this agent's software: a JSON string per
43
+ /// `AgentDistributionV1` (agent-profile; JCS-canonical; mirrors the ACP registry agent.schema.json
44
+ /// `distribution` + `acp`/`version`). SA-keyed identity property, string datatype; the indexer
45
+ /// projects it to approf:distribution and registry files (ACP registry.json / ARD) are projections.
46
+ bytes32 internal constant ATL_DISTRIBUTION = keccak256("atl:distribution");
31
47
  bytes32 internal constant ATL_HOMEPAGE = keccak256("atl:homepage");
48
+ /// `atl:projectionSigner` — spec 439 F2.5: the key an ESTATE AGENT declares as the one that anchors its
49
+ /// estate's roots on neutral ground (`EstateProjectionRegistry.signerOf(estateId)`). Public ground cannot
50
+ /// verify who governs an estate on another chain, so `register` is first-come-wins; this record, written by
51
+ /// the estate agent on ITS OWN chain, is what a verifier cross-checks `signerOf` against. SA-keyed, `address`.
52
+ /// Zero = undeclared (a verifier says so); a mismatch is a refusal. Evidence, never authority.
53
+ bytes32 internal constant ATL_PROJECTION_SIGNER = keccak256("atl:projectionSigner");
54
+
32
55
  bytes32 internal constant ATL_AVATAR = keccak256("atl:avatar");
33
56
  bytes32 internal constant ATL_PROFILE_SCHEMA_URI = keccak256("atl:profileSchemaURI");
34
57
  bytes32 internal constant ATL_PROFILE_ACTIVE = keccak256("atl:profileActive");
@@ -2,7 +2,9 @@
2
2
  pragma solidity ^0.8.28;
3
3
 
4
4
  import "../ontology/AttributeStorage.sol";
5
+ import {Eip7702} from "../libraries/Eip7702.sol";
5
6
  import "./AgentProfilePredicates.sol";
7
+ import "../governance/StableProxyGoverned.sol";
6
8
 
7
9
  /**
8
10
  * @title AgentProfileResolver
@@ -31,7 +33,7 @@ import "./AgentProfilePredicates.sol";
31
33
  * - Off-chain `AgentCard` JSON is the source of truth; this
32
34
  * resolver stores the content-hash anchor + typed metadata only.
33
35
  */
34
- contract AgentProfileResolver is AttributeStorage {
36
+ contract AgentProfileResolver is AttributeStorage, StableProxyGoverned {
35
37
  address[] private _agents;
36
38
  mapping(address => bool) private _registered;
37
39
 
@@ -47,6 +49,7 @@ contract AgentProfileResolver is AttributeStorage {
47
49
  /// other principal, callers must route through their own
48
50
  /// CustodyPolicy / AgentAccount execute path.
49
51
  modifier onlyAgent(address agent) {
52
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
50
53
  if (msg.sender != agent) revert NotAgentOwner();
51
54
  _;
52
55
  }
@@ -56,7 +59,10 @@ contract AgentProfileResolver is AttributeStorage {
56
59
  _;
57
60
  }
58
61
 
59
- constructor(address ontologyRegistry) AttributeStorage(ontologyRegistry) {}
62
+ /// @notice A DIRECT deployment, with no upgrade governance (frozen code, as before). Spec 447 — behind a stable
63
+ /// proxy, `initialize(governance_)` instead. `ONTOLOGY` stays an immutable: it is the ontology
64
+ /// registry's stable proxy address, which never changes.
65
+ constructor(address ontologyRegistry) AttributeStorage(ontologyRegistry) initializer {}
60
66
 
61
67
  function _subject(address agent) internal pure returns (bytes32) {
62
68
  return bytes32(uint256(uint160(agent)));
@@ -188,7 +194,21 @@ contract AgentProfileResolver is AttributeStorage {
188
194
  return _agents;
189
195
  }
190
196
 
197
+ /// @notice REG-12 — a bounded window of the agent index: `limit` agents from `offset`.
198
+ /// `getAllAgents()` is unbounded (any agent may register) and is kept for small deployments.
199
+ function getAgentsPage(uint256 offset, uint256 limit) external view returns (address[] memory page) {
200
+ uint256 n = _agents.length;
201
+ if (offset >= n) return new address[](0);
202
+ uint256 end = offset + limit;
203
+ if (end > n) end = n;
204
+ page = new address[](end - offset);
205
+ for (uint256 i = offset; i < end; i++) page[i - offset] = _agents[i];
206
+ }
207
+
191
208
  function subjectFor(address agent) external pure returns (bytes32) {
192
209
  return bytes32(uint256(uint160(agent)));
193
210
  }
211
+
212
+ /// @dev Spec 447 — storage gap: the contract may sit behind a stable proxy; layout gated by `check:storage-layouts`.
213
+ uint256[33] private __gap;
194
214
  }
@@ -0,0 +1,36 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+
4
+ /**
5
+ * @title Eip7702
6
+ * @notice The one test for "this address is an EOA that has attached code with an EIP-7702 delegation".
7
+ *
8
+ * @dev Such an address's code is exactly the 23-byte designator `0xef0100 ‖ delegate` (EXTCODESIZE and
9
+ * EXTCODECOPY read the designator, not the delegate's code). No deployed contract can match it: EIP-3541
10
+ * refuses new code that starts with `0xef`.
11
+ *
12
+ * The rule this library serves (spec 448 §0, 2026-12-02 EIP-7702): an address whose code is a delegation
13
+ * designator is an EOA for every authority purpose — it signs by ECDSA, or it has no voice. Its attached
14
+ * code is chosen by whoever obtained one authorization signature from the key, so it is never asked
15
+ * "is this signature yours?" (ERC-1271) and is never trusted as `msg.sender` where a role is decided.
16
+ */
17
+ library Eip7702 {
18
+ /// @notice A delegated-EOA caller was refused where a role is decided by `msg.sender`.
19
+ error DelegatedEOA(address account);
20
+
21
+ /// @notice True iff `account`'s code is an EIP-7702 delegation designator.
22
+ function isDelegatedEOA(address account) internal view returns (bool delegated) {
23
+ assembly ("memory-safe") {
24
+ if eq(extcodesize(account), 23) {
25
+ // Scratch space: copy the first 3 bytes of code to memory 0 and compare the top 24 bits.
26
+ extcodecopy(account, 0, 0, 3)
27
+ delegated := eq(shr(232, mload(0)), 0xef0100)
28
+ }
29
+ }
30
+ }
31
+
32
+ /// @notice Reverts `DelegatedEOA(account)` when `account` is a delegated EOA.
33
+ function refuseDelegatedEOA(address account) internal view {
34
+ if (isDelegatedEOA(account)) revert DelegatedEOA(account);
35
+ }
36
+ }