@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.
- package/AUDIT.md +119 -27
- package/README.md +47 -12
- package/deployments-base-sepolia.json +52 -1
- package/deployments-faithchain.json +103 -0
- package/deployments-hopechain.json +78 -0
- package/deployments-paymaster-anvil.json +1 -0
- package/deployments-registries-base-sepolia.json +1 -0
- package/deployments-registries-hopechain.json +1 -0
- package/dist/abi/AccountBootstrap.json +99 -0
- package/dist/abi/AgentAccount.json +461 -67
- package/dist/abi/AgentAccountFactory.json +309 -0
- package/dist/abi/AgentNameAttributeResolver.json +212 -0
- package/dist/abi/AgentNameRegistry.json +544 -0
- package/dist/abi/AgentNameUniversalResolver.json +222 -0
- package/dist/abi/AgentProfileResolver.json +236 -0
- package/dist/abi/AgentRegistryBase.json +1003 -0
- package/dist/abi/AgentRelationship.json +405 -0
- package/dist/abi/AgenticGovernance.json +155 -0
- package/dist/abi/AgreementRegistry.json +203 -5
- package/dist/abi/AllowedMethodsEnforcer.json +193 -0
- package/dist/abi/AllowedTargetsEnforcer.json +193 -0
- package/dist/abi/ApprovedHashRegistry.json +267 -2
- package/dist/abi/AttestationRegistry.json +242 -0
- package/dist/abi/AttributeStorage.json +24 -0
- package/dist/abi/CallDataHashEnforcer.json +193 -0
- package/dist/abi/CustodyPolicy.json +422 -55
- package/dist/abi/DelegationManager.json +292 -0
- package/dist/abi/DigestBindingEnforcer.json +541 -0
- package/dist/abi/Eip7702.json +13 -0
- package/dist/abi/EstateProjectionRegistry.json +599 -0
- package/dist/abi/Generation5Bridge.json +355 -0
- package/dist/abi/GeoFeatureRegistry.json +235 -0
- package/dist/abi/IAgentAccountFactoryView.json +26 -0
- package/dist/abi/IAgentAccountGovernanceTimelockView.json +15 -0
- package/dist/abi/IApprovedHashRegistryWrite.json +35 -0
- package/dist/abi/ICustodyEpochView.json +28 -0
- package/dist/abi/ICustodyPolicyAccountModuleView.json +31 -0
- package/dist/abi/ICustodyPolicyFactoryView.json +13 -0
- package/dist/abi/ICustodyPolicyPasskeyView.json +50 -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/IPaymentReceiptRegistry.json +50 -0
- package/dist/abi/IRedemptionContext.json +15 -0
- package/dist/abi/IRegistryMembershipPolicy.json +70 -0
- package/dist/abi/ITimelockVeto.json +93 -0
- package/dist/abi/ITreasurySpendPolicyAccountView.json +44 -0
- package/dist/abi/IUpgradeVoucherView.json +26 -0
- package/dist/abi/MockUSDC.json +621 -0
- package/dist/abi/OntologyTermRegistry.json +268 -0
- package/dist/abi/PayloadClassesEnforcer.json +310 -0
- package/dist/abi/PaymentEnforcer.json +639 -0
- package/dist/abi/PaymentEscrow.json +501 -0
- package/dist/abi/PaymentReceiptRegistry.json +388 -0
- package/dist/abi/PermissionlessSubregistry.json +353 -0
- package/dist/abi/PricedSubregistry.json +1141 -0
- package/dist/abi/QuorumEnforcer.json +209 -0
- package/dist/abi/ReceiptAnchorRegistry.json +346 -0
- package/dist/abi/RelationshipTypeRegistry.json +268 -0
- package/dist/abi/ShapeRegistry.json +268 -0
- package/dist/abi/SignatureVerifier.json +196 -0
- package/dist/abi/SkillDefinitionRegistry.json +235 -0
- package/dist/abi/SmartAgentPaymaster.json +445 -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 +667 -0
- package/dist/abi/UpgradeVoucher.json +328 -0
- package/dist/abi/ValueEnforcer.json +193 -0
- package/dist/abi/index.d.ts +35 -0
- package/dist/abi/index.js +35 -0
- package/dist/deployments/base-sepolia.d.ts +11 -0
- package/dist/deployments/base-sepolia.js +51 -28
- package/dist/deployments/faithchain.d.ts +77 -0
- package/dist/deployments/faithchain.js +107 -0
- package/dist/deployments/hopechain.d.ts +68 -0
- package/dist/deployments/hopechain.js +82 -0
- package/dist/deployments/index.d.ts +7 -2
- package/dist/deployments/index.js +15 -0
- package/dist/deployments/paymaster-anvil.d.ts +11 -0
- package/dist/deployments/paymaster-anvil.js +9 -0
- package/dist/deployments/registries-base-sepolia.d.ts +10 -0
- package/dist/deployments/registries-base-sepolia.js +8 -0
- package/dist/deployments/registries-hopechain.d.ts +10 -0
- package/dist/deployments/registries-hopechain.js +8 -0
- package/package.json +37 -7
- package/src/AccountBootstrap.sol +38 -0
- package/src/AgentAccount.sol +1091 -134
- package/src/AgentAccountFactory.sol +198 -21
- package/src/ApprovedHashRegistry.sol +134 -10
- package/src/IAgentAccount.sol +37 -0
- package/src/SmartAgentPaymaster.sol +275 -22
- package/src/UniversalSignatureValidator.sol +7 -0
- package/src/UpgradeVoucher.sol +87 -0
- package/src/agency/DelegationManager.sol +299 -76
- package/src/agency/ICaveatEnforcer.sol +10 -0
- package/src/agency/IDelegationManager.sol +37 -5
- package/src/agreement/AgreementRegistry.sol +105 -35
- package/src/attestation/AttestationRegistry.sol +220 -40
- package/src/custody/CustodyPolicy.sol +588 -70
- package/src/custody/TreasurySpendPolicy.sol +338 -0
- package/src/enforcers/AllowedMethodsEnforcer.sol +13 -2
- package/src/enforcers/AllowedTargetsEnforcer.sol +13 -2
- package/src/enforcers/CallDataHashEnforcer.sol +7 -1
- package/src/enforcers/DigestBindingEnforcer.sol +182 -0
- package/src/enforcers/PayloadClassesEnforcer.sol +36 -0
- package/src/enforcers/PaymentEnforcer.sol +291 -0
- package/src/enforcers/QuorumEnforcer.sol +24 -3
- package/src/enforcers/TimestampEnforcer.sol +7 -1
- package/src/enforcers/ValueEnforcer.sol +13 -2
- package/src/geo/GeoFeatureRegistry.sol +67 -22
- package/src/governance/AgenticGovernance.sol +187 -4
- package/src/governance/GovernanceManaged.sol +2 -0
- package/src/governance/StableProxyGoverned.sol +79 -0
- package/src/governance/StableProxyGovernedOneShot.sol +93 -0
- package/src/identity/AgentProfilePredicates.sol +23 -0
- package/src/identity/AgentProfileResolver.sol +22 -2
- package/src/libraries/Eip7702.sol +36 -0
- package/src/libraries/SignatureSlotRecovery.sol +28 -7
- package/src/libraries/SignatureVerifier.sol +52 -0
- package/src/libraries/WebAuthnLib.sol +16 -0
- package/src/migration/Generation5Bridge.sol +364 -0
- package/src/mocks/MockUSDC.sol +152 -0
- package/src/naming/AgentNameAttributeResolver.sol +29 -4
- package/src/naming/AgentNamePredicates.sol +89 -0
- package/src/naming/AgentNameRegistry.sol +324 -20
- package/src/naming/AgentNameUniversalResolver.sol +35 -2
- package/src/naming/PermissionlessSubregistry.sol +82 -25
- package/src/naming/PricedSubregistry.sol +293 -0
- package/src/ontology/AttributeStorage.sol +93 -80
- package/src/ontology/OntologyTermRegistry.sol +58 -2
- package/src/ontology/ShapeRegistry.sol +58 -2
- package/src/payments/PaymentEscrow.sol +187 -0
- package/src/payments/PaymentReceiptRegistry.sol +100 -0
- package/src/provenance/ReceiptAnchorRegistry.sol +67 -0
- package/src/registry/AgentRegistryBase.sol +372 -0
- package/src/registry/EstateProjectionRegistry.sol +177 -0
- package/src/registry/IRegistryMembershipPolicy.sol +30 -0
- package/src/relationships/AgentRelationship.sol +129 -8
- package/src/relationships/RelationshipTypeRegistry.sol +58 -2
- package/src/skills/SkillDefinitionRegistry.sol +61 -17
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.28;
|
|
3
|
+
import "../governance/StableProxyGoverned.sol";
|
|
4
|
+
import {Eip7702} from "../libraries/Eip7702.sol";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @title EstateProjectionRegistry — an estate's authority, projected onto PUBLIC GROUND (spec 410 §4)
|
|
8
|
+
* @notice One registry, many estates. An estate's grants and relationships are enforced on its own chain and
|
|
9
|
+
* held in its principals' vaults; a verifier elsewhere can read neither. What the estate anchors here
|
|
10
|
+
* is two Merkle roots over BLINDED commitments — the live-grant root (every grant currently live) and
|
|
11
|
+
* the membership root (every countersigned relationship credential) — plus the hash of its signed
|
|
12
|
+
* charter (spec 410 §9), under a monotonic sequence. A presentation against these roots tells a
|
|
13
|
+
* verifier in another estate that a grant is live or an agent is a member in that estate as of that
|
|
14
|
+
* sequence, and nothing else (the estate-projection SDK package).
|
|
15
|
+
*
|
|
16
|
+
* WHO MAY WRITE (generation 4, spec 445 / REG-2). ANYONE may anchor roots for an estate id — under
|
|
17
|
+
* THEIR OWN address. A row is keyed by `(estateId, signer)`, the pattern `ReceiptAnchorRegistry`
|
|
18
|
+
* adopted in spec 408 §1.5: WHO anchored is the evidence, never a gate. There is no registration to
|
|
19
|
+
* win and therefore nothing to squat: `estateId = keccak256("eip155:<chainId>:<governance>")` is
|
|
20
|
+
* predictable, and a stranger anchoring under it writes a row no verifier reads.
|
|
21
|
+
*
|
|
22
|
+
* WHICH ROW A VERIFIER READS. The estate says who its projection signer is, and the verifier reads
|
|
23
|
+
* exactly that row — `roots(estateId, signer)`:
|
|
24
|
+
* - the estate's agent declares it on the ESTATE'S OWN chain (`atl:projectionSigner`, spec 439
|
|
25
|
+
* F2.5). This is the only proof available across chains: public ground cannot call ERC-1271 on,
|
|
26
|
+
* or read the storage of, a governance account that lives on another chain.
|
|
27
|
+
* - when the estate's governance account lives on THIS chain, it can also say so here:
|
|
28
|
+
* `declareSigner(signer)` is callable only by the governance address the id is derived from
|
|
29
|
+
* (`estateIdOf(block.chainid, msg.sender)`), and `declaredSignerOf(estateId)` is then a proof
|
|
30
|
+
* this chain checked itself.
|
|
31
|
+
* A verifier that knows neither has no row to read; it never picks one by being first.
|
|
32
|
+
*
|
|
33
|
+
* ROTATION. The current signer retires its row with `rotateSigner(estateId, to)` — the old key can
|
|
34
|
+
* anchor nothing more, and the row names its successor and the sequence it stopped at, so a
|
|
35
|
+
* verifier can require the successor's sequence to continue above it. A LOST key needs no
|
|
36
|
+
* ceremony here at all: the estate re-declares a new signer (on its chain, or `declareSigner`) and
|
|
37
|
+
* that signer starts its own row. No admin, no pause, no upgrade, no recovery governor: public
|
|
38
|
+
* ground has no operator, and with rows keyed by signer it does not need one.
|
|
39
|
+
*
|
|
40
|
+
* `setRoots` takes a sequence strictly above the row's last (a replayed or reordered projection is
|
|
41
|
+
* refused) and at most `MAX_SEQUENCE_STEP` above it (a mistaken `type(uint64).max` cannot brick
|
|
42
|
+
* the row).
|
|
43
|
+
*
|
|
44
|
+
* WHAT THIS IS NOT: authority. A root proves what the estate vouches for at a moment; whether the
|
|
45
|
+
* receiving estate lets an agent ACT is its own mandate, per step (ADR-0056 / ADR-0057).
|
|
46
|
+
*/
|
|
47
|
+
contract EstateProjectionRegistry is StableProxyGoverned {
|
|
48
|
+
/// @notice Spec 447 — a DIRECT deployment, initialized here with no governance (its code is frozen, as
|
|
49
|
+
/// before). Behind a stable proxy, `initialize(governance_)` instead; the governance is then the only
|
|
50
|
+
/// upgrade authority. This contract has no admin of its own: governance can replace the code behind
|
|
51
|
+
/// the proxy and nothing else.
|
|
52
|
+
constructor() initializer {}
|
|
53
|
+
|
|
54
|
+
struct Roots {
|
|
55
|
+
bytes32 liveGrantRoot;
|
|
56
|
+
bytes32 membershipRoot;
|
|
57
|
+
bytes32 charterHash;
|
|
58
|
+
uint64 sequence;
|
|
59
|
+
uint64 anchoredAt;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/// @notice The furthest one `setRoots` may advance a row's sequence. Sequences are small counters (one
|
|
63
|
+
/// per revocation / membership change); this bounds an operator mistake, not honest use.
|
|
64
|
+
uint64 public constant MAX_SEQUENCE_STEP = 1 << 32;
|
|
65
|
+
|
|
66
|
+
/// estateId => signer => the roots that signer anchored. A stranger's row for the same estate id is a
|
|
67
|
+
/// different row: it can neither pre-empt the estate's nor be mistaken for it.
|
|
68
|
+
mapping(bytes32 estateId => mapping(address signer => Roots)) private _roots;
|
|
69
|
+
/// estateId => signer => the successor it rotated to (non-zero ⇒ the row is retired).
|
|
70
|
+
mapping(bytes32 estateId => mapping(address signer => address)) public successorOf;
|
|
71
|
+
/// estateId => the signer declared by the estate's governance account ON THIS CHAIN (zero when the
|
|
72
|
+
/// governance lives elsewhere or has not declared).
|
|
73
|
+
mapping(bytes32 estateId => address signer) public declaredSignerOf;
|
|
74
|
+
|
|
75
|
+
event EstateRegistered(bytes32 indexed estateId, address indexed signer);
|
|
76
|
+
event EstateSignerRotated(bytes32 indexed estateId, address indexed from, address indexed to);
|
|
77
|
+
event EstateSignerDeclared(bytes32 indexed estateId, address indexed governance, address indexed signer);
|
|
78
|
+
event RootsAnchored(bytes32 indexed estateId, address indexed signer, uint64 indexed sequence, bytes32 liveGrantRoot, bytes32 membershipRoot, bytes32 charterHash);
|
|
79
|
+
|
|
80
|
+
error NotRegistered(bytes32 estateId, address signer);
|
|
81
|
+
error SignerRetired(bytes32 estateId, address signer, address successor);
|
|
82
|
+
error SequenceNotAbove(uint64 last, uint64 given);
|
|
83
|
+
error SequenceStepTooLarge(uint64 last, uint64 given);
|
|
84
|
+
error ZeroAddress();
|
|
85
|
+
|
|
86
|
+
/// @notice Anchor the caller's roots for `estateId` under `sequence` (strictly above the caller's last,
|
|
87
|
+
/// by at most `MAX_SEQUENCE_STEP`). The first anchor opens the caller's row. Refreshed on every
|
|
88
|
+
/// revocation and membership change; a verifier's freshness policy reads `anchoredAt`.
|
|
89
|
+
function setRoots(bytes32 estateId, bytes32 liveGrantRoot, bytes32 membershipRoot, bytes32 charterHash, uint64 sequence) external {
|
|
90
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
91
|
+
address successor = successorOf[estateId][msg.sender];
|
|
92
|
+
if (successor != address(0)) revert SignerRetired(estateId, msg.sender, successor);
|
|
93
|
+
Roots storage r = _roots[estateId][msg.sender];
|
|
94
|
+
uint64 last = r.sequence;
|
|
95
|
+
if (sequence <= last) revert SequenceNotAbove(last, sequence);
|
|
96
|
+
if (sequence - last > MAX_SEQUENCE_STEP) revert SequenceStepTooLarge(last, sequence);
|
|
97
|
+
// slither-disable-next-line incorrect-equality
|
|
98
|
+
if (r.anchoredAt == 0) emit EstateRegistered(estateId, msg.sender); // first-anchor sentinel
|
|
99
|
+
r.liveGrantRoot = liveGrantRoot;
|
|
100
|
+
r.membershipRoot = membershipRoot;
|
|
101
|
+
r.charterHash = charterHash;
|
|
102
|
+
r.sequence = sequence;
|
|
103
|
+
r.anchoredAt = uint64(block.timestamp);
|
|
104
|
+
emit RootsAnchored(estateId, msg.sender, sequence, liveGrantRoot, membershipRoot, charterHash);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/// @notice Retire the caller's row for `estateId` and name its successor. The caller must have anchored
|
|
108
|
+
/// at least once; afterwards it can anchor nothing under this estate id. This writes NOTHING
|
|
109
|
+
/// into the successor's row (a stranger rotating "to" the estate's real signer changes nothing
|
|
110
|
+
/// for it) — the successor anchors for itself, and the estate's declaration is what makes a
|
|
111
|
+
/// verifier read it.
|
|
112
|
+
function rotateSigner(bytes32 estateId, address to) external {
|
|
113
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
114
|
+
if (to == address(0) || to == msg.sender) revert ZeroAddress();
|
|
115
|
+
// `anchoredAt == 0` is the "this signer never anchored" sentinel (storage default), not arithmetic.
|
|
116
|
+
// slither-disable-next-line incorrect-equality
|
|
117
|
+
if (_roots[estateId][msg.sender].anchoredAt == 0) revert NotRegistered(estateId, msg.sender);
|
|
118
|
+
address successor = successorOf[estateId][msg.sender];
|
|
119
|
+
if (successor != address(0)) revert SignerRetired(estateId, msg.sender, successor);
|
|
120
|
+
successorOf[estateId][msg.sender] = to;
|
|
121
|
+
emit EstateSignerRotated(estateId, msg.sender, to);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/// @notice Same-chain proof: the governance account an estate id is derived from names its projection
|
|
125
|
+
/// signer. Only meaningful for an estate whose governance lives on this chain — the id is
|
|
126
|
+
/// computed from `msg.sender` and `block.chainid`, so nobody can declare for another estate.
|
|
127
|
+
/// Callable again to re-declare (rotation, or a lost key); zero clears the declaration.
|
|
128
|
+
function declareSigner(address signer) external returns (bytes32 estateId) {
|
|
129
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
130
|
+
estateId = estateIdOf(block.chainid, msg.sender);
|
|
131
|
+
declaredSignerOf[estateId] = signer;
|
|
132
|
+
emit EstateSignerDeclared(estateId, msg.sender, signer);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/// @notice The one read a verifier makes: the roots `signer` anchored for `estateId`, with the sequence
|
|
136
|
+
/// and when. Zeros when that signer anchored nothing. The verifier names the signer from the
|
|
137
|
+
/// estate's own declaration and decides what absence means.
|
|
138
|
+
function roots(bytes32 estateId, address signer) external view returns (bytes32 liveGrantRoot, bytes32 membershipRoot, bytes32 charterHash, uint64 sequence, uint64 anchoredAt) {
|
|
139
|
+
Roots storage r = _roots[estateId][signer];
|
|
140
|
+
return (r.liveGrantRoot, r.membershipRoot, r.charterHash, r.sequence, r.anchoredAt);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/// @notice Has `signer` retired its row for `estateId`? A retired row keeps its last roots readable
|
|
144
|
+
/// (history), but a verifier MUST NOT accept a presentation against it.
|
|
145
|
+
function isRetired(bytes32 estateId, address signer) external view returns (bool) {
|
|
146
|
+
return successorOf[estateId][signer] != address(0);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/// @notice keccak256("eip155:<chainId>:<governance>") — the same derivation the SDK's `estateIdOf` uses.
|
|
150
|
+
function estateIdOf(uint256 chainId, address governance) public pure returns (bytes32) {
|
|
151
|
+
return keccak256(abi.encodePacked("eip155:", _utoa(chainId), ":", _lowerHex(governance)));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function _utoa(uint256 v) private pure returns (string memory) {
|
|
155
|
+
if (v == 0) return "0";
|
|
156
|
+
uint256 j = v; uint256 len;
|
|
157
|
+
while (j != 0) { len++; j /= 10; }
|
|
158
|
+
bytes memory b = new bytes(len);
|
|
159
|
+
while (v != 0) { len -= 1; b[len] = bytes1(uint8(48 + v % 10)); v /= 10; }
|
|
160
|
+
return string(b);
|
|
161
|
+
}
|
|
162
|
+
function _lowerHex(address a) private pure returns (string memory) {
|
|
163
|
+
bytes memory alphabet = "0123456789abcdef";
|
|
164
|
+
bytes memory s = new bytes(42);
|
|
165
|
+
s[0] = "0"; s[1] = "x";
|
|
166
|
+
uint160 v = uint160(a);
|
|
167
|
+
for (uint256 i = 0; i < 20; i++) {
|
|
168
|
+
uint8 bt = uint8(v >> (8 * (19 - i)));
|
|
169
|
+
s[2 + i * 2] = alphabet[bt >> 4];
|
|
170
|
+
s[3 + i * 2] = alphabet[bt & 0x0f];
|
|
171
|
+
}
|
|
172
|
+
return string(s);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/// @dev Spec 447 — storage gap: the contract may sit behind a stable proxy; layout gated by `check:storage-layouts`.
|
|
176
|
+
uint256[47] private __gap;
|
|
177
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.28;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @title IRegistryMembershipPolicy
|
|
6
|
+
* @notice Pluggable membership/validation hook for {AgentRegistryBase} (spec 279 §4.2). It answers two
|
|
7
|
+
* yes/no questions and NOTHING else:
|
|
8
|
+
*
|
|
9
|
+
* - `canRegister` — may `subjectAgent` create `entryId` in `registryId` with these claims?
|
|
10
|
+
* - `canAdminister` — may a NON-subject `actor` suspend / revoke / update `entryId`?
|
|
11
|
+
*
|
|
12
|
+
* Implementations live OUTSIDE Ring 0 (issuer-attested, stake/bond, quorum-approved,
|
|
13
|
+
* domain-control-proof, skill-claim-proof, …) — they MUST NOT push vertical business logic into
|
|
14
|
+
* the registry base. Both methods are `view`, so {AgentRegistryBase} reaches them via STATICCALL
|
|
15
|
+
* (no state mutation, no reentrancy). A policy that returns `false` OR reverts is treated as a
|
|
16
|
+
* denial: the base fails closed (ADR-0013) — there is no second, weaker authorization path.
|
|
17
|
+
*/
|
|
18
|
+
interface IRegistryMembershipPolicy {
|
|
19
|
+
/// @return ok whether `subjectAgent` may register `entryId` in `registryId` with `cardHash`/`claimHashes`.
|
|
20
|
+
function canRegister(
|
|
21
|
+
bytes32 registryId,
|
|
22
|
+
bytes32 entryId,
|
|
23
|
+
address subjectAgent,
|
|
24
|
+
bytes32 cardHash,
|
|
25
|
+
bytes32[] calldata claimHashes
|
|
26
|
+
) external view returns (bool ok);
|
|
27
|
+
|
|
28
|
+
/// @return ok whether `actor` (not the entry's subject) may administer (suspend / revoke / update) the entry.
|
|
29
|
+
function canAdminister(bytes32 registryId, bytes32 entryId, address actor) external view returns (bool ok);
|
|
30
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
|
+
import "../governance/StableProxyGoverned.sol";
|
|
4
|
+
import {Eip7702} from "../libraries/Eip7702.sol";
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* @title AgentRelationship
|
|
@@ -41,7 +43,13 @@ pragma solidity ^0.8.28;
|
|
|
41
43
|
// Disabling Slither's `incorrect-equality` at the contract scope
|
|
42
44
|
// keeps these inline reads idiomatic.
|
|
43
45
|
// slither-disable-start incorrect-equality
|
|
44
|
-
contract AgentRelationship {
|
|
46
|
+
contract AgentRelationship is StableProxyGoverned {
|
|
47
|
+
/// @notice Spec 447 — a DIRECT deployment, initialized here with no governance (its code is frozen, as
|
|
48
|
+
/// before). Behind a stable proxy, `initialize(governance_)` instead; the governance is then the only
|
|
49
|
+
/// upgrade authority. This contract has no admin of its own: governance can replace the code behind
|
|
50
|
+
/// the proxy and nothing else.
|
|
51
|
+
constructor() initializer {}
|
|
52
|
+
|
|
45
53
|
enum EdgeStatus {
|
|
46
54
|
NONE, // 0 — never set (sentinel)
|
|
47
55
|
PROPOSED, // 1
|
|
@@ -97,6 +105,25 @@ contract AgentRelationship {
|
|
|
97
105
|
error RoleNotFound();
|
|
98
106
|
error NotAuthorized();
|
|
99
107
|
error InvalidTransition();
|
|
108
|
+
/// @notice REG-9 — more than `MAX_ROLES` roles on one edge.
|
|
109
|
+
error TooManyRoles();
|
|
110
|
+
/// @notice REG-9 — the caller already proposed this role; the COUNTERPARTY must call `addRole` to accept it.
|
|
111
|
+
error RoleAwaitingCounterparty();
|
|
112
|
+
|
|
113
|
+
/// @notice REG-9 — a role proposed on a confirmed edge; it joins the edge when the counterparty also
|
|
114
|
+
/// calls `addRole(edgeId, role)`.
|
|
115
|
+
event RoleProposed(bytes32 indexed edgeId, bytes32 indexed role, address indexed proposer);
|
|
116
|
+
event RoleProposalWithdrawn(bytes32 indexed edgeId, bytes32 indexed role, address indexed proposer);
|
|
117
|
+
/// @notice REG-9 — a REVOKED triple was proposed again (a new life for the same edge id).
|
|
118
|
+
event EdgeReproposed(bytes32 indexed edgeId, uint32 generation);
|
|
119
|
+
|
|
120
|
+
/// @notice REG-9 — the role bag is bounded (a re-proposal clears it in one loop).
|
|
121
|
+
uint256 public constant MAX_ROLES = 32;
|
|
122
|
+
|
|
123
|
+
/// @dev edgeId → how many times the triple has been re-proposed after a revocation.
|
|
124
|
+
mapping(bytes32 => uint32) private _generation;
|
|
125
|
+
/// @dev edgeId → generation → role → who proposed it on a confirmed edge (zero = no open proposal).
|
|
126
|
+
mapping(bytes32 => mapping(uint32 => mapping(bytes32 => address))) private _roleProposedBy;
|
|
100
127
|
|
|
101
128
|
// ─── Edge ID ────────────────────────────────────────────────────
|
|
102
129
|
|
|
@@ -136,9 +163,26 @@ contract AgentRelationship {
|
|
|
136
163
|
) external returns (bytes32 edgeId) {
|
|
137
164
|
if (subject == address(0) || object_ == address(0)) revert InvalidEdge();
|
|
138
165
|
if (subject == object_) revert InvalidEdge();
|
|
166
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
139
167
|
if (msg.sender != subject) revert NotAuthorized();
|
|
140
168
|
edgeId = computeEdgeId(subject, object_, relationshipType);
|
|
141
|
-
|
|
169
|
+
bool reproposal = false;
|
|
170
|
+
if (_edges[edgeId].createdAt != 0) {
|
|
171
|
+
// REG-9: REVOKED was terminal FOR EVER, so two agents who ended a relationship could never
|
|
172
|
+
// state it again. A revoked triple may be proposed anew by its subject; it starts over at
|
|
173
|
+
// PROPOSED with an empty role bag, and the object must confirm again. Any other status is live.
|
|
174
|
+
if (_edges[edgeId].status != EdgeStatus.REVOKED) revert EdgeAlreadyExists();
|
|
175
|
+
reproposal = true;
|
|
176
|
+
bytes32[] storage old = _roles[edgeId];
|
|
177
|
+
for (uint256 i = old.length; i > 0; i--) {
|
|
178
|
+
_hasRole[edgeId][old[i - 1]] = false;
|
|
179
|
+
old.pop();
|
|
180
|
+
}
|
|
181
|
+
uint32 g = _generation[edgeId] + 1;
|
|
182
|
+
_generation[edgeId] = g; // open role proposals of the previous life are unreachable
|
|
183
|
+
emit EdgeReproposed(edgeId, g);
|
|
184
|
+
}
|
|
185
|
+
if (initialRoles.length > MAX_ROLES) revert TooManyRoles();
|
|
142
186
|
|
|
143
187
|
_edges[edgeId] = Edge({
|
|
144
188
|
edgeId: edgeId,
|
|
@@ -153,11 +197,14 @@ contract AgentRelationship {
|
|
|
153
197
|
metadataHash: metadataHash
|
|
154
198
|
});
|
|
155
199
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
200
|
+
if (!reproposal) {
|
|
201
|
+
_edgesBySubject[subject].push(edgeId);
|
|
202
|
+
_edgesByObject[object_].push(edgeId);
|
|
203
|
+
_byTriple[subject][object_][relationshipType] = edgeId;
|
|
204
|
+
}
|
|
159
205
|
|
|
160
206
|
for (uint256 i = 0; i < initialRoles.length; i++) {
|
|
207
|
+
if (_hasRole[edgeId][initialRoles[i]]) revert RoleAlreadyExists();
|
|
161
208
|
_addRole(edgeId, initialRoles[i]);
|
|
162
209
|
emit RoleAdded(edgeId, initialRoles[i], msg.sender);
|
|
163
210
|
}
|
|
@@ -175,6 +222,7 @@ contract AgentRelationship {
|
|
|
175
222
|
Edge storage e = _edges[edgeId];
|
|
176
223
|
if (e.createdAt == 0) revert EdgeNotFound();
|
|
177
224
|
if (e.status != EdgeStatus.PROPOSED) revert InvalidTransition();
|
|
225
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
178
226
|
if (msg.sender != e.object_) revert NotAuthorized();
|
|
179
227
|
e.status = EdgeStatus.CONFIRMED;
|
|
180
228
|
e.updatedAt = uint64(block.timestamp);
|
|
@@ -190,6 +238,7 @@ contract AgentRelationship {
|
|
|
190
238
|
Edge storage e = _edges[edgeId];
|
|
191
239
|
if (e.createdAt == 0) revert EdgeNotFound();
|
|
192
240
|
if (e.status != EdgeStatus.CONFIRMED) revert InvalidTransition();
|
|
241
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
193
242
|
if (msg.sender != e.subject && msg.sender != e.object_) revert NotAuthorized();
|
|
194
243
|
e.status = EdgeStatus.ACTIVE;
|
|
195
244
|
e.updatedAt = uint64(block.timestamp);
|
|
@@ -214,35 +263,80 @@ contract AgentRelationship {
|
|
|
214
263
|
// ─── Roles ──────────────────────────────────────────────────────
|
|
215
264
|
|
|
216
265
|
/**
|
|
217
|
-
* @notice Add a role to an
|
|
218
|
-
*
|
|
266
|
+
* @notice Add a role to an edge (spec 445 / REG-9).
|
|
267
|
+
*
|
|
268
|
+
* - PROPOSED: the proposal is the subject's, so only the SUBJECT adds — the object's levers are
|
|
269
|
+
* confirm and revoke, and what it confirms is what the subject wrote.
|
|
270
|
+
* - CONFIRMED / ACTIVE: the edge says "both agreed", so a new role needs BOTH. The first party's
|
|
271
|
+
* call records a proposal (`RoleProposed`); the role joins the edge when the counterparty makes
|
|
272
|
+
* the same call. Previously either party could add `TREASURER` to an edge the other had only
|
|
273
|
+
* confirmed as `MEMBER`, and the edge still read as confirmed.
|
|
274
|
+
* - REVOKED: nothing changes on a revoked edge.
|
|
219
275
|
*/
|
|
220
276
|
function addRole(bytes32 edgeId, bytes32 role) external {
|
|
221
277
|
Edge storage e = _edges[edgeId];
|
|
222
278
|
if (e.createdAt == 0) revert EdgeNotFound();
|
|
279
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
223
280
|
if (msg.sender != e.subject && msg.sender != e.object_) revert NotAuthorized();
|
|
281
|
+
if (e.status == EdgeStatus.REVOKED) revert InvalidTransition();
|
|
224
282
|
if (_hasRole[edgeId][role]) revert RoleAlreadyExists();
|
|
283
|
+
if (e.status == EdgeStatus.PROPOSED) {
|
|
284
|
+
if (msg.sender != e.subject) revert NotAuthorized();
|
|
285
|
+
} else {
|
|
286
|
+
uint32 g = _generation[edgeId];
|
|
287
|
+
address proposer = _roleProposedBy[edgeId][g][role];
|
|
288
|
+
if (proposer == address(0)) {
|
|
289
|
+
_roleProposedBy[edgeId][g][role] = msg.sender;
|
|
290
|
+
emit RoleProposed(edgeId, role, msg.sender);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (proposer == msg.sender) revert RoleAwaitingCounterparty();
|
|
294
|
+
delete _roleProposedBy[edgeId][g][role];
|
|
295
|
+
}
|
|
296
|
+
if (_roles[edgeId].length >= MAX_ROLES) revert TooManyRoles();
|
|
225
297
|
_addRole(edgeId, role);
|
|
226
298
|
e.updatedAt = uint64(block.timestamp);
|
|
227
299
|
emit RoleAdded(edgeId, role, msg.sender);
|
|
228
300
|
}
|
|
229
301
|
|
|
302
|
+
/**
|
|
303
|
+
* @notice Remove a role — a reduction, so either party may do it alone on a live edge (either may
|
|
304
|
+
* revoke the whole edge alone). Also withdraws the caller's own open role proposal.
|
|
305
|
+
*/
|
|
230
306
|
function removeRole(bytes32 edgeId, bytes32 role) external {
|
|
231
307
|
Edge storage e = _edges[edgeId];
|
|
232
308
|
if (e.createdAt == 0) revert EdgeNotFound();
|
|
233
309
|
if (msg.sender != e.subject && msg.sender != e.object_) revert NotAuthorized();
|
|
234
|
-
if (
|
|
310
|
+
if (e.status == EdgeStatus.REVOKED) revert InvalidTransition();
|
|
311
|
+
if (!_hasRole[edgeId][role]) {
|
|
312
|
+
uint32 g = _generation[edgeId];
|
|
313
|
+
if (_roleProposedBy[edgeId][g][role] != msg.sender) revert RoleNotFound();
|
|
314
|
+
delete _roleProposedBy[edgeId][g][role];
|
|
315
|
+
emit RoleProposalWithdrawn(edgeId, role, msg.sender);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
235
318
|
_removeRole(edgeId, role);
|
|
236
319
|
e.updatedAt = uint64(block.timestamp);
|
|
237
320
|
emit RoleRemoved(edgeId, role, msg.sender);
|
|
238
321
|
}
|
|
239
322
|
|
|
323
|
+
/// @notice Who proposed `role` on this (confirmed) edge and is waiting for the counterparty; zero if nobody.
|
|
324
|
+
function roleProposedBy(bytes32 edgeId, bytes32 role) external view returns (address) {
|
|
325
|
+
return _roleProposedBy[edgeId][_generation[edgeId]][role];
|
|
326
|
+
}
|
|
327
|
+
|
|
240
328
|
// ─── Metadata ───────────────────────────────────────────────────
|
|
241
329
|
|
|
330
|
+
/// @dev While PROPOSED the metadata is the subject's proposal; afterwards either party may update it
|
|
331
|
+
/// (the event names the updater — metadata is descriptive, roles are what an edge asserts).
|
|
332
|
+
/// Nothing changes on a REVOKED edge.
|
|
242
333
|
function setMetadata(bytes32 edgeId, string calldata metadataURI, bytes32 metadataHash) external {
|
|
243
334
|
Edge storage e = _edges[edgeId];
|
|
244
335
|
if (e.createdAt == 0) revert EdgeNotFound();
|
|
336
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
245
337
|
if (msg.sender != e.subject && msg.sender != e.object_) revert NotAuthorized();
|
|
338
|
+
if (e.status == EdgeStatus.REVOKED) revert InvalidTransition();
|
|
339
|
+
if (e.status == EdgeStatus.PROPOSED && msg.sender != e.subject) revert NotAuthorized();
|
|
246
340
|
e.metadataURI = metadataURI;
|
|
247
341
|
e.metadataHash = metadataHash;
|
|
248
342
|
e.updatedAt = uint64(block.timestamp);
|
|
@@ -268,6 +362,30 @@ contract AgentRelationship {
|
|
|
268
362
|
function getEdgesByObject(address object_) external view returns (bytes32[] memory) {
|
|
269
363
|
return _edgesByObject[object_];
|
|
270
364
|
}
|
|
365
|
+
function edgeCountBySubject(address subject) external view returns (uint256) {
|
|
366
|
+
return _edgesBySubject[subject].length;
|
|
367
|
+
}
|
|
368
|
+
function edgeCountByObject(address object_) external view returns (uint256) {
|
|
369
|
+
return _edgesByObject[object_].length;
|
|
370
|
+
}
|
|
371
|
+
/// @notice REG-12 — a bounded window of a subject's edges. `getEdgesBySubject` is unbounded.
|
|
372
|
+
function getEdgesBySubjectPage(address subject, uint256 offset, uint256 limit) external view returns (bytes32[] memory) {
|
|
373
|
+
return _page(_edgesBySubject[subject], offset, limit);
|
|
374
|
+
}
|
|
375
|
+
/// @notice REG-12 — a bounded window of the edges naming `object_`. `getEdgesByObject` is unbounded and
|
|
376
|
+
/// grows by one for every UNSOLICITED proposal naming the object (anyone can extend it), so a
|
|
377
|
+
/// reader of a popular agent uses this.
|
|
378
|
+
function getEdgesByObjectPage(address object_, uint256 offset, uint256 limit) external view returns (bytes32[] memory) {
|
|
379
|
+
return _page(_edgesByObject[object_], offset, limit);
|
|
380
|
+
}
|
|
381
|
+
function _page(bytes32[] storage all, uint256 offset, uint256 limit) private view returns (bytes32[] memory page) {
|
|
382
|
+
uint256 n = all.length;
|
|
383
|
+
if (offset >= n) return new bytes32[](0);
|
|
384
|
+
uint256 end = offset + limit;
|
|
385
|
+
if (end > n) end = n;
|
|
386
|
+
page = new bytes32[](end - offset);
|
|
387
|
+
for (uint256 i = offset; i < end; i++) page[i - offset] = all[i];
|
|
388
|
+
}
|
|
271
389
|
function getEdgeByTriple(address subject, address object_, bytes32 relationshipType) external view returns (bytes32) {
|
|
272
390
|
return _byTriple[subject][object_][relationshipType];
|
|
273
391
|
}
|
|
@@ -293,5 +411,8 @@ contract AgentRelationship {
|
|
|
293
411
|
}
|
|
294
412
|
}
|
|
295
413
|
}
|
|
414
|
+
|
|
415
|
+
/// @dev Spec 447 — storage gap: the contract may sit behind a stable proxy; layout gated by `check:storage-layouts`.
|
|
416
|
+
uint256[42] private __gap;
|
|
296
417
|
}
|
|
297
418
|
// slither-disable-end incorrect-equality
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.28;
|
|
3
|
+
import "../governance/StableProxyGoverned.sol";
|
|
4
|
+
import {Eip7702} from "../libraries/Eip7702.sol";
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* @title RelationshipTypeRegistry
|
|
@@ -20,7 +22,7 @@ pragma solidity ^0.8.28;
|
|
|
20
22
|
* (`packages/contracts/src/RelationshipTypeRegistry.sol`, 138 LOC) —
|
|
21
23
|
* structurally identical with constructor zero-governor guard.
|
|
22
24
|
*/
|
|
23
|
-
contract RelationshipTypeRegistry {
|
|
25
|
+
contract RelationshipTypeRegistry is StableProxyGoverned {
|
|
24
26
|
struct TypeSemantics {
|
|
25
27
|
bytes32 relationshipType;
|
|
26
28
|
string label;
|
|
@@ -45,13 +47,35 @@ contract RelationshipTypeRegistry {
|
|
|
45
47
|
error TypeExists();
|
|
46
48
|
error TypeNotFound();
|
|
47
49
|
error ZeroGovernor();
|
|
50
|
+
/// @dev Spec 447 — `initialize(address)` alone would leave the governor unset.
|
|
51
|
+
error GovernorRequired();
|
|
48
52
|
|
|
49
53
|
modifier onlyGovernor() {
|
|
54
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
50
55
|
if (msg.sender != governor) revert NotGovernor();
|
|
51
56
|
_;
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
|
|
59
|
+
/// @notice A DIRECT deployment: `governor_` runs the registry, and there is no upgrade governance (the code is
|
|
60
|
+
/// frozen, as before). Spec 447 — behind a stable proxy, `initialize(governance_, governor_)` instead.
|
|
61
|
+
constructor(address governor_) initializer {
|
|
62
|
+
_initGovernor(governor_);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// @notice Spec 447 — the proxy's initializer: `governance_` is the upgrade authority (only); `governor_` runs
|
|
66
|
+
/// the registry, exactly as the constructor's argument does. Once per proxy; never on the implementation.
|
|
67
|
+
function initialize(address governance_, address governor_) external initializer {
|
|
68
|
+
_initializeGovernance(governance_);
|
|
69
|
+
_initGovernor(governor_);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/// @dev Spec 447 — the one-argument path would leave `governor` unset (a registry nobody can run), so it is
|
|
73
|
+
/// refused: `initialize(governance_, governor_)` is this contract's only initializer.
|
|
74
|
+
function initialize(address) external pure override {
|
|
75
|
+
revert GovernorRequired();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function _initGovernor(address governor_) private {
|
|
55
79
|
if (governor_ == address(0)) revert ZeroGovernor();
|
|
56
80
|
governor = governor_;
|
|
57
81
|
}
|
|
@@ -60,6 +84,35 @@ contract RelationshipTypeRegistry {
|
|
|
60
84
|
if (newGovernor == address(0)) revert ZeroGovernor();
|
|
61
85
|
emit GovernorTransferred(governor, newGovernor);
|
|
62
86
|
governor = newGovernor;
|
|
87
|
+
pendingGovernor = address(0); // a proposal made by the previous governor does not survive it
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ─── Two-step governor hand-over (spec 445 / REG-11) ────────────
|
|
91
|
+
//
|
|
92
|
+
// `transferGovernor` is one step: a wrong address is permanent. It stays for the scripted bootstrap
|
|
93
|
+
// hand-over, where the deploy script asserts the end state in the same run (spec 445 §2.1). Every
|
|
94
|
+
// LATER rotation should use this pair — the successor proves it can act before the role moves.
|
|
95
|
+
|
|
96
|
+
/// @notice The successor named by `proposeGovernor`, until it accepts. Zero otherwise.
|
|
97
|
+
address public pendingGovernor;
|
|
98
|
+
|
|
99
|
+
event GovernorProposed(address indexed governor, address indexed pendingGovernor);
|
|
100
|
+
|
|
101
|
+
error NotPendingGovernor();
|
|
102
|
+
|
|
103
|
+
/// @notice Name a successor (zero cancels). The governor keeps the role until the successor accepts.
|
|
104
|
+
function proposeGovernor(address newGovernor) external onlyGovernor {
|
|
105
|
+
pendingGovernor = newGovernor;
|
|
106
|
+
emit GovernorProposed(governor, newGovernor);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/// @notice Take the governor role. Only the proposed successor.
|
|
110
|
+
function acceptGovernor() external {
|
|
111
|
+
Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
|
|
112
|
+
if (msg.sender != pendingGovernor || msg.sender == address(0)) revert NotPendingGovernor();
|
|
113
|
+
emit GovernorTransferred(governor, msg.sender);
|
|
114
|
+
governor = msg.sender;
|
|
115
|
+
pendingGovernor = address(0);
|
|
63
116
|
}
|
|
64
117
|
|
|
65
118
|
// ─── Registration ───────────────────────────────────────────────
|
|
@@ -140,4 +193,7 @@ contract RelationshipTypeRegistry {
|
|
|
140
193
|
function getAllTypeIds() external view returns (bytes32[] memory) {
|
|
141
194
|
return _typeIds;
|
|
142
195
|
}
|
|
196
|
+
|
|
197
|
+
/// @dev Spec 447 — storage gap: the registry may sit behind a stable proxy; layout gated by `check:storage-layouts`.
|
|
198
|
+
uint256[46] private __gap;
|
|
143
199
|
}
|