Skip to main content

VM Version History

The CKB network has introduced various CKB-VM versions over time to enhance security, performance, resolve bugs, and support new RISC-V extensions. This article lists all versions of the CKB-VM from previous hard fork events.

It is important to note that, even though a hard fork upgrades the network, it is crucial to prevent the hard fork from breaking the old Script codes. CKB makes best effort to ensure users have the opt-in option to specify the VM version for their Script. For the specific mechanism that determines how the CKB node chooses the CKB-VM version for a transaction's Script group, please refer to vm-selection.

VM 0

Since the genesis of CKB network.

Full description: RFC

Instruction Set

rv64imc architecture: based on core RV64I ISA with M standard extension for integer multiplication and division, and C standard extension for RCV(RISC-V Compressed Instructions)

Syscalls

Full description: RFC

Cost Model

Full description: RFC

Specify the cycles needed by each CKB-VM instructions or syscalls.

  1. Cycles for RISC-V instructions are determined based on real hardware that implement RISC-V ISA.
  2. Cycles for syscalls are measured based on real runtime performance metrics obtained while benchmarking current CKB implementation.

Initial Loading Cycles

For each byte loaded into CKB-VM in the initial ELF loading phase, 0.25 cycles will be charged. This is to encourage dApp developers to ship smaller Scripts as well as preventing DDoS attacks using large binaries. Notice fractions will be rounded up here, so 30.25 cycles will become 31 cycles.

instructions Cycles

All instructions consume 1 cycle except the following ones:

InstructionCycles
JALR3
JAL3
J3
JR3
BEQ3
BNE3
BLT3
BGE3
BLTU3
BGEU3
BEQZ3
BNEZ3
LD2
SD2
LDSP2
SDSP2
LW3
LH3
LB3
LWU3
LHU3
LBU3
SW3
SH3
SB3
LWSP3
SWSP3
MUL5
MULW5
MULH5
MULHU5
MULHSU5
DIV32
DIVW32
DIVU32
DIVUW32
REM32
REMW32
REMU32
REMUW32
ECALL500 (see note below)
EBREAK500 (see note below)

Syscall Cycles

As shown in the above chart, each syscall will have 500 initial cycle consumptions. This is based on real performance metrics gathered benchmarking CKB implementation, certain bookkeeping logics are required for each syscall here.

In addition, for each byte loaded into CKB-VM in the syscalls, 0.25 cycles will be charged. Notice fractions will also be rounded up here, so 30.25 cycles will become 31 cycles.

VM 1

Introduced since 1st Hard Fork – CKB Edition Mirana (2021)

Full description: RFC

Instruction Set

  1. Added the RISC-V B extension (v1.0.0) 1. This extension aims at covering the four major categories of bit manipulation: counting, extracting, inserting and swapping.
  2. 10 MOPs added:
OpcodeOrigin
ADC 2add + sltu + add + sltu + or
SBBsub + sltu + sub + sltu + or
WIDE_MULmulh + mul
WIDE_MULUmulhu + mul
WIDE_MULSUmulhsu + mul
WIDE_DIVdiv + rem
WIDE_DIVUdivu + remu
FAR_JUMP_RELauipc + jalr
FAR_JUMP_ABSlui + jalr
LD_SIGN_EXTENDED_32_CONSTANTlui + addiw

Syscalls

No new added syscalls.

Cost Model

  • For all B instructions, 1 cycle will be consumed.
  • 10 MOPs cycle cost:
OpcodeOriginCycles
ADC 2add + sltu + add + sltu + or1 + 0 + 0 + 0 + 0
SBBsub + sltu + sub + sltu + or1 + 0 + 0 + 0 + 0
WIDE_MULmulh + mul5 + 0
WIDE_MULUmulhu + mul5 + 0
WIDE_MULSUmulhsu + mul5 + 0
WIDE_DIVdiv + rem32 + 0
WIDE_DIVUdivu + remu32 + 0
FAR_JUMP_RELauipc + jalr0 + 3
FAR_JUMP_ABSlui + jalr0 + 3
LD_SIGN_EXTENDED_32_CONSTANTlui + addiw1 + 0

VM 2

Introduced since 2nd Hard Fork – CKB Edition Meepo (2024)

Full description: RFC

Instruction Set

5 MOPs added:

OpcodeOriginDescription
ADCSadd + sltuOverflowing addition
SBBSsub + sltuBorrowing subtraction
ADD3Aadd + sltu + addOverflowing addition and add the overflow flag to the third number
ADD3Badd + sltu + addSimilar to ADD3A but the registers order is different
ADD3Cadd + sltu + addSimilar to ADD3A but the registers order is different

Syscalls

Added 8 spawn-related syscalls and one block-related syscall:

Full description: RFC

Cost Model

  • 5 MOPs cycle cost:
OpcodeOriginCycles
ADCSadd + sltu1 + 0
SBBSsub + sltu1 + 0
ADD3Aadd + sltu + add1 + 0 + 0
ADD3Badd + sltu + add1 + 0 + 0
ADD3Cadd + sltu + add1 + 0 + 0
  • Spawn syscall cycles:
Syscall NameCycles Charge
spawn500 + SPAWN_YIELD_CYCLES_BASE + BYTES_TRANSFERRED_CYCLES + SPAWN_EXTRA_CYCLES_BASE
pipe500 + SPAWN_YIELD_CYCLES_BASE
inherited_fd500 + SPAWN_YIELD_CYCLES_BASE
read500 + SPAWN_YIELD_CYCLES_BASE + BYTES_TRANSFERRED_CYCLES
write500 + SPAWN_YIELD_CYCLES_BASE + BYTES_TRANSFERRED_CYCLES
close500 + SPAWN_YIELD_CYCLES_BASE
wait500 + SPAWN_YIELD_CYCLES_BASE
process_id500
load block extension500 + BYTES_TRANSFERRED_CYCLES