@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.
- package/AUDIT.md +36 -4
- package/dist/abi/AccountBootstrap.json +99 -0
- package/dist/abi/AgentAccount.json +95 -56
- package/dist/abi/AgentAccountFactory.json +189 -0
- package/dist/abi/AgentNameAttributeResolver.json +188 -0
- package/dist/abi/AgentNameRegistry.json +170 -0
- package/dist/abi/AgentNameUniversalResolver.json +188 -0
- package/dist/abi/AgentProfileResolver.json +188 -0
- package/dist/abi/AgentRegistryBase.json +193 -0
- package/dist/abi/AgentRelationship.json +193 -0
- package/dist/abi/AgenticGovernance.json +123 -0
- package/dist/abi/AgreementRegistry.json +193 -0
- package/dist/abi/AllowedMethodsEnforcer.json +193 -0
- package/dist/abi/AllowedTargetsEnforcer.json +193 -0
- package/dist/abi/ApprovedHashRegistry.json +220 -0
- package/dist/abi/AttestationRegistry.json +193 -0
- package/dist/abi/CallDataHashEnforcer.json +193 -0
- package/dist/abi/CustodyPolicy.json +195 -80
- package/dist/abi/DelegationManager.json +185 -0
- package/dist/abi/DigestBindingEnforcer.json +188 -0
- package/dist/abi/Eip7702.json +13 -0
- package/dist/abi/EstateProjectionRegistry.json +193 -0
- package/dist/abi/Generation5Bridge.json +355 -0
- package/dist/abi/GeoFeatureRegistry.json +193 -0
- package/dist/abi/ICustodyEpochView.json +28 -0
- package/dist/abi/IDelegationManager.json +18 -0
- package/dist/abi/IGeneration4Reads.json +143 -0
- package/dist/abi/IGeneration5Account.json +33 -0
- package/dist/abi/IGeneration5Voucher.json +26 -0
- package/dist/abi/IMoveAccountView.json +57 -0
- package/dist/abi/IMoveCustodyView.json +169 -0
- package/dist/abi/IMoveFactoryView.json +41 -0
- package/dist/abi/ITimelockVeto.json +93 -0
- package/dist/abi/OntologyTermRegistry.json +211 -0
- package/dist/abi/PayloadClassesEnforcer.json +193 -0
- package/dist/abi/PaymentEnforcer.json +188 -0
- package/dist/abi/PaymentEscrow.json +177 -0
- package/dist/abi/PaymentReceiptRegistry.json +206 -0
- package/dist/abi/PermissionlessSubregistry.json +188 -0
- package/dist/abi/PricedSubregistry.json +215 -0
- package/dist/abi/QuorumEnforcer.json +193 -0
- package/dist/abi/ReceiptAnchorRegistry.json +193 -0
- package/dist/abi/RelationshipTypeRegistry.json +211 -0
- package/dist/abi/ShapeRegistry.json +211 -0
- package/dist/abi/SignatureVerifier.json +196 -0
- package/dist/abi/SkillDefinitionRegistry.json +193 -0
- package/dist/abi/SmartAgentPaymaster.json +236 -1
- package/dist/abi/StableProxyGoverned.json +190 -0
- package/dist/abi/StableProxyGovernedOneShot.json +172 -0
- package/dist/abi/TimestampEnforcer.json +193 -0
- package/dist/abi/TreasurySpendPolicy.json +193 -0
- package/dist/abi/UpgradeVoucher.json +156 -4
- package/dist/abi/ValueEnforcer.json +193 -0
- package/dist/abi/index.d.ts +14 -0
- package/dist/abi/index.js +14 -0
- package/package.json +1 -1
- package/src/AccountBootstrap.sol +38 -0
- package/src/AgentAccount.sol +149 -41
- package/src/AgentAccountFactory.sol +52 -13
- package/src/ApprovedHashRegistry.sol +98 -9
- package/src/SmartAgentPaymaster.sol +96 -12
- package/src/UniversalSignatureValidator.sol +7 -0
- package/src/UpgradeVoucher.sol +16 -3
- package/src/agency/DelegationManager.sol +106 -32
- package/src/agency/IDelegationManager.sol +28 -0
- package/src/agreement/AgreementRegistry.sol +16 -15
- package/src/attestation/AttestationRegistry.sol +39 -16
- package/src/custody/CustodyPolicy.sol +36 -35
- package/src/custody/TreasurySpendPolicy.sol +10 -1
- package/src/enforcers/AllowedMethodsEnforcer.sol +7 -1
- package/src/enforcers/AllowedTargetsEnforcer.sol +7 -1
- package/src/enforcers/CallDataHashEnforcer.sol +7 -1
- package/src/enforcers/DigestBindingEnforcer.sol +5 -2
- package/src/enforcers/PayloadClassesEnforcer.sol +7 -1
- package/src/enforcers/PaymentEnforcer.sol +5 -2
- package/src/enforcers/QuorumEnforcer.sol +7 -1
- package/src/enforcers/TimestampEnforcer.sol +7 -1
- package/src/enforcers/ValueEnforcer.sol +7 -1
- package/src/geo/GeoFeatureRegistry.sol +15 -1
- package/src/governance/AgenticGovernance.sol +145 -0
- package/src/governance/GovernanceManaged.sol +2 -0
- package/src/governance/StableProxyGoverned.sol +79 -0
- package/src/governance/StableProxyGovernedOneShot.sol +93 -0
- package/src/identity/AgentProfileResolver.sol +11 -2
- package/src/libraries/Eip7702.sol +36 -0
- package/src/libraries/SignatureSlotRecovery.sol +4 -0
- package/src/libraries/SignatureVerifier.sol +52 -0
- package/src/libraries/WebAuthnLib.sol +3 -0
- package/src/migration/Generation5Bridge.sol +364 -0
- package/src/naming/AgentNameAttributeResolver.sol +12 -2
- package/src/naming/AgentNameRegistry.sol +84 -10
- package/src/naming/AgentNameUniversalResolver.sol +9 -2
- package/src/naming/PermissionlessSubregistry.sol +13 -2
- package/src/naming/PricedSubregistry.sol +59 -3
- package/src/ontology/OntologyTermRegistry.sol +30 -2
- package/src/ontology/ShapeRegistry.sol +30 -2
- package/src/payments/PaymentEscrow.sol +16 -1
- package/src/payments/PaymentReceiptRegistry.sol +28 -3
- package/src/provenance/ReceiptAnchorRegistry.sol +13 -1
- package/src/registry/AgentRegistryBase.sol +21 -1
- package/src/registry/EstateProjectionRegistry.sol +15 -1
- package/src/relationships/AgentRelationship.sol +17 -1
- package/src/relationships/RelationshipTypeRegistry.sol +30 -2
- package/src/skills/SkillDefinitionRegistry.sol +15 -1
|
@@ -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
|
|
@@ -49,7 +50,42 @@ import "./IGovernance.sol";
|
|
|
49
50
|
* an AgentAccount is exercised by any one of its credentials. `Deploy.s.sol` proves the lift for the
|
|
50
51
|
* roles it installs (`_assertPauseLiftable`); `test/governance/PauseIsLiftable445.t.sol` proves it
|
|
51
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).
|
|
52
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
|
+
|
|
53
89
|
contract AgenticGovernance is IGovernanceView {
|
|
54
90
|
// ─── Immutables ───────────────────────────────────────────────
|
|
55
91
|
|
|
@@ -79,6 +115,13 @@ contract AgenticGovernance is IGovernanceView {
|
|
|
79
115
|
error NotGuardian(address caller);
|
|
80
116
|
error ExecuteFailed(address target, bytes returndata);
|
|
81
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();
|
|
82
125
|
|
|
83
126
|
// ─── Events ───────────────────────────────────────────────────
|
|
84
127
|
|
|
@@ -88,6 +131,8 @@ contract AgenticGovernance is IGovernanceView {
|
|
|
88
131
|
event Executed(address indexed target, uint256 value, bytes data);
|
|
89
132
|
/// @notice GOV-1 — the guardian (fast-pause) role was rotated by the timelock.
|
|
90
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);
|
|
91
136
|
|
|
92
137
|
// ─── Constructor ──────────────────────────────────────────────
|
|
93
138
|
|
|
@@ -119,6 +164,7 @@ contract AgenticGovernance is IGovernanceView {
|
|
|
119
164
|
|
|
120
165
|
/// @notice Emergency pause. Callable by the guardian without delay.
|
|
121
166
|
function pause() external {
|
|
167
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
122
168
|
if (msg.sender != guardian) revert NotGuardian(msg.sender);
|
|
123
169
|
_paused = true;
|
|
124
170
|
emit Paused(msg.sender);
|
|
@@ -127,6 +173,7 @@ contract AgenticGovernance is IGovernanceView {
|
|
|
127
173
|
/// @notice Unpause. Requires the timelock (a deliberate 24h
|
|
128
174
|
/// decision); guardian alone cannot unpause.
|
|
129
175
|
function unpause() external {
|
|
176
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
130
177
|
if (msg.sender != timelock) revert NotTimelock(msg.sender);
|
|
131
178
|
_paused = false;
|
|
132
179
|
emit Unpaused(msg.sender);
|
|
@@ -143,9 +190,15 @@ contract AgenticGovernance is IGovernanceView {
|
|
|
143
190
|
payable
|
|
144
191
|
returns (bytes memory)
|
|
145
192
|
{
|
|
193
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
146
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);
|
|
147
199
|
(bool ok, bytes memory result) = target.call{value: value}(data);
|
|
148
200
|
if (!ok) revert ExecuteFailed(target, result);
|
|
201
|
+
if (upgrade && _systemWiring(target) != wiringBefore) revert UpgradeChangesSystemWiring(target); // audit C5-6
|
|
149
202
|
emit Executed(target, value, data);
|
|
150
203
|
return result;
|
|
151
204
|
}
|
|
@@ -153,6 +206,7 @@ contract AgenticGovernance is IGovernanceView {
|
|
|
153
206
|
/// @notice Add / remove a signer (consumed by `isSigner` reads from
|
|
154
207
|
/// downstream `GovernanceManaged` contracts).
|
|
155
208
|
function setSigner(address who, bool sig) external {
|
|
209
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
156
210
|
if (msg.sender != timelock) revert NotTimelock(msg.sender);
|
|
157
211
|
_signers[who] = sig;
|
|
158
212
|
emit SignerSet(who, sig);
|
|
@@ -165,13 +219,104 @@ contract AgenticGovernance is IGovernanceView {
|
|
|
165
219
|
/// address. Cannot be the zero address (would make `pause()` an
|
|
166
220
|
/// accidental no-op while looking live).
|
|
167
221
|
function setGuardian(address newGuardian) external {
|
|
222
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
168
223
|
if (msg.sender != timelock) revert NotTimelock(msg.sender);
|
|
169
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
|
|
170
226
|
address old = guardian;
|
|
171
227
|
guardian = newGuardian;
|
|
172
228
|
emit GuardianRotated(old, newGuardian);
|
|
173
229
|
}
|
|
174
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
|
+
|
|
175
320
|
// ─── Receive ETH ──────────────────────────────────────────────
|
|
176
321
|
|
|
177
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
|
+
}
|
|
@@ -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
|
-
|
|
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)));
|
|
@@ -202,4 +208,7 @@ contract AgentProfileResolver is AttributeStorage {
|
|
|
202
208
|
function subjectFor(address agent) external pure returns (bytes32) {
|
|
203
209
|
return bytes32(uint256(uint160(agent)));
|
|
204
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;
|
|
205
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
|
+
}
|
|
@@ -4,6 +4,7 @@ pragma solidity ^0.8.28;
|
|
|
4
4
|
import "../ApprovedHashRegistry.sol";
|
|
5
5
|
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
|
|
6
6
|
import {WebAuthnLib} from "./WebAuthnLib.sol";
|
|
7
|
+
import {Eip7702} from "./Eip7702.sol";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @title SignatureSlotRecovery
|
|
@@ -111,6 +112,9 @@ library SignatureSlotRecovery {
|
|
|
111
112
|
// (left-padded); s holds the offset into `signatures` to a
|
|
112
113
|
// (length, blob) tail.
|
|
113
114
|
signer = address(uint160(uint256(r)));
|
|
115
|
+
// Spec 448 §0 (EIP-7702): a delegated EOA's code was chosen by whoever got one authorization
|
|
116
|
+
// signature from its key, so it is never asked to vouch for a vote. Its vote is v = 27/28 or none.
|
|
117
|
+
Eip7702.refuseDelegatedEOA(signer);
|
|
114
118
|
uint256 sigOffset = uint256(s);
|
|
115
119
|
// H7-C.3 / CON-SIG-SLOT-001: bound the length-prefix read.
|
|
116
120
|
// sigOffset must leave room for the 32-byte length word.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.28;
|
|
3
|
+
|
|
4
|
+
import {WebAuthnLib} from "./WebAuthnLib.sol";
|
|
5
|
+
import {SignatureSlotRecovery} from "./SignatureSlotRecovery.sol";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @title SignatureVerifier
|
|
9
|
+
* @notice Spec 449 — the pure signature arithmetic of `AgentAccount` and `CustodyPolicy`, moved out of their
|
|
10
|
+
* bytecode so both keep room under EIP-170. Nothing here is new: each function is the library code the
|
|
11
|
+
* two contracts ran inline before, behind an external entry point.
|
|
12
|
+
*
|
|
13
|
+
* STATELESS. It has no storage, no owner, no constructor argument and no upgrade path. Every input comes
|
|
14
|
+
* from its caller; it reads nothing of anyone's except through the view calls the moved library code
|
|
15
|
+
* already made (the RIP-7212 precompile; for a quorum slot, the approved-hash registry the caller names
|
|
16
|
+
* and an ERC-1271 signer's `isValidSignature`). Its callers reach it by STATICCALL (their verifying
|
|
17
|
+
* functions are `view`), so nothing it runs can write.
|
|
18
|
+
*
|
|
19
|
+
* WHO TRUSTS IT. Only the contract that created it: `AgentAccount` and `CustodyPolicy` each create their
|
|
20
|
+
* own instance in their constructor and keep its address as an immutable. The address is therefore a
|
|
21
|
+
* function of the implementation's own address (CREATE, nonce 1) and part of the implementation's runtime
|
|
22
|
+
* code — what the upgrade voucher (an account implementation) or governance (the policy proxy's
|
|
23
|
+
* implementation) vouched. No caller, custodian or governance action can point either at another verifier.
|
|
24
|
+
* It grants nothing: it answers true/false or a recovered address, and the caller decides.
|
|
25
|
+
*/
|
|
26
|
+
contract SignatureVerifier {
|
|
27
|
+
/// @notice The credential an `AgentAccount` WebAuthn signature payload (`abi.encode(WebAuthnLib.Assertion)`)
|
|
28
|
+
/// names. Reverts on a payload that does not decode (the caller treats a revert as "invalid").
|
|
29
|
+
function credentialOf(bytes calldata payload) external pure returns (bytes32) {
|
|
30
|
+
return abi.decode(payload, (WebAuthnLib.Assertion)).credentialIdDigest;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/// @notice `WebAuthnLib.verify` over a decoded `payload`, with User Verification required.
|
|
34
|
+
function verifyWebAuthn(bytes calldata payload, bytes32 hash, uint256 x, uint256 y, bytes32 rpIdHash)
|
|
35
|
+
external
|
|
36
|
+
view
|
|
37
|
+
returns (bool)
|
|
38
|
+
{
|
|
39
|
+
return WebAuthnLib.verify(abi.decode(payload, (WebAuthnLib.Assertion)), hash, x, y, rpIdHash, true);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/// @notice `SignatureSlotRecovery.recoverFromSlot`, unchanged; its errors revert through this call verbatim.
|
|
43
|
+
function recoverFromSlot(
|
|
44
|
+
bytes32 payloadHash,
|
|
45
|
+
bytes calldata signatures,
|
|
46
|
+
uint256 index,
|
|
47
|
+
address approvedHashRegistry,
|
|
48
|
+
address passkeyScope
|
|
49
|
+
) external view returns (address) {
|
|
50
|
+
return SignatureSlotRecovery.recoverFromSlot(payloadHash, signatures, index, approvedHashRegistry, passkeyScope);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -126,6 +126,9 @@ library WebAuthnLib {
|
|
|
126
126
|
) private pure returns (bool) {
|
|
127
127
|
bytes memory buf = bytes(cdj);
|
|
128
128
|
bytes memory typeExpected = bytes('"type":"webauthn.get"');
|
|
129
|
+
// Audit 2026-12-02 C1-8 (ACCT-8): an index past the buffer is a malformed assertion — false, never an
|
|
130
|
+
// arithmetic panic (the sums below cannot overflow once each index is bounded by `buf.length`).
|
|
131
|
+
if (typeIndex > buf.length || challengeIndex > buf.length) return false;
|
|
129
132
|
if (typeIndex + typeExpected.length > buf.length) return false;
|
|
130
133
|
for (uint256 i; i < typeExpected.length; i++) {
|
|
131
134
|
if (buf[typeIndex + i] != typeExpected[i]) return false;
|