Skip to content

Commit

Permalink
Document CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
guidanoli committed Jul 15, 2024
1 parent 00cada3 commit 399b517
Show file tree
Hide file tree
Showing 8 changed files with 498 additions and 51 deletions.
97 changes: 97 additions & 0 deletions apps/site/pages/docs/cli/cmd/decode/input.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# cmioc decode input

Decodes an input blob according to the [`EvmAdvance`] function signature.

:::code-group

```bash [Command]
cmioc decode input
```

```json [Output JSON Schema]
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Input",
"definitions": {
"Hex": {
"type": "string",
"pattern": "^0x([0-9A-Fa-f]{2})*$"
},
"Address": {
"type": "string",
"pattern": "^0x[0-9A-Fa-f]{40}$"
},
"bigint": {
"type": "string",
"pattern": "^[0-9]+$"
}
},
"type": "object",
"properties": {
"chainId": { "$ref": "#/definitions/bigint" },
"appContract": { "$ref": "#/definitions/Address" },
"msgSender": { "$ref": "#/definitions/Address" },
"blockNumber": { "$ref": "#/definitions/bigint" },
"blockTimestamp": { "$ref": "#/definitions/bigint" },
"prevRandao": { "$ref": "#/definitions/bigint" },
"index": { "$ref": "#/definitions/bigint" },
"payload": { "$ref": "#/definitions/Hex" }
},
"required": [
"chainId",
"appContract",
"msgSender",
"blockNumber",
"blockTimestamp",
"prevRandao",
"index",
"payload"
],
"additionalProperties": false
}
```

:::

## Example

:::code-group

```txt [Input]
0x415bf363000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070ac08179605af2d9e75782b8decdd3c22aa4d0c000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000000002a00000000000000000000000000000000000000000000000000000000000111705a41539c3688747a1a8c7811b98b0427331ff73aab018eb5c9921993d617f314000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000
```

```json [Output]
{
"chainId": "1",
"appContract": "0x70ac08179605AF2D9e75782b8DEcDD3c22aA4D0C",
"msgSender": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"blockNumber": "42",
"blockTimestamp": "70000",
"prevRandao": "40823578488146031703637781058841789769586951870728503003341100870835983872788",
"index": "10",
"payload": "0xdeadbeef"
}
```

:::

## Positional arguments

### [blob]

`bytes`

The input blob. If absent, reads from standard input.

## Options

### -b, --binary

If a blob is not provided as argument, read from standard input in binary format.

### -h, --help

Display help for command.

[`EvmAdvance`]: https://github.com/cartesi/rollups-contracts/blob/v2.0.0-rc.4/contracts/common/Inputs.sol#L9-L28
140 changes: 140 additions & 0 deletions apps/site/pages/docs/cli/cmd/decode/output.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# cmioc decode output

Decodes an output blob according to the [`Outputs`] interface.

:::code-group

```bash [Command]
cmioc decode output
```

```json [Output JSON Schema]
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Output",
"definitions": {
"Hex": {
"type": "string",
"pattern": "^0x([0-9A-Fa-f]{2})*$"
},
"Address": {
"type": "string",
"pattern": "^0x[0-9A-Fa-f]{40}$"
},
"bigint": {
"type": "string",
"pattern": "^[0-9]+$"
}
},
"oneOf": [
{
"type": "object",
"properties": {
"type": { "const": "notice" },
"payload": { "$ref": "#/definitions/Hex" }
},
"required": ["type", "payload"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": { "const": "voucher" },
"destination": { "$ref": "#/definitions/Address" },
"value": { "$ref": "#/definitions/bigint" },
"payload": { "$ref": "#/definitions/Hex" }
},
"required": ["type", "destination", "value", "payload"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": { "const": "delegatecallvoucher" },
"destination": { "$ref": "#/definitions/Address" },
"payload": { "$ref": "#/definitions/Hex" }
},
"required": ["type", "destination", "payload"],
"additionalProperties": false
}
]
}
```

:::

## Examples

### Notice

:::code-group

```txt [Input]
0xc258d6e500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000
```

```json [Output]
{
"type": "notice",
"payload": "0xdeadbeef"
}
```

:::

### Voucher

:::code-group

```txt [Input]
0x237a816f000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000003fafafa0000000000000000000000000000000000000000000000000000000000
```

```json [Output]
{
"type": "voucher",
"destination": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"value": "1000000000000000000",
"payload": "0xfafafa"
}
```

:::

### Delegate Call Voucher

:::code-group

```txt [Input]
0x10321e8b000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003fafafa0000000000000000000000000000000000000000000000000000000000
```

```json [Output]
{
"type": "delegatecallvoucher",
"destination": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"payload": "0xfafafa"
}
```

:::

## Positional arguments

### [blob]

`bytes`

The output blob. If absent, reads from standard input.

## Options

### -b, --binary

If a blob is not provided as argument, read from standard input in binary format.

### -h, --help

Display help for command.

[`Outputs`]: https://github.com/cartesi/rollups-contracts/blob/v2.0.0-rc.4/contracts/common/Outputs.sol
48 changes: 48 additions & 0 deletions apps/site/pages/docs/cli/cmd/encode/delegatecallvoucher.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# cmioc encode delegatecallvoucher

Encodes a delegate call voucher according to the [`DelegateCallVoucher`] function signature.
A delegate call voucher represents a [`DELEGATECALL`] instruction to be performed in the context of the [`Application`] contract.

:::code-group

```bash [Command]
cmioc encode delegatecallvoucher \
--destination 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
--payload 0xfafafa
```

```txt [Output]
0x10321e8b000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb9226600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003fafafa0000000000000000000000000000000000000000000000000000000000
```

:::

## Required options

### --destination \<address\>

`address`

The Ethereum address to be called, which is typically that of a smart contract.

### --payload \<blob\>

`bytes`

The data to be passed along the call, which typically encodes a [Solidity function call].

## Other options

### -b, --binary

Write the blob to standard output in binary format.

### -h, --help

Display help for command.

[Solidity function call]: https://docs.soliditylang.org/en/latest/abi-spec.html#function-selector-and-argument-encoding
[Wei]: https://ethereum.org/en/glossary/#wei
[`Application`]: https://github.com/cartesi/rollups-contracts/blob/v2.0.0-rc.4/contracts/dapp/Application.sol
[`DELEGATECALL`]: https://www.evm.codes/#f4?fork=cancun
[`DelegateCallVoucher`]: https://github.com/cartesi/rollups-contracts/blob/v2.0.0-rc.4/contracts/common/Outputs.sol#L26-L34
94 changes: 94 additions & 0 deletions apps/site/pages/docs/cli/cmd/encode/input.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# cmioc encode input

Encodes an input according to the [`EvmAdvance`] function signature.

:::code-group

```bash [Command]
cmioc encode input \
--chain-id 1 \
--app-contract 0x70ac08179605AF2D9e75782b8DEcDD3c22aA4D0C \
--msg-sender 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
--block-number 42 \
--block-timestamp 70000 \
--prev-randao 123456789 \
--index 10 \
--payload 0xdeadbeef
```

```txt [Output]
0x415bf363000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070ac08179605af2d9e75782b8decdd3c22aa4d0c000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000001117000000000000000000000000000000000000000000000000000000000075bcd15000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000004deadbeef00000000000000000000000000000000000000000000000000000000
```

:::

## Required options

### --chain-id \<id\>

`uint256`

The [EIP-155] ID of the chain to which the [`InputBox`] contract was deployed.

### --app-contract \<address\>

`address`

The address of the [`Application`] contract to which the input is destined.

### --msg-sender \<address\>

`address`

The address of the account that called the [`addInput`] function on the [`InputBox`] contract.
In the case of a deposit input, this should be the address of the appropriate portal contract.

### --block-number \<num\>

`uint256`

The number of the block in which the input was added.

### --block-timestamp \<ts\>

`uint256`

The timestamp of the block in which the input was added.

### --prev-randao \<num\>

`uint256`

The latest RANDAO mix of the post beacon state of the previous block.
See [EIP-4399] for notes on how to safely use this value as a source of randomness.

### --index \<num\>

`uint256`

The zero-based index of the input in the input box of the application.

### --payload \<blob\>

`bytes`

The actual data being transmitted to the application.
From the perspective of the smart contracts and the node, this is an opaque blob.
The application is free to specify any encoding for input payloads.

## Other options

### -b, --binary

Write the blob to standard output in binary format.

### -h, --help

Display help for command.

[`addInput`]: https://github.com/cartesi/rollups-contracts/blob/v2.0.0-rc.4/contracts/inputs/IInputBox.sol#L32-L40
[`Application`]: https://github.com/cartesi/rollups-contracts/blob/v2.0.0-rc.4/contracts/dapp/Application.sol
[`EvmAdvance`]: https://github.com/cartesi/rollups-contracts/blob/v2.0.0-rc.4/contracts/common/Inputs.sol#L9-L28
[`InputBox`]: https://github.com/cartesi/rollups-contracts/blob/v2.0.0-rc.4/contracts/inputs/InputBox.sol
[EIP-4399]: https://eips.ethereum.org/EIPS/eip-4399
[EIP-155]: https://eips.ethereum.org/EIPS/eip-155
Loading

0 comments on commit 399b517

Please sign in to comment.