@agenticprimitives/contracts 1.0.0-alpha.48 → 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.
Files changed (104) hide show
  1. package/AUDIT.md +36 -4
  2. package/dist/abi/AccountBootstrap.json +99 -0
  3. package/dist/abi/AgentAccount.json +95 -56
  4. package/dist/abi/AgentAccountFactory.json +189 -0
  5. package/dist/abi/AgentNameAttributeResolver.json +188 -0
  6. package/dist/abi/AgentNameRegistry.json +170 -0
  7. package/dist/abi/AgentNameUniversalResolver.json +188 -0
  8. package/dist/abi/AgentProfileResolver.json +188 -0
  9. package/dist/abi/AgentRegistryBase.json +193 -0
  10. package/dist/abi/AgentRelationship.json +193 -0
  11. package/dist/abi/AgenticGovernance.json +123 -0
  12. package/dist/abi/AgreementRegistry.json +193 -0
  13. package/dist/abi/AllowedMethodsEnforcer.json +193 -0
  14. package/dist/abi/AllowedTargetsEnforcer.json +193 -0
  15. package/dist/abi/ApprovedHashRegistry.json +220 -0
  16. package/dist/abi/AttestationRegistry.json +193 -0
  17. package/dist/abi/CallDataHashEnforcer.json +193 -0
  18. package/dist/abi/CustodyPolicy.json +195 -80
  19. package/dist/abi/DelegationManager.json +185 -0
  20. package/dist/abi/DigestBindingEnforcer.json +188 -0
  21. package/dist/abi/Eip7702.json +13 -0
  22. package/dist/abi/EstateProjectionRegistry.json +193 -0
  23. package/dist/abi/Generation5Bridge.json +355 -0
  24. package/dist/abi/GeoFeatureRegistry.json +193 -0
  25. package/dist/abi/ICustodyEpochView.json +28 -0
  26. package/dist/abi/IDelegationManager.json +18 -0
  27. package/dist/abi/IGeneration4Reads.json +143 -0
  28. package/dist/abi/IGeneration5Account.json +33 -0
  29. package/dist/abi/IGeneration5Voucher.json +26 -0
  30. package/dist/abi/IMoveAccountView.json +57 -0
  31. package/dist/abi/IMoveCustodyView.json +169 -0
  32. package/dist/abi/IMoveFactoryView.json +41 -0
  33. package/dist/abi/ITimelockVeto.json +93 -0
  34. package/dist/abi/OntologyTermRegistry.json +211 -0
  35. package/dist/abi/PayloadClassesEnforcer.json +193 -0
  36. package/dist/abi/PaymentEnforcer.json +188 -0
  37. package/dist/abi/PaymentEscrow.json +177 -0
  38. package/dist/abi/PaymentReceiptRegistry.json +206 -0
  39. package/dist/abi/PermissionlessSubregistry.json +188 -0
  40. package/dist/abi/PricedSubregistry.json +215 -0
  41. package/dist/abi/QuorumEnforcer.json +193 -0
  42. package/dist/abi/ReceiptAnchorRegistry.json +193 -0
  43. package/dist/abi/RelationshipTypeRegistry.json +211 -0
  44. package/dist/abi/ShapeRegistry.json +211 -0
  45. package/dist/abi/SignatureVerifier.json +196 -0
  46. package/dist/abi/SkillDefinitionRegistry.json +193 -0
  47. package/dist/abi/SmartAgentPaymaster.json +236 -1
  48. package/dist/abi/StableProxyGoverned.json +190 -0
  49. package/dist/abi/StableProxyGovernedOneShot.json +172 -0
  50. package/dist/abi/TimestampEnforcer.json +193 -0
  51. package/dist/abi/TreasurySpendPolicy.json +193 -0
  52. package/dist/abi/UpgradeVoucher.json +156 -4
  53. package/dist/abi/ValueEnforcer.json +193 -0
  54. package/dist/abi/index.d.ts +14 -0
  55. package/dist/abi/index.js +14 -0
  56. package/package.json +1 -1
  57. package/src/AccountBootstrap.sol +38 -0
  58. package/src/AgentAccount.sol +149 -41
  59. package/src/AgentAccountFactory.sol +52 -13
  60. package/src/ApprovedHashRegistry.sol +98 -9
  61. package/src/SmartAgentPaymaster.sol +96 -12
  62. package/src/UniversalSignatureValidator.sol +7 -0
  63. package/src/UpgradeVoucher.sol +16 -3
  64. package/src/agency/DelegationManager.sol +106 -32
  65. package/src/agency/IDelegationManager.sol +28 -0
  66. package/src/agreement/AgreementRegistry.sol +16 -15
  67. package/src/attestation/AttestationRegistry.sol +39 -16
  68. package/src/custody/CustodyPolicy.sol +36 -35
  69. package/src/custody/TreasurySpendPolicy.sol +10 -1
  70. package/src/enforcers/AllowedMethodsEnforcer.sol +7 -1
  71. package/src/enforcers/AllowedTargetsEnforcer.sol +7 -1
  72. package/src/enforcers/CallDataHashEnforcer.sol +7 -1
  73. package/src/enforcers/DigestBindingEnforcer.sol +5 -2
  74. package/src/enforcers/PayloadClassesEnforcer.sol +7 -1
  75. package/src/enforcers/PaymentEnforcer.sol +5 -2
  76. package/src/enforcers/QuorumEnforcer.sol +7 -1
  77. package/src/enforcers/TimestampEnforcer.sol +7 -1
  78. package/src/enforcers/ValueEnforcer.sol +7 -1
  79. package/src/geo/GeoFeatureRegistry.sol +15 -1
  80. package/src/governance/AgenticGovernance.sol +145 -0
  81. package/src/governance/GovernanceManaged.sol +2 -0
  82. package/src/governance/StableProxyGoverned.sol +79 -0
  83. package/src/governance/StableProxyGovernedOneShot.sol +93 -0
  84. package/src/identity/AgentProfileResolver.sol +11 -2
  85. package/src/libraries/Eip7702.sol +36 -0
  86. package/src/libraries/SignatureSlotRecovery.sol +4 -0
  87. package/src/libraries/SignatureVerifier.sol +52 -0
  88. package/src/libraries/WebAuthnLib.sol +3 -0
  89. package/src/migration/Generation5Bridge.sol +364 -0
  90. package/src/naming/AgentNameAttributeResolver.sol +12 -2
  91. package/src/naming/AgentNameRegistry.sol +84 -10
  92. package/src/naming/AgentNameUniversalResolver.sol +9 -2
  93. package/src/naming/PermissionlessSubregistry.sol +13 -2
  94. package/src/naming/PricedSubregistry.sol +59 -3
  95. package/src/ontology/OntologyTermRegistry.sol +30 -2
  96. package/src/ontology/ShapeRegistry.sol +30 -2
  97. package/src/payments/PaymentEscrow.sol +16 -1
  98. package/src/payments/PaymentReceiptRegistry.sol +28 -3
  99. package/src/provenance/ReceiptAnchorRegistry.sol +13 -1
  100. package/src/registry/AgentRegistryBase.sol +21 -1
  101. package/src/registry/EstateProjectionRegistry.sol +15 -1
  102. package/src/relationships/AgentRelationship.sol +17 -1
  103. package/src/relationships/RelationshipTypeRegistry.sol +30 -2
  104. package/src/skills/SkillDefinitionRegistry.sol +15 -1
