ckb-vm version 1 将会添加 3 个新的 syscall:
- [VM Version]
- [Current Cycles]
- [Exec]
这 3 个 syscall 都仅在 ckb-vm version 1 上才支持, 如果运行在 version 0 上, 都将会返回错误
VM Version
获取 ckb-vm 版本信息, 接口如下:
int ckb_vm_version()
{
return syscall(2041, 0, 0, 0, 0, 0, 0);
}
在 ckb-vm version 1 上将会返回 1, 本指令消耗 cycle 数是 500
Current Cycles
获取当前 vm 已经消耗的 cycle 数, 接口如下:
uint64_t ckb_current_cycles()
{
return syscall(2042, 0, 0, 0, 0, 0, 0);
}
返回值是在执行本指令之前, ckb-vm 已经消耗的 cycle 数, 本指令消耗 cycle 数是 500
Exec
在当前 vm 从一个指定的 cell 加载新程序, 取代当前的可执行文件并运行。已经消耗的 cycles 数不会被清除,但是 vm 的代码、寄存器和内存都将会被新程序所取代。本指令消耗的 cycle 数由两部分组成:
- 固定的 500 cycles
- 加载新程序大小对应的 cycles
接口如下:
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);
}
接口使用的参数
-
index
: 和 source 参数配合, 代表加载第几个 cell -
source
: 代表加载新程序的 cell 来源-
0x0000000000000001
: input cells -
0x0100000000000001
: input cells group -
0x0000000000000002
: output cells -
0x0100000000000002
: output cells group -
0x0000000000000003
: dep cells
-
-
place
: 加载 cell 的字段- 0: cell data
- 1: witness
-
bounds
: 高32位表示 offset, 低32位表示 length, 如果 length 等于 0 , 它将读到结束, 而不是读 0 字节 -
argc
: 传递给程序的参数数量 -
argv
: 参数数组 (1维 string 数组)
更多关于 cycle 和 vm-version 1 可以参考 [RFC14] 和 [RFC3]