@rootzero/contracts 1.29.0 → 1.30.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/CHANGELOG.md +64 -0
- package/Codec.sol +2 -1
- package/Commands.sol +1 -1
- package/Core.sol +1 -1
- package/Endpoints.sol +2 -2
- package/README.md +90 -43
- package/Utils.sol +2 -1
- package/codec/Blocks.sol +41 -67
- package/codec/Decoders.sol +12 -20
- package/codec/Descriptors.sol +3 -14
- package/codec/Keys.sol +1 -3
- package/codec/Schema.sol +1 -3
- package/codec/Specs.sol +2 -4
- package/codec/Writers.sol +8 -9
- package/commands/Base.sol +3 -2
- package/commands/Cashout.sol +18 -16
- package/commands/Relay.sol +14 -15
- package/commands/admin/Execute.sol +2 -2
- package/core/Access.sol +14 -12
- package/core/Calls.sol +90 -102
- package/core/Host.sol +13 -11
- package/core/Pipeline.sol +173 -19
- package/core/Settlement.sol +1 -1
- package/execution/Execution.sol +25 -37
- package/package.json +1 -1
- package/ports/Allowance.sol +7 -17
- package/ports/Base.sol +4 -1
- package/ports/Dispatch.sol +1 -1
- package/ports/Pipe.sol +1 -1
- package/queries/Base.sol +1 -1
- package/utils/Accounts.sol +4 -4
- package/utils/Assets.sol +4 -5
- package/utils/Cursors.sol +24 -1
- package/utils/Flags.sol +18 -0
- package/utils/Layout.sol +3 -3
- package/utils/Nodes.sol +36 -31
- package/utils/Utils.sol +5 -5
package/utils/Nodes.sol
CHANGED
|
@@ -6,21 +6,6 @@ import {InvalidId} from "./Errors.sol";
|
|
|
6
6
|
import {Ids} from "./Ids.sol";
|
|
7
7
|
import {ensureAddr, isFamily, matchesBase, toLocalBase} from "./Utils.sol";
|
|
8
8
|
|
|
9
|
-
/// @notice Validate and unpack a command node into its ABI selector and target address.
|
|
10
|
-
/// @dev Validates only the command type prefix; chain locality and authorization are caller concerns.
|
|
11
|
-
/// @param cmd Command node ID to unpack.
|
|
12
|
-
/// @return selector ABI selector stored in bits [191:160].
|
|
13
|
-
/// @return target Contract address stored in bits [159:0].
|
|
14
|
-
function unpackCommand(uint cmd) pure returns (bytes4 selector, address target) {
|
|
15
|
-
uint32 command = (uint32(Layout.Evm) << 16) | (uint32(Layout.Node) << 8) | uint32(Layout.Command);
|
|
16
|
-
if (uint32(cmd >> 224) != command) revert InvalidId();
|
|
17
|
-
|
|
18
|
-
assembly ("memory-safe") {
|
|
19
|
-
selector := shl(224, and(shr(160, cmd), 0xffffffff))
|
|
20
|
-
target := and(cmd, 0xffffffffffffffffffffffffffffffffffffffff)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
9
|
/// @title Nodes
|
|
25
10
|
/// @notice Encoding and decoding helpers for 256-bit node identifiers.
|
|
26
11
|
///
|
|
@@ -36,20 +21,20 @@ function unpackCommand(uint cmd) pure returns (bytes4 selector, address target)
|
|
|
36
21
|
///
|
|
37
22
|
/// The helpers in this library validate and deconstruct structured node IDs.
|
|
38
23
|
library Nodes {
|
|
39
|
-
/// @dev
|
|
40
|
-
|
|
24
|
+
/// @dev 16-bit family tag shared by all node types (Evm + Node category).
|
|
25
|
+
uint16 constant Family = (uint16(Layout.Evm) << 8) | uint16(Layout.Node);
|
|
41
26
|
/// @dev Full 4-byte type prefix for chain/domain nodes.
|
|
42
|
-
uint32 constant Chain = (uint32(Layout.Evm) <<
|
|
27
|
+
uint32 constant Chain = (uint32(Layout.Evm) << 24) | (uint32(Layout.Node) << 16) | (uint32(Layout.Chain) << 8);
|
|
43
28
|
/// @dev Full 4-byte type prefix for host nodes.
|
|
44
|
-
uint32 constant Host = (uint32(Layout.Evm) <<
|
|
29
|
+
uint32 constant Host = (uint32(Layout.Evm) << 24) | (uint32(Layout.Node) << 16) | (uint32(Layout.Host) << 8);
|
|
45
30
|
/// @dev Full 4-byte type prefix for command nodes.
|
|
46
|
-
uint32 constant Command = (uint32(Layout.Evm) <<
|
|
31
|
+
uint32 constant Command = (uint32(Layout.Evm) << 24) | (uint32(Layout.Node) << 16) | (uint32(Layout.Command) << 8);
|
|
47
32
|
/// @dev Full 4-byte type prefix for port nodes.
|
|
48
|
-
uint32 constant Port = (uint32(Layout.Evm) <<
|
|
33
|
+
uint32 constant Port = (uint32(Layout.Evm) << 24) | (uint32(Layout.Node) << 16) | (uint32(Layout.Port) << 8);
|
|
49
34
|
/// @dev Full 4-byte type prefix for query nodes.
|
|
50
|
-
uint32 constant Query = (uint32(Layout.Evm) <<
|
|
35
|
+
uint32 constant Query = (uint32(Layout.Evm) << 24) | (uint32(Layout.Node) << 16) | (uint32(Layout.Query) << 8);
|
|
51
36
|
/// @dev Full 4-byte type prefix for guard action nodes.
|
|
52
|
-
uint32 constant Guard = (uint32(Layout.Evm) <<
|
|
37
|
+
uint32 constant Guard = (uint32(Layout.Evm) << 24) | (uint32(Layout.Node) << 16) | (uint32(Layout.Guard) << 8);
|
|
53
38
|
|
|
54
39
|
/// @notice Return true if `node` is a host node ID.
|
|
55
40
|
function isHost(uint node) internal pure returns (bool) {
|
|
@@ -58,22 +43,22 @@ library Nodes {
|
|
|
58
43
|
|
|
59
44
|
/// @notice Return true if `node` is a command node ID.
|
|
60
45
|
function isCommand(uint node) internal pure returns (bool) {
|
|
61
|
-
return uint32(node >> 224) == Command;
|
|
46
|
+
return (uint32(node >> 224) & 0xffffff00) == Command;
|
|
62
47
|
}
|
|
63
48
|
|
|
64
49
|
/// @notice Return true if `node` is a port node ID.
|
|
65
50
|
function isPort(uint node) internal pure returns (bool) {
|
|
66
|
-
return uint32(node >> 224) == Port;
|
|
51
|
+
return (uint32(node >> 224) & 0xffffff00) == Port;
|
|
67
52
|
}
|
|
68
53
|
|
|
69
54
|
/// @notice Return true if `node` is a query node ID.
|
|
70
55
|
function isQuery(uint node) internal pure returns (bool) {
|
|
71
|
-
return uint32(node >> 224) == Query;
|
|
56
|
+
return (uint32(node >> 224) & 0xffffff00) == Query;
|
|
72
57
|
}
|
|
73
58
|
|
|
74
59
|
/// @notice Return true if `node` is a guard action node ID.
|
|
75
60
|
function isGuard(uint node) internal pure returns (bool) {
|
|
76
|
-
return uint32(node >> 224) == Guard;
|
|
61
|
+
return (uint32(node >> 224) & 0xffffff00) == Guard;
|
|
77
62
|
}
|
|
78
63
|
|
|
79
64
|
/// @notice Return true if `node` belongs to the EVM node family.
|
|
@@ -210,7 +195,12 @@ library Nodes {
|
|
|
210
195
|
/// @param target Command contract address.
|
|
211
196
|
/// @return node Command node ID embedding both the selector and address.
|
|
212
197
|
function toCommand(string memory name, address target) internal view returns (uint node) {
|
|
213
|
-
|
|
198
|
+
return toCommand(name, target, 0);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/// @notice Build a chain-local command ID carrying endpoint behavior flags.
|
|
202
|
+
function toCommand(string memory name, address target, uint8 flags) internal view returns (uint node) {
|
|
203
|
+
node = toLocalBase(Command | uint32(flags)) | uint(uint160(target));
|
|
214
204
|
node |= uint(uint32(toSelector(name, "(bytes)"))) << 160;
|
|
215
205
|
}
|
|
216
206
|
|
|
@@ -219,7 +209,12 @@ library Nodes {
|
|
|
219
209
|
/// @param target Port contract address.
|
|
220
210
|
/// @return node Port node ID embedding both the selector and address.
|
|
221
211
|
function toPort(string memory name, address target) internal view returns (uint node) {
|
|
222
|
-
|
|
212
|
+
return toPort(name, target, 0);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/// @notice Build a chain-local port ID carrying endpoint behavior flags.
|
|
216
|
+
function toPort(string memory name, address target, uint8 flags) internal view returns (uint node) {
|
|
217
|
+
node = toLocalBase(Port | uint32(flags)) | uint(uint160(target));
|
|
223
218
|
node |= uint(uint32(toSelector(name, "(bytes)"))) << 160;
|
|
224
219
|
}
|
|
225
220
|
|
|
@@ -228,7 +223,12 @@ library Nodes {
|
|
|
228
223
|
/// @param target Query contract address.
|
|
229
224
|
/// @return node Query node ID embedding both the selector and address.
|
|
230
225
|
function toQuery(string memory name, address target) internal view returns (uint node) {
|
|
231
|
-
|
|
226
|
+
return toQuery(name, target, 0);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/// @notice Build a chain-local query ID carrying endpoint behavior flags.
|
|
230
|
+
function toQuery(string memory name, address target, uint8 flags) internal view returns (uint node) {
|
|
231
|
+
node = toLocalBase(Query | uint32(flags)) | uint(uint160(target));
|
|
232
232
|
node |= uint(uint32(toSelector(name, "(bytes)"))) << 160;
|
|
233
233
|
}
|
|
234
234
|
|
|
@@ -237,7 +237,12 @@ library Nodes {
|
|
|
237
237
|
/// @param target Guard action contract address.
|
|
238
238
|
/// @return node Guard action node ID embedding both the selector and address.
|
|
239
239
|
function toGuard(string memory name, address target) internal view returns (uint node) {
|
|
240
|
-
|
|
240
|
+
return toGuard(name, target, 0);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/// @notice Build a chain-local guard ID carrying endpoint behavior flags.
|
|
244
|
+
function toGuard(string memory name, address target, uint8 flags) internal view returns (uint node) {
|
|
245
|
+
node = toLocalBase(Guard | uint32(flags)) | uint(uint160(target));
|
|
241
246
|
node |= uint(uint32(toSelector(name, "(bytes)"))) << 160;
|
|
242
247
|
}
|
|
243
248
|
|
package/utils/Utils.sol
CHANGED
|
@@ -207,13 +207,13 @@ function toUnspecifiedBase(uint32 prefix) pure returns (uint) {
|
|
|
207
207
|
return uint(prefix) << 224;
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
/// @notice Check whether `value` belongs to the given
|
|
211
|
-
/// Only tests the top
|
|
210
|
+
/// @notice Check whether `value` belongs to the given 16-bit representation/category family.
|
|
211
|
+
/// Only tests the top 2 bytes (bits [255:240]); does not check subtype, flags, or chainid.
|
|
212
212
|
/// @param value ID to test.
|
|
213
213
|
/// @param family Expected family tag.
|
|
214
|
-
/// @return True if the top
|
|
215
|
-
function isFamily(uint value,
|
|
216
|
-
return
|
|
214
|
+
/// @return True if the top 2 bytes of `value` match `family`.
|
|
215
|
+
function isFamily(uint value, uint16 family) pure returns (bool) {
|
|
216
|
+
return uint16(value >> 240) == family;
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
/// @notice Check whether two IDs share the same 64-bit base (type tag + chainid).
|