@@ -0,0 +1,364 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.28;
3
+
4
+ import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
5
+
6
+ interface IGeneration5Account {
7
+ function migrateFactory(address newFactory, bytes calldata custodyInit) external;
8
+ function upgradeVoucher() external view returns (address);
9
+ }
10
+
11
+ interface IGeneration5Voucher {
12
+ function isVouched(address implementation, bytes32 dataHash) external view returns (bool);
13
+ }
14
+
15
+ interface IMoveFactoryView {
16
+ function accountImplementation() external view returns (address);
17
+ function custodyPolicy() external view returns (address);
18
+ function approvedHashRegistry() external view returns (address);
19
+ }
20
+
21
+ interface IMoveAccountView {
22
+ function factory() external view returns (address);
23
+ function isModuleInstalled(uint256 moduleTypeId, address module, bytes calldata additionalContext)
24
+ external
25
+ view
26
+ returns (bool);
27
+ function custodianCount() external view returns (uint256);
28
+ }
29
+
30
+ /// @dev The generation-4 account reads a bridged account still answers (its generation-4 policy makes them).
31
+ interface IGeneration4Reads {
32
+ function custodianCount() external view returns (uint256);
33
+ function isCustodian(address account) external view returns (bool);
34
+ function factory() external view returns (address);
35
+ function isModuleInstalled(uint256 moduleTypeId, address module, bytes calldata additionalContext)
36
+ external
37
+ view
38
+ returns (bool);
39
+ function getPasskey(bytes32 credentialIdDigest) external view returns (uint256 x, uint256 y);
40
+ function getPasskeyRpIdHash(bytes32 credentialIdDigest) external view returns (bytes32);
41
+ function passkeyIdentity(uint256 x, uint256 y) external view returns (address);
42
+ }
43
+
44
+ interface IMoveCustodyView {
45
+ function custodyMode(address account) external view returns (uint8);
46
+ function approvalsRequired(address account, uint8 tier) external view returns (uint8);
47
+ function recoveryApprovals(address account) external view returns (uint8);
48
+ function isTrustee(address account, address signer) external view returns (bool);
49
+ function trusteeCount(address account) external view returns (uint256);
50
+ function safetyDelay(address account, uint8 tier) external view returns (uint32);
51
+ function approvedHashRegistry(address account) external view returns (address);
52
+ function t3HighValueCeiling(address account) external view returns (uint256);
53
+ }
54
+
55
+ /**
56
+ * @title Generation5Bridge — the implementation a generation-4 account passes through on its way to generation 5.
57
+ * @notice Spec 447 §3.4 / §4.1 (audit H-1). WHY IT EXISTS. An account's upgrade is executed by the code it runs
58
+ * NOW. Generation-4 code can deliver a migration call only from a self-governed account; a
59
+ * custody-governed account (every treasury) upgrades through the generation-4 `CustodyPolicy`, a plain
60
+ * deployment whose `ApplySystemUpdate` always sends EMPTY migration data. The one thing every generation-4
61
+ * account can do, in every custody mode, is a PLAIN vouched upgrade. This contract is the target of that
62
+ * plain upgrade, and it does one thing: finish the move.
63
+ *
64
+ * THE MOVE, any custody mode, two steps:
65
+ * 1. the account's own custody (a credential's user operation; the quorum's `ApplySystemUpdate`; a
66
+ * matured queued upgrade) upgrades it to this bridge — `(bridge, keccak256(""))` vouched on the
67
+ * GENERATION-4 voucher;
68
+ * 2. anyone calls `completeMove(custodyInit)` on the account. The bridge switches the account to the
69
+ * generation-5 implementation and runs its `migrateFactory(factory5, custodyInit)` — the same
70
+ * function, with the same checks, a vouched generation-5 migration runs. Inside that one call the
71
+ * account's factory moves, a governed account's custody is installed on the stable policy, and
72
+ * every digest approved for it in the generation-5 registry is revoked (audit H-2).
73
+ * Run both in one transaction (step 1 is `applyCustodyChange`, callable by anyone holding the quorum's
74
+ * signatures): if step 2 would fail, nothing happened.
75
+ *
76
+ * ENTERING IS REFUSED, NOT RECOVERED FROM (audit 2026-12-02 review, item 2). Step 1 runs this bridge's
77
+ * `proxiableUUID()` with the account as caller; it answers only for an account of `factory4` whose
78
+ * generation-4 custody the stable policy can install — unchanged or made stricter by a vouch: per-mode
79
+ * trustee bounds (≥ mode, ≤ 32), a recovery quorum the trustees can reach, every tier reachable by the
80
+ * custodians (and, in mode 3, two custodians and the separation-of-duties cap). Generation 4 permits
81
+ * states outside these (a trustee removed below the mode's bound; more than 32 trustees), and the trustee
82
+ * set cannot be changed by the move, so such an account would otherwise wait on the bridge for good. Its
83
+ * upgrade to the bridge reverts instead — whoever submits it, the quorum's runner or a front-runner
84
+ * holding the apply signatures.
85
+ *
86
+ * THE EXIT. A custody-governed account on the bridge whose completion cannot happen (its vouch was never
87
+ * made, or its quorum changed its generation-4 policy after entering) goes back: its quorum applies
88
+ * `ApplySystemUpdate(implementation4)` on the GENERATION-4 policy, under that policy's tier, delay and
89
+ * pause rules. The bridge answers that one module call (`executeFromModule`) by restoring the
90
+ * generation-4 implementation — nothing else of the account was touched while it was here, so its
91
+ * custody is exactly what it was. A self-governed account needs no exit: its completion has no input
92
+ * that can be missing.
93
+ *
94
+ * WHAT AN ACCOUNT ON THE BRIDGE CAN DO: step 2, or the exit. The bridge has no `execute`, no
95
+ * `validateUserOp`, no `isValidSignature`, no `custodyEpoch`, no `receive`: between the two steps the
96
+ * account moves no value, validates no signature, honours no approval and can approve none (the
97
+ * generation-5 registry reads the epoch of an account signer). It answers the generation-4 READS its
98
+ * generation-4 policy makes of it (`custodianCount`, `isCustodian`, `factory`, `isModuleInstalled`, the
99
+ * passkey views) — the generation-4 implementation's own answers over the account's storage. Through the
100
+ * fallback they run under STATICCALL; `readAsGeneration4` also refuses any selector but those seven, so the
101
+ * generation-4 frame that upgraded the account (still running in the move's transaction) cannot use it to
102
+ * write — so the quorum can still schedule and apply on that policy (the
103
+ * exit). That is the point — the account never runs generation-5 code against generation-4 system
104
+ * contracts, and a digest planted in the generation-5 registry is never live, not even for one block.
105
+ *
106
+ * WHO DECIDES WHAT. Where the account goes is fixed in this bytecode (`implementation5`, `factory5`), and
107
+ * governance vouched this bytecode. A self-governed account carries no custody configuration, so its
108
+ * completion needs nothing more. A CUSTODY-GOVERNED account's configuration on the stable policy
109
+ * (`custodyInit`: mode, trustees, thresholds, delays) is taken only from a vouch that names THAT ACCOUNT:
110
+ * `voucher5.isVouched(implementation5, moveVouchHash(account, custodyInit))`. One account's vouched
111
+ * configuration cannot be applied to another, and a caller cannot supply its own. The account's quorum
112
+ * consents by upgrading to the bridge. An account upgraded to the bridge before its vouch exists waits,
113
+ * frozen, until governance vouches — vouch first.
114
+ *
115
+ * A VOUCH CANNOT WEAKEN CUSTODY. After the stable policy is installed the bridge compares it, view by
116
+ * view, with the account's generation-4 policy and reverts the whole move unless every field of the
117
+ * generation-4 `CustodyPolicy.Config` is carried or deliberately dropped, as follows:
118
+ * mode — the same;
119
+ * trustees, trusteeCount — the same set;
120
+ * recoveryApprovals — not lower;
121
+ * approvalsRequiredByTier 1–5 — not lower;
122
+ * approvalsRequiredByTier 6 — not compared: no action is authorized by it (T6 is recovery, whose
123
+ * quorum is `recoveryApprovals`);
124
+ * safetyDelayByTier 1–6 — not shorter;
125
+ * t3HighValueCeiling — the same (neither direction is "stricter" for every reader);
126
+ * approvedHashRegistry — the generation-5 registry, or none;
127
+ * installed — true by construction (the install is what just ran);
128
+ * permanentlyUninstalled — false by construction (a fresh install); an account whose generation-4
129
+ * policy was uninstalled is not custody-governed and carries no
130
+ * configuration;
131
+ * nextChangeId, pending, proposerCustodians — DROPPED: changes scheduled in the generation-4 policy (a
132
+ * recovery in flight included) do not apply after the move.
133
+ * Governance may vouch a STRICTER configuration (generation 5 refuses some delays generation 4 accepted);
134
+ * it cannot vouch a looser one, another trustee or another ceiling.
135
+ *
136
+ * WHAT ELSE IS NOT CARRIED. The account's delegation manager slot is untouched (a governed account
137
+ * rotates to the stable manager through its new policy).
138
+ *
139
+ * @dev LAYOUT COUPLING, STATED. `migrateFactory` runs only while the account implementation's transient
140
+ * `_upgradeMigrationCtx` flag is set. The bridge executes as the account (delegatecall), so it sets that
141
+ * flag itself: the transient variables below mirror `AgentAccount`'s, in order. After the move it also sets
142
+ * `_epochBumpedThisTx`, which the generation-5 code reads for the rest of the transaction. If the layouts
143
+ * ever disagreed `migrateFactory` would revert `MigrationOnly` and the move with it (fail closed);
144
+ * `Generation5Move448` runs the move on generation-4 bytecode and `check:storage-layouts` gates both
145
+ * transient layouts (offsets 0–5 identical).
146
+ */
147
+ contract Generation5Bridge {
148
+ /// @dev Domain tag of a per-account move vouch; keeps it disjoint from every `keccak256(migration data)`.
149
+ bytes32 private constant MOVE_VOUCH_TAG = keccak256("agenticprimitives.generation-5-move.v1");
150
+
151
+ address private immutable __self = address(this);
152
+
153
+ /// @notice The generation-5 account implementation every account leaves the bridge for.
154
+ address public immutable implementation5;
155
+ /// @notice The stable factory every account is moved to.
156
+ address public immutable factory5;
157
+ /// @notice The generation-5 voucher (the one `implementation5` carries) that holds per-account move vouches.
158
+ address public immutable voucher5;
159
+ /// @notice The generation-4 account implementation (the code the accounts leave).
160
+ address public immutable implementation4;
161
+ /// @notice The generation-4 custody policy (the canonical policy of the factory the accounts leave).
162
+ address public immutable policy4;
163
+ /// @notice The stable custody policy (`factory5`'s).
164
+ address public immutable policy5;
165
+ /// @notice The generation-5 approved-hash registry (`factory5`'s).
166
+ address public immutable registry5;
167
+ /// @notice The generation-4 factory: the only factory whose accounts may enter.
168
+ address public immutable factory4;
169
+
170
+ // Mirror of `AgentAccount`'s transient layout (see @dev above). Only `_upgradeMigrationCtx` and
171
+ // `_epochBumpedThisTx` are written.
172
+ bool private transient _upgradeAuthorizedCtx;
173
+ bool private transient _custodyGovCtx;
174
+ bool private transient _delegationExecCtx;
175
+ bool private transient _upgradeMigrationCtx;
176
+ bool private transient _initializedThisTx;
177
+ bool private transient _epochBumpedThisTx;
178
+
179
+ /// @dev The largest trustee set the stable policy installs (`CustodyPolicy.MAX_INSTALL_TRUSTEES`).
180
+ uint256 private constant MAX_INSTALL_TRUSTEES = 32;
181
+ uint256 private constant MODULE_TYPE_EXECUTOR = 2;
182
+
183
+ error ZeroAddress();
184
+ /// @dev Called on the bridge itself, or on a proxy whose implementation is not the bridge.
185
+ error NotAnAccountOnTheBridge();
186
+ /// @dev `readAsGeneration4` was asked for a selector outside the seven generation-4 reads.
187
+ error NotAGeneration4Read();
188
+ /// @dev A custody-governed account's configuration was not vouched for this account.
189
+ error MoveNotVouched(address account, bytes32 vouchHash);
190
+ /// @dev The vouched configuration is not the account's generation-4 custody, or is weaker. `check` names the
191
+ /// comparison that failed: 1 mode, 2 trustee count, 3 a trustee, 4 recovery quorum, 5 a tier's approvals,
192
+ /// 6 a tier's delay, 7 the approved-hash registry, 8 the T3 high-value ceiling.
193
+ error CustodyNotCarried(address account, uint8 check);
194
+ /// @dev The account cannot enter the bridge: its move could never complete. `check` names why: 1 not an
195
+ /// account of `factory4`, 2 trustees outside the stable policy's bounds for its mode, 3 a recovery quorum
196
+ /// its trustees cannot reach, 4 a tier its custodians cannot reach (or mode 3 with fewer than two).
197
+ error NotMovable(address account, uint8 check);
198
+ /// @dev A module call on a bridged account other than its generation-4 policy restoring `implementation4`.
199
+ error NotTheExit();
200
+
201
+ /// @notice A custody-governed account left the bridge for the generation-4 implementation, unchanged.
202
+ event MoveAborted(address indexed account);
203
+
204
+ constructor(address implementation5_, address factory5_, address factory4_) {
205
+ if (implementation5_.code.length == 0 || factory5_.code.length == 0 || factory4_.code.length == 0) {
206
+ revert ZeroAddress();
207
+ }
208
+ address v = IGeneration5Account(implementation5_).upgradeVoucher();
209
+ address p4 = IMoveFactoryView(factory4_).custodyPolicy();
210
+ address p5 = IMoveFactoryView(factory5_).custodyPolicy();
211
+ address i4 = IMoveFactoryView(factory4_).accountImplementation();
212
+ if (v.code.length == 0 || p4.code.length == 0 || p5.code.length == 0 || i4.code.length == 0) revert ZeroAddress();
213
+ implementation4 = i4;
214
+ implementation5 = implementation5_;
215
+ factory5 = factory5_;
216
+ voucher5 = v;
217
+ policy4 = p4;
218
+ policy5 = p5;
219
+ registry5 = IMoveFactoryView(factory5_).approvedHashRegistry();
220
+ factory4 = factory4_;
221
+ }
222
+
223
+ /// @notice ERC-1822: what the generation-4 `upgradeToAndCall` asks of its target, with the upgrading account
224
+ /// as caller. Answered only by the bridge itself, never through an account, and only for an account
225
+ /// whose move can complete (see ENTERING above) — so an account that could not leave is never let in.
226
+ function proxiableUUID() external view returns (bytes32) {
227
+ if (address(this) != __self) revert NotAnAccountOnTheBridge();
228
+ _requireMovable(msg.sender);
229
+ return ERC1967Utils.IMPLEMENTATION_SLOT;
230
+ }
231
+
232
+ /// @dev What the stable policy's `onInstall` would refuse in the account's generation-4 custody that no vouch
233
+ /// can repair (a vouch may raise thresholds, quorums and delays; it cannot change the mode or the trustee
234
+ /// set, or lower anything). Read while the account still runs generation-4 code.
235
+ function _requireMovable(address a) private view {
236
+ if (IMoveAccountView(a).factory() != factory4) revert NotMovable(a, 1);
237
+ if (!IMoveAccountView(a).isModuleInstalled(MODULE_TYPE_EXECUTOR, policy4, "")) return; // self-governed
238
+ IMoveCustodyView p = IMoveCustodyView(policy4);
239
+ uint8 mode = p.custodyMode(a);
240
+ uint256 trustees = p.trusteeCount(a);
241
+ if (mode >= 1 && (trustees < mode || trustees > MAX_INSTALL_TRUSTEES)) revert NotMovable(a, 2);
242
+ if (p.recoveryApprovals(a) > trustees) revert NotMovable(a, 3);
243
+ uint256 n = IMoveAccountView(a).custodianCount();
244
+ if (mode == 3 && n < 2) revert NotMovable(a, 4);
245
+ for (uint8 tier = 1; tier <= 5; tier++) {
246
+ if (p.approvalsRequired(a, tier) > ((mode == 3 && tier >= 4) ? n / 2 : n)) revert NotMovable(a, 4);
247
+ }
248
+ }
249
+
250
+ /// @notice The generation-4 READS a bridged account still answers (see WHAT AN ACCOUNT ON THE BRIDGE CAN DO):
251
+ /// `custodianCount()`, `isCustodian(address)`, `factory()`, `isModuleInstalled(uint256,address,bytes)`,
252
+ /// `getPasskey(bytes32)`, `getPasskeyRpIdHash(bytes32)`, `passkeyIdentity(uint256,uint256)`. Every other
253
+ /// selector, and any call carrying value, reverts.
254
+ // Deliberately non-trivial: a bridged account answers a fixed allowlist of generation-4 reads by staticcall to itself.
255
+ // solhint-disable-next-line no-complex-fallback
256
+ fallback() external {
257
+ if (address(this) == __self || !_isGeneration4Read(msg.sig)) revert NotAnAccountOnTheBridge();
258
+ (bool ok, bytes memory ret) = address(this).staticcall(abi.encodeCall(this.readAsGeneration4, (msg.data)));
259
+ if (!ok) revert NotAnAccountOnTheBridge();
260
+ ret = abi.decode(ret, (bytes));
261
+ assembly {
262
+ return(add(ret, 0x20), mload(ret))
263
+ }
264
+ }
265
+
266
+ /// @dev The seven generation-4 reads a bridged account answers: the ONE allowlist, used by the fallback and by
267
+ /// `readAsGeneration4`. Every one is a `view` of the generation-4 implementation, so a call that carries
268
+ /// only these selectors cannot write, static or not.
269
+ function _isGeneration4Read(bytes4 s) private pure returns (bool) {
270
+ return s == IGeneration4Reads.custodianCount.selector || s == IGeneration4Reads.isCustodian.selector
271
+ || s == IGeneration4Reads.factory.selector || s == IGeneration4Reads.isModuleInstalled.selector
272
+ || s == IGeneration4Reads.getPasskey.selector || s == IGeneration4Reads.getPasskeyRpIdHash.selector
273
+ || s == IGeneration4Reads.passkeyIdentity.selector;
274
+ }
275
+
276
+ /// @notice The body of a forwarded read: `implementation4` delegatecalled over the account's storage. Only the
277
+ /// account itself may call it, and only with one of the seven generation-4 reads (`NotAGeneration4Read`
278
+ /// otherwise). The fallback reaches it by STATICCALL; generation-4 code still running in the move's own
279
+ /// transaction can reach it by an ordinary self-call, which the allowlist alone confines to views.
280
+ function readAsGeneration4(bytes calldata data) external returns (bytes memory) {
281
+ if (msg.sender != address(this) || address(this) == __self) revert NotAnAccountOnTheBridge();
282
+ if (data.length < 4 || !_isGeneration4Read(bytes4(data[0:4]))) revert NotAGeneration4Read();
283
+ // Reviewed: the target is an immutable fixed at construction (never caller-chosen); only the account itself may
284
+ // reach this; and the selector is checked against the seven-read allowlist just above, every one a `view`.
285
+ // Slither sees "input-controlled function id" and cannot see that gate.
286
+ // slither-disable-next-line controlled-delegatecall
287
+ (bool ok, bytes memory ret) = implementation4.delegatecall(data);
288
+ if (!ok) revert NotAnAccountOnTheBridge();
289
+ return ret;
290
+ }
291
+
292
+ /// @notice THE EXIT. The generation-4 policy's `ApplySystemUpdate(implementation4)` — scheduled and applied by
293
+ /// the account's quorum on that policy, under its tier, delay and pause rules — reaches the account as
294
+ /// `executeFromModule(account, 0, upgradeToAndCall(implementation4, ""))`. The bridge accepts that one
295
+ /// call, from that one module, on an account that has it installed, and restores the generation-4
296
+ /// implementation. Nothing else is a module call here.
297
+ function executeFromModule(address target, uint256 value, bytes calldata data) external returns (bytes memory) {
298
+ if (address(this) == __self || ERC1967Utils.getImplementation() != __self) revert NotAnAccountOnTheBridge();
299
+ if (
300
+ msg.sender != policy4 || target != address(this) || value != 0
301
+ || keccak256(data) != keccak256(abi.encodeWithSignature("upgradeToAndCall(address,bytes)", implementation4, ""))
302
+ || !IMoveAccountView(address(this)).isModuleInstalled(MODULE_TYPE_EXECUTOR, policy4, "")
303
+ ) revert NotTheExit();
304
+ ERC1967Utils.upgradeToAndCall(implementation4, "");
305
+ emit MoveAborted(address(this));
306
+ return "";
307
+ }
308
+
309
+ /// @notice What governance vouches (on `voucher5`, for `implementation5`) so that the custody-governed
310
+ /// `account` can complete its move with exactly `custodyInit`.
311
+ function moveVouchHash(address account, bytes calldata custodyInit) public view returns (bytes32) {
312
+ return keccak256(abi.encode(MOVE_VOUCH_TAG, account, factory5, custodyInit));
313
+ }
314
+
315
+ /// @notice Finish the move of the account this is called on. Callable by anyone: every input that matters is
316
+ /// fixed in this bytecode or vouched for this account. `custodyInit` is empty for a self-governed
317
+ /// account and the vouched `CustodyPolicy.onInstall` encoding for a custody-governed one
318
+ /// (`migrateFactory` refuses the wrong one of the two).
319
+ function completeMove(bytes calldata custodyInit) external {
320
+ if (address(this) == __self || ERC1967Utils.getImplementation() != __self) revert NotAnAccountOnTheBridge();
321
+ if (custodyInit.length != 0) {
322
+ bytes32 h = moveVouchHash(address(this), custodyInit);
323
+ if (!IGeneration5Voucher(voucher5).isVouched(implementation5, h)) revert MoveNotVouched(address(this), h);
324
+ }
325
+ _upgradeMigrationCtx = true;
326
+ ERC1967Utils.upgradeToAndCall(
327
+ implementation5, abi.encodeCall(IGeneration5Account.migrateFactory, (factory5, custodyInit))
328
+ );
329
+ _upgradeMigrationCtx = false;
330
+ // The generation-4 code that ran before this call bumps no generation-5 flag, so a custodian retired by a
331
+ // generation-4 change applied earlier in this transaction could otherwise approve under the new epoch
332
+ // after the move. Marked here: for the rest of the transaction a governed account approves nothing except
333
+ // through its custody policy (`AgentAccount.approvalRefused`; audit 2026-12-02 H-2).
334
+ _epochBumpedThisTx = true;
335
+ if (custodyInit.length != 0) _requireCustodyCarried(custodyInit);
336
+ }
337
+
338
+ /// @dev Runs after `migrateFactory` installed the stable policy with `custodyInit` (which it does only for an
339
+ /// account governed by its old factory's policy). Trustees: the stable policy refuses a duplicate, so
340
+ /// "same count, and each one a generation-4 trustee" is "the same set".
341
+ function _requireCustodyCarried(bytes calldata custodyInit) private view {
342
+ address a = address(this);
343
+ IMoveCustodyView old = IMoveCustodyView(policy4);
344
+ IMoveCustodyView nu = IMoveCustodyView(policy5);
345
+ if (nu.custodyMode(a) != old.custodyMode(a)) revert CustodyNotCarried(a, 1);
346
+ if (nu.trusteeCount(a) != old.trusteeCount(a)) revert CustodyNotCarried(a, 2);
347
+ (,, address[] memory trustees,,,,) =
348
+ abi.decode(custodyInit, (uint8, uint8, address[], uint8[7], uint32[7], uint256, address));
349
+ for (uint256 i; i < trustees.length; i++) {
350
+ if (!old.isTrustee(a, trustees[i])) revert CustodyNotCarried(a, 3);
351
+ }
352
+ if (nu.recoveryApprovals(a) < old.recoveryApprovals(a)) revert CustodyNotCarried(a, 4);
353
+ // Tier 6 (recovery) has its quorum in `recoveryApprovals` (above); its delay is in the per-tier table.
354
+ for (uint8 tier = 1; tier <= 6; tier++) {
355
+ if (tier != 6 && nu.approvalsRequired(a, tier) < old.approvalsRequired(a, tier)) {
356
+ revert CustodyNotCarried(a, 5);
357
+ }
358
+ if (nu.safetyDelay(a, tier) < old.safetyDelay(a, tier)) revert CustodyNotCarried(a, 6);
359
+ }
360
+ address reg = nu.approvedHashRegistry(a);
361
+ if (reg != address(0) && reg != registry5) revert CustodyNotCarried(a, 7);
362
+ if (nu.t3HighValueCeiling(a) != old.t3HighValueCeiling(a)) revert CustodyNotCarried(a, 8);
363
+ }
364
+ }
@@ -2,7 +2,9 @@
2
2
  pragma solidity ^0.8.28;
3
3
 
4
4
  import "./AgentNameRegistry.sol";
5
+ import {Eip7702} from "../libraries/Eip7702.sol";
5
6
  import "../ontology/AttributeStorage.sol";
7
+ import "../governance/StableProxyGoverned.sol";
6
8
 
7
9
  /**
8
10
  * @title AgentNameAttributeResolver
@@ -29,13 +31,17 @@ import "../ontology/AttributeStorage.sol";
29
31
  * the same predicate ids and routes encode / decode through the typed
30
32
  * setters here. See `AgentNamePredicates.sol` for the canonical set.
31
33
  */
32
- contract AgentNameAttributeResolver is AttributeStorage {
34
+ contract AgentNameAttributeResolver is AttributeStorage, StableProxyGoverned {
33
35
  AgentNameRegistry public immutable REGISTRY;
34
36
 
35
37
  error NotAuthorized();
36
38
  error NodeNotFound();
37
39
 
38
- constructor(AgentNameRegistry registry, address ontology) AttributeStorage(ontology) {
40
+ /// @notice A DIRECT deployment, with no upgrade governance (frozen code, as before). Spec 447 — behind a stable
41
+ /// proxy, `initialize(governance_)` instead. `REGISTRY` and `ONTOLOGY` stay immutables: they are the
42
+ /// addresses of other stable proxies, which never change, so a fix is a new implementation built with
43
+ /// the same two addresses.
44
+ constructor(AgentNameRegistry registry, address ontology) AttributeStorage(ontology) initializer {
39
45
  REGISTRY = registry;
40
46
  }
41
47
 
@@ -105,6 +111,10 @@ contract AgentNameAttributeResolver is AttributeStorage {
105
111
 
106
112
  function _requireAuth(bytes32 node) internal view {
107
113
  if (!REGISTRY.recordExists(node)) revert NodeNotFound();
114
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
108
115
  if (msg.sender != REGISTRY.owner(node)) revert NotAuthorized();
109
116
  }
117
+
118
+ /// @dev Spec 447 — storage gap: the contract may sit behind a stable proxy; layout gated by `check:storage-layouts`.
119
+ uint256[35] private __gap;
110
120
  }
@@ -1,7 +1,9 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  pragma solidity ^0.8.28;
3
3
 
4
- import "../governance/GovernanceManaged.sol";
4
+ import "../governance/StableProxyGovernedOneShot.sol";
5
+ import {Eip7702} from "../libraries/Eip7702.sol";
6
+ import "../governance/IGovernance.sol";
5
7
 
6
8
  /**
7
9
  * @title AgentNameRegistry
@@ -38,11 +40,21 @@ import "../governance/GovernanceManaged.sol";
38
40
  * discipline (a primary name only counts when the forward record
39
41
  * agrees).
40
42
  */
41
- /// @dev R6.8 — inherits `GovernanceManaged` to gain the
42
- /// `whenNotPaused` modifier on its mutating surface. The registry
43
- /// still owns its own per-node auth (`_requireParentAuth` /
44
- /// `msg.sender == owner`); governance only owns the pause flag.
45
- contract AgentNameRegistry is GovernanceManaged {
43
+ /// @dev R6.8 — `governance` gates the `whenNotPaused` modifier on the mutating surface. The registry
44
+ /// still owns its own per-node auth (`_requireParentAuth` / `msg.sender == owner`); governance owns
45
+ /// the pause flag, naming administration (with the initializer) and — spec 447 — the upgrade.
46
+ ///
47
+ /// Spec 447 (generation 5): deployable behind an ERC-1967 UUPS proxy at an address that never changes.
48
+ /// Before 447 this inherited `GovernanceManaged` (governance an IMMUTABLE); it now sits on
49
+ /// `StableProxyGovernedOneShot` (governance in an ERC-7201 slot, the sole upgrade authority) and keeps
50
+ /// `GovernanceManaged`'s surface here: the same `whenNotPaused` / `paused()` semantics and the same
51
+ /// error names (`NotGovernance`, `SystemPaused`, `ZeroGovernance`), so selectors are unchanged.
52
+ /// It cannot inherit OpenZeppelin's `Initializable`: the published `initializer()` role getter collides
53
+ /// with its `initializer` modifier; the base's one-shot guard in `Initializable`'s own ERC-7201 slot
54
+ /// stands in (`_initOnce`, same `InvalidInitialization` error). A direct deployment is initialized in the
55
+ /// constructor and can never be upgraded (`onlyProxy`); behind a proxy, `initialize(governance_,
56
+ /// initializer_)` is the only initializer.
57
+ contract AgentNameRegistry is StableProxyGovernedOneShot {
46
58
  // ─── H7-C.4 / CON-NAMING-001 — root-initializer gate ───────────────
47
59
  //
48
60
  // `initializeRoot` was permissionless: any mempool observer could
@@ -86,6 +98,9 @@ contract AgentNameRegistry is GovernanceManaged {
86
98
  // ─── Errors ─────────────────────────────────────────────────────
87
99
 
88
100
  error NotAuthorized();
101
+ /// @dev The `GovernanceManaged` errors this registry kept (same selectors as before spec 447).
102
+ error SystemPaused();
103
+ error ZeroGovernance();
89
104
  error NodeAlreadyExists();
90
105
  error NodeNotFound();
91
106
  error ParentNotFound();
@@ -202,7 +217,49 @@ contract AgentNameRegistry is GovernanceManaged {
202
217
  /// can't be frontrun. R6.8 added `governance_` so the
203
218
  /// registry can read the system pause flag through
204
219
  /// `GovernanceManaged._pausedSafe()`.
205
- constructor(address initializer_, address governance_) GovernanceManaged(governance_) {
220
+ constructor(address initializer_, address governance_) {
221
+ _initOnce();
222
+ _initializeGovernance(governance_);
223
+ _initNaming(initializer_);
224
+ }
225
+
226
+ /// @notice Spec 447 — the proxy's initializer: what the constructor sets, once per proxy. The
227
+ /// implementation itself can never be initialized (its constructor already was).
228
+ function initialize(address governance_, address initializer_) external {
229
+ _initOnce();
230
+ _initializeGovernance(governance_);
231
+ _initNaming(initializer_);
232
+ }
233
+
234
+ // ─── Spec 447 — initialization guard + governance (the kept `GovernanceManaged` surface) ─────
235
+
236
+ /// @dev As `GovernanceManaged`'s constructor: a registry needs a governance (pause + admin + upgrade).
237
+ function _initializeGovernance(address governance_) internal override {
238
+ if (governance_ == address(0)) revert ZeroGovernance();
239
+ super._initializeGovernance(governance_);
240
+ }
241
+
242
+ /// @dev Reverts when the governance pause flag is set (as `GovernanceManaged.whenNotPaused`).
243
+ modifier whenNotPaused() {
244
+ if (_pausedSafe()) revert SystemPaused();
245
+ _;
246
+ }
247
+
248
+ /// @notice Read the global pause flag. Returns false when governance is non-conforming.
249
+ function paused() external view returns (bool) {
250
+ return _pausedSafe();
251
+ }
252
+
253
+ /// @dev As `GovernanceManaged._pausedSafe`: an EOA / non-conforming governance is "not paused".
254
+ function _pausedSafe() internal view returns (bool) {
255
+ address gov = governance();
256
+ if (gov.code.length == 0) return false;
257
+ (bool ok, bytes memory data) = gov.staticcall(abi.encodeWithSelector(IGovernanceView.isPaused.selector));
258
+ if (!ok || data.length < 32) return false;
259
+ return abi.decode(data, (bool));
260
+ }
261
+
262
+ function _initNaming(address initializer_) private {
206
263
  if (initializer_ == address(0)) revert ZeroOwner();
207
264
  initializer = initializer_;
208
265
  // The fixed infrastructure hosts (agent-naming `RESERVED_LABELS` minus the type words, which
@@ -221,6 +278,7 @@ contract AgentNameRegistry is GovernanceManaged {
221
278
  /// this call (it can neither initialize a root nor name another successor afterwards), and
222
279
  /// nobody holds it until `to` accepts.
223
280
  function transferInitializer(address to) external {
281
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
224
282
  if (msg.sender != initializer) revert NotInitializer(msg.sender, initializer);
225
283
  if (initializerHandedOver) revert InitializerAlreadyHandedOver();
226
284
  if (to == address(0)) revert ZeroOwner();
@@ -233,6 +291,7 @@ contract AgentNameRegistry is GovernanceManaged {
233
291
  /// @notice Take the initializer role. Only the successor named by `transferInitializer`.
234
292
  function acceptInitializer() external {
235
293
  address to = pendingInitializer;
294
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
236
295
  if (to == address(0) || msg.sender != to) revert NotPendingInitializer(msg.sender);
237
296
  pendingInitializer = address(0);
238
297
  initializer = to;
@@ -244,7 +303,8 @@ contract AgentNameRegistry is GovernanceManaged {
244
303
  /// @dev Governance (the timelocked system authority) or the current initializer (the only account
245
304
  /// that may create a root, so strictly the stronger role during bootstrap).
246
305
  function _requireNamingAdmin() internal view {
247
- if (msg.sender != governance && (msg.sender != initializer || initializer == address(0))) revert NotAuthorized();
306
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
307
+ if (msg.sender != governance() && (msg.sender != initializer || initializer == address(0))) revert NotAuthorized();
248
308
  }
249
309
 
250
310
  /// @notice Reserve or release labels, by labelhash. Affects FUTURE registrations only.
@@ -323,6 +383,7 @@ contract AgentNameRegistry is GovernanceManaged {
323
383
  // frontrun window exists.
324
384
  // Spec 445: `initializer` is zero between `transferInitializer` and `acceptInitializer`, and
325
385
  // msg.sender is never zero, so nobody initializes during a hand-over.
386
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
326
387
  if (msg.sender != initializer) revert NotInitializer(msg.sender, initializer);
327
388
  // AN-1-ONCHAIN: canonical charset on chain. NAME-8: a root label carries no hyphen, so the
328
389
  // typed host `<label>-<type>` splits one way only (the suffix is the segment after the LAST `-`).
@@ -454,7 +515,14 @@ contract AgentNameRegistry is GovernanceManaged {
454
515
  // REG-4: records are the previous owner's statements (`atl:addr`, `atl:agentType`,
455
516
  // endpoints). They stop resolving here; the new owner writes its own. The `resolver` and
456
517
  // `subregistry` POINTERS are registry fields the new owner can read in one call and are
457
- // left as they are (a root hand-over keeps its subregistry) — a receiver checks them.
518
+ // left as they are (a root hand-over keeps a subregistry CONTRACT) — a receiver checks them.
519
+ // Audit 2026-12-02 C4-3 — with one exception: a subregistry pointer that names the OUTGOING
520
+ // owner (how every root is born) is that owner's own authority to issue names under the node.
521
+ // It leaves with the owner; the pointer follows the node to the new one.
522
+ if (r.subregistry == r.owner) {
523
+ r.subregistry = newOwner;
524
+ emit SubregistryChanged(node, newOwner);
525
+ }
458
526
  r.owner = newOwner;
459
527
  uint64 epoch = r.epoch + 1;
460
528
  r.epoch = epoch;
@@ -507,6 +575,7 @@ contract AgentNameRegistry is GovernanceManaged {
507
575
  // Storage default IS exactly 0; not a numeric precision concern.
508
576
  // slither-disable-next-line incorrect-equality
509
577
  if (node != bytes32(0) && _records[node].registeredAt == 0) revert NodeNotFound();
578
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
510
579
  _primaryName[msg.sender] = node;
511
580
  if (node == bytes32(0)) emit PrimaryNameCleared(msg.sender);
512
581
  else emit PrimaryNameSet(msg.sender, node);
@@ -583,6 +652,7 @@ contract AgentNameRegistry is GovernanceManaged {
583
652
  function _requireNodeAuth(bytes32 node) internal view {
584
653
  NameRecord storage r = _records[node];
585
654
  if (r.registeredAt == 0) revert NodeNotFound();
655
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
586
656
  if (msg.sender != r.owner) revert NotAuthorized();
587
657
  // REG-6: an expired name is nobody's — its former owner cannot move it, re-point it or
588
658
  // delegate under it while it waits to be reclaimed.
@@ -592,6 +662,7 @@ contract AgentNameRegistry is GovernanceManaged {
592
662
  function _requireParentAuth(bytes32 parentNode) internal view {
593
663
  NameRecord storage r = _records[parentNode];
594
664
  if (r.registeredAt == 0) revert ParentNotFound();
665
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
595
666
  if (msg.sender == r.owner) return;
596
667
  if (r.subregistry != address(0) && msg.sender == r.subregistry) return;
597
668
  revert NotAuthorized();
@@ -600,5 +671,8 @@ contract AgentNameRegistry is GovernanceManaged {
600
671
  function _requireNotExpired(bytes32 node) internal view {
601
672
  if (isExpired(node)) revert NameExpired();
602
673
  }
603
- }
604
674
 
675
+ /// @dev Spec 447 — storage gap: the registry may sit behind a stable proxy; layout gated by
676
+ /// `check:storage-layouts`.
677
+ uint256[36] private __gap;
678
+ }
@@ -4,6 +4,7 @@ pragma solidity ^0.8.28;
4
4
  import "./AgentNameRegistry.sol";
5
5
  import "./AgentNameAttributeResolver.sol";
6
6
  import "./AgentNamePredicates.sol";
7
+ import "../governance/StableProxyGoverned.sol";
7
8
 
8
9
  /**
9
10
  * @title AgentNameUniversalResolver
@@ -21,10 +22,13 @@ import "./AgentNamePredicates.sol";
21
22
  * permissive so callers can sequence forward + reverse writes
22
23
  * independently.
23
24
  */
24
- contract AgentNameUniversalResolver {
25
+ contract AgentNameUniversalResolver is StableProxyGoverned {
25
26
  AgentNameRegistry public immutable REGISTRY;
26
27
 
27
- constructor(AgentNameRegistry registry) {
28
+ /// @notice A DIRECT deployment, with no upgrade governance (frozen code, as before). Spec 447 — behind a stable
29
+ /// proxy, `initialize(governance_)` instead. `REGISTRY` stays an immutable: it is the name registry's
30
+ /// stable proxy address, which never changes. Stateless, so no storage gap.
31
+ constructor(AgentNameRegistry registry) initializer {
28
32
  REGISTRY = registry;
29
33
  }
30
34
 
@@ -175,6 +179,9 @@ contract AgentNameUniversalResolver {
175
179
  unchecked { depth++; }
176
180
  }
177
181
  if (depth == 0) return "";
182
+ // Audit 2026-12-02 C4-1: the walk stopped at the depth bound with ancestors left. The labels collected so
183
+ // far are NOT the name — joined, they read as a name under a different root. No name is the answer.
184
+ if (cur != bytes32(0)) return "";
178
185
 
179
186
  // Concatenate labels[0..depth-1] with '.' separators.
180
187
  uint256 totalLen = depth - 1; // for the dots