From fe318f60b8ac780f16fd59434df530880e866748 Mon Sep 17 00:00:00 2001 From: mohanson Date: Thu, 27 May 2021 14:50:15 +0800 Subject: [PATCH 1/6] RFC: vm syscalls 2 --- rfcs/0000-vm-syscalls-2/0000-vm-syscalls-2.md | 87 +++++++++++++++++++ rfcs/0009-vm-syscalls/0009-vm-syscalls.md | 4 +- 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 rfcs/0000-vm-syscalls-2/0000-vm-syscalls-2.md diff --git a/rfcs/0000-vm-syscalls-2/0000-vm-syscalls-2.md b/rfcs/0000-vm-syscalls-2/0000-vm-syscalls-2.md new file mode 100644 index 000000000..f5a499590 --- /dev/null +++ b/rfcs/0000-vm-syscalls-2/0000-vm-syscalls-2.md @@ -0,0 +1,87 @@ +--- +Number: "0000" +Category: Standards Track +Status: Proposal +Author: Wanbiao Ye +Organization: Nervos Foundation +Created: 2021-05-25 +--- + +# VM Syscalls 2 + +## Abstract + +This document describes the addition of the syscalls during the ckb's first hard fork. + +- [VM Version] +- [Current Cycles] +- [Exec] + +### VM Version +[vm version]: #vm-version + +As shown above, *VM Version* syscall has a signature like following: + +```c +int ckb_vm_version() +{ + return syscall(2041, 0, 0, 0, 0, 0, 0); +} +``` + +*VM version* syscall returns current running VM version, so far 2 values will be returned: 0 for Lina CKB-VM version, 1 for the new hardfork version. This syscall consumes 500 cycles. + +### Current Cycles +[current cycles]: #current-cycles + +*Current Cycles* syscall has a signature like following: + +```c +uint64_t ckb_current_cycles() +{ + return syscall(2042, 0, 0, 0, 0, 0, 0); +} +``` + +*Current Cycles* returns current cycle consumption just before executing this syscall. This syscall consumes 500 cycles. + + +### Exec +[exec]: #exec + +Exec runs an executable file from specified cell data in the context of an already existing machine, replacing the previous executable. The used cycles does not change, but the code, registers and memory of the vm are replaced by those of the new program. It's cycles consumption consists of two parts: + +- Fixed 500 cycles +- Initial Loading Cycles [1] + +*Exec* syscall has a signature like following: + +```c +int ckb_exec(size_t index, size_t source, size_t place, size_t bounds, int argc, char* argv[]) +{ + return syscall(2043, index, source, place, bounds, argc, argv); +} +``` + +The arguments used here are: + +* `index`: an index value denoting the index of entries to read. +* `source`: a flag denoting the source of cells or witnesses to locate, possible values include: + + 1: input cells. + + `0x0100000000000001`: input cells with the same running script as current script + + 2: output cells. + + `0x0100000000000002`: output cells with the same running script as current script + + 3: dep cells. +* `place`: A value of 0 or 1: + + 0: read from cell data + + 1: read from witness +* `bounds`: high 32 bits means `offset`, low 32 bits means `length`. if `length` equals to zero, it read to end instead of reading 0 bytes. +* `argc`: argc contains the number of arguments passed to the program +* `argv`: argv is a one-dimensional array of strings + + +# Reference + +* [1]: [Vm Cycle Limits][1] + +[1]: ../0014-vm-cycle-limits/0014-vm-cycle-limits.md diff --git a/rfcs/0009-vm-syscalls/0009-vm-syscalls.md b/rfcs/0009-vm-syscalls/0009-vm-syscalls.md index a7a9ff4af..33a6c7d2f 100644 --- a/rfcs/0009-vm-syscalls/0009-vm-syscalls.md +++ b/rfcs/0009-vm-syscalls/0009-vm-syscalls.md @@ -11,7 +11,7 @@ Created: 2018-12-14 ## Abstract -This document describes all the RISC-V VM syscalls implemented in CKB so far. +This document describes all the RISC-V VM syscalls implemented in CKB Lina. Note that 3 new syscalls have been added to CKB Hardfork [2]. ## Introduction @@ -538,5 +538,7 @@ This syscall accepts a null terminated string and prints it out as debug log in # Reference * [1]: [Molecule Encoding][1] +* [2]: [VM Syscalls 2][2] [1]: ../0008-serialization/0008-serialization.md +[2]: ../0000-vm-syscalls-2/0000-vm-syscalls-2.md From e2c7a6e038e09cd1dec16cac05a4e32725307224 Mon Sep 17 00:00:00 2001 From: mohanson Date: Fri, 28 May 2021 14:58:21 +0800 Subject: [PATCH 2/6] Give it a RFC number 0237 --- rfcs/0009-vm-syscalls/0009-vm-syscalls.md | 2 +- .../0237-vm-syscalls-2.md} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename rfcs/{0000-vm-syscalls-2/0000-vm-syscalls-2.md => 0237-vm-syscalls-2/0237-vm-syscalls-2.md} (100%) diff --git a/rfcs/0009-vm-syscalls/0009-vm-syscalls.md b/rfcs/0009-vm-syscalls/0009-vm-syscalls.md index 33a6c7d2f..1703aed1b 100644 --- a/rfcs/0009-vm-syscalls/0009-vm-syscalls.md +++ b/rfcs/0009-vm-syscalls/0009-vm-syscalls.md @@ -541,4 +541,4 @@ This syscall accepts a null terminated string and prints it out as debug log in * [2]: [VM Syscalls 2][2] [1]: ../0008-serialization/0008-serialization.md -[2]: ../0000-vm-syscalls-2/0000-vm-syscalls-2.md +[2]: ../0237-vm-syscalls-2/0237-vm-syscalls-2.md diff --git a/rfcs/0000-vm-syscalls-2/0000-vm-syscalls-2.md b/rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md similarity index 100% rename from rfcs/0000-vm-syscalls-2/0000-vm-syscalls-2.md rename to rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md From 4b2f3fa73d182abdb33001578819869c6ddcd7aa Mon Sep 17 00:00:00 2001 From: mohanson Date: Fri, 28 May 2021 15:25:33 +0800 Subject: [PATCH 3/6] Give it a RFC number 0237 --- rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md b/rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md index f5a499590..e73d666c4 100644 --- a/rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md +++ b/rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md @@ -1,5 +1,5 @@ --- -Number: "0000" +Number: "0237" Category: Standards Track Status: Proposal Author: Wanbiao Ye From fab8d59a4676399c01abd4cc9729dfe847aa4bd0 Mon Sep 17 00:00:00 2001 From: mohanson Date: Tue, 15 Jun 2021 12:26:46 +0800 Subject: [PATCH 4/6] Mention ckb-vm version selection --- rfcs/0009-vm-syscalls/0009-vm-syscalls.md | 2 +- rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rfcs/0009-vm-syscalls/0009-vm-syscalls.md b/rfcs/0009-vm-syscalls/0009-vm-syscalls.md index 1703aed1b..1ecfdae62 100644 --- a/rfcs/0009-vm-syscalls/0009-vm-syscalls.md +++ b/rfcs/0009-vm-syscalls/0009-vm-syscalls.md @@ -11,7 +11,7 @@ Created: 2018-12-14 ## Abstract -This document describes all the RISC-V VM syscalls implemented in CKB Lina. Note that 3 new syscalls have been added to CKB Hardfork [2]. +This document describes all the RISC-V VM syscalls implemented in CKB Lina. Note that 3 new syscalls have been added to ckb2021 [2]. ## Introduction diff --git a/rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md b/rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md index e73d666c4..883ce98c8 100644 --- a/rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md +++ b/rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md @@ -11,7 +11,7 @@ Created: 2021-05-25 ## Abstract -This document describes the addition of the syscalls during the ckb's first hard fork. +This document describes the addition of the syscalls during the ckb2021. These syscalls are only available since ckb-vm version 1 and ckb2021 [2]. - [VM Version] - [Current Cycles] @@ -83,5 +83,7 @@ The arguments used here are: # Reference * [1]: [Vm Cycle Limits][1] +* [2]: [CKB VM version selection][2] [1]: ../0014-vm-cycle-limits/0014-vm-cycle-limits.md +[2]: ../0232-ckb-vm-version-selection/0232-ckb-vm-version-selection.md From 7e5436c597882974452c67422f75772d47f918e3 Mon Sep 17 00:00:00 2001 From: mohanson Date: Tue, 13 Jul 2021 17:12:08 +0800 Subject: [PATCH 5/6] Fix the description of VM version for CKB Lina --- rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md b/rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md index 883ce98c8..3d955dc90 100644 --- a/rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md +++ b/rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md @@ -29,7 +29,12 @@ int ckb_vm_version() } ``` -*VM version* syscall returns current running VM version, so far 2 values will be returned: 0 for Lina CKB-VM version, 1 for the new hardfork version. This syscall consumes 500 cycles. +*VM version* syscall returns current running VM version, so far 2 values will be returned: + +- Error for Lina CKB-VM version +- 1 for the new hardfork CKB-VM version. + +This syscall consumes 500 cycles. ### Current Cycles [current cycles]: #current-cycles From 6fd3c0d71d6b983915151e6ed45f836b8e4d42d2 Mon Sep 17 00:00:00 2001 From: mohanson Date: Fri, 23 Jul 2021 15:14:16 +0800 Subject: [PATCH 6/6] Update rfc number to 0034 --- rfcs/0009-vm-syscalls/0009-vm-syscalls.md | 2 +- .../0034-vm-syscalls-2.md} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename rfcs/{0237-vm-syscalls-2/0237-vm-syscalls-2.md => 0034-vm-syscalls-2/0034-vm-syscalls-2.md} (99%) diff --git a/rfcs/0009-vm-syscalls/0009-vm-syscalls.md b/rfcs/0009-vm-syscalls/0009-vm-syscalls.md index 1ecfdae62..d4c723ec8 100644 --- a/rfcs/0009-vm-syscalls/0009-vm-syscalls.md +++ b/rfcs/0009-vm-syscalls/0009-vm-syscalls.md @@ -541,4 +541,4 @@ This syscall accepts a null terminated string and prints it out as debug log in * [2]: [VM Syscalls 2][2] [1]: ../0008-serialization/0008-serialization.md -[2]: ../0237-vm-syscalls-2/0237-vm-syscalls-2.md +[2]: ../0034-vm-syscalls-2/0034-vm-syscalls-2.md diff --git a/rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md b/rfcs/0034-vm-syscalls-2/0034-vm-syscalls-2.md similarity index 99% rename from rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md rename to rfcs/0034-vm-syscalls-2/0034-vm-syscalls-2.md index 3d955dc90..7bbb7f1e3 100644 --- a/rfcs/0237-vm-syscalls-2/0237-vm-syscalls-2.md +++ b/rfcs/0034-vm-syscalls-2/0034-vm-syscalls-2.md @@ -1,5 +1,5 @@ --- -Number: "0237" +Number: "0034" Category: Standards Track Status: Proposal Author: Wanbiao Ye