EWASM VM - 次世代的
Ethereum Virtual Machine
@hydai
2019/08/17
hydai
Blog: hyd.ai
Mail: hydai@hyd.ai
GitHub: @hydai
Work: @SecondState
Focus on Compiler and Virtual
Machine technology.
– Eth1x/Istanbul meetup Berlin
Save Ethereum,
Scale Ethereum.
EVM recap
• Stack-based virtual machine (or interpreter…)
• 256 bit stack items
• Too many high level instructions
• Storage(SSTORE, SLOAD)
• SHA3(keccak-256)
• Call, Create Contract…
• Too far away from actual machine architecture
• Less language support (Vyper, Solidity)
How about wasm?
• Also, a stack-based machine but…
• has locals ( ~= register or memory)
• only access top 3 items from stack v.s EVM’s 16
• Support 32/64 bit operations
• No high level instructions
• RISC Instruction Set, can map to a common CPU ISA
• Large community power
• Supported in all major browser
• Lots of implementations
• Lots of language support (C++, Rust, …)
wasm engine
• Tool
• binaryen (a toolkit contains an interpreter in C++)
• wabt (a toolkit contains an interpreter in C++)
• wavm (LLVM-based JIT)
• wagon (interpreter in Golang)
• parity-wasm (interpreter in Rust)
• Browser (hyper interpreter/JIT)
• Chrome (V8)
• Edge (chakra)
• Firefox (spidermonkey)
What is ewasm?
• ewasm ⊂ wasm
• NOT support floating point number
• LIMITED imports and exports (wasm section)
• Will inject bytecode metering and has runtime
metering
Where did the high level
instructions go?
Ethereum Environment Interface
• EEI defines a set of ewasm imported functions
• With standard interface, clients can implement
easier
• Because EEI is not native instructions in bytecode
• Quick prototyping and doing specific upgrades
ewasm module EEI blockchain
Definition
Use
How about
Invalid instructions issues?
System Contract
• Compiled into wasm bytecode
• Deployed on chain (like normal contract)
• Or be part of client (like precompiles)
• Examples:
• Byzantium precompiles
• sha256, ripemd160, ecrecover, modexp, …
• Use upper-bound metering
• Sentinel (verification and metering)
Sentinel Contract?
• Before contract deployment
• Reject non-ewasm bytecode (e.g. floating point)
• Insert metering statements
• basic-block-based metering (call useGas in the beginning
of block)
ewasm
bytecode
Sentinel
deployed
on chain
ewasm stack
Client
with EVM-C support
EVM-C
Heru
Wasm Engine in C++
EEI
Runtime
ewasm
bytecode
Sentinel
EVM-C
• Connect client and VM implementation
• Ethereum Virtual Machine includes EVM1 and eWASM
• With EVM-C, VM can be linked statically or loaded
as plugin (.dll, .so)
• C means C language API
wasm sections
src: https://rsms.me/wasm-intro
wasm engine
ewasm
bytecode
Parse
ewasm
module
Validate
validated
ewasm module
Instantiate
ewasm
module
instance
Execute
Is ewasm a panacea for
ethereum?
Calm Down
Issue 1 - Storage Model
• eWASM = EVM 1.0 mirrored in wasm
• Storage model is not compatible with rent
• Here comes eWASM 1.X!!!
• New storage model designed for rent!!!
Issue 2 - Performance
Is eWASM always better than EVM1?
What happens?!!!!!
• General wasm engine supports 32/64 bit operations
• 128/256 bit operations will be simulated by 32/64
bit operations
• EVM has the precompiles……
Issue 3 - Metering
• Basic block metering
• Super block metering
• Upper bound metering
Basic Block Metering
Super Block Metering
Q & A
Reference
• ewasm for sharding
• https://drive.google.com/file/d/19t4qCqEK2RPt0p1XYx-
a2FdZSAlCq7H0/view
• ewasm updates
• https://drive.google.com/file/d/
1CRc0qBQTebNKw7NRZXzxbHovrigW0bqf/view
• ewasm design
• https://github.com/ewasm/design
• EEI
• https://github.com/ewasm/design/blob/master/eth_interface.md
• wasm-intro
• https://rsms.me/wasm-intro

Introduction to ewasm

  • 1.
    EWASM VM -次世代的 Ethereum Virtual Machine @hydai 2019/08/17
  • 2.
    hydai Blog: hyd.ai Mail: hydai@hyd.ai GitHub:@hydai Work: @SecondState Focus on Compiler and Virtual Machine technology.
  • 3.
    – Eth1x/Istanbul meetupBerlin Save Ethereum, Scale Ethereum.
  • 4.
    EVM recap • Stack-basedvirtual machine (or interpreter…) • 256 bit stack items • Too many high level instructions • Storage(SSTORE, SLOAD) • SHA3(keccak-256) • Call, Create Contract… • Too far away from actual machine architecture • Less language support (Vyper, Solidity)
  • 5.
    How about wasm? •Also, a stack-based machine but… • has locals ( ~= register or memory) • only access top 3 items from stack v.s EVM’s 16 • Support 32/64 bit operations • No high level instructions • RISC Instruction Set, can map to a common CPU ISA • Large community power • Supported in all major browser • Lots of implementations • Lots of language support (C++, Rust, …)
  • 6.
    wasm engine • Tool •binaryen (a toolkit contains an interpreter in C++) • wabt (a toolkit contains an interpreter in C++) • wavm (LLVM-based JIT) • wagon (interpreter in Golang) • parity-wasm (interpreter in Rust) • Browser (hyper interpreter/JIT) • Chrome (V8) • Edge (chakra) • Firefox (spidermonkey)
  • 7.
    What is ewasm? •ewasm ⊂ wasm • NOT support floating point number • LIMITED imports and exports (wasm section) • Will inject bytecode metering and has runtime metering
  • 8.
    Where did thehigh level instructions go?
  • 9.
    Ethereum Environment Interface •EEI defines a set of ewasm imported functions • With standard interface, clients can implement easier • Because EEI is not native instructions in bytecode • Quick prototyping and doing specific upgrades ewasm module EEI blockchain
  • 10.
  • 11.
  • 12.
    System Contract • Compiledinto wasm bytecode • Deployed on chain (like normal contract) • Or be part of client (like precompiles) • Examples: • Byzantium precompiles • sha256, ripemd160, ecrecover, modexp, … • Use upper-bound metering • Sentinel (verification and metering)
  • 13.
    Sentinel Contract? • Beforecontract deployment • Reject non-ewasm bytecode (e.g. floating point) • Insert metering statements • basic-block-based metering (call useGas in the beginning of block) ewasm bytecode Sentinel deployed on chain
  • 14.
  • 15.
    Client with EVM-C support EVM-C Heru WasmEngine in C++ EEI Runtime ewasm bytecode Sentinel
  • 16.
    EVM-C • Connect clientand VM implementation • Ethereum Virtual Machine includes EVM1 and eWASM • With EVM-C, VM can be linked statically or loaded as plugin (.dll, .so) • C means C language API
  • 17.
  • 18.
  • 19.
    Is ewasm apanacea for ethereum?
  • 20.
  • 21.
    Issue 1 -Storage Model • eWASM = EVM 1.0 mirrored in wasm • Storage model is not compatible with rent • Here comes eWASM 1.X!!! • New storage model designed for rent!!!
  • 22.
    Issue 2 -Performance Is eWASM always better than EVM1?
  • 26.
    What happens?!!!!! • Generalwasm engine supports 32/64 bit operations • 128/256 bit operations will be simulated by 32/64 bit operations • EVM has the precompiles……
  • 27.
    Issue 3 -Metering • Basic block metering • Super block metering • Upper bound metering
  • 28.
  • 29.
  • 31.
  • 32.
    Reference • ewasm forsharding • https://drive.google.com/file/d/19t4qCqEK2RPt0p1XYx- a2FdZSAlCq7H0/view • ewasm updates • https://drive.google.com/file/d/ 1CRc0qBQTebNKw7NRZXzxbHovrigW0bqf/view • ewasm design • https://github.com/ewasm/design • EEI • https://github.com/ewasm/design/blob/master/eth_interface.md • wasm-intro • https://rsms.me/wasm-intro