@agenticprimitives/contracts 1.0.0-alpha.46 → 1.0.0-alpha.47
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 +60 -26
- package/deployments-base-sepolia.json +2 -0
- package/deployments-faithchain.json +2 -0
- package/deployments-hopechain.json +2 -0
- package/dist/abi/AgentAccount.json +175 -0
- package/dist/abi/AgentAccountFactory.json +47 -0
- package/dist/abi/AgentNameAttributeResolver.json +24 -0
- package/dist/abi/AgentNameRegistry.json +369 -0
- package/dist/abi/AgentNameUniversalResolver.json +34 -0
- package/dist/abi/AgentProfileResolver.json +48 -0
- package/dist/abi/AgentRegistryBase.json +158 -0
- package/dist/abi/AgentRelationship.json +212 -0
- package/dist/abi/AgreementRegistry.json +10 -0
- package/dist/abi/AttestationRegistry.json +49 -0
- package/dist/abi/AttributeStorage.json +24 -0
- package/dist/abi/CustodyPolicy.json +184 -0
- package/dist/abi/DelegationManager.json +96 -0
- package/dist/abi/DigestBindingEnforcer.json +103 -1
- package/dist/abi/EstateProjectionRegistry.json +137 -24
- package/dist/abi/GeoFeatureRegistry.json +42 -0
- package/dist/abi/IAgentAccountFactoryView.json +13 -0
- package/dist/abi/IAgentAccountGovernanceTimelockView.json +15 -0
- package/dist/abi/ICustodyPolicyFactoryView.json +13 -0
- package/dist/abi/ICustodyPolicyPasskeyView.json +50 -0
- package/dist/abi/IRedemptionContext.json +15 -0
- package/dist/abi/ITreasurySpendPolicyAccountView.json +44 -0
- package/dist/abi/IUpgradeVoucherView.json +26 -0
- package/dist/abi/OntologyTermRegistry.json +57 -0
- package/dist/abi/PaymentEnforcer.json +10 -0
- package/dist/abi/PermissionlessSubregistry.json +165 -0
- package/dist/abi/PricedSubregistry.json +57 -0
- package/dist/abi/RelationshipTypeRegistry.json +57 -0
- package/dist/abi/ShapeRegistry.json +57 -0
- package/dist/abi/SkillDefinitionRegistry.json +42 -0
- package/dist/abi/TreasurySpendPolicy.json +106 -1
- package/dist/abi/UpgradeVoucher.json +176 -0
- package/dist/abi/index.d.ts +6 -0
- package/dist/abi/index.js +6 -0
- package/dist/deployments/base-sepolia.d.ts +2 -0
- package/dist/deployments/base-sepolia.js +4 -0
- package/dist/deployments/faithchain.d.ts +2 -0
- package/dist/deployments/faithchain.js +4 -0
- package/dist/deployments/hopechain.d.ts +2 -0
- package/dist/deployments/hopechain.js +4 -0
- package/package.json +1 -1
- package/src/AgentAccount.sol +531 -92
- package/src/AgentAccountFactory.sol +28 -2
- package/src/IAgentAccount.sol +14 -0
- package/src/SmartAgentPaymaster.sol +30 -3
- package/src/UpgradeVoucher.sol +74 -0
- package/src/agency/DelegationManager.sol +177 -52
- package/src/agency/ICaveatEnforcer.sol +10 -0
- package/src/agency/IDelegationManager.sol +6 -5
- package/src/agreement/AgreementRegistry.sol +61 -17
- package/src/attestation/AttestationRegistry.sol +115 -22
- package/src/custody/CustodyPolicy.sol +393 -47
- package/src/custody/TreasurySpendPolicy.sol +192 -29
- package/src/enforcers/AllowedMethodsEnforcer.sol +6 -1
- package/src/enforcers/AllowedTargetsEnforcer.sol +6 -1
- package/src/enforcers/DigestBindingEnforcer.sol +91 -19
- package/src/enforcers/PaymentEnforcer.sol +32 -1
- package/src/enforcers/QuorumEnforcer.sol +1 -1
- package/src/enforcers/ValueEnforcer.sol +6 -1
- package/src/geo/GeoFeatureRegistry.sol +25 -1
- package/src/governance/AgenticGovernance.sol +16 -0
- package/src/identity/AgentProfileResolver.sol +11 -0
- package/src/naming/AgentNameAttributeResolver.sol +17 -2
- package/src/naming/AgentNamePredicates.sol +1 -1
- package/src/naming/AgentNameRegistry.sol +205 -10
- package/src/naming/AgentNameUniversalResolver.sol +26 -0
- package/src/naming/PermissionlessSubregistry.sol +69 -23
- package/src/naming/PricedSubregistry.sol +28 -0
- package/src/ontology/AttributeStorage.sol +93 -80
- package/src/ontology/OntologyTermRegistry.sol +28 -0
- package/src/ontology/ShapeRegistry.sol +28 -0
- package/src/payments/PaymentEscrow.sol +23 -15
- package/src/payments/PaymentReceiptRegistry.sol +11 -3
- package/src/registry/AgentRegistryBase.sol +39 -0
- package/src/registry/EstateProjectionRegistry.sol +94 -40
- package/src/relationships/AgentRelationship.sol +112 -7
- package/src/relationships/RelationshipTypeRegistry.sol +28 -0
- package/src/skills/SkillDefinitionRegistry.sol +25 -1
|
@@ -21,12 +21,21 @@ import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol
|
|
|
21
21
|
* is owned by `newOwner` (caller decides — typically themselves
|
|
22
22
|
* OR a PSA they control).
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
24
|
+
* Front-running (spec 445 / REG-5, ledger SUB-1): registration is COMMIT-REVEAL. A claimant first
|
|
25
|
+
* publishes `commit(keccak256(this, chainId, label, newOwner, secret))`, waits `MIN_COMMIT_AGE`, then
|
|
26
|
+
* reveals with `register(label, newOwner, secret)` before `MAX_COMMIT_AGE`. The label is not visible
|
|
27
|
+
* until the reveal, and a mempool observer who copies the reveal has no matured commitment of its own;
|
|
28
|
+
* copying the SAME reveal only registers the name to the owner the claimant chose (the commitment
|
|
29
|
+
* binds the owner, not the caller, so a relayer may reveal).
|
|
30
|
+
*
|
|
31
|
+
* The cap (ledger SUB-2) is one reveal per CALLER (`claimedBy[msg.sender]`). It is a courtesy rate
|
|
32
|
+
* limit and NOT a security control: a fresh address is free, so this contract does not ration names
|
|
33
|
+
* and nothing may rely on the cap. (A per-owner cap was considered and rejected: anyone could spend
|
|
34
|
+
* a victim's only slot by registering a junk name to them.) A root whose names are scarce or
|
|
35
|
+
* valuable MUST use `PricedSubregistry` (a coin and a gate's ticket); this contract is the testnet /
|
|
36
|
+
* demo posture and a production deploy does not put it in front of a typed root (spec 445 §2.1).
|
|
37
|
+
*
|
|
38
|
+
* Reserved labels and DNS-host injectivity are the registry's rule (`AgentNameRegistry.register`).
|
|
30
39
|
*
|
|
31
40
|
* Authority model:
|
|
32
41
|
* - The contract calls `REGISTRY.register(...)`; the registry sees
|
|
@@ -52,7 +61,16 @@ contract PermissionlessSubregistry is ReentrancyGuard {
|
|
|
52
61
|
|
|
53
62
|
uint256 public constant MIN_LABEL_LENGTH = 3;
|
|
54
63
|
|
|
55
|
-
/// @notice
|
|
64
|
+
/// @notice A commitment must be at least this old to be revealed — the reveal lands in a later block
|
|
65
|
+
/// than the commit, so an observer of the reveal cannot commit-and-reveal ahead of it.
|
|
66
|
+
uint256 public constant MIN_COMMIT_AGE = 10 seconds;
|
|
67
|
+
/// @notice …and at most this old. A stale commitment is void and may be re-committed.
|
|
68
|
+
uint256 public constant MAX_COMMIT_AGE = 1 days;
|
|
69
|
+
|
|
70
|
+
/// @notice commitment → when it was committed (0 = none / consumed).
|
|
71
|
+
mapping(bytes32 => uint256) public committedAt;
|
|
72
|
+
|
|
73
|
+
/// @notice msg.sender → the child node they've already claimed. Courtesy limit, not sybil resistance.
|
|
56
74
|
mapping(address => bytes32) public claimedBy;
|
|
57
75
|
/// @notice Total claims served by this subregistry instance.
|
|
58
76
|
uint256 public claimCount;
|
|
@@ -68,6 +86,15 @@ contract PermissionlessSubregistry is ReentrancyGuard {
|
|
|
68
86
|
error LabelTooShort();
|
|
69
87
|
error EmptyLabel();
|
|
70
88
|
error ZeroNewOwner();
|
|
89
|
+
error ZeroCommitment();
|
|
90
|
+
/// @notice A live (not yet expired) commitment with this hash already exists — re-committing would
|
|
91
|
+
/// reset its age, which a griefer could use to keep a claimant's reveal immature.
|
|
92
|
+
error CommitmentPending(bytes32 commitment);
|
|
93
|
+
error CommitmentNotFound(bytes32 commitment);
|
|
94
|
+
error CommitmentTooNew(bytes32 commitment, uint256 matureAt);
|
|
95
|
+
error CommitmentExpired(bytes32 commitment);
|
|
96
|
+
|
|
97
|
+
event Committed(bytes32 indexed commitment, address indexed by);
|
|
71
98
|
|
|
72
99
|
constructor(AgentNameRegistry registry, bytes32 parentNode, address defaultResolver) {
|
|
73
100
|
REGISTRY = registry;
|
|
@@ -75,30 +102,49 @@ contract PermissionlessSubregistry is ReentrancyGuard {
|
|
|
75
102
|
DEFAULT_RESOLVER = defaultResolver;
|
|
76
103
|
}
|
|
77
104
|
|
|
105
|
+
/// @notice The commitment for a claim: binds this subregistry, the chain, the label, the owner the
|
|
106
|
+
/// name will be registered to, and a secret only the claimant knows.
|
|
107
|
+
function makeCommitment(string calldata label, address newOwner, bytes32 secret) public view returns (bytes32) {
|
|
108
|
+
return keccak256(abi.encode(address(this), block.chainid, keccak256(bytes(label)), newOwner, secret));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// @notice Step 1 — publish a commitment. Anyone may; it reveals nothing about the label.
|
|
112
|
+
function commit(bytes32 commitment) external {
|
|
113
|
+
if (commitment == bytes32(0)) revert ZeroCommitment();
|
|
114
|
+
uint256 at = committedAt[commitment];
|
|
115
|
+
if (at != 0 && block.timestamp <= at + MAX_COMMIT_AGE) revert CommitmentPending(commitment);
|
|
116
|
+
committedAt[commitment] = block.timestamp;
|
|
117
|
+
emit Committed(commitment, msg.sender);
|
|
118
|
+
}
|
|
119
|
+
|
|
78
120
|
/**
|
|
79
|
-
* @notice
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* (e.g. label already taken).
|
|
121
|
+
* @notice Step 2 — reveal: claim `<label>.<parent>` for `newOwner`. Reverts when there is no matured,
|
|
122
|
+
* unexpired commitment for (label, newOwner, secret), when the caller already revealed a
|
|
123
|
+
* name here (courtesy limit), when the label fails the minimum-length guard, or when the registry
|
|
124
|
+
* refuses (label taken, reserved, or reading as a typed name).
|
|
84
125
|
*
|
|
85
|
-
* The caller pays gas. The contract does NOT collect a
|
|
86
|
-
*
|
|
87
|
-
* shape if needed.
|
|
126
|
+
* The caller pays gas. The contract does NOT collect a fee — fee gating is
|
|
127
|
+
* `PricedSubregistry`.
|
|
88
128
|
*/
|
|
89
|
-
function register(string calldata label, address newOwner) external nonReentrant returns (bytes32 childNode) {
|
|
129
|
+
function register(string calldata label, address newOwner, bytes32 secret) external nonReentrant returns (bytes32 childNode) {
|
|
90
130
|
if (bytes(label).length == 0) revert EmptyLabel();
|
|
91
131
|
if (bytes(label).length < MIN_LABEL_LENGTH) revert LabelTooShort();
|
|
92
132
|
if (newOwner == address(0)) revert ZeroNewOwner();
|
|
93
133
|
bytes32 prior = claimedBy[msg.sender];
|
|
94
134
|
if (prior != bytes32(0)) revert AlreadyClaimed(prior);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
135
|
+
|
|
136
|
+
bytes32 commitment = makeCommitment(label, newOwner, secret);
|
|
137
|
+
uint256 at = committedAt[commitment];
|
|
138
|
+
if (at == 0) revert CommitmentNotFound(commitment);
|
|
139
|
+
if (block.timestamp < at + MIN_COMMIT_AGE) revert CommitmentTooNew(commitment, at + MIN_COMMIT_AGE);
|
|
140
|
+
if (block.timestamp > at + MAX_COMMIT_AGE) revert CommitmentExpired(commitment);
|
|
141
|
+
delete committedAt[commitment];
|
|
142
|
+
claimedBy[msg.sender] = bytes32(uint256(1)); // provisional: written before the external call
|
|
143
|
+
|
|
144
|
+
// REGISTRY is an immutable contract we control that does not call back into this contract, and
|
|
145
|
+
// the function is `nonReentrant`; the claim slot and the consumed commitment are written BEFORE
|
|
146
|
+
// the call, and only the slot's final value (the node the registry returned) after it.
|
|
147
|
+
// R9 / docs/audits/r9-static-analysis-triage.md § Slither M-1: triaged false positive.
|
|
102
148
|
// slither-disable-next-line reentrancy-no-eth
|
|
103
149
|
childNode = REGISTRY.register(PARENT_NODE, label, newOwner, DEFAULT_RESOLVER, 0);
|
|
104
150
|
claimedBy[msg.sender] = childNode;
|
|
@@ -205,5 +205,33 @@ contract PricedSubregistry is ReentrancyGuard, EIP712 {
|
|
|
205
205
|
if (newGovernor == address(0)) revert ZeroAddress();
|
|
206
206
|
emit GovernorTransferred(governor, newGovernor);
|
|
207
207
|
governor = newGovernor;
|
|
208
|
+
pendingGovernor = address(0); // a proposal made by the previous governor does not survive it
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ─── Two-step governor hand-over (spec 445 / REG-11) ────────────
|
|
212
|
+
//
|
|
213
|
+
// `transferGovernor` is one step: a wrong address is permanent. It stays for the scripted bootstrap
|
|
214
|
+
// hand-over, where the deploy script asserts the end state in the same run (spec 445 §2.1). Every
|
|
215
|
+
// LATER rotation should use this pair — the successor proves it can act before the role moves.
|
|
216
|
+
|
|
217
|
+
/// @notice The successor named by `proposeGovernor`, until it accepts. Zero otherwise.
|
|
218
|
+
address public pendingGovernor;
|
|
219
|
+
|
|
220
|
+
event GovernorProposed(address indexed governor, address indexed pendingGovernor);
|
|
221
|
+
|
|
222
|
+
error NotPendingGovernor();
|
|
223
|
+
|
|
224
|
+
/// @notice Name a successor (zero cancels). The governor keeps the role until the successor accepts.
|
|
225
|
+
function proposeGovernor(address newGovernor) external onlyGovernor {
|
|
226
|
+
pendingGovernor = newGovernor;
|
|
227
|
+
emit GovernorProposed(governor, newGovernor);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/// @notice Take the governor role. Only the proposed successor.
|
|
231
|
+
function acceptGovernor() external {
|
|
232
|
+
if (msg.sender != pendingGovernor || msg.sender == address(0)) revert NotPendingGovernor();
|
|
233
|
+
emit GovernorTransferred(governor, msg.sender);
|
|
234
|
+
governor = msg.sender;
|
|
235
|
+
pendingGovernor = address(0);
|
|
208
236
|
}
|
|
209
237
|
}
|
|
@@ -86,97 +86,91 @@ abstract contract AttributeStorage {
|
|
|
86
86
|
function DT_ADDRESS_ARR_PUB() external pure returns (uint8) { return DT_ADDRESS_ARR; }
|
|
87
87
|
function DT_BYTES32_ARR_PUB() external pure returns (uint8) { return DT_BYTES32_ARR; }
|
|
88
88
|
|
|
89
|
+
// ─── Storage key (spec 445 / REG-4) ─────────────────────────────
|
|
90
|
+
|
|
91
|
+
/// @notice The key a subject's VALUES are stored under. Identity by default. A subclass whose subject can
|
|
92
|
+
/// change hands (a name node) overrides this to fold in an owner epoch, so a record written by a
|
|
93
|
+
/// previous owner is unreachable for the next one WITHOUT a delete loop and without a log scan:
|
|
94
|
+
/// every setter and every getter goes through this one function, so a read can never see a value
|
|
95
|
+
/// the current key did not write. Enumeration (`allSubjects`) and the version watermark stay keyed
|
|
96
|
+
/// by the OUTWARD subject — they are indexes, not records.
|
|
97
|
+
function _storageKey(bytes32 subject) internal view virtual returns (bytes32) {
|
|
98
|
+
return subject;
|
|
99
|
+
}
|
|
100
|
+
|
|
89
101
|
// ─── Internal setters (subclass-only) ───────────────────────────
|
|
90
102
|
|
|
91
103
|
function _setString(bytes32 subject, bytes32 predicate, string memory value) internal {
|
|
92
|
-
|
|
93
|
-
_string[
|
|
94
|
-
_record(subject, predicate, DT_STRING);
|
|
104
|
+
bytes32 k = _write(subject, predicate, DT_STRING, false);
|
|
105
|
+
_string[k][predicate] = value;
|
|
95
106
|
}
|
|
96
107
|
|
|
97
108
|
function _setAddress(bytes32 subject, bytes32 predicate, address value) internal {
|
|
98
|
-
|
|
99
|
-
_address[
|
|
100
|
-
_record(subject, predicate, DT_ADDRESS);
|
|
109
|
+
bytes32 k = _write(subject, predicate, DT_ADDRESS, false);
|
|
110
|
+
_address[k][predicate] = value;
|
|
101
111
|
}
|
|
102
112
|
|
|
103
113
|
function _setBool(bytes32 subject, bytes32 predicate, bool value) internal {
|
|
104
|
-
|
|
105
|
-
_bool[
|
|
106
|
-
_record(subject, predicate, DT_BOOL);
|
|
114
|
+
bytes32 k = _write(subject, predicate, DT_BOOL, false);
|
|
115
|
+
_bool[k][predicate] = value;
|
|
107
116
|
}
|
|
108
117
|
|
|
109
118
|
function _setUint(bytes32 subject, bytes32 predicate, uint256 value) internal {
|
|
110
|
-
|
|
111
|
-
_uint[
|
|
112
|
-
_record(subject, predicate, DT_UINT256);
|
|
119
|
+
bytes32 k = _write(subject, predicate, DT_UINT256, false);
|
|
120
|
+
_uint[k][predicate] = value;
|
|
113
121
|
}
|
|
114
122
|
|
|
115
123
|
function _setBytes32(bytes32 subject, bytes32 predicate, bytes32 value) internal {
|
|
116
|
-
|
|
117
|
-
_bytes32[
|
|
118
|
-
_record(subject, predicate, DT_BYTES32);
|
|
124
|
+
bytes32 k = _write(subject, predicate, DT_BYTES32, false);
|
|
125
|
+
_bytes32[k][predicate] = value;
|
|
119
126
|
}
|
|
120
127
|
|
|
121
128
|
function _setStringArr(bytes32 subject, bytes32 predicate, string[] memory values) internal {
|
|
122
|
-
|
|
123
|
-
delete _stringArr[
|
|
129
|
+
bytes32 k = _write(subject, predicate, DT_STRING_ARR, false);
|
|
130
|
+
delete _stringArr[k][predicate];
|
|
124
131
|
for (uint256 i = 0; i < values.length; i++) {
|
|
125
|
-
_stringArr[
|
|
132
|
+
_stringArr[k][predicate].push(values[i]);
|
|
126
133
|
}
|
|
127
|
-
_record(subject, predicate, DT_STRING_ARR);
|
|
128
134
|
}
|
|
129
135
|
|
|
130
136
|
function _setAddressArr(bytes32 subject, bytes32 predicate, address[] memory values) internal {
|
|
131
|
-
|
|
132
|
-
delete _addressArr[
|
|
137
|
+
bytes32 k = _write(subject, predicate, DT_ADDRESS_ARR, false);
|
|
138
|
+
delete _addressArr[k][predicate];
|
|
133
139
|
for (uint256 i = 0; i < values.length; i++) {
|
|
134
|
-
_addressArr[
|
|
140
|
+
_addressArr[k][predicate].push(values[i]);
|
|
135
141
|
}
|
|
136
|
-
_record(subject, predicate, DT_ADDRESS_ARR);
|
|
137
142
|
}
|
|
138
143
|
|
|
139
144
|
function _setBytes32Arr(bytes32 subject, bytes32 predicate, bytes32[] memory values) internal {
|
|
140
|
-
|
|
141
|
-
delete _bytes32Arr[
|
|
145
|
+
bytes32 k = _write(subject, predicate, DT_BYTES32_ARR, false);
|
|
146
|
+
delete _bytes32Arr[k][predicate];
|
|
142
147
|
for (uint256 i = 0; i < values.length; i++) {
|
|
143
|
-
_bytes32Arr[
|
|
148
|
+
_bytes32Arr[k][predicate].push(values[i]);
|
|
144
149
|
}
|
|
145
|
-
_record(subject, predicate, DT_BYTES32_ARR);
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
function _appendString(bytes32 subject, bytes32 predicate, string memory value) internal {
|
|
149
|
-
|
|
150
|
-
_stringArr[
|
|
151
|
-
_recordAppend(subject, predicate, DT_STRING_ARR);
|
|
153
|
+
bytes32 k = _write(subject, predicate, DT_STRING_ARR, true);
|
|
154
|
+
_stringArr[k][predicate].push(value);
|
|
152
155
|
}
|
|
153
156
|
|
|
154
157
|
function _appendAddress(bytes32 subject, bytes32 predicate, address value) internal {
|
|
155
|
-
|
|
156
|
-
_addressArr[
|
|
157
|
-
_recordAppend(subject, predicate, DT_ADDRESS_ARR);
|
|
158
|
+
bytes32 k = _write(subject, predicate, DT_ADDRESS_ARR, true);
|
|
159
|
+
_addressArr[k][predicate].push(value);
|
|
158
160
|
}
|
|
159
161
|
|
|
160
162
|
function _appendBytes32(bytes32 subject, bytes32 predicate, bytes32 value) internal {
|
|
161
|
-
|
|
162
|
-
_bytes32Arr[
|
|
163
|
-
_recordAppend(subject, predicate, DT_BYTES32_ARR);
|
|
163
|
+
bytes32 k = _write(subject, predicate, DT_BYTES32_ARR, true);
|
|
164
|
+
_bytes32Arr[k][predicate].push(value);
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
function _unset(bytes32 subject, bytes32 predicate) internal {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
else if (dt == DT_BYTES32) delete _bytes32[subject][predicate];
|
|
174
|
-
else if (dt == DT_STRING_ARR) delete _stringArr[subject][predicate];
|
|
175
|
-
else if (dt == DT_ADDRESS_ARR) delete _addressArr[subject][predicate];
|
|
176
|
-
else if (dt == DT_BYTES32_ARR) delete _bytes32Arr[subject][predicate];
|
|
177
|
-
_isSet[subject][predicate] = false;
|
|
178
|
-
delete _datatype[subject][predicate];
|
|
179
|
-
delete _updatedAt[subject][predicate];
|
|
168
|
+
bytes32 k = _storageKey(subject);
|
|
169
|
+
if (!_isSet[k][predicate]) revert AttributeNotSet();
|
|
170
|
+
_clearValue(k, predicate, _datatype[k][predicate]);
|
|
171
|
+
_isSet[k][predicate] = false;
|
|
172
|
+
delete _datatype[k][predicate];
|
|
173
|
+
delete _updatedAt[k][predicate];
|
|
180
174
|
uint64 v = _bumpVersion(subject);
|
|
181
175
|
emit AttributeUnset(subject, predicate, v);
|
|
182
176
|
}
|
|
@@ -184,51 +178,62 @@ abstract contract AttributeStorage {
|
|
|
184
178
|
// ─── Public getters ─────────────────────────────────────────────
|
|
185
179
|
|
|
186
180
|
function getString(bytes32 subject, bytes32 predicate) external view returns (string memory) {
|
|
187
|
-
return _string[subject][predicate];
|
|
181
|
+
return _string[_storageKey(subject)][predicate];
|
|
188
182
|
}
|
|
189
183
|
function getAddress(bytes32 subject, bytes32 predicate) external view returns (address) {
|
|
190
|
-
return _address[subject][predicate];
|
|
184
|
+
return _address[_storageKey(subject)][predicate];
|
|
191
185
|
}
|
|
192
186
|
function getBool(bytes32 subject, bytes32 predicate) external view returns (bool) {
|
|
193
|
-
return _bool[subject][predicate];
|
|
187
|
+
return _bool[_storageKey(subject)][predicate];
|
|
194
188
|
}
|
|
195
189
|
function getUint(bytes32 subject, bytes32 predicate) external view returns (uint256) {
|
|
196
|
-
return _uint[subject][predicate];
|
|
190
|
+
return _uint[_storageKey(subject)][predicate];
|
|
197
191
|
}
|
|
198
192
|
function getBytes32(bytes32 subject, bytes32 predicate) external view returns (bytes32) {
|
|
199
|
-
return _bytes32[subject][predicate];
|
|
193
|
+
return _bytes32[_storageKey(subject)][predicate];
|
|
200
194
|
}
|
|
201
195
|
function getStringArr(bytes32 subject, bytes32 predicate) external view returns (string[] memory) {
|
|
202
|
-
return _stringArr[subject][predicate];
|
|
196
|
+
return _stringArr[_storageKey(subject)][predicate];
|
|
203
197
|
}
|
|
204
198
|
function getAddressArr(bytes32 subject, bytes32 predicate) external view returns (address[] memory) {
|
|
205
|
-
return _addressArr[subject][predicate];
|
|
199
|
+
return _addressArr[_storageKey(subject)][predicate];
|
|
206
200
|
}
|
|
207
201
|
function getBytes32Arr(bytes32 subject, bytes32 predicate) external view returns (bytes32[] memory) {
|
|
208
|
-
return _bytes32Arr[subject][predicate];
|
|
202
|
+
return _bytes32Arr[_storageKey(subject)][predicate];
|
|
209
203
|
}
|
|
210
204
|
|
|
211
205
|
function predicatesOf(bytes32 subject) external view returns (bytes32[] memory) {
|
|
212
|
-
return _predicates[subject];
|
|
206
|
+
return _predicates[_storageKey(subject)];
|
|
213
207
|
}
|
|
214
208
|
function datatypeOf(bytes32 subject, bytes32 predicate) external view returns (uint8) {
|
|
215
|
-
return _datatype[subject][predicate];
|
|
209
|
+
return _datatype[_storageKey(subject)][predicate];
|
|
216
210
|
}
|
|
217
211
|
function updatedAt(bytes32 subject, bytes32 predicate) external view returns (uint64) {
|
|
218
|
-
return _updatedAt[subject][predicate];
|
|
212
|
+
return _updatedAt[_storageKey(subject)][predicate];
|
|
219
213
|
}
|
|
220
214
|
function isSet(bytes32 subject, bytes32 predicate) external view returns (bool) {
|
|
221
|
-
return _isSet[subject][predicate];
|
|
215
|
+
return _isSet[_storageKey(subject)][predicate];
|
|
222
216
|
}
|
|
223
217
|
function subjectVersion(bytes32 subject) external view returns (uint64) {
|
|
224
218
|
return _subjectVersion[subject];
|
|
225
219
|
}
|
|
220
|
+
/// @dev REG-12: unbounded — anyone who can write a first record extends it. Kept for small deployments;
|
|
221
|
+
/// a reader of a large one uses `subjectsPage`.
|
|
226
222
|
function allSubjects() external view returns (bytes32[] memory) {
|
|
227
223
|
return _allSubjects;
|
|
228
224
|
}
|
|
229
225
|
function subjectCount() external view returns (uint256) {
|
|
230
226
|
return _allSubjects.length;
|
|
231
227
|
}
|
|
228
|
+
/// @notice REG-12 — a bounded window of the subject index: `limit` entries from `offset` (fewer at the end).
|
|
229
|
+
function subjectsPage(uint256 offset, uint256 limit) external view returns (bytes32[] memory page) {
|
|
230
|
+
uint256 n = _allSubjects.length;
|
|
231
|
+
if (offset >= n) return new bytes32[](0);
|
|
232
|
+
uint256 end = offset + limit;
|
|
233
|
+
if (end > n) end = n;
|
|
234
|
+
page = new bytes32[](end - offset);
|
|
235
|
+
for (uint256 i = offset; i < end; i++) page[i - offset] = _allSubjects[i];
|
|
236
|
+
}
|
|
232
237
|
|
|
233
238
|
// ─── Internal helpers ───────────────────────────────────────────
|
|
234
239
|
|
|
@@ -236,28 +241,36 @@ abstract contract AttributeStorage {
|
|
|
236
241
|
if (!ONTOLOGY.isActive(predicate)) revert PredicateNotActive();
|
|
237
242
|
}
|
|
238
243
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
_datatype[subject][predicate] = dt;
|
|
246
|
-
uint64 v = _bumpVersion(subject);
|
|
247
|
-
_updatedAt[subject][predicate] = v;
|
|
248
|
-
emit AttributeSet(subject, predicate, dt, v);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
function _recordAppend(bytes32 subject, bytes32 predicate, uint8 dt) internal {
|
|
244
|
+
/// @dev One write path: predicate active → storage key → (REG-14) if the predicate was set with ANOTHER
|
|
245
|
+
/// datatype, delete that family's value so `getString` cannot keep answering after the predicate was
|
|
246
|
+
/// rewritten as an address → index + version + event. Returns the key the caller writes under.
|
|
247
|
+
function _write(bytes32 subject, bytes32 predicate, uint8 dt, bool append) private returns (bytes32 k) {
|
|
248
|
+
_requirePredicate(predicate);
|
|
249
|
+
k = _storageKey(subject);
|
|
252
250
|
_trackSubject(subject);
|
|
253
|
-
if (!_isSet[
|
|
254
|
-
_predicates[
|
|
255
|
-
_isSet[
|
|
251
|
+
if (!_isSet[k][predicate]) {
|
|
252
|
+
_predicates[k].push(predicate);
|
|
253
|
+
_isSet[k][predicate] = true;
|
|
254
|
+
} else {
|
|
255
|
+
uint8 prior = _datatype[k][predicate];
|
|
256
|
+
if (prior != dt) _clearValue(k, predicate, prior);
|
|
256
257
|
}
|
|
257
|
-
_datatype[
|
|
258
|
+
_datatype[k][predicate] = dt;
|
|
258
259
|
uint64 v = _bumpVersion(subject);
|
|
259
|
-
_updatedAt[
|
|
260
|
-
emit AttributeAppended(subject, predicate, dt, v);
|
|
260
|
+
_updatedAt[k][predicate] = v;
|
|
261
|
+
if (append) emit AttributeAppended(subject, predicate, dt, v);
|
|
262
|
+
else emit AttributeSet(subject, predicate, dt, v);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function _clearValue(bytes32 k, bytes32 predicate, uint8 dt) private {
|
|
266
|
+
if (dt == DT_STRING) delete _string[k][predicate];
|
|
267
|
+
else if (dt == DT_ADDRESS) delete _address[k][predicate];
|
|
268
|
+
else if (dt == DT_BOOL) delete _bool[k][predicate];
|
|
269
|
+
else if (dt == DT_UINT256) delete _uint[k][predicate];
|
|
270
|
+
else if (dt == DT_BYTES32) delete _bytes32[k][predicate];
|
|
271
|
+
else if (dt == DT_STRING_ARR) delete _stringArr[k][predicate];
|
|
272
|
+
else if (dt == DT_ADDRESS_ARR) delete _addressArr[k][predicate];
|
|
273
|
+
else if (dt == DT_BYTES32_ARR) delete _bytes32Arr[k][predicate];
|
|
261
274
|
}
|
|
262
275
|
|
|
263
276
|
function _trackSubject(bytes32 subject) internal {
|
|
@@ -60,6 +60,34 @@ contract OntologyTermRegistry {
|
|
|
60
60
|
if (newGovernor == address(0)) revert ZeroGovernor();
|
|
61
61
|
emit GovernorTransferred(governor, newGovernor);
|
|
62
62
|
governor = newGovernor;
|
|
63
|
+
pendingGovernor = address(0); // a proposal made by the previous governor does not survive it
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ─── Two-step governor hand-over (spec 445 / REG-11) ────────────
|
|
67
|
+
//
|
|
68
|
+
// `transferGovernor` is one step: a wrong address is permanent. It stays for the scripted bootstrap
|
|
69
|
+
// hand-over, where the deploy script asserts the end state in the same run (spec 445 §2.1). Every
|
|
70
|
+
// LATER rotation should use this pair — the successor proves it can act before the role moves.
|
|
71
|
+
|
|
72
|
+
/// @notice The successor named by `proposeGovernor`, until it accepts. Zero otherwise.
|
|
73
|
+
address public pendingGovernor;
|
|
74
|
+
|
|
75
|
+
event GovernorProposed(address indexed governor, address indexed pendingGovernor);
|
|
76
|
+
|
|
77
|
+
error NotPendingGovernor();
|
|
78
|
+
|
|
79
|
+
/// @notice Name a successor (zero cancels). The governor keeps the role until the successor accepts.
|
|
80
|
+
function proposeGovernor(address newGovernor) external onlyGovernor {
|
|
81
|
+
pendingGovernor = newGovernor;
|
|
82
|
+
emit GovernorProposed(governor, newGovernor);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/// @notice Take the governor role. Only the proposed successor.
|
|
86
|
+
function acceptGovernor() external {
|
|
87
|
+
if (msg.sender != pendingGovernor || msg.sender == address(0)) revert NotPendingGovernor();
|
|
88
|
+
emit GovernorTransferred(governor, msg.sender);
|
|
89
|
+
governor = msg.sender;
|
|
90
|
+
pendingGovernor = address(0);
|
|
63
91
|
}
|
|
64
92
|
|
|
65
93
|
function registerTerm(
|
|
@@ -86,6 +86,34 @@ contract ShapeRegistry {
|
|
|
86
86
|
if (newGovernor == address(0)) revert ZeroGovernor();
|
|
87
87
|
emit GovernorTransferred(governor, newGovernor);
|
|
88
88
|
governor = newGovernor;
|
|
89
|
+
pendingGovernor = address(0); // a proposal made by the previous governor does not survive it
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ─── Two-step governor hand-over (spec 445 / REG-11) ────────────
|
|
93
|
+
//
|
|
94
|
+
// `transferGovernor` is one step: a wrong address is permanent. It stays for the scripted bootstrap
|
|
95
|
+
// hand-over, where the deploy script asserts the end state in the same run (spec 445 §2.1). Every
|
|
96
|
+
// LATER rotation should use this pair — the successor proves it can act before the role moves.
|
|
97
|
+
|
|
98
|
+
/// @notice The successor named by `proposeGovernor`, until it accepts. Zero otherwise.
|
|
99
|
+
address public pendingGovernor;
|
|
100
|
+
|
|
101
|
+
event GovernorProposed(address indexed governor, address indexed pendingGovernor);
|
|
102
|
+
|
|
103
|
+
error NotPendingGovernor();
|
|
104
|
+
|
|
105
|
+
/// @notice Name a successor (zero cancels). The governor keeps the role until the successor accepts.
|
|
106
|
+
function proposeGovernor(address newGovernor) external onlyGovernor {
|
|
107
|
+
pendingGovernor = newGovernor;
|
|
108
|
+
emit GovernorProposed(governor, newGovernor);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// @notice Take the governor role. Only the proposed successor.
|
|
112
|
+
function acceptGovernor() external {
|
|
113
|
+
if (msg.sender != pendingGovernor || msg.sender == address(0)) revert NotPendingGovernor();
|
|
114
|
+
emit GovernorTransferred(governor, msg.sender);
|
|
115
|
+
governor = msg.sender;
|
|
116
|
+
pendingGovernor = address(0);
|
|
89
117
|
}
|
|
90
118
|
|
|
91
119
|
// ─── Shape definition ───────────────────────────────────────────
|
|
@@ -88,30 +88,38 @@ contract PaymentEscrow is ReentrancyGuard {
|
|
|
88
88
|
if (asset == address(0) || payee == address(0)) revert ZeroAddress();
|
|
89
89
|
if (expiry <= block.timestamp) revert BadExpiry();
|
|
90
90
|
|
|
91
|
-
//
|
|
92
|
-
//
|
|
93
|
-
// the
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
// Triaged false positive: `deposit` is `nonReentrant`, so the balanceOf delta cannot be
|
|
98
|
-
// manipulated by re-entering between the two reads — the guard blocks any callback. The
|
|
99
|
-
// before/after balance read is the EXT-PMT-3 realized-amount fix for fee-on-transfer assets.
|
|
100
|
-
// slither-disable-next-line reentrancy-balance
|
|
101
|
-
IERC20(asset).safeTransferFrom(msg.sender, address(this), amount);
|
|
102
|
-
uint256 received = IERC20(asset).balanceOf(address(this)) - beforeBal;
|
|
103
|
-
if (received == 0) revert ZeroAmount();
|
|
104
|
-
|
|
91
|
+
// Spec 445 (Slither `reentrancy-no-eth`): the hold is WRITTEN BEFORE the token is called. It
|
|
92
|
+
// is created `Held` with amount 0, so the (payer, orderHash) key is occupied for the whole of
|
|
93
|
+
// the pull — a token that calls back into `deposit` meets `HoldExists` on its own key even if
|
|
94
|
+
// the guard were not there, and nothing written during the callback can be overwritten by the
|
|
95
|
+
// tail of this function. `nonReentrant` (on every entry point) still blocks the callback
|
|
96
|
+
// outright; the ordering makes the property structural rather than guard-dependent.
|
|
105
97
|
_holds[key] = Hold({
|
|
106
98
|
payer: msg.sender,
|
|
107
99
|
asset: asset,
|
|
108
|
-
amount:
|
|
100
|
+
amount: 0,
|
|
109
101
|
payee: payee,
|
|
110
102
|
refundTo: refundTo == address(0) ? msg.sender : refundTo,
|
|
111
103
|
releaser: releaser,
|
|
112
104
|
expiry: expiry,
|
|
113
105
|
status: Status.Held
|
|
114
106
|
});
|
|
107
|
+
|
|
108
|
+
// EXT-PMT-3: credit the REALIZED amount received (balance delta), not the requested `amount`. A
|
|
109
|
+
// fee-on-transfer / rebasing asset delivers less than `amount`, which would otherwise over-credit
|
|
110
|
+
// the hold and let it draw from other holds' funds in the shared pool (cross-hold drain).
|
|
111
|
+
uint256 beforeBal = IERC20(asset).balanceOf(address(this));
|
|
112
|
+
// Triaged: every entry point is `nonReentrant`, so the balance delta cannot be manipulated by
|
|
113
|
+
// re-entering between the two reads, and the only post-call write is the realized amount of the
|
|
114
|
+
// hold this call already owns (created above; no other frame can reach it while the guard is held).
|
|
115
|
+
// slither-disable-next-line reentrancy-balance,reentrancy-no-eth
|
|
116
|
+
IERC20(asset).safeTransferFrom(msg.sender, address(this), amount);
|
|
117
|
+
uint256 received = IERC20(asset).balanceOf(address(this)) - beforeBal;
|
|
118
|
+
// A pull that delivered nothing is no deposit: revert (which also unwinds the hold above).
|
|
119
|
+
// slither-disable-next-line incorrect-equality
|
|
120
|
+
if (received == 0) revert ZeroAmount();
|
|
121
|
+
_holds[key].amount = received;
|
|
122
|
+
|
|
115
123
|
emit EscrowDeposited(orderHash);
|
|
116
124
|
}
|
|
117
125
|
|
|
@@ -13,6 +13,14 @@ pragma solidity ^0.8.28;
|
|
|
13
13
|
* app cache, never inline `eth_getLogs` in product hot paths (ADR-0012). The
|
|
14
14
|
* `PaymentEnforcer.PaymentCharged` event is the primary on-chain receipt; `PaymentSettled`
|
|
15
15
|
* here adds payer/payee/mandateId-indexed querying for treasury views.
|
|
16
|
+
*
|
|
17
|
+
* WHAT A ROW PROVES (spec 445 / audit DLG-8). Enforced on chain before the row is written:
|
|
18
|
+
* `amount > 0` of `asset` reached `payee`, from `payer` — the ROOT delegator, the account the
|
|
19
|
+
* redemption executed through — under `delegationHash`, once for `nonce`. NOT proved:
|
|
20
|
+
* `mandateId` and `resourceHash`. They are copied from the redeemer's unsigned caveat `args`;
|
|
21
|
+
* they are the redeemer's ASSERTION of which mandate and resource the charge was for. A reader
|
|
22
|
+
* that needs them to be true compares them with a record it trusts (the mandate it issued, the
|
|
23
|
+
* resource it served); it never treats the row as that record.
|
|
16
24
|
*/
|
|
17
25
|
contract PaymentReceiptRegistry {
|
|
18
26
|
/// @notice The deployer who wires the sole authorized recorder once.
|
|
@@ -21,12 +29,12 @@ contract PaymentReceiptRegistry {
|
|
|
21
29
|
address public enforcer;
|
|
22
30
|
|
|
23
31
|
event PaymentSettled(
|
|
24
|
-
bytes32 indexed mandateId,
|
|
25
|
-
address indexed payer,
|
|
32
|
+
bytes32 indexed mandateId, // redeemer-asserted (unsigned)
|
|
33
|
+
address indexed payer, // the root delegator whose funds moved
|
|
26
34
|
address indexed payee,
|
|
27
35
|
address asset,
|
|
28
36
|
uint256 amount,
|
|
29
|
-
bytes32 resourceHash,
|
|
37
|
+
bytes32 resourceHash, // redeemer-asserted (unsigned)
|
|
30
38
|
bytes32 delegationHash,
|
|
31
39
|
bytes32 nonce
|
|
32
40
|
);
|