Based on my previous talk - Introduction to Ewasm 1.0 in COSCUP 2019 and lots of sessions in Ethereum devcon V, I remake this presentation to give an introduction to Ewasm 1.0 and 2.0.
3. www.secondstate.io
EVM bytecode 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, ...)
4. www.secondstate.io
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 language support (C++, Rust, …)
8. www.secondstate.io
What is Ewasm 1.0
● Ewasm ⊂ wasm
● NOT support floating point number
● LIMITED imports and exports (wasm section)
● Will inject bytecode metering and has runtime metering
10. www.secondstate.io
Ethereum Environment Interface (EEI)
● 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
14. www.secondstate.io
System Contracts
● 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)
15. www.secondstate.io
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)
18. www.secondstate.io
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
21. www.secondstate.io
What happens?!!!!!
● General wasm engine supports 32/64 bit operations
● 256 bit operations will be simulated by 32/64 bit
operations
○ ONE 256 bit operations may be replaced by 25 64 bit
operations
● As EVM provides precompiles, Wasm engine can support
`bignum` library to speed up.
27. www.secondstate.io
Execution Environments (EEs)
● “Contracts” are now called EEs
● EEs are Wasm bytecode
● EEs are executed on shards
● Shards only store a short (32-byte) state root for an EE
● On-shard execution goal is to verify the current state
root and calculate the new state root based on a
submitted proof and transactions
28. www.secondstate.io
Two Ewasms
● Ewasm 1.0 - Stateful, EVM-like design, with all the
legacy EVM brings
● Ewasm 2.0 - Stateless and pure execution oriented
design
● Can launch Ewasm 1.0 on Eth 1.0 if optimising EVM in
clients fails
● Can use Ewasm 1.0 contracts within EEs on Eth 2.0
30. www.secondstate.io
Phase One and Done - Very First Step
● Start simple - minimal execution
● Add EEs (Now we have code fields)
● Execute the EEs in shard blocks
● Here comes a testing tool - Scout!!!
31. www.secondstate.io
Open Questions
● How will cross-shard calls work?
○ Nobody knows
● How will the Eth1 switchover work?
○ Nobody is exactly sure.
● When Serenity?
○ January 3rd, MAYBE
33. www.secondstate.io
What is Scout?
● An Eth 2.0 execution prototyping framework
● Based on “ETH 2.0 Phase 2 Proposal 2”
● Defines an API for the EEs (the EEI)
● Defines a test format (YAML format)
● Provides a tool which can execute on that format
● Provides example EEs
36. www.secondstate.io
Playground
● SOLL - Compile your Solidity Smart Contract into
Ewasm via LLVM
○ Can deploy Ewasm bytecode on Ethereum Ewasm testnet
○ https://github.com/second-state/soll
○ Demo Video: https://youtu.be/X-A6sP_HTy0
● Scout - Ethereum 2.0 Phase 2 execution prototyping
engine
○ https://github.com/ewasm/scout
37. www.secondstate.io
Reference
● Ewasm overview and the precompile problem: Alex Beregszaszi and
Casey Detrio @ Ethereum Part 1 - YouTube
● Ewasm overview and the precompile problem: Alex Beregszaszi and
Casey Detrio @ Ethereum Part 2 - YouTube
● Wasm for blockchain&Eth2 execution: Paul Dworzanski,Alex
Beregszaszi,Casey Detrio@Ethereum Part 2 - YouTube
● Ewasm for sharding
● Ewasm updates
● Ewasm design
● wasm-intro