(instruction set architecture) enabling a new era of innovation for processor architectures. CKB VM is a software implementation of RISC-V following its current standards.
n) { int a = 0, b = 1, c, i; if (n == 0) return a; for (i = 2; i <= n; i++) { c = a + b; a = b; b = c; } return b; } fib: li a5,0 beqz a0,.L2 li a4,2 li a5,1 li a3,0 .L3: ble a4,a0,.L4 .L2: mv a0,a5 ret .L4: addw a2,a3,a5 addiw a4,a4,1 mv a3,a5 mv a5,a2 j .L3
numerous crypto algorithms, which one should we use? • Compile secp256k1 via GCC to RISC-V, then deploy it on CKB. • No need to wait for precompiles. Deploy your favorite algorithm as you wish. • Your contracts are treated exactly the as the official ones.
what should I do with my current dapp? • Compile an existing blockchain VM(Bitcoin Script, EVM, …) to RISC-V, then deploy it on CKB. • Preserve , keep a more , ecosystem.
want to use JavaScript and enjoy the rich npm ecosystem? • Compile a JS implementation(e.g: duktape) to RISC-V, then deploy to CKB. • Performance might or might not be a problem, it greatly depends on the use case. ◦ As adoption grows, optimizations will be applied due to economy.
level languages(C/C++, Rust, Go, etc.) typically require heaps for dynamic allocations. • WebAssembly only allows declaring fixed length buffer in modules in advance. • To implement a growable heap, typical solution is to create an ArrayBuffer in JavaScript, then expose it to WebAssembly. • This works for Web, but what about blockchains?
“Nondeterminism is only specified as a compromise when there is no other practical way to: - Achieve portable native performance. - Lower resource usage. - Reduce implementation complexity (both of WebAssembly VMs as well as compilers generating WebAssembly binaries). - Allow usage of new hardware features. - Allows implementations to security-harden certain usecases.”
“As WebAssembly gets implemented and tested with multiple languages on multiple architectures we may revisit some of the design decisions: - (omitted …) - When different languages have different expectations then it’s unfortunate if WebAssembly measurably penalizes one’s performance by enforcing determinism which that language doesn’t care about, but which another language may want.”
transpiler. • Ship higher-level features(GC, Tail Call, Expressive Control Flows, Floating Point calculations, etc.) in your contract as used. • Evergreen WASM implementation.
Rust balances between code clarity and low level control • Leverage RAW assembly for hot loops. • Rust is awesome in most cases, but watch out for quirks
a zero prologue). movzx ebp, ah Decode RC (split of RD) movzx eax, al Decode RB (split of RD) // The instruction itself. cmp [edx+ebp*8+0x4], -13 Type check of [RB] ja ->lj_vmeta_arith_vn movsd xmm0, [edx+ebp*8] Load of [RB] addsd xmm0, [edi+eax*8] Add to [RC] movsd [edx+ecx*8], xmm0 Store in [RA] // Standard epilogue: decode + dispatch the next instruction. mov eax, [esi] Load next bytecode movzx ecx, ah Decode RA movzx ebp, al Decode opcode add esi, 0x4 Increment PC shr eax, 0x10 Decode RD jmp [ebx+ebp*4] Dispatch to next instruction Inspirations from masters