@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
@@ -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
@@ -54,7 +66,18 @@ contract AgentNameRegistry is GovernanceManaged {
54
66
  // The role is INITIALIZATION-ONLY. Once a root is initialized, control
55
67
  // belongs to its `rootOwner` (a smart-agent governance address) — the
56
68
  // initializer cannot rotate it.
57
- address public immutable initializer;
69
+ //
70
+ // Spec 445 (generation 4): the role can be handed over ONCE, in two steps. A bootstrap key
71
+ // initializes the roots, then `transferInitializer(authority)` — from that call on the old
72
+ // initializer holds nothing (`initializer` reads zero, `initializeRoot` refuses everyone) and only
73
+ // the named successor can take the role with `acceptInitializer()`. There is no second hand-over
74
+ // and no path for a stranger: the front-run protection (AUDIT.md invariant 2.6) is unchanged —
75
+ // at every moment at most one address may initialize a root, and it is one the previous holder named.
76
+ address public initializer;
77
+ /// @notice The successor named by `transferInitializer`, until it accepts. Zero otherwise.
78
+ address public pendingInitializer;
79
+ /// @notice True once `transferInitializer` was called — the hand-over is one-shot.
80
+ bool public initializerHandedOver;
58
81
 
59
82
  // ─── Types ──────────────────────────────────────────────────────
60
83
 
@@ -66,23 +89,49 @@ contract AgentNameRegistry is GovernanceManaged {
66
89
  bytes32 labelhash; // keccak256(bytes(label))
67
90
  uint64 expiry; // 0 = no expiry
68
91
  uint64 registeredAt;
92
+ /// @dev REG-4 — owner epoch: bumped on every change of owner (transfer, or re-registration of an
93
+ /// expired name). The attribute resolver keys records by (node, epoch), so records never
94
+ /// carry over to a new owner. Packs into the expiry/registeredAt slot.
95
+ uint64 epoch;
69
96
  }
70
97
 
71
98
  // ─── Errors ─────────────────────────────────────────────────────
72
99
 
73
100
  error NotAuthorized();
101
+ /// @dev The `GovernanceManaged` errors this registry kept (same selectors as before spec 447).
102
+ error SystemPaused();
103
+ error ZeroGovernance();
74
104
  error NodeAlreadyExists();
75
105
  error NodeNotFound();
76
106
  error ParentNotFound();
77
107
  error NameExpired();
78
108
  error RootAlreadyInitialized();
79
109
  error EmptyLabel();
110
+ /// @notice AN-1-ONCHAIN (audit 2026-06-10) — the label is not in canonical form. The off-chain
111
+ /// SDK `normalizeLabel` (NFC + lowercase + `[a-z0-9-]`, 1..63, no leading/trailing `-`) was
112
+ /// bypassable by any DIRECT contract caller, allowing homoglyph / mixed-case / zero-width /
113
+ /// embedded-dot squatting of names. The charset is now enforced ON CHAIN; because a valid
114
+ /// label is already lowercase ASCII, raw-byte hashing equals hashing the normalized label.
115
+ error InvalidLabel();
80
116
  error ZeroOwner();
81
117
  /// @notice H7-C.4 / CON-NAMING-001 — `initializeRoot` may only be called
82
118
  /// by the immutable `initializer` set at construction. Closes the
83
119
  /// permissionless-frontrun vector where any mempool observer
84
120
  /// could claim a TLD before the deployer's first init landed.
85
121
  error NotInitializer(address caller, address initializer);
122
+ /// @notice Spec 445 — the initializer hand-over is one-shot; a second `transferInitializer` is refused.
123
+ error InitializerAlreadyHandedOver();
124
+ /// @notice Spec 445 — `acceptInitializer` by anyone but the named successor.
125
+ error NotPendingInitializer(address caller);
126
+ /// @notice Spec 445 / NAME-8 — the label is reserved (an infrastructure host such as `www`, `api`,
127
+ /// `mtls`, or the label of an initialized typed root) and names no agent.
128
+ error ReservedLabel();
129
+ /// @notice Spec 445 / NAME-8 — under a root that takes the bare DNS host, a label ending in
130
+ /// `-<typed root>` would share the host of `<prefix>.<typed root>`.
131
+ error LabelReadsAsTypedName();
132
+ /// @notice REG-6 — `renew` may only extend: a permanent name stays permanent, an expiry never moves
133
+ /// earlier (a parent that could shorten an expiry could seize a live name).
134
+ error ExpiryNotExtended();
86
135
 
87
136
  // ─── Events ─────────────────────────────────────────────────────
88
137
 
@@ -99,6 +148,13 @@ contract AgentNameRegistry is GovernanceManaged {
99
148
  event ResolverChanged(bytes32 indexed node, address indexed resolver);
100
149
  event SubregistryChanged(bytes32 indexed node, address indexed subregistry);
101
150
  event NameRenewed(bytes32 indexed node, uint64 newExpiry);
151
+ /// @notice REG-4 — the node's owner changed; every record written under an earlier epoch stopped resolving.
152
+ event RecordEpochBumped(bytes32 indexed node, uint64 epoch);
153
+ event LabelBackfilled(bytes32 indexed node, string label);
154
+ event InitializerTransferStarted(address indexed from, address indexed to);
155
+ event InitializerTransferred(address indexed from, address indexed to);
156
+ event ReservedLabelSet(bytes32 indexed labelhash, bool reserved);
157
+ event RootBareHostSet(bytes32 indexed rootNode, bool takesBareHost);
102
158
  event PrimaryNameSet(address indexed agent, bytes32 indexed node);
103
159
  event PrimaryNameCleared(address indexed agent);
104
160
 
@@ -132,6 +188,26 @@ contract AgentNameRegistry is GovernanceManaged {
132
188
 
133
189
  /// @notice Default kind tags downstream callers may use.
134
190
  bytes32 public constant KIND_AGENT = keccak256("namespace:Agent");
191
+ /// @notice The kind of the person root. Persons and the untyped legacy root take the BARE DNS host
192
+ /// `<label>.<zone>`; every other root is typed and takes `<label>-<type>.<zone>` (spec 346 §5).
193
+ bytes32 public constant KIND_PERSON = keccak256("namespace:Person");
194
+
195
+ // ─── Reserved labels + DNS-host injectivity (spec 445 decision 6 / NAME-8) ──────────────────────
196
+ //
197
+ // The SDK refuses these claims (`labelClaimViolation`); a direct contract caller bypassed it. The
198
+ // chain now refuses them on EVERY registration path — `register` is the one function the root
199
+ // owner, `PermissionlessSubregistry.register` and `PricedSubregistry.claim` all end in.
200
+
201
+ /// @notice labelhash → reserved. Seeded at construction with the fixed infrastructure hosts
202
+ /// (`ws www mtls edge api well-known`); governance or the initializer may add or remove.
203
+ mapping(bytes32 => bool) public isReservedLabel;
204
+ /// @notice labelhash → the label of an initialized TYPED root (any root whose kind is not
205
+ /// `KIND_AGENT`). A typed root's label is reserved under every parent, and is the suffix a
206
+ /// label under a bare-host root may not end in.
207
+ mapping(bytes32 => bool) public isTypedRootLabel;
208
+ /// @notice rootNode → does a name under this root take the bare host? Set at `initializeRoot`
209
+ /// from the kind (person or legacy ⇒ true); governance or the initializer may correct it.
210
+ mapping(bytes32 => bool) public rootTakesBareHost;
135
211
 
136
212
  // ─── Constructor (H7-C.4) ───────────────────────────────────────
137
213
 
@@ -141,9 +217,113 @@ contract AgentNameRegistry is GovernanceManaged {
141
217
  /// can't be frontrun. R6.8 added `governance_` so the
142
218
  /// registry can read the system pause flag through
143
219
  /// `GovernanceManaged._pausedSafe()`.
144
- 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 {
145
263
  if (initializer_ == address(0)) revert ZeroOwner();
146
264
  initializer = initializer_;
265
+ // The fixed infrastructure hosts (agent-naming `RESERVED_LABELS` minus the type words, which
266
+ // become reserved when their root is initialized).
267
+ _setReserved(keccak256("ws"), true);
268
+ _setReserved(keccak256("www"), true);
269
+ _setReserved(keccak256("mtls"), true);
270
+ _setReserved(keccak256("edge"), true);
271
+ _setReserved(keccak256("api"), true);
272
+ _setReserved(keccak256("well-known"), true);
273
+ }
274
+
275
+ // ─── Initializer hand-over (spec 445) ───────────────────────────
276
+
277
+ /// @notice Name the successor of the initializer role. One-shot: the caller gives the role up in
278
+ /// this call (it can neither initialize a root nor name another successor afterwards), and
279
+ /// nobody holds it until `to` accepts.
280
+ function transferInitializer(address to) external {
281
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
282
+ if (msg.sender != initializer) revert NotInitializer(msg.sender, initializer);
283
+ if (initializerHandedOver) revert InitializerAlreadyHandedOver();
284
+ if (to == address(0)) revert ZeroOwner();
285
+ initializerHandedOver = true;
286
+ pendingInitializer = to;
287
+ initializer = address(0);
288
+ emit InitializerTransferStarted(msg.sender, to);
289
+ }
290
+
291
+ /// @notice Take the initializer role. Only the successor named by `transferInitializer`.
292
+ function acceptInitializer() external {
293
+ address to = pendingInitializer;
294
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
295
+ if (to == address(0) || msg.sender != to) revert NotPendingInitializer(msg.sender);
296
+ pendingInitializer = address(0);
297
+ initializer = to;
298
+ emit InitializerTransferred(address(0), to);
299
+ }
300
+
301
+ // ─── Reserved labels / root host shape — naming administration ──
302
+
303
+ /// @dev Governance (the timelocked system authority) or the current initializer (the only account
304
+ /// that may create a root, so strictly the stronger role during bootstrap).
305
+ function _requireNamingAdmin() internal view {
306
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
307
+ if (msg.sender != governance() && (msg.sender != initializer || initializer == address(0))) revert NotAuthorized();
308
+ }
309
+
310
+ /// @notice Reserve or release labels, by labelhash. Affects FUTURE registrations only.
311
+ function setReservedLabels(bytes32[] calldata labelhashes, bool reserved) external {
312
+ _requireNamingAdmin();
313
+ for (uint256 i = 0; i < labelhashes.length; i++) _setReserved(labelhashes[i], reserved);
314
+ }
315
+
316
+ /// @notice Correct whether names under `rootNode` take the bare DNS host.
317
+ function setRootBareHost(bytes32 rootNode, bool takesBareHost) external {
318
+ _requireNamingAdmin();
319
+ if (!isRoot[rootNode]) revert NodeNotFound();
320
+ rootTakesBareHost[rootNode] = takesBareHost;
321
+ emit RootBareHostSet(rootNode, takesBareHost);
322
+ }
323
+
324
+ function _setReserved(bytes32 lh, bool reserved) internal {
325
+ isReservedLabel[lh] = reserved;
326
+ emit ReservedLabelSet(lh, reserved);
147
327
  }
148
328
 
149
329
  // ─── Namehash Helpers ───────────────────────────────────────────
@@ -160,6 +340,29 @@ contract AgentNameRegistry is GovernanceManaged {
160
340
  return keccak256(abi.encodePacked(bytes32(0), keccak256(bytes("agent"))));
161
341
  }
162
342
 
343
+ /// @notice AN-1-ONCHAIN — enforce the canonical single-label charset on chain. Mirrors the SDK
344
+ /// `normalizeLabel`: a single label of 1..63 bytes drawn from `[a-z0-9-]`, with no leading
345
+ /// or trailing `-`. Reverts `EmptyLabel` / `InvalidLabel`. Reusable from `register` +
346
+ /// `initializeRoot` so NO write path can anchor a non-canonical (squattable) label.
347
+ /// @return lastHyphen index of the last `-` in the label, or `type(uint256).max` when it has none
348
+ /// (NAME-8: the caller reads the type suffix a label ends in without a second pass).
349
+ function _validateLabel(bytes memory b) internal pure returns (uint256 lastHyphen) {
350
+ lastHyphen = type(uint256).max;
351
+ uint256 len = b.length;
352
+ if (len == 0) revert EmptyLabel();
353
+ if (len > 63) revert InvalidLabel();
354
+ // no leading / trailing hyphen (0x2d)
355
+ if (b[0] == 0x2d || b[len - 1] == 0x2d) revert InvalidLabel();
356
+ for (uint256 i = 0; i < len; i++) {
357
+ uint8 c = uint8(b[i]);
358
+ bool ok = (c >= 0x61 && c <= 0x7a) // a-z
359
+ || (c >= 0x30 && c <= 0x39) // 0-9
360
+ || c == 0x2d; // -
361
+ if (!ok) revert InvalidLabel();
362
+ if (c == 0x2d) lastHyphen = i;
363
+ }
364
+ }
365
+
163
366
  // ─── Root Initialization (multi-root) ───────────────────────────
164
367
 
165
368
  /**
@@ -178,9 +381,16 @@ contract AgentNameRegistry is GovernanceManaged {
178
381
  // H7-C.4 / CON-NAMING-001: only the immutable initializer may claim a
179
382
  // TLD. The deploy script bundles deploy+init in one transaction so no
180
383
  // frontrun window exists.
384
+ // Spec 445: `initializer` is zero between `transferInitializer` and `acceptInitializer`, and
385
+ // msg.sender is never zero, so nobody initializes during a hand-over.
386
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
181
387
  if (msg.sender != initializer) revert NotInitializer(msg.sender, initializer);
182
- if (bytes(label).length == 0) revert EmptyLabel();
388
+ // AN-1-ONCHAIN: canonical charset on chain. NAME-8: a root label carries no hyphen, so the
389
+ // typed host `<label>-<type>` splits one way only (the suffix is the segment after the LAST `-`).
390
+ if (_validateLabel(bytes(label)) != type(uint256).max) revert InvalidLabel();
183
391
  if (rootOwner == address(0)) revert ZeroOwner();
392
+ bytes32 rootLh = keccak256(bytes(label));
393
+ if (isReservedLabel[rootLh]) revert ReservedLabel();
184
394
  rootNode = namehashRoot(label);
185
395
  if (_records[rootNode].registeredAt != 0) revert RootAlreadyInitialized();
186
396
 
@@ -189,11 +399,20 @@ contract AgentNameRegistry is GovernanceManaged {
189
399
  resolver: resolverContract,
190
400
  subregistry: rootOwner,
191
401
  parent: bytes32(0),
192
- labelhash: keccak256(bytes(label)),
402
+ labelhash: rootLh,
193
403
  expiry: 0,
194
- registeredAt: uint64(block.timestamp)
404
+ registeredAt: uint64(block.timestamp),
405
+ epoch: 0
195
406
  });
196
407
 
408
+ // NAME-8: a typed root's label is reserved everywhere and is a refused suffix under a bare-host
409
+ // root; persons and the untyped legacy root take the bare host.
410
+ if (kind != KIND_AGENT) isTypedRootLabel[rootLh] = true;
411
+ if (kind == KIND_AGENT || kind == KIND_PERSON) {
412
+ rootTakesBareHost[rootNode] = true;
413
+ emit RootBareHostSet(rootNode, true);
414
+ }
415
+
197
416
  isRoot[rootNode] = true;
198
417
  rootKind[rootNode] = kind;
199
418
  _rootByLabel[label] = rootNode;
@@ -229,14 +448,27 @@ contract AgentNameRegistry is GovernanceManaged {
229
448
  address resolverContract,
230
449
  uint64 expiry
231
450
  ) external whenNotPaused returns (bytes32 childNode) {
232
- if (bytes(label).length == 0) revert EmptyLabel();
451
+ uint256 lastHyphen = _validateLabel(bytes(label)); // AN-1-ONCHAIN: canonical charset on chain
233
452
  if (newOwner == address(0)) revert ZeroOwner();
234
453
  _requireParentAuth(parentNode);
235
454
  _requireNotExpired(parentNode);
236
455
 
237
456
  bytes32 lh = keccak256(bytes(label));
457
+ // NAME-8 (spec 445 decision 6): reserved labels name no agent under any parent; under a root
458
+ // that takes the bare host, a label ending in `-<typed root>` is refused (`foo-org` under `.me`
459
+ // would share the DNS host of `foo.org`). No exception for the root owner.
460
+ if (isReservedLabel[lh] || isTypedRootLabel[lh]) revert ReservedLabel();
461
+ if (lastHyphen != type(uint256).max && rootTakesBareHost[parentNode]) {
462
+ if (isTypedRootLabel[keccak256(bytes(label)[lastHyphen + 1:])]) revert LabelReadsAsTypedName();
463
+ }
238
464
  childNode = keccak256(abi.encodePacked(parentNode, lh));
239
- if (_records[childNode].registeredAt != 0) revert NodeAlreadyExists();
465
+ // M2 (seam audit): an EXPIRED name is reclaimable (parent-authorized re-register). Only a LIVE
466
+ // record blocks re-registration — previously expiry was inert and a name could never be reclaimed.
467
+ bool reclaiming = _records[childNode].registeredAt != 0;
468
+ if (reclaiming && !isExpired(childNode)) revert NodeAlreadyExists();
469
+ // REG-4: a reclaim is a change of owner — the previous owner's resolver records must not carry
470
+ // over, so the node starts a new record epoch.
471
+ uint64 epoch = reclaiming ? _records[childNode].epoch + 1 : 0;
240
472
 
241
473
  _records[childNode] = NameRecord({
242
474
  owner: newOwner,
@@ -245,14 +477,17 @@ contract AgentNameRegistry is GovernanceManaged {
245
477
  parent: parentNode,
246
478
  labelhash: lh,
247
479
  expiry: expiry,
248
- registeredAt: uint64(block.timestamp)
480
+ registeredAt: uint64(block.timestamp),
481
+ epoch: epoch
249
482
  });
250
483
 
251
484
  _children[parentNode][lh] = childNode;
252
- _childLabels[parentNode].push(lh);
485
+ // Only index a brand-new child; a reclaim reuses the existing _childLabels entry (no duplicate).
486
+ if (!reclaiming) _childLabels[parentNode].push(lh);
253
487
  _label[childNode] = label;
254
488
 
255
489
  emit NameRegistered(childNode, parentNode, label, newOwner, resolverContract, expiry);
490
+ if (reclaiming) emit RecordEpochBumped(childNode, epoch);
256
491
  }
257
492
 
258
493
  /**
@@ -267,6 +502,7 @@ contract AgentNameRegistry is GovernanceManaged {
267
502
  if (keccak256(bytes(label_)) != _records[node].labelhash) revert NotAuthorized();
268
503
  if (bytes(_label[node]).length != 0) revert NotAuthorized();
269
504
  _label[node] = label_;
505
+ emit LabelBackfilled(node, label_);
270
506
  }
271
507
 
272
508
  // ─── Setters ────────────────────────────────────────────────────
@@ -274,7 +510,24 @@ contract AgentNameRegistry is GovernanceManaged {
274
510
  function setOwner(bytes32 node, address newOwner) external whenNotPaused {
275
511
  _requireNodeAuth(node);
276
512
  if (newOwner == address(0)) revert ZeroOwner();
277
- _records[node].owner = newOwner;
513
+ NameRecord storage r = _records[node];
514
+ if (newOwner != r.owner) {
515
+ // REG-4: records are the previous owner's statements (`atl:addr`, `atl:agentType`,
516
+ // endpoints). They stop resolving here; the new owner writes its own. The `resolver` and
517
+ // `subregistry` POINTERS are registry fields the new owner can read in one call and are
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
+ }
526
+ r.owner = newOwner;
527
+ uint64 epoch = r.epoch + 1;
528
+ r.epoch = epoch;
529
+ emit RecordEpochBumped(node, epoch);
530
+ }
278
531
  emit OwnerChanged(node, newOwner);
279
532
  }
280
533
 
@@ -290,9 +543,24 @@ contract AgentNameRegistry is GovernanceManaged {
290
543
  emit SubregistryChanged(node, subregistryContract);
291
544
  }
292
545
 
546
+ /**
547
+ * @notice Extend a name's expiry. REG-6: expiry is the PARENT's term, not the holder's — only the
548
+ * authority that may register under the parent (its owner or its subregistry) may renew, so
549
+ * a holder can neither strip the expiry it was given nor revive a name after it lapsed.
550
+ * Extension only: `newExpiry` is 0 (make permanent) or later than both the current expiry
551
+ * and now; a permanent name (expiry 0) cannot be given an expiry, and an expiry never moves
552
+ * earlier — otherwise a parent could expire and re-issue a live name, which is seizure.
553
+ * A root has no parent and no expiry; `renew` on it reverts.
554
+ */
293
555
  function renew(bytes32 node, uint64 newExpiry) external whenNotPaused {
294
- _requireNodeAuth(node);
295
- _records[node].expiry = newExpiry;
556
+ NameRecord storage r = _records[node];
557
+ if (r.registeredAt == 0) revert NodeNotFound();
558
+ _requireParentAuth(r.parent);
559
+ _requireNotExpired(r.parent);
560
+ uint64 cur = r.expiry;
561
+ if (cur == 0) revert ExpiryNotExtended();
562
+ if (newExpiry != 0 && (newExpiry <= cur || newExpiry <= block.timestamp)) revert ExpiryNotExtended();
563
+ r.expiry = newExpiry;
296
564
  emit NameRenewed(node, newExpiry);
297
565
  }
298
566
 
@@ -307,6 +575,7 @@ contract AgentNameRegistry is GovernanceManaged {
307
575
  // Storage default IS exactly 0; not a numeric precision concern.
308
576
  // slither-disable-next-line incorrect-equality
309
577
  if (node != bytes32(0) && _records[node].registeredAt == 0) revert NodeNotFound();
578
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
310
579
  _primaryName[msg.sender] = node;
311
580
  if (node == bytes32(0)) emit PrimaryNameCleared(msg.sender);
312
581
  else emit PrimaryNameSet(msg.sender, node);
@@ -327,8 +596,23 @@ contract AgentNameRegistry is GovernanceManaged {
327
596
  function parent(bytes32 node) external view returns (bytes32) { return _records[node].parent; }
328
597
  function labelhash(bytes32 node) external view returns (bytes32) { return _records[node].labelhash; }
329
598
  function expiry(bytes32 node) external view returns (uint64) { return _records[node].expiry; }
330
- function recordExists(bytes32 node) external view returns (bool) { return _records[node].registeredAt != 0; }
599
+ /// @dev M2 (seam audit): an EXPIRED record does NOT exist for read purposes — so the resolver
600
+ /// (resolveName/resolveString, which gate on recordExists) and any other reader stop resolving
601
+ /// an expired name. Expiry now provides real revocation, not a decorative field. Registry
602
+ /// mutators gate on the raw `registeredAt`/`isExpired`, not this, so re-registration is unaffected.
603
+ function recordExists(bytes32 node) external view returns (bool) {
604
+ return _records[node].registeredAt != 0 && !isExpired(node);
605
+ }
331
606
  function registeredAt(bytes32 node) external view returns (uint64) { return _records[node].registeredAt; }
607
+ /// @notice REG-4 — the node's owner epoch (0 until its owner first changes).
608
+ function recordEpoch(bytes32 node) external view returns (uint64) { return _records[node].epoch; }
609
+ /// @notice REG-4 / REG-6 — is the node live (registered and not expired), and under which owner
610
+ /// epoch? The one read a resolver needs to key a record; a view call, never a log scan.
611
+ function recordState(bytes32 node) external view returns (bool live, uint64 epoch) {
612
+ NameRecord storage r = _records[node];
613
+ live = r.registeredAt != 0 && !(r.expiry != 0 && block.timestamp > r.expiry);
614
+ epoch = r.epoch;
615
+ }
332
616
 
333
617
  function childNode(bytes32 parentNode, bytes32 lh) external view returns (bytes32) {
334
618
  return _children[parentNode][lh];
@@ -336,9 +620,21 @@ contract AgentNameRegistry is GovernanceManaged {
336
620
  function childCount(bytes32 parentNode) external view returns (uint256) {
337
621
  return _childLabels[parentNode].length;
338
622
  }
623
+ /// @dev REG-12: unbounded under a permissionless subregistry — a reader of a large root uses
624
+ /// `childLabelhashesPage`.
339
625
  function childLabelhashes(bytes32 parentNode) external view returns (bytes32[] memory) {
340
626
  return _childLabels[parentNode];
341
627
  }
628
+ /// @notice REG-12 — `limit` child labelhashes of `parentNode` from `offset` (fewer at the end).
629
+ function childLabelhashesPage(bytes32 parentNode, uint256 offset, uint256 limit) external view returns (bytes32[] memory page) {
630
+ bytes32[] storage all = _childLabels[parentNode];
631
+ uint256 n = all.length;
632
+ if (offset >= n) return new bytes32[](0);
633
+ uint256 end = offset + limit;
634
+ if (end > n) end = n;
635
+ page = new bytes32[](end - offset);
636
+ for (uint256 i = offset; i < end; i++) page[i - offset] = all[i];
637
+ }
342
638
  function isExpired(bytes32 node) public view returns (bool) {
343
639
  uint64 exp = _records[node].expiry;
344
640
  return exp != 0 && block.timestamp > exp;
@@ -356,12 +652,17 @@ contract AgentNameRegistry is GovernanceManaged {
356
652
  function _requireNodeAuth(bytes32 node) internal view {
357
653
  NameRecord storage r = _records[node];
358
654
  if (r.registeredAt == 0) revert NodeNotFound();
655
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
359
656
  if (msg.sender != r.owner) revert NotAuthorized();
657
+ // REG-6: an expired name is nobody's — its former owner cannot move it, re-point it or
658
+ // delegate under it while it waits to be reclaimed.
659
+ if (r.expiry != 0 && block.timestamp > r.expiry) revert NameExpired();
360
660
  }
361
661
 
362
662
  function _requireParentAuth(bytes32 parentNode) internal view {
363
663
  NameRecord storage r = _records[parentNode];
364
664
  if (r.registeredAt == 0) revert ParentNotFound();
665
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
365
666
  if (msg.sender == r.owner) return;
366
667
  if (r.subregistry != address(0) && msg.sender == r.subregistry) return;
367
668
  revert NotAuthorized();
@@ -370,5 +671,8 @@ contract AgentNameRegistry is GovernanceManaged {
370
671
  function _requireNotExpired(bytes32 node) internal view {
371
672
  if (isExpired(node)) revert NameExpired();
372
673
  }
373
- }
374
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
 
@@ -53,6 +57,8 @@ contract AgentNameUniversalResolver {
53
57
 
54
58
  /// @notice Resolve a single string-valued record by predicate id.
55
59
  function resolveString(bytes32 node, bytes32 predicate) external view returns (string memory) {
60
+ // REG-6: an expired or unregistered name answers nothing, for every record type.
61
+ if (!REGISTRY.recordExists(node)) return "";
56
62
  address resolverAddr = REGISTRY.resolver(node);
57
63
  if (resolverAddr == address(0)) return "";
58
64
  try AgentNameAttributeResolver(resolverAddr).getString(node, predicate) returns (string memory value) {
@@ -64,6 +70,8 @@ contract AgentNameUniversalResolver {
64
70
 
65
71
  /// @notice Resolve a single bytes32-valued record by predicate id.
66
72
  function resolveBytes32(bytes32 node, bytes32 predicate) external view returns (bytes32) {
73
+ // REG-6: an expired or unregistered name answers nothing, for every record type.
74
+ if (!REGISTRY.recordExists(node)) return bytes32(0);
67
75
  address resolverAddr = REGISTRY.resolver(node);
68
76
  if (resolverAddr == address(0)) return bytes32(0);
69
77
  try AgentNameAttributeResolver(resolverAddr).getBytes32(node, predicate) returns (bytes32 value) {
@@ -75,6 +83,8 @@ contract AgentNameUniversalResolver {
75
83
 
76
84
  /// @notice Resolve a single address-valued record by predicate id.
77
85
  function resolveAddress(bytes32 node, bytes32 predicate) external view returns (address) {
86
+ // REG-6: an expired or unregistered name answers nothing, for every record type.
87
+ if (!REGISTRY.recordExists(node)) return address(0);
78
88
  address resolverAddr = REGISTRY.resolver(node);
79
89
  if (resolverAddr == address(0)) return address(0);
80
90
  try AgentNameAttributeResolver(resolverAddr).getAddress(node, predicate) returns (address value) {
@@ -91,6 +101,7 @@ contract AgentNameUniversalResolver {
91
101
  returns (string[] memory values)
92
102
  {
93
103
  values = new string[](predicates.length);
104
+ if (!REGISTRY.recordExists(node)) return values; // REG-6
94
105
  address resolverAddr = REGISTRY.resolver(node);
95
106
  if (resolverAddr == address(0)) return values;
96
107
  for (uint256 i = 0; i < predicates.length; i++) {
@@ -155,6 +166,8 @@ contract AgentNameUniversalResolver {
155
166
  // Collect labels walking up to root. Bounded depth = 10 to
156
167
  // match the SDK's previous _reconstructName cap (no demo path
157
168
  // exceeds 4 — alice7.demo.agent is 3).
169
+ // A memory array is zero-initialized; entries are written before they are read (0..depth-1).
170
+ // slither-disable-next-line uninitialized-local
158
171
  string[10] memory labels;
159
172
  uint256 depth = 0;
160
173
  bytes32 cur = startNode;
@@ -166,6 +179,9 @@ contract AgentNameUniversalResolver {
166
179
  unchecked { depth++; }
167
180
  }
168
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 "";
169
185
 
170
186
  // Concatenate labels[0..depth-1] with '.' separators.
171
187
  uint256 totalLen = depth - 1; // for the dots
@@ -192,7 +208,24 @@ contract AgentNameUniversalResolver {
192
208
 
193
209
  // ─── Directory listing ──────────────────────────────────────────
194
210
 
211
+ /// @notice REG-12 — a bounded window of a node's children: `limit` entries from `offset`.
212
+ function getChildrenPage(bytes32 parentNode, uint256 offset, uint256 limit)
213
+ external
214
+ view
215
+ returns (bytes32[] memory childNodes, address[] memory owners)
216
+ {
217
+ bytes32[] memory labelhashes = REGISTRY.childLabelhashesPage(parentNode, offset, limit);
218
+ childNodes = new bytes32[](labelhashes.length);
219
+ owners = new address[](labelhashes.length);
220
+ for (uint256 i = 0; i < labelhashes.length; i++) {
221
+ bytes32 child = REGISTRY.childNode(parentNode, labelhashes[i]);
222
+ childNodes[i] = child;
223
+ owners[i] = REGISTRY.owner(child);
224
+ }
225
+ }
226
+
195
227
  /// @notice List a node's children and their resolved addresses.
228
+ /// @dev REG-12: one external call per child and unbounded — use `getChildrenPage` for a large root.
196
229
  function getChildren(bytes32 parentNode)
197
230
  external
198
231
  view