@rootzero/contracts 1.18.0 → 1.20.0

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/ports/Post.sol CHANGED
@@ -10,10 +10,10 @@ import {Actions} from "../utils/Actions.sol";
10
10
 
11
11
  using Executions for Execution;
12
12
 
13
- /// @title PortPost
13
+ /// @title PostPort
14
14
  /// @notice Port that posts peer-supplied TRANSACTION blocks through debit and credit hooks.
15
15
  /// Each TRANSACTION block calls `debitAccount` for `from` and `creditAccount` for `to`.
16
- abstract contract PortPost is PortBase, PostHook, Action {
16
+ abstract contract PostPort is PortBase, PostHook, Action {
17
17
  uint private immutable descriptor;
18
18
 
19
19
  constructor() {
package/ports/Redeem.sol CHANGED
@@ -16,11 +16,11 @@ abstract contract RedeemBalanceHook {
16
16
  function redeemBalance(uint peer, bytes32 asset, uint amount) internal virtual;
17
17
  }
18
18
 
19
- /// @title PortRedeemBalance
19
+ /// @title RedeemBalancePort
20
20
  /// @notice Port that redeems balance state from a peer host into local assets.
21
21
  /// Each BALANCE block in the input calls `redeemBalance(peer, asset, amount)`.
22
22
  /// Restricted to trusted peers.
23
- abstract contract PortRedeemBalance is PortBase, RedeemBalanceHook {
23
+ abstract contract RedeemBalancePort is PortBase, RedeemBalanceHook {
24
24
  uint private immutable descriptor;
25
25
 
26
26
  constructor() {
package/queries/Base.sol CHANGED
@@ -5,7 +5,6 @@ import { InputEndpointBase } from "../core/Endpoint.sol";
5
5
  import { Descriptors } from "../codec/Descriptors.sol";
6
6
  import { Specs } from "../codec/Specs.sol";
7
7
  import { Nodes } from "../utils/Nodes.sol";
8
- import { Selectors } from "../utils/Selectors.sol";
9
8
 
10
9
  /// @title QueryBase
11
10
  /// @notice Abstract base for rootzero query contracts.
@@ -39,7 +38,7 @@ abstract contract QueryBase is InputEndpointBase {
39
38
  string memory name,
40
39
  uint descriptor
41
40
  ) internal returns (uint id, uint published) {
42
- id = Nodes.toQuery(Selectors.query(name), address(this));
41
+ id = Nodes.toQuery(name, address(this));
43
42
  published = endpoint(id, name, descriptor);
44
43
  }
45
44
  }
package/utils/Cursors.sol CHANGED
@@ -36,6 +36,11 @@ struct Cur {
36
36
  /// to marks. A zero mark identifies the empty cursor at position zero; `before`
37
37
  /// therefore treats it as already reached.
38
38
  ///
39
+ /// Cursor navigation assumes packed cursor inputs satisfy `i <= len`.
40
+ /// Constructors and composition helpers establish this invariant, and navigation
41
+ /// helpers preserve it. Manually constructing or modifying packed cursor words
42
+ /// may cause arithmetic panics instead of cursor-specific errors.
43
+ ///
39
44
  /// The zero word represents an absent cursor.
40
45
  library Cursors {
41
46
  /// @dev A cursor position exceeds its logical length.
@@ -214,11 +219,12 @@ library Cursors {
214
219
  }
215
220
 
216
221
  /// @notice Advance the current position of the lower cursor.
222
+ /// @dev Assumes `cur` satisfies the cursor invariant `i <= len`.
217
223
  /// @param cur Packed cursor or cursor pair.
218
224
  /// @param amount Number of bytes to advance.
219
225
  /// @return updated Cursor advanced by `amount`.
220
226
  function advance(uint cur, uint amount) internal pure returns (uint updated) {
221
- uint i = uint32(validate(cur));
227
+ uint i = uint32(cur);
222
228
  uint len = uint32(cur >> 64);
223
229
  if (amount > len - i) revert OutOfBounds();
224
230
  updated = cur + amount;
@@ -236,14 +242,15 @@ library Cursors {
236
242
 
237
243
  /// @notice Create a child cursor over `[start, end)` within the lower cursor.
238
244
  /// @dev The child starts at position zero, has no recorded count, and uses the
239
- /// supplied tag. Any higher cursor is omitted.
245
+ /// supplied tag. Any higher cursor is omitted. Assumes `cur` satisfies the
246
+ /// cursor invariant `i <= len`.
240
247
  /// @param cur Parent cursor or cursor pair.
241
248
  /// @param start Child start relative to the parent base.
242
249
  /// @param end Child exclusive end relative to the parent base.
243
250
  /// @param tag Child identity tag.
244
251
  /// @return child Packed child cursor.
245
252
  function slice(uint cur, uint start, uint end, uint8 tag) internal pure returns (uint child) {
246
- (, uint offset, uint len) = decode(validate(cur));
253
+ (, uint offset, uint len) = decode(cur);
247
254
  if (start > end || end > len) revert OutOfBounds();
248
255
  child = create(offset + start, end - start, 0, 0, tag);
249
256
  }
package/utils/Nodes.sol CHANGED
@@ -192,40 +192,45 @@ library Nodes {
192
192
  return toLocalBase(Host) | uint(uint160(target));
193
193
  }
194
194
 
195
- /// @notice Build a chain-local command ID for the given selector and contract.
196
- /// @param selector 4-byte ABI selector of the command entry point.
195
+ /// @notice Build a chain-local command ID for the given endpoint name and contract.
196
+ /// @param name Command function name.
197
197
  /// @param target Command contract address.
198
198
  /// @return node Command node ID embedding both the selector and address.
199
- function toCommand(bytes4 selector, address target) internal view returns (uint node) {
199
+ function toCommand(string memory name, address target) internal view returns (uint node) {
200
200
  node = toLocalBase(Command) | uint(uint160(target));
201
- node |= uint(uint32(selector)) << 160;
201
+ node |= uint(uint32(toSelector(name, "(bytes32,bytes,bytes)"))) << 160;
202
202
  }
203
203
 
204
- /// @notice Build a chain-local port ID for the given selector and contract.
205
- /// @param selector 4-byte ABI selector of the port entry point.
204
+ /// @notice Build a chain-local port ID for the given endpoint name and contract.
205
+ /// @param name Port function name.
206
206
  /// @param target Port contract address.
207
207
  /// @return node Port node ID embedding both the selector and address.
208
- function toPort(bytes4 selector, address target) internal view returns (uint node) {
208
+ function toPort(string memory name, address target) internal view returns (uint node) {
209
209
  node = toLocalBase(Port) | uint(uint160(target));
210
- node |= uint(uint32(selector)) << 160;
210
+ node |= uint(uint32(toSelector(name, "(bytes)"))) << 160;
211
211
  }
212
212
 
213
- /// @notice Build a chain-local query ID for the given selector and contract.
214
- /// @param selector 4-byte ABI selector of the query entry point.
213
+ /// @notice Build a chain-local query ID for the given endpoint name and contract.
214
+ /// @param name Query function name.
215
215
  /// @param target Query contract address.
216
216
  /// @return node Query node ID embedding both the selector and address.
217
- function toQuery(bytes4 selector, address target) internal view returns (uint node) {
217
+ function toQuery(string memory name, address target) internal view returns (uint node) {
218
218
  node = toLocalBase(Query) | uint(uint160(target));
219
- node |= uint(uint32(selector)) << 160;
219
+ node |= uint(uint32(toSelector(name, "(bytes)"))) << 160;
220
220
  }
221
221
 
222
- /// @notice Build a chain-local guard action ID for the given selector and contract.
223
- /// @param selector 4-byte ABI selector of the guard action entry point.
222
+ /// @notice Build a chain-local guard action ID for the given endpoint name and contract.
223
+ /// @param name Guard action function name.
224
224
  /// @param target Guard action contract address.
225
225
  /// @return node Guard action node ID embedding both the selector and address.
226
- function toGuard(bytes4 selector, address target) internal view returns (uint node) {
226
+ function toGuard(string memory name, address target) internal view returns (uint node) {
227
227
  node = toLocalBase(Guard) | uint(uint160(target));
228
- node |= uint(uint32(selector)) << 160;
228
+ node |= uint(uint32(toSelector(name, "(bytes)"))) << 160;
229
+ }
230
+
231
+ /// @dev Derive an ABI selector from an endpoint name and argument signature.
232
+ function toSelector(string memory name, string memory args) private pure returns (bytes4) {
233
+ return bytes4(keccak256(bytes(string.concat(name, args))));
229
234
  }
230
235
 
231
236
  /// @notice Derive an opaque node ID from a keccak preimage.
@@ -1,49 +0,0 @@
1
- // SPDX-License-Identifier: GPL-3.0-only
2
- pragma solidity ^0.8.33;
3
-
4
- /// @title Selectors
5
- /// @notice Canonical ABI selector derivation for rootzero endpoint types.
6
- library Selectors {
7
- /// @notice Derive the ABI selector for a command entrypoint.
8
- /// @param name Command function name.
9
- /// @return Selector for `name(bytes32,bytes,bytes)`.
10
- function command(string memory name) internal pure returns (bytes4) {
11
- return derive(name, "(bytes32,bytes,bytes)");
12
- }
13
-
14
- /// @notice Derive the ABI selector for a port entrypoint.
15
- /// @param name Port function name.
16
- /// @return Selector for `name(bytes)`.
17
- function port(string memory name) internal pure returns (bytes4) {
18
- return direct(name);
19
- }
20
-
21
- /// @notice Derive the ABI selector for a query entrypoint.
22
- /// @param name Query function name.
23
- /// @return Selector for `name(bytes)`.
24
- function query(string memory name) internal pure returns (bytes4) {
25
- return direct(name);
26
- }
27
-
28
- /// @notice Derive the ABI selector for a guard action entrypoint.
29
- /// @param name Guard action function name.
30
- /// @return Selector for `name(bytes)`.
31
- function guard(string memory name) internal pure returns (bytes4) {
32
- return direct(name);
33
- }
34
-
35
- /// @dev Derive a direct endpoint selector with a single `bytes` argument.
36
- /// @param name Endpoint function name.
37
- /// @return Selector for `name(bytes)`.
38
- function direct(string memory name) private pure returns (bytes4) {
39
- return derive(name, "(bytes)");
40
- }
41
-
42
- /// @dev Derive an ABI selector from a function name and argument signature suffix.
43
- /// @param name Function name.
44
- /// @param args Parenthesized ABI argument signature.
45
- /// @return First four bytes of the function signature hash.
46
- function derive(string memory name, string memory args) private pure returns (bytes4) {
47
- return bytes4(keccak256(bytes(string.concat(name, args))));
48
- }
49
- }