-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add files to tech explanation (#339)
* add files to tech explanation * fmt * update links * rename to script-args
- Loading branch information
Showing
14 changed files
with
138 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
id: script-args | ||
title: script_args | ||
--- | ||
|
||
`script_args` refers to the arguments imported into the CKB-VM instance as input for the Scripts. In CKB, public key information is conventionally stored in `script_args`, while signature information is in `witnesses`, though it's not mandatory. | ||
|
||
:::note | ||
When a Script is validated, CKB runs it in a RISC-V VM, and `script_args` must be loaded via special CKB syscalls. The UNIX standard `argc`/`argv` convention is NOT used in CKB. For more information on CKB-VM, please refer to [RFC003: CKB-VM](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0003-ckb-vm/0003-ckb-vm.md). | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
id: capacity | ||
title: Capacity | ||
--- | ||
|
||
Capacity is the storage limit of a Cell in a transaction. Capacity refers to both the quantity of stored tokens and the maximum amount of data the Cell can hold. The capacity of a Cell determines its ability to store various fields, including data, lock, type, and its own capacity. | ||
|
||
Transactions must create an output Cell whose occupied capacity is less than the capacity of the referenced Cell. | ||
|
||
``` | ||
Occupied (Cell) ≤ Cell's capacity | ||
``` | ||
|
||
When a new Cell is generated via a transaction, one of the validation rules is `capacity_in_bytes >= len(capacity) + len(data) + len(type) + len(lock)`. This value also represents the balance of CKB tokens, similar to the [`nValue` field in Bitcoin's CTxOut](https://www.bitcoinabc.org/doc/dev/class_c_tx_out.html). For instance, if Alice owns 100 CKB, she can unlock a group of Cells with a total quantity of 100 bytes. | ||
|
||
:::note | ||
For Lock Script, another arg is appended to the array of CellInput to form a complete list of input parameters. | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
id: cell | ||
title: Cell | ||
--- | ||
|
||
# Cell | ||
|
||
## Structure | ||
|
||
A Cell is the smallest and fundamental unit in Nervos CKB, used for storing states. | ||
|
||
```bash | ||
Cell: { | ||
capacity: HexString; | ||
lock: Script; | ||
type: Script; | ||
data: HexString; | ||
} | ||
``` | ||
|
||
## Fields & Description{#fields-and-description} | ||
|
||
| Name | Type | Description | | ||
| ---------- | ------------------------------------------------- | -------------------------------------------------------------- | | ||
| `capacity` | Uint64 | Size of the Cell in shannon. 1 CKB = 100,000,000 shannons. | | ||
| `lock` | [Script](/docs/tech-explanation/script#structure) | See [Lock Script](/docs/tech-explanation/glossary#lock-script) | | ||
| `type` | [Script](/docs/tech-explanation/script#structure) | See [Type Script](/docs/tech-explanation/glossary#type-script) | | ||
| `data` | Bytes | Used for storing states. | | ||
|
||
## Example | ||
|
||
```json | ||
{ | ||
"capacity": "0x19995d0ccf", | ||
"lock": { | ||
"code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", | ||
"args": "0x0a486fb8f6fe60f76f001d6372da41be91172259", | ||
"hash_type": "type" | ||
}, | ||
"type": null | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
id: code-hash | ||
title: code_hash | ||
--- | ||
|
||
`code_hash` represents the hash of the ELF-formatted RISC-V binary that contains a CKB Script. For efficiency, the Script itself is stored in a dep Cell attached to the current transaction. Depending on the `hash_type` value, the `code_hash` should either match the hash of the Cell data, or that of the Type Script in the dep Cell. During transaction verification, the actual binary is loaded into a CKB-VM instance when specified. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
id: hash-type | ||
title: hash_type | ||
--- | ||
|
||
`hash_type` defines the interpretation of the `code_hash` when looking for matching dep Cells. | ||
|
||
- If it is 0, i.e., data, `code_hash` should match the blake2b hash of data in a dep Cell; | ||
- if it is 1, i.e., type, `code_hash` should match the Type Script hash of a dep Cell. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
id: script | ||
title: Script | ||
--- | ||
|
||
# Script | ||
|
||
## Structure | ||
|
||
In addition to the rules defined by the CKB protocol, verification based on the Scripts in the input and output Cells of the transaction is also required. | ||
|
||
```bash | ||
Script: { | ||
code_hash: HexString | ||
args: HexString | ||
hash_type: Uint8, there are 4 allowed values: {0: "data", 1: "type", 2: "data1", 3: "data2"} | ||
} | ||
``` | ||
|
||
## Fields & Description{#fields-and-description} | ||
|
||
| Name | Type | Description | | ||
| ----------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | | ||
| `code_hash` | H256 | Hash of the ELF formatted RISC-V binary that contains a CKB Script. For more, see [`code_hash`](/docs/tech-explanation/code-hash) | | ||
| `hash_type` | Uint8, one of the 4 values: \{0: "data", 1: "type", 2: "data1", 3: "data2"\} | Interpretation of the code hash when looking for matching dep cells. For more, see [`hash_type`](/docs/tech-explanation/hash-type) | | ||
| `args` | H256 | Arguments as the Script input. For more, see [`script_args`](/docs/tech-explanation/script-args) | | ||
|
||
## Script vs. Code | ||
|
||
We differentiate the terms Script and Code as follows: | ||
|
||
- Script is a data structure referencing to runnable on-chain code. | ||
- Code refers to the RISC-V binary, runnable in CKB-VM and can be referenced to by the Script structure. | ||
- A code Cell is a Cell containing RISC-V binary code. | ||
- Script does not directly include code; it simply stores a pointer to reference the code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters