@rootzero/contracts 1.0.0 → 1.0.1

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.
@@ -562,23 +562,23 @@ library Cursors {
562
562
  return createBlock(Keys.Pipe, bytes.concat(bytes32(value), toContextBlock(account, state, steps)));
563
563
  }
564
564
 
565
- /// @notice Encode a RELAY block.
566
- /// @param chain Destination chain node ID.
567
- /// @param endowment Native value requested for the destination pipe.
568
- /// @param steps Nested step block stream.
569
- /// @return Encoded RELAY block bytes.
570
- function toRelayBlock(uint chain, uint endowment, bytes memory steps) internal pure returns (bytes memory) {
571
- return createBlock(Keys.Relay, bytes.concat(bytes32(chain), bytes32(endowment), toBytesBlock(steps)));
572
- }
573
-
574
- /// @notice Encode a DISPATCH block.
575
- /// @param chain Destination chain node ID.
576
- /// @param endowment Native value requested for the destination dispatch.
577
- /// @param payload Encoded cross-chain payload.
578
- /// @return Encoded DISPATCH block bytes.
579
- function toDispatchBlock(uint chain, uint endowment, bytes memory payload) internal pure returns (bytes memory) {
580
- return createBlock(Keys.Dispatch, bytes.concat(bytes32(chain), bytes32(endowment), toBytesBlock(payload)));
581
- }
565
+ /// @notice Encode a RELAY block.
566
+ /// @param chain Destination chain node ID.
567
+ /// @param resources Chain-adapter-specific resources for the destination pipe.
568
+ /// @param steps Nested step block stream.
569
+ /// @return Encoded RELAY block bytes.
570
+ function toRelayBlock(uint chain, uint resources, bytes memory steps) internal pure returns (bytes memory) {
571
+ return createBlock(Keys.Relay, bytes.concat(bytes32(chain), bytes32(resources), toBytesBlock(steps)));
572
+ }
573
+
574
+ /// @notice Encode a DISPATCH block.
575
+ /// @param chain Destination chain node ID.
576
+ /// @param resources Chain-adapter-specific resources for the destination dispatch.
577
+ /// @param payload Encoded cross-chain payload.
578
+ /// @return Encoded DISPATCH block bytes.
579
+ function toDispatchBlock(uint chain, uint resources, bytes memory payload) internal pure returns (bytes memory) {
580
+ return createBlock(Keys.Dispatch, bytes.concat(bytes32(chain), bytes32(resources), toBytesBlock(payload)));
581
+ }
582
582
 
583
583
  // -------------------------------------------------------------------------
584
584
  // Raw calldata loaders
@@ -590,19 +590,31 @@ library Cursors {
590
590
  /// @param cur Cursor whose current position is advanced by `n` bytes.
591
591
  /// @param n Number of bytes to advance.
592
592
  /// @return value Loaded word.
593
- function read(Cur memory cur, uint n) internal pure returns (bytes32 value) {
594
- uint abs = cur.offset + cur.i;
595
- assembly ("memory-safe") {
596
- value := calldataload(abs)
597
- }
598
- cur.i += n;
599
- }
600
-
601
- /// @notice Read the next 16 bytes from the cursor and advance by 16 bytes.
602
- /// @dev Performs no bounds, key, length, or cursor checks.
603
- /// @param cur Cursor whose current position is advanced by 16 bytes.
604
- /// @return value Loaded bytes16 value.
605
- function read16(Cur memory cur) internal pure returns (bytes16 value) {
593
+ function read(Cur memory cur, uint n) internal pure returns (bytes32 value) {
594
+ uint abs = cur.offset + cur.i;
595
+ assembly ("memory-safe") {
596
+ value := calldataload(abs)
597
+ }
598
+ cur.i += n;
599
+ }
600
+
601
+ /// @notice Read the next 4 bytes from the cursor and advance by 4 bytes.
602
+ /// @dev Performs no bounds, key, length, or cursor checks.
603
+ /// @param cur Cursor whose current position is advanced by 4 bytes.
604
+ /// @return value Loaded bytes4 value.
605
+ function read4(Cur memory cur) internal pure returns (bytes4 value) {
606
+ uint abs = cur.offset + cur.i;
607
+ assembly ("memory-safe") {
608
+ value := calldataload(abs)
609
+ }
610
+ cur.i += 4;
611
+ }
612
+
613
+ /// @notice Read the next 16 bytes from the cursor and advance by 16 bytes.
614
+ /// @dev Performs no bounds, key, length, or cursor checks.
615
+ /// @param cur Cursor whose current position is advanced by 16 bytes.
616
+ /// @return value Loaded bytes16 value.
617
+ function read16(Cur memory cur) internal pure returns (bytes16 value) {
606
618
  uint abs = cur.offset + cur.i;
607
619
  assembly ("memory-safe") {
608
620
  value := calldataload(abs)
@@ -614,18 +626,30 @@ library Cursors {
614
626
  /// @dev Performs no bounds, key, length, or cursor checks.
615
627
  /// @param cur Cursor whose current position is advanced by 32 bytes.
616
628
  /// @return value Loaded word.
617
- function read32(Cur memory cur) internal pure returns (bytes32 value) {
618
- uint abs = cur.offset + cur.i;
619
- assembly ("memory-safe") {
620
- value := calldataload(abs)
621
- }
622
- cur.i += 32;
623
- }
624
-
625
- /// @notice Read the next two 32-byte words from the cursor and advance by 64 bytes.
626
- /// @dev Performs no bounds, key, length, or cursor checks.
627
- /// @param cur Cursor whose current position is advanced by 64 bytes.
628
- /// @return a First loaded word.
629
+ function read32(Cur memory cur) internal pure returns (bytes32 value) {
630
+ uint abs = cur.offset + cur.i;
631
+ assembly ("memory-safe") {
632
+ value := calldataload(abs)
633
+ }
634
+ cur.i += 32;
635
+ }
636
+
637
+ /// @notice Read the next uint from the cursor and advance by one word.
638
+ /// @dev Performs no bounds, key, length, or cursor checks.
639
+ /// @param cur Cursor whose current position is advanced by 32 bytes.
640
+ /// @return value Loaded uint value.
641
+ function readUint(Cur memory cur) internal pure returns (uint value) {
642
+ uint abs = cur.offset + cur.i;
643
+ assembly ("memory-safe") {
644
+ value := calldataload(abs)
645
+ }
646
+ cur.i += 32;
647
+ }
648
+
649
+ /// @notice Read the next two 32-byte words from the cursor and advance by 64 bytes.
650
+ /// @dev Performs no bounds, key, length, or cursor checks.
651
+ /// @param cur Cursor whose current position is advanced by 64 bytes.
652
+ /// @return a First loaded word.
629
653
  /// @return b Second loaded word.
630
654
  function read64(Cur memory cur) internal pure returns (bytes32 a, bytes32 b) {
631
655
  uint abs = cur.offset + cur.i;
@@ -1110,35 +1134,35 @@ library Cursors {
1110
1134
  cur.exit(end);
1111
1135
  }
1112
1136
 
1113
- /// @notice Consume a RELAY block and return its destination chain, endowment, and step stream.
1114
- /// @param cur Cursor; advanced past the block.
1115
- /// @return chain Destination chain node ID.
1116
- /// @return endowment Native value requested for the destination pipe.
1117
- /// @return steps Embedded step block stream.
1118
- function unpackRelay(
1119
- Cur memory cur
1120
- ) internal pure returns (uint chain, uint endowment, bytes calldata steps) {
1121
- uint end = cur.enter(Keys.Relay, 64 + Sizes.Header, 0);
1122
- chain = uint(cur.read32());
1123
- endowment = uint(cur.read32());
1124
- steps = cur.unpackBytes();
1125
- cur.exit(end);
1126
- }
1127
-
1128
- /// @notice Consume a DISPATCH block and return its destination chain, endowment, and payload.
1129
- /// @param cur Cursor; advanced past the block.
1130
- /// @return chain Destination chain node ID.
1131
- /// @return endowment Native value requested for the destination dispatch.
1132
- /// @return payload Encoded cross-chain payload.
1133
- function unpackDispatch(
1134
- Cur memory cur
1135
- ) internal pure returns (uint chain, uint endowment, bytes calldata payload) {
1136
- uint end = cur.enter(Keys.Dispatch, 64 + Sizes.Header, 0);
1137
- chain = uint(cur.read32());
1138
- endowment = uint(cur.read32());
1139
- payload = cur.unpackBytes();
1140
- cur.exit(end);
1141
- }
1137
+ /// @notice Consume a RELAY block and return its destination chain, resources, and step stream.
1138
+ /// @param cur Cursor; advanced past the block.
1139
+ /// @return chain Destination chain node ID.
1140
+ /// @return resources Chain-adapter-specific resources for the destination pipe.
1141
+ /// @return steps Embedded step block stream.
1142
+ function unpackRelay(
1143
+ Cur memory cur
1144
+ ) internal pure returns (uint chain, uint resources, bytes calldata steps) {
1145
+ uint end = cur.enter(Keys.Relay, 64 + Sizes.Header, 0);
1146
+ chain = cur.readUint();
1147
+ resources = cur.readUint();
1148
+ steps = cur.unpackBytes();
1149
+ cur.exit(end);
1150
+ }
1151
+
1152
+ /// @notice Consume a DISPATCH block and return its destination chain, resources, and payload.
1153
+ /// @param cur Cursor; advanced past the block.
1154
+ /// @return chain Destination chain node ID.
1155
+ /// @return resources Chain-adapter-specific resources for the destination dispatch.
1156
+ /// @return payload Encoded cross-chain payload.
1157
+ function unpackDispatch(
1158
+ Cur memory cur
1159
+ ) internal pure returns (uint chain, uint resources, bytes calldata payload) {
1160
+ uint end = cur.enter(Keys.Dispatch, 64 + Sizes.Header, 0);
1161
+ chain = cur.readUint();
1162
+ resources = cur.readUint();
1163
+ payload = cur.unpackBytes();
1164
+ cur.exit(end);
1165
+ }
1142
1166
 
1143
1167
  // Type-specific validators
1144
1168
 
package/blocks/Keys.sol CHANGED
@@ -39,10 +39,10 @@ library Keys {
39
39
  bytes4 constant Transaction = bytes4(keccak256("#transaction"));
40
40
  /// @dev Sub-command invocation - (uint target, uint value, #bytes as request)
41
41
  bytes4 constant Step = bytes4(keccak256("#step"));
42
- /// @dev Cross-chain pipe relay - (uint chain, uint endowment, #bytes as steps)
43
- bytes4 constant Relay = bytes4(keccak256("#relay"));
44
- /// @dev Cross-chain encoded payload dispatch - (uint chain, uint endowment, #bytes as payload)
45
- bytes4 constant Dispatch = bytes4(keccak256("#dispatch"));
42
+ /// @dev Cross-chain pipe relay - (uint chain, uint resources, #bytes as steps)
43
+ bytes4 constant Relay = bytes4(keccak256("#relay"));
44
+ /// @dev Cross-chain encoded payload dispatch - (uint chain, uint resources, #bytes as payload)
45
+ bytes4 constant Dispatch = bytes4(keccak256("#dispatch"));
46
46
  /// @dev Raw external call - (uint target, uint value, #bytes as payload)
47
47
  bytes4 constant Call = bytes4(keccak256("#call"));
48
48
  /// @dev Command context transport - (bytes32 account, #bytes as state, #bytes as request)
package/blocks/Schema.sol CHANGED
@@ -65,8 +65,8 @@ library Schemas {
65
65
  string constant Pipe = "#pipe { uint value, #context { bytes32 account, #bytes as state, #bytes as steps } }";
66
66
  string constant Call = "#call { uint target, uint value, #bytes as payload }";
67
67
  string constant Step = "#step { uint target, uint value, #bytes as request }";
68
- string constant Relay = "#relay { uint chain, uint endowment, #bytes as steps }";
69
- string constant Dispatch = "#dispatch { uint chain, uint endowment, #bytes as payload }";
68
+ string constant Relay = "#relay { uint chain, uint resources, #bytes as steps }";
69
+ string constant Dispatch = "#dispatch { uint chain, uint resources, #bytes as payload }";
70
70
  string constant Bounty = "#bounty { uint amount, bytes32 relayer }";
71
71
  string constant Fee = "#fee { uint amount }";
72
72
  string constant Auth = "#auth { uint cid, uint deadline, #bytes as proof }";
@@ -8,24 +8,23 @@ import {Budget} from "../utils/Value.sol";
8
8
 
9
9
  using Cursors for Cur;
10
10
 
11
- abstract contract RelayPayableHook {
12
- /// @notice Override to relay `steps` to `chain` with the current account and state.
13
- /// @param chain Destination chain node ID.
14
- /// @param endowment Native value requested for the destination pipe. The hook
15
- /// decides how much source-chain budget must be spent to fund this value on
16
- /// the destination chain.
17
- /// @param account Command account identifier.
18
- /// @param state Current command state block stream.
19
- /// @param steps Embedded destination step block stream.
20
- /// @param budget Source-chain native-value budget available for transport
21
- /// fees and destination endowment funding.
22
- function relay(
23
- uint chain,
24
- uint endowment,
25
- bytes32 account,
26
- bytes calldata state,
27
- bytes calldata steps,
28
- Budget memory budget
11
+ abstract contract RelayPayableHook {
12
+ /// @notice Override to relay `steps` to `chain` with the current account and state.
13
+ /// @param chain Destination chain node ID.
14
+ /// @param resources Chain-adapter-specific destination resources. EVM adapters
15
+ /// may interpret this as packed execution gas and destination value.
16
+ /// @param account Command account identifier.
17
+ /// @param state Current command state block stream.
18
+ /// @param steps Embedded destination step block stream.
19
+ /// @param budget Source-chain native-value budget available for transport
20
+ /// fees and destination resource funding.
21
+ function relay(
22
+ uint chain,
23
+ uint resources,
24
+ bytes32 account,
25
+ bytes calldata state,
26
+ bytes calldata steps,
27
+ Budget memory budget
29
28
  ) internal virtual;
30
29
  }
31
30
 
@@ -47,12 +46,12 @@ abstract contract RelayPayable is CommandBase, Payable, RelayPayableHook {
47
46
  /// @param c Command context; `c.request` must contain exactly one RELAY block.
48
47
  /// @return output Empty output state.
49
48
  function relayPayable(CommandContext calldata c) external payable onlyCommand returns (bytes memory output) {
50
- (Cur memory request, ) = Cursors.init(c.request, 0, 1, 1);
51
- Budget memory budget = valueBudget();
52
-
53
- (uint chain, uint endowment, bytes calldata steps) = request.unpackRelay();
54
- relay(chain, endowment, c.account, c.state, steps, budget);
55
- request.complete();
56
- return "";
57
- }
58
- }
49
+ (Cur memory request, ) = Cursors.init(c.request, 0, 1, 1);
50
+ Budget memory budget = valueBudget();
51
+
52
+ (uint chain, uint resources, bytes calldata steps) = request.unpackRelay();
53
+ relay(chain, resources, c.account, c.state, steps, budget);
54
+ request.complete();
55
+ return "";
56
+ }
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rootzero/contracts",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Solidity contracts and protocol building blocks for rootzero hosts and commands.",
5
5
  "private": false,
6
6
  "license": "GPL-3.0-only",
package/peer/Dispatch.sol CHANGED
@@ -8,17 +8,16 @@ import { Budget } from "../utils/Value.sol";
8
8
 
9
9
  using Cursors for Cur;
10
10
 
11
- abstract contract PeerDispatchPayableHook {
12
- /// @notice Override to dispatch an already encoded payload to `chain`.
13
- /// @param chain Destination chain node ID.
14
- /// @param endowment Native value requested for the destination dispatch. The
15
- /// hook decides how much source-chain budget must be spent to fund this
16
- /// value on the destination chain.
17
- /// @param payload Encoded payload ready for the transport layer.
18
- /// @param budget Source-chain native-value budget available for transport
19
- /// fees and destination endowment funding.
20
- function dispatch(uint chain, uint endowment, bytes calldata payload, Budget memory budget) internal virtual;
21
- }
11
+ abstract contract PeerDispatchPayableHook {
12
+ /// @notice Override to dispatch an already encoded payload to `chain`.
13
+ /// @param chain Destination chain node ID.
14
+ /// @param resources Chain-adapter-specific destination resources. EVM adapters
15
+ /// may interpret this as packed execution gas and destination value.
16
+ /// @param payload Encoded payload ready for the transport layer.
17
+ /// @param budget Source-chain native-value budget available for transport
18
+ /// fees and destination resource funding.
19
+ function dispatch(uint chain, uint resources, bytes calldata payload, Budget memory budget) internal virtual;
20
+ }
22
21
 
23
22
  /// @title PeerDispatchPayable
24
23
  /// @notice Peer endpoint that forwards DISPATCH blocks to a host-defined dispatch hook.
@@ -37,14 +36,14 @@ abstract contract PeerDispatchPayable is PeerBase, Payable, PeerDispatchPayableH
37
36
  /// @return output Empty response bytes.
38
37
  function peerDispatchPayable(bytes calldata request) external payable onlyPeer returns (bytes memory output) {
39
38
  (Cur memory input, , ) = Cursors.init(request, 0, 1);
40
- Budget memory budget = valueBudget();
41
-
42
- while (input.i < input.len) {
43
- (uint chain, uint endowment, bytes calldata payload) = input.unpackDispatch();
44
- dispatch(chain, endowment, payload, budget);
45
- }
46
-
47
- input.complete();
39
+ Budget memory budget = valueBudget();
40
+
41
+ while (input.i < input.len) {
42
+ (uint chain, uint resources, bytes calldata payload) = input.unpackDispatch();
43
+ dispatch(chain, resources, payload, budget);
44
+ }
45
+
46
+ input.complete();
48
47
  return "";
49
48
  }
50
49