@rootzero/contracts 1.13.0 → 1.15.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 +87 -3
- package/Codec.sol +21 -0
- package/Commands.sol +14 -0
- package/Core.sol +8 -6
- package/Endpoints.sol +2 -7
- package/Events.sol +1 -2
- package/README.md +70 -37
- package/Utils.sol +2 -4
- package/annotations/Action.sol +17 -0
- package/annotations/Label.sol +23 -0
- package/annotations/Schema.sol +53 -0
- package/codec/Blocks.sol +1643 -0
- package/codec/Buffers.sol +165 -0
- package/codec/Decoders.sol +570 -0
- package/codec/Descriptors.sol +124 -0
- package/{blocks → codec}/Keys.sol +10 -18
- package/codec/Readers.sol +114 -0
- package/{blocks → codec}/Schema.sol +43 -80
- package/codec/Specs.sol +240 -0
- package/codec/Writers.sol +485 -0
- package/commands/Allocate.sol +21 -20
- package/commands/Base.sol +83 -45
- package/commands/Burn.sol +23 -14
- package/commands/Credit.sol +21 -20
- package/commands/Debit.sol +25 -28
- package/commands/Deposit.sol +41 -36
- package/commands/Payout.sol +26 -16
- package/commands/Provision.sol +37 -38
- package/commands/Recover.sol +20 -19
- package/commands/Relay.sol +24 -22
- package/commands/Withdraw.sol +20 -19
- package/commands/admin/AllowAssets.sol +19 -16
- package/commands/admin/Allowance.sol +18 -13
- package/commands/admin/Annotate.sol +36 -0
- package/commands/admin/Appoint.sol +19 -16
- package/commands/admin/Authorize.sol +23 -14
- package/commands/admin/Base.sol +9 -2
- package/commands/admin/DenyAssets.sol +19 -16
- package/commands/admin/Dismiss.sol +19 -16
- package/commands/admin/Execute.sol +21 -19
- package/commands/admin/Unauthorize.sol +23 -14
- package/core/Access.sol +91 -49
- package/core/Calls.sol +30 -33
- package/core/Endpoint.sol +46 -143
- package/core/Host.sol +63 -21
- package/core/Pipeline.sol +16 -15
- package/core/Types.sol +1 -1
- package/docs/Schema.md +48 -31
- package/events/Annotation.sol +24 -0
- package/events/Endpoint.sol +2 -2
- package/events/Guardian.sol +2 -2
- package/events/Introduction.sol +3 -2
- package/execution/Budget.sol +40 -0
- package/execution/Execution.sol +1104 -0
- package/guards/Base.sol +11 -12
- package/guards/Revoke.sol +11 -9
- package/package.json +1 -1
- package/ports/AllowAssets.sol +12 -15
- package/ports/Allowance.sol +11 -9
- package/ports/Base.sol +35 -16
- package/ports/Credit.sol +11 -9
- package/ports/Debit.sol +11 -9
- package/ports/DenyAssets.sol +10 -13
- package/ports/Dispatch.sol +13 -15
- package/ports/Pipe.sol +14 -12
- package/ports/Redeem.sol +12 -9
- package/ports/Settle.sol +16 -10
- package/queries/Assets.sol +15 -15
- package/queries/Balances.sol +17 -17
- package/queries/Base.sol +26 -12
- package/utils/Accounts.sol +0 -23
- package/utils/Actions.sol +1 -0
- package/utils/Cursors.sol +367 -0
- package/utils/Lanes.sol +14 -0
- package/utils/Layout.sol +0 -2
- package/utils/Selectors.sol +2 -2
- package/utils/Utils.sol +46 -0
- package/Cursors.sol +0 -16
- package/blocks/Cursors.sol +0 -1529
- package/blocks/Writers.sol +0 -1036
- package/commands/admin/Label.sol +0 -32
- package/commands/admin/Schemas.sol +0 -32
- package/core/Payable.sol +0 -53
- package/events/Labeled.sol +0 -21
- package/events/Schema.sol +0 -23
- package/utils/Value.sol +0 -43
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {Specs} from "./Specs.sol";
|
|
5
|
+
import {Lanes} from "../utils/Lanes.sol";
|
|
6
|
+
|
|
7
|
+
/// @title Descriptors
|
|
8
|
+
/// @notice Packing and lane metadata helpers for endpoint descriptors.
|
|
9
|
+
library Descriptors {
|
|
10
|
+
/// @dev The requested lane is not part of an endpoint descriptor.
|
|
11
|
+
error InvalidLane();
|
|
12
|
+
|
|
13
|
+
/// @dev Endpoint accepts nonzero native value.
|
|
14
|
+
uint8 internal constant Funded = 1 << 0;
|
|
15
|
+
/// @dev Endpoint is restricted to the admin account.
|
|
16
|
+
uint8 internal constant Admin = 1 << 1;
|
|
17
|
+
|
|
18
|
+
/// @notice Create a descriptor from endpoint lane specifications and flags.
|
|
19
|
+
/// @dev Layout: `[state key:4][stride:1]`
|
|
20
|
+
/// `[input key:4][item:4][stride:1]`
|
|
21
|
+
/// `[output key:4][min:4][max:4][hint:3][stride:1]`
|
|
22
|
+
/// `[transactions:1]`
|
|
23
|
+
/// `[flags:1]`. Flag bits: funded = 0, admin = 1.
|
|
24
|
+
/// @param state State lane specification.
|
|
25
|
+
/// @param input Input lane specification, optionally wrapped in a container.
|
|
26
|
+
/// @param output Output writer specification.
|
|
27
|
+
/// @param transactions Transactions produced per batch.
|
|
28
|
+
/// @param flags Endpoint behavior flags.
|
|
29
|
+
/// @return descriptor Packed endpoint descriptor.
|
|
30
|
+
function create(
|
|
31
|
+
uint state,
|
|
32
|
+
uint input,
|
|
33
|
+
uint output,
|
|
34
|
+
uint8 transactions,
|
|
35
|
+
uint8 flags
|
|
36
|
+
) internal pure returns (uint descriptor) {
|
|
37
|
+
state = Specs.normalize(state, true);
|
|
38
|
+
input = Specs.normalize(input, false);
|
|
39
|
+
output = Specs.normalize(output, true);
|
|
40
|
+
|
|
41
|
+
descriptor = pack(state, input, output, transactions, flags);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// @dev Pack normalized endpoint specs and flags into a descriptor.
|
|
45
|
+
/// @param state Normalized direct state specification.
|
|
46
|
+
/// @param input Normalized input specification.
|
|
47
|
+
/// @param output Normalized direct output specification.
|
|
48
|
+
/// @param transactions Transactions produced per batch.
|
|
49
|
+
/// @param flags Endpoint behavior flags.
|
|
50
|
+
/// @return descriptor Packed endpoint descriptor.
|
|
51
|
+
function pack(
|
|
52
|
+
uint state,
|
|
53
|
+
uint input,
|
|
54
|
+
uint output,
|
|
55
|
+
uint8 transactions,
|
|
56
|
+
uint8 flags
|
|
57
|
+
) private pure returns (uint descriptor) {
|
|
58
|
+
(bytes4 outer, bytes4 child) = Specs.keys(input);
|
|
59
|
+
|
|
60
|
+
descriptor |= uint(uint32(Specs.key(state))) << 224;
|
|
61
|
+
descriptor |= uint(Specs.stride(state)) << 216;
|
|
62
|
+
descriptor |= uint(uint32(outer)) << 184;
|
|
63
|
+
descriptor |= uint(uint32(child)) << 152;
|
|
64
|
+
descriptor |= uint(Specs.stride(input)) << 144;
|
|
65
|
+
descriptor |= (output >> 128) << 16;
|
|
66
|
+
descriptor |= uint(transactions) << 8;
|
|
67
|
+
descriptor |= flags;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/// @notice Return whether a descriptor contains `flag`.
|
|
71
|
+
/// @param descriptor Packed endpoint descriptor.
|
|
72
|
+
/// @param flag Flag bit or bit set to test.
|
|
73
|
+
/// @return Whether any requested flag bit is present.
|
|
74
|
+
function flagged(uint descriptor, uint8 flag) internal pure returns (bool) {
|
|
75
|
+
return uint8(descriptor) & flag != 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/// @notice Return the effective per-batch stride for `lane`.
|
|
79
|
+
/// @dev Descriptor creation resolves implicit spec strides, so every lane
|
|
80
|
+
/// stores its effective value directly.
|
|
81
|
+
/// @param descriptor Packed endpoint descriptor.
|
|
82
|
+
/// @param lane Lane identifier from `Lanes`.
|
|
83
|
+
/// @return Effective blocks per batch for the lane.
|
|
84
|
+
function stride(uint descriptor, uint8 lane) internal pure returns (uint8) {
|
|
85
|
+
if (lane == Lanes.State) return uint8(descriptor >> 216);
|
|
86
|
+
if (lane == Lanes.Input) return uint8(descriptor >> 144);
|
|
87
|
+
if (lane == Lanes.Output) return uint8(descriptor >> 16);
|
|
88
|
+
if (lane == Lanes.Transactions) return uint8(descriptor >> 8);
|
|
89
|
+
revert InvalidLane();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/// @notice Return the effective block key for `lane`.
|
|
93
|
+
/// @dev Input returns its outer key. Transaction blocks have a fixed
|
|
94
|
+
/// protocol key that is not stored in the descriptor.
|
|
95
|
+
/// @param descriptor Packed endpoint descriptor.
|
|
96
|
+
/// @param lane Lane identifier from `Lanes`.
|
|
97
|
+
/// @return Effective outer block key for the lane.
|
|
98
|
+
function key(uint descriptor, uint8 lane) internal pure returns (bytes4) {
|
|
99
|
+
if (lane == Lanes.State) return bytes4(uint32(descriptor >> 224));
|
|
100
|
+
if (lane == Lanes.Input) return bytes4(uint32(descriptor >> 184));
|
|
101
|
+
if (lane == Lanes.Output) return bytes4(uint32(descriptor >> 112));
|
|
102
|
+
if (lane == Lanes.Transactions) return Specs.key(Specs.Transaction);
|
|
103
|
+
revert InvalidLane();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/// @notice Return the buffer configuration for descriptor writer `lane`.
|
|
107
|
+
/// @param descriptor Packed endpoint descriptor.
|
|
108
|
+
/// @param lane Output or transaction writer lane.
|
|
109
|
+
/// @param groups Number of execution batches to allocate for.
|
|
110
|
+
/// @return capacity Initial logical byte capacity.
|
|
111
|
+
/// @return growable Whether the writer may grow beyond that capacity.
|
|
112
|
+
function allocation(uint descriptor, uint8 lane, uint groups) internal pure returns (uint capacity, bool growable) {
|
|
113
|
+
if (lane == Lanes.Output) {
|
|
114
|
+
uint spec = uint(uint128(descriptor >> 16)) << 128;
|
|
115
|
+
return Specs.allocation(spec, groups);
|
|
116
|
+
}
|
|
117
|
+
if (lane == Lanes.Transactions) {
|
|
118
|
+
uint count = groups * stride(descriptor, lane);
|
|
119
|
+
return Specs.allocation(Specs.Transaction, count);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
revert InvalidLane();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -5,7 +5,7 @@ pragma solidity ^0.8.33;
|
|
|
5
5
|
/// @notice Standard block type selectors for the rootzero block stream protocol.
|
|
6
6
|
/// Standard keys use the first 4 bytes of `keccak256("#name")` by convention.
|
|
7
7
|
/// Custom block keys only need to be unique in the context where they are used;
|
|
8
|
-
/// hosts may publish custom key meanings with
|
|
8
|
+
/// hosts may publish custom key meanings with `#schema` annotations.
|
|
9
9
|
library Keys {
|
|
10
10
|
/// @dev Empty / unset key.
|
|
11
11
|
bytes4 constant Empty = bytes4(0);
|
|
@@ -15,18 +15,12 @@ library Keys {
|
|
|
15
15
|
bytes4 constant Amount = bytes4(keccak256("#amount"));
|
|
16
16
|
/// @dev Ledger balance - (bytes32 asset, uint amount)
|
|
17
17
|
bytes4 constant Balance = bytes4(keccak256("#balance"));
|
|
18
|
-
/// @dev
|
|
19
|
-
bytes4 constant BalanceLimit = bytes4(keccak256("#balanceLimit"));
|
|
20
|
-
/// @dev Host-scoped request amount - (uint host, bytes32 asset, uint amount)
|
|
18
|
+
/// @dev Host-scoped input amount - (uint host, bytes32 asset, uint amount)
|
|
21
19
|
bytes4 constant Allocation = bytes4(keccak256("#allocation"));
|
|
22
20
|
/// @dev Host-scoped allowance cap - (uint host, bytes32 asset, uint amount)
|
|
23
21
|
bytes4 constant Allowance = bytes4(keccak256("#allowance"));
|
|
24
22
|
/// @dev Cross-host custody state - (uint host, bytes32 asset, uint amount)
|
|
25
23
|
bytes4 constant Custody = bytes4(keccak256("#custody"));
|
|
26
|
-
/// @dev Cross-host custody constraint - (uint host, bytes32 asset, uint min, uint max)
|
|
27
|
-
bytes4 constant CustodyLimit = bytes4(keccak256("#custodyLimit"));
|
|
28
|
-
/// @dev Fee amount - (uint amount)
|
|
29
|
-
bytes4 constant Fee = bytes4(keccak256("#fee"));
|
|
30
24
|
/// @dev List wrapper; payload is an embedded repeated block stream
|
|
31
25
|
bytes4 constant List = bytes4(keccak256("#list"));
|
|
32
26
|
/// @dev EVM-encoded payload field; layout follows standard ABI tuple encoding
|
|
@@ -39,11 +33,11 @@ library Keys {
|
|
|
39
33
|
bytes4 constant Account = bytes4(keccak256("#account"));
|
|
40
34
|
/// @dev Transfer record passed through the pipeline - (bytes32 from, bytes32 to, bytes32 asset, uint amount)
|
|
41
35
|
bytes4 constant Transaction = bytes4(keccak256("#transaction"));
|
|
42
|
-
/// @dev Sub-command invocation - (uint
|
|
36
|
+
/// @dev Sub-command invocation - (uint cmd, uint resources, #bytes as input)
|
|
43
37
|
bytes4 constant Step = bytes4(keccak256("#step"));
|
|
44
|
-
/// @dev Portal relay
|
|
38
|
+
/// @dev Portal relay input - (uint portal, uint resources, #bytes as input)
|
|
45
39
|
bytes4 constant Relay = bytes4(keccak256("#relay"));
|
|
46
|
-
/// @dev Command context transport - (bytes32 account, #bytes as state, #bytes as
|
|
40
|
+
/// @dev Command context transport - (bytes32 account, #bytes as state, #bytes as input)
|
|
47
41
|
bytes4 constant Context = bytes4(keccak256("#context"));
|
|
48
42
|
/// @dev Recoverable witness - (uint handler, uint resources, bytes32 key, #bytes as witness)
|
|
49
43
|
bytes4 constant Recover = bytes4(keccak256("#recover"));
|
|
@@ -51,23 +45,21 @@ library Keys {
|
|
|
51
45
|
bytes4 constant Dispatch = bytes4(keccak256("#dispatch"));
|
|
52
46
|
/// @dev Raw external call - (uint target, uint resources, #bytes as payload)
|
|
53
47
|
bytes4 constant Call = bytes4(keccak256("#call"));
|
|
54
|
-
/// @dev Authentication proof - (uint cid, uint deadline, #bytes as proof); must appear last in its segment
|
|
55
|
-
bytes4 constant Auth = bytes4(keccak256("#auth"));
|
|
56
48
|
/// @dev Asset descriptor without amount - (bytes32 asset)
|
|
57
49
|
bytes4 constant Asset = bytes4(keccak256("#asset"));
|
|
58
50
|
/// @dev Node identifier - (uint id)
|
|
59
51
|
bytes4 constant Node = bytes4(keccak256("#node"));
|
|
60
|
-
/// @dev
|
|
61
|
-
bytes4 constant Bounty = bytes4(keccak256("#bounty"));
|
|
62
|
-
/// @dev Mutable node label - (uint id, bytes32 namespace, #string as name)
|
|
52
|
+
/// @dev Entity label annotation - (bytes32 namespace, #string as name)
|
|
63
53
|
bytes4 constant Label = bytes4(keccak256("#label"));
|
|
54
|
+
/// @dev Entity annotations - (uint entity, #bytes as data)
|
|
55
|
+
bytes4 constant Annotation = bytes4(keccak256("#annotation"));
|
|
56
|
+
/// @dev Primary semantic action annotation - (uint action)
|
|
57
|
+
bytes4 constant Action = bytes4(keccak256("#action"));
|
|
64
58
|
/// @dev Block schema publication - (bytes4 key, #string as body, bytes32 name)
|
|
65
59
|
bytes4 constant Schema = bytes4(keccak256("#schema"));
|
|
66
60
|
|
|
67
61
|
/// @dev Structural status form - (uint code)
|
|
68
62
|
bytes4 constant Status = bytes4(keccak256("#status"));
|
|
69
|
-
/// @dev Structural asset amount form - (bytes32 asset, uint amount)
|
|
70
|
-
bytes4 constant AssetAmount = bytes4(keccak256("#assetAmount"));
|
|
71
63
|
/// @dev Structural account asset form - (bytes32 account, bytes32 asset)
|
|
72
64
|
bytes4 constant AccountAsset = bytes4(keccak256("#accountAsset"));
|
|
73
65
|
/// @dev Structural account amount form - (bytes32 account, bytes32 asset, uint amount)
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-only
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
|
+
|
|
4
|
+
import {Sizes, Specs} from "./Specs.sol";
|
|
5
|
+
import {Keys} from "./Keys.sol";
|
|
6
|
+
|
|
7
|
+
/// @notice Mutable reader over a block stream stored in memory.
|
|
8
|
+
/// All positions (`i`) are byte offsets relative to the start of `source`.
|
|
9
|
+
struct Reader {
|
|
10
|
+
/// @dev Current read position, relative to the source start.
|
|
11
|
+
uint i;
|
|
12
|
+
/// @dev Memory bytes containing the complete source region.
|
|
13
|
+
bytes source;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
using Readers for Reader;
|
|
17
|
+
|
|
18
|
+
/// @title Readers
|
|
19
|
+
/// @notice Memory block stream parser for the rootzero protocol.
|
|
20
|
+
/// A `Reader` advances through an existing `bytes memory` source without copying its contents.
|
|
21
|
+
/// Blocks are encoded as `[bytes4 key][bytes4 payloadLen][payload]`.
|
|
22
|
+
library Readers {
|
|
23
|
+
/// @dev The current block has a truncated header or payload, an unexpected key,
|
|
24
|
+
/// or a payload size outside the accepted range.
|
|
25
|
+
error InvalidBlock();
|
|
26
|
+
|
|
27
|
+
/// @notice Create a reader backed by a memory byte array.
|
|
28
|
+
/// @param source Memory bytes containing the block stream.
|
|
29
|
+
/// @return cur Reader positioned at the beginning of `source`.
|
|
30
|
+
function open(bytes memory source) internal pure returns (Reader memory cur) {
|
|
31
|
+
cur.source = source;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// @notice Return whether the reader has consumed its entire source.
|
|
35
|
+
/// @param cur Reader whose position should be checked.
|
|
36
|
+
/// @return Whether `cur.i` equals the source length.
|
|
37
|
+
function done(Reader memory cur) internal pure returns (bool) {
|
|
38
|
+
return cur.i == cur.source.length;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// @notice Return whether the reader has bytes left to consume.
|
|
42
|
+
/// @param cur Reader whose position should be checked.
|
|
43
|
+
/// @return Whether `cur.i` differs from the source length.
|
|
44
|
+
function more(Reader memory cur) internal pure returns (bool) {
|
|
45
|
+
return cur.i != cur.source.length;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// @notice Validate and consume the current block, advancing `cur.i` past it.
|
|
49
|
+
/// @param cur Reader to advance.
|
|
50
|
+
/// @param key Expected block key.
|
|
51
|
+
/// @param min Minimum payload length.
|
|
52
|
+
/// @param max Maximum payload length; zero means unbounded.
|
|
53
|
+
/// @return abs Absolute memory address of the payload start.
|
|
54
|
+
function consume(
|
|
55
|
+
Reader memory cur,
|
|
56
|
+
bytes4 key,
|
|
57
|
+
uint min,
|
|
58
|
+
uint max
|
|
59
|
+
) private pure returns (uint abs) {
|
|
60
|
+
bytes memory source = cur.source;
|
|
61
|
+
uint i = cur.i;
|
|
62
|
+
|
|
63
|
+
if (i > source.length || source.length - i < Sizes.Header) revert InvalidBlock();
|
|
64
|
+
|
|
65
|
+
bytes4 current;
|
|
66
|
+
uint len;
|
|
67
|
+
assembly ("memory-safe") {
|
|
68
|
+
let header := mload(add(add(source, 0x20), i))
|
|
69
|
+
current := header
|
|
70
|
+
len := and(shr(192, header), 0xffffffff)
|
|
71
|
+
abs := add(add(source, 0x28), i)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (current != key || len < min || (max != 0 && len > max)) revert InvalidBlock();
|
|
75
|
+
if (len > source.length - i - Sizes.Header) revert InvalidBlock();
|
|
76
|
+
cur.i = i + Sizes.Header + len;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/// @notice Validate and consume the current block described by `spec`.
|
|
80
|
+
function consume(Reader memory cur, uint spec) internal pure returns (uint abs) {
|
|
81
|
+
(bytes4 key, uint32 min, uint32 max) = Specs.decode(spec);
|
|
82
|
+
return consume(cur, key, min, max);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/// @notice Consume a BALANCE block and return its fields.
|
|
86
|
+
/// @param cur Reader; advanced past the block.
|
|
87
|
+
/// @return asset Asset identifier.
|
|
88
|
+
/// @return amount Token amount.
|
|
89
|
+
function unpackBalance(Reader memory cur) internal pure returns (bytes32 asset, uint amount) {
|
|
90
|
+
uint abs = consume(cur, Keys.Balance, 64, 64);
|
|
91
|
+
assembly ("memory-safe") {
|
|
92
|
+
asset := mload(abs)
|
|
93
|
+
amount := mload(add(abs, 0x20))
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// @notice Consume a TRANSACTION block and return its fields.
|
|
98
|
+
/// @param cur Reader; advanced past the block.
|
|
99
|
+
/// @return from Source account identifier.
|
|
100
|
+
/// @return to Destination account identifier.
|
|
101
|
+
/// @return asset Asset identifier.
|
|
102
|
+
/// @return amount Token amount.
|
|
103
|
+
function unpackTransaction(
|
|
104
|
+
Reader memory cur
|
|
105
|
+
) internal pure returns (bytes32 from, bytes32 to, bytes32 asset, uint amount) {
|
|
106
|
+
uint abs = consume(cur, Keys.Transaction, 128, 128);
|
|
107
|
+
assembly ("memory-safe") {
|
|
108
|
+
from := mload(abs)
|
|
109
|
+
to := mload(add(abs, 0x20))
|
|
110
|
+
asset := mload(add(abs, 0x40))
|
|
111
|
+
amount := mload(add(abs, 0x60))
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -12,7 +12,7 @@ pragma solidity ^0.8.33;
|
|
|
12
12
|
// - an empty schema string means the block has no structured payload
|
|
13
13
|
// - commas separate siblings at every level
|
|
14
14
|
// - braces define the current block payload body
|
|
15
|
-
// - command
|
|
15
|
+
// - command inputs are a single run when the input schema is non-empty
|
|
16
16
|
// - command state is a single active state run without trailing globals
|
|
17
17
|
// - run items may repeat at top level for batching
|
|
18
18
|
// - `maybe #x` marks an optional block item
|
|
@@ -36,11 +36,11 @@ pragma solidity ^0.8.33;
|
|
|
36
36
|
// - generic lists use the stable key derived from `#list`
|
|
37
37
|
// - standard keys are derived from block aliases, e.g. bytes4(keccak256("#amount"))
|
|
38
38
|
// - custom keys are opaque bytes4 tags and only need to be unique in their
|
|
39
|
-
// active context; use
|
|
39
|
+
// active context; use a `#schema` annotation to publish their meaning
|
|
40
40
|
// - see `docs/Schema.md` for the full working spec
|
|
41
41
|
//
|
|
42
42
|
// Pipeline state:
|
|
43
|
-
// - command
|
|
43
|
+
// - command input and state streams are each a single run of blocks under the
|
|
44
44
|
// current protocol convention; the block format may support other shapes in
|
|
45
45
|
// future protocol surfaces
|
|
46
46
|
// - `balance(...)` and `custody(...)` are live, linear state in the active command pipeline
|
|
@@ -48,102 +48,65 @@ pragma solidity ^0.8.33;
|
|
|
48
48
|
// - while a balance or custody is in-flight as pipeline state, it is not simultaneously persisted
|
|
49
49
|
// in another ledger/store by this protocol
|
|
50
50
|
// - commands must preserve, transform, settle, or intentionally consume pipeline state
|
|
51
|
-
// -
|
|
51
|
+
// - input blocks such as `amount(...)`, `allocation(...)`, and `allowance(...)`
|
|
52
52
|
// express intent, constraints, or references
|
|
53
|
-
// -
|
|
53
|
+
// - input and value/response blocks are not live state
|
|
54
54
|
//
|
|
55
|
-
// Signed blocks:
|
|
56
|
-
// - an authenticated input segment ends with one trailing AUTH block
|
|
57
|
-
// - only the final AUTH is treated specially; earlier AUTH blocks remain ordinary signed bytes
|
|
58
|
-
// - the signed slice runs from the segment start through the AUTH head, excluding only AUTH proof bytes
|
|
59
|
-
// - `cid` binds the signature to one command; `deadline` acts as expiry and nonce
|
|
60
|
-
// - current helpers assume proof layout `[bytes20 signer][bytes65 sig]`
|
|
61
|
-
|
|
62
55
|
/// @title Schemas
|
|
63
56
|
/// @notice Human-readable schema string constants for each block type.
|
|
64
57
|
/// These strings describe payload layout for discovery events and docs; block
|
|
65
58
|
/// aliases map to standard keys by convention. Custom blocks may use any unique
|
|
66
59
|
/// bytes4 key in their active context.
|
|
67
60
|
library Schemas {
|
|
61
|
+
// Empty and reserved payloads
|
|
62
|
+
|
|
68
63
|
string constant Unit = "";
|
|
69
|
-
string constant Node = "{ uint id }";
|
|
70
|
-
string constant Account = "{ bytes32 account }";
|
|
71
|
-
string constant Asset = "{ bytes32 asset }";
|
|
72
|
-
string constant Amount = "{ bytes32 asset, uint amount }";
|
|
73
|
-
string constant Balance = "{ bytes32 asset, uint amount }";
|
|
74
|
-
string constant BalanceLimit = "{ bytes32 asset, uint min, uint max }";
|
|
75
|
-
string constant Custody = "{ uint host, bytes32 asset, uint amount }";
|
|
76
|
-
string constant CustodyLimit = "{ uint host, bytes32 asset, uint min, uint max }";
|
|
77
|
-
string constant Allocation = "{ uint host, bytes32 asset, uint amount }";
|
|
78
|
-
string constant Allowance = "{ uint host, bytes32 asset, uint amount }";
|
|
79
|
-
string constant Transaction = "{ bytes32 from, bytes32 to, bytes32 asset, uint amount }";
|
|
80
|
-
string constant Context = "{ bytes32 account, #bytes as state, #bytes as request }";
|
|
81
|
-
string constant Recover = "{ uint handler, uint resources, bytes32 key, #bytes as witness }";
|
|
82
|
-
string constant Call = "{ uint target, uint resources, #bytes as payload }";
|
|
83
|
-
string constant Step = "{ uint target, uint resources, #bytes as request }";
|
|
84
|
-
string constant Relay = "{ uint portal, uint resources, #bytes as request }";
|
|
85
|
-
string constant Dispatch = "{ uint portal, uint resources, #bytes as payload }";
|
|
86
|
-
string constant Bounty = "{ uint amount, bytes32 relayer }";
|
|
87
|
-
string constant Fee = "{ uint amount }";
|
|
88
|
-
string constant Auth = "{ uint cid, uint deadline, #bytes as proof }";
|
|
89
|
-
string constant Label = "{ uint id, bytes32 namespace, #string as name }";
|
|
90
|
-
string constant Schema = "{ bytes4 key, #string as body, bytes32 name }";
|
|
91
64
|
string constant Bytes = "";
|
|
92
65
|
string constant String = "";
|
|
93
66
|
string constant List = "";
|
|
94
67
|
string constant Evm = "";
|
|
95
|
-
}
|
|
96
68
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
69
|
+
// One-word payloads
|
|
70
|
+
|
|
71
|
+
string constant Node = "{ uint id }";
|
|
72
|
+
string constant Account = "{ bytes32 account }";
|
|
73
|
+
string constant Asset = "{ bytes32 asset }";
|
|
101
74
|
string constant Status = "{ uint code }";
|
|
102
|
-
|
|
75
|
+
|
|
76
|
+
// Two-word payloads
|
|
77
|
+
|
|
78
|
+
string constant Amount = "{ bytes32 asset, uint amount }";
|
|
79
|
+
string constant Balance = "{ bytes32 asset, uint amount }";
|
|
103
80
|
string constant AccountAsset = "{ bytes32 account, bytes32 asset }";
|
|
81
|
+
|
|
82
|
+
// Three-word payloads
|
|
83
|
+
|
|
84
|
+
string constant Allocation = "{ uint host, bytes32 asset, uint amount }";
|
|
85
|
+
string constant Allowance = "{ uint host, bytes32 asset, uint amount }";
|
|
86
|
+
string constant Custody = "{ uint host, bytes32 asset, uint amount }";
|
|
104
87
|
string constant AccountAmount = "{ bytes32 account, bytes32 asset, uint amount }";
|
|
105
88
|
string constant HostAmount = "{ uint host, bytes32 asset, uint amount }";
|
|
106
89
|
string constant HostAccountAsset = "{ uint host, bytes32 account, bytes32 asset }";
|
|
90
|
+
|
|
91
|
+
// Four-word payloads
|
|
92
|
+
|
|
93
|
+
string constant Transaction = "{ bytes32 from, bytes32 to, bytes32 asset, uint amount }";
|
|
107
94
|
string constant HostAccountAmount = "{ uint host, bytes32 account, bytes32 asset, uint amount }";
|
|
108
|
-
}
|
|
109
95
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
/// @dev 8 header + 160 payload = 168 bytes total.
|
|
126
|
-
uint constant B160 = Header + 5 * Word;
|
|
127
|
-
/// @dev AUTH proof segment only: 20-byte signer + 65-byte signature = 85 bytes
|
|
128
|
-
uint constant Proof = 85;
|
|
129
|
-
/// @dev AUTH block: 8 header + 32 cid + 32 deadline + nested BYTES block with 85-byte proof = 165 bytes
|
|
130
|
-
uint constant Auth = B64 + Header + Proof;
|
|
131
|
-
/// @dev STATUS block: 8 header + 32 status code = 40 bytes
|
|
132
|
-
uint constant Status = B32;
|
|
133
|
-
/// @dev AMOUNT block: 8 header + 32 asset + 32 amount = 72 bytes
|
|
134
|
-
uint constant Amount = B64;
|
|
135
|
-
/// @dev BALANCE block: 8 header + 32 asset + 32 amount = 72 bytes
|
|
136
|
-
uint constant Balance = B64;
|
|
137
|
-
/// @dev BALANCE_LIMIT block: 8 header + 32 asset + 32 min + 32 max = 104 bytes
|
|
138
|
-
uint constant BalanceLimit = B96;
|
|
139
|
-
/// @dev FEE block: 8 header + 32 amount = 40 bytes
|
|
140
|
-
uint constant Fee = B32;
|
|
141
|
-
/// @dev BOUNTY block: 8 header + 32 amount + 32 relayer = 72 bytes
|
|
142
|
-
uint constant Bounty = B64;
|
|
143
|
-
/// @dev ALLOCATION/CUSTODY block: 8 header + 32 host + 32 asset + 32 amount = 104 bytes
|
|
144
|
-
uint constant HostAmount = B96;
|
|
145
|
-
/// @dev CUSTODY_LIMIT block: 8 header + 32 host + 32 asset + 32 min + 32 max = 136 bytes
|
|
146
|
-
uint constant CustodyLimit = B128;
|
|
147
|
-
/// @dev TRANSACTION block: 8 header + 32 from + 32 to + 32 asset + 32 amount = 136 bytes
|
|
148
|
-
uint constant Transaction = B128;
|
|
96
|
+
// Composite payloads
|
|
97
|
+
|
|
98
|
+
string constant Call = "{ uint target, uint resources, #bytes as payload }";
|
|
99
|
+
string constant Step = "{ uint cmd, uint resources, #bytes as input }";
|
|
100
|
+
string constant Relay = "{ uint portal, uint resources, #bytes as input }";
|
|
101
|
+
string constant Dispatch = "{ uint portal, uint resources, #bytes as payload }";
|
|
102
|
+
string constant Context = "{ bytes32 account, #bytes as state, #bytes as input }";
|
|
103
|
+
string constant Recover = "{ uint handler, uint resources, bytes32 key, #bytes as witness }";
|
|
104
|
+
string constant Annotation = "{ uint entity, #bytes as data }";
|
|
105
|
+
|
|
106
|
+
// Annotation payloads
|
|
107
|
+
|
|
108
|
+
string constant Action = "{ uint action }";
|
|
109
|
+
string constant Label = "{ bytes32 namespace, #string as name }";
|
|
110
|
+
string constant Schema = "{ uint spec, #string as body, bytes32 name }";
|
|
149
111
|
}
|
|
112
|
+
|