Number | Category | Status | Author | Created |
---|---|---|---|---|
0033 |
Informational |
Draft |
Wanbiao Ye <[email protected]> |
2021-05-25 |
This RFC describes version 1 of the CKB-VM, in comparison to version 0, which
- Fixed several bugs
- Behavioural changes not affecting execution results
- New features
- Performance optimisations
CKB-VM Version 1 has fixed identified bugs discovered in Version 0.
In the previous version, SP incorrectly aligned during stack initialisation. See issue.
C Standard 5.1.2.2.1/2 states: argv[argc]
should be a null pointer. NULL
was unfortunately omitted during the initialization of the stack, and now it has returned. See issue.
The problem arose with the JALR instruction, where the CKB-VM had made an error in the sequence of its different steps. The correct step to follow would be to calculate the pc first and then update the rd. See problem.
We have fixed it, as described in the title.
We have fixed it, as described in the title.
This error occurred during the loading of elf. The CKB-VM has incorrectly set a freeze flag on a writeable page, which made the page unmodifiable.
It happened mainly with external variables that have dynamic links.
goblin is a cross-platform trifecta of binary parsing and loading fun. ckb-vm uses it to load RISC-V programs. But in the past period of time goblin fixed many bugs and produced destructive upgrades, we decided to upgrade goblin: this will cause the binary that could not be loaded before can now be normal Load, or vice versa.
For ckb scripts, argc is always 0 and the memory is initialised to 0, so memory writing can be safely skipped. Note that when "chaos_mode" is enabled and "argv" is empty, the reading of "argc" will return an unexpected data. This happens uncommonly, and never happens on the mainnet.
For the sake of fast decoding and cache convenience, RISC-V instruction is decoded into the 64-bit unsigned integer. Such a format used only internally in ckb-vm rather than the original RISC-V instruction format.
We have 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. For all B instructions, 1 cycle will be consumed.
Chaos memory mode was added for the debugging tools. Under this mode, the program memory forcibly initializes randomly, helping us to discover uninitialized objects/values in the script.
It is possible to suspend a running CKB VM, save the state to a certain place and to resume the previously running VM later on, possibly even on a different machine.
In version 0, when the VM was initialised, the program memory would be initialised to zero value. Now, we have deferred the initialisation of program memory. The program memory is divided into several different frames, so that only when a frame is used (read, write), the corresponding program memory area of that frame will be initialised with zero value. As a result , small programs that do not need to use large volumes of memory will be able to run faster.
Macro-Operation Fusion (also Macro-Op Fusion, MOP Fusion, or Macrofusion) is a hardware optimization technique found in many modern microarchitectures whereby a series of adjacent macro-operations are merged into a single macro-operation prior or during decoding. Those instructions are later decoded into fused-µOPs.
The cycle consumption of the merged instructions is the maximum cycle value of the two instructions before the merge. We have verified that the use of MOPs can lead to significant improvements in some encryption algorithms.
Opcode | Origin | Cycles |
---|---|---|
ADC 2 | add + sltu + add + sltu + or | 1 + 0 + 0 + 0 + 0 |
SBB | sub + sltu + sub + sltu + or | 1 + 0 + 0 + 0 + 0 |
WIDE_MUL | mulh + mul | 5 + 0 |
WIDE_MULU | mulhu + mul | 5 + 0 |
WIDE_MULSU | mulhsu + mul | 5 + 0 |
WIDE_DIV | div + rem | 32 + 0 |
WIDE_DIVU | divu + remu | 32 + 0 |
FAR_JUMP_REL | auipc + jalr | 0 + 3 |
FAR_JUMP_ABS | lui + jalr | 0 + 3 |
LD_SIGN_EXTENDED_32_CONSTANT | lui + addiw | 1 + 0 |