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. Even though hard forks upgrade the network, CKB ensures old Scripts continue to run and gives users the option to specify the VM version for their Script. For details on how the CKB node chooses the CKB-VM version, see vm-selection.

CKB offers a high degree of flexibility in Script referencing. By choosing between data hash and type hash, developers and users can decide whether to lock a Script to a specific VM version or allow it to track upgrades over time.

While this flexibility enables both immutable and upgradable designs, it also places responsibility on users and developers to understand the characteristics of each VM version. Certain versions may have known issues that could affect Script behavior or security.

This page lists all VM versions and discloses known issues so you can:

  • Assess risks before deploying or interacting with a Script.
  • Avoid unexpected behavior by being aware of edge cases, performance changes, or vulnerabilities.

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.

Known Issues

No known issues have been reported for this VM version.

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

Added 3 new syscalls:

Full description: RFC

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

Known Issues

  • Exec is deprecated and not recommended for use in VM 1. Under VM 1, the exec syscall can cause unexpected behavior theoretically. However, this issue does not exist in VM 2.

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

Known Issues

No known issues have been reported for this VM version.