Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Designing a WebAssembly Runtime for Blockchains

Designing a WebAssembly Runtime for Blockchains

In this presentation we will overview how Wasmer is providing the best infrastructure for the Blockchain platforms

Syrus Akbary

June 08, 2019

More Decks by Syrus Akbary

Other Decks in Technology


  1. [email protected] @wasmerio github.com/wasmerio How to execute
 outside of the

    Browser? • Interpreter • Compile Ahead of Time / Just in Time (AOT / JIT)
  2. [email protected] @wasmerio github.com/wasmerio How to execute
 WebAssembly performantly
 outside of

    the Browser? • Interpreter • Compile Ahead of Time / Just in Time (AOT / JIT)
  3. [email protected] @wasmerio github.com/wasmerio • Cranelift
 Internal project of Mozilla to

    eventually replace their IonMonkey JS implementation • Singlepass
 Compiler focused on compilation speed and fast runtime • LLVM
 Compiler focused on optimizations
  4. [email protected] @wasmerio github.com/wasmerio Compilation speed Runtime speed Singlepass Fast (1x)

    Efficient (2~3x) Cranelift Slow (10x) A bit faster (1.8x) LLVM Very slow (20x~50x) Almost Native (1~1.2x) Expected to have better optimizations over time
  5. [email protected] @wasmerio github.com/wasmerio Singlepass is a backend for the WebAssembly

    runtime focused on compilation speed. It emits machine code as the module is being parsed
  6. [email protected] @wasmerio github.com/wasmerio But we have embeddings for almost any

    other language • Go: Perlin, Cosmos, Ethereum • Rust: Polkadot, EVM • Python • …and many more!
  7. [email protected] @wasmerio github.com/wasmerio Metering consists on measuring the cost of

    running certain instructions while being able to halt the execution if the costs is greater than expected
  8. [email protected] @wasmerio github.com/wasmerio How metering is done today • Transforms

    the WebAssembly module, injecting the calls to the gas meter
  9. [email protected] @wasmerio github.com/wasmerio This is the best strategy if you

    can’t access the VM directly (e.g. browser environments)
  10. [email protected] @wasmerio github.com/wasmerio How? • The metering code is generated

    at parsing time through Middleware • Gas functions are inlined into the function body. No extra calls are required
  11. [email protected] @wasmerio github.com/wasmerio Metering in Numbers 0us 1.75us 3.5us 5.25us

    7us Not metered Middleware WASM Transforms Baseline Time spent on metering
  12. [email protected] @wasmerio github.com/wasmerio Let’s take a closer look • Metering

    8x faster than with code generated with WASM transforms (460us vs 3,680us) • 2x faster in overall runtime speed • No WASM transforms overhead
  13. [email protected] @wasmerio github.com/wasmerio How? • Using the filesystem to get

    the contract input and • Use Commands to call a contract • Use environment vars to get the amount of tokens transferred to the contract (VALUE) • Use environment args to get the blockchain address
  14. [email protected] @wasmerio github.com/wasmerio WASI vs Ewasm • Oasis WASI proposal

    uses the WASI ABI to interact with the environment • It would seem like WASI would help on running other modules that already run on WASI • eWASM have a explicit API
  15. [email protected] @wasmerio github.com/wasmerio Package Signing is like the modern version

    of using sealing wax with a difficult to replicate imprint to verify the authenticity and integrity of the letter.
  16. [email protected] @wasmerio github.com/wasmerio But wait, there is more! • Preparing

    support for AArch64 (ARM) coming in the next months • More languages! • Tiering!
  17. [email protected] @wasmerio github.com/wasmerio Why use Wasmer? • Vendor Neutral. No

    hidden interests. Our business is on creating the best WebAssembly runtime • Trusted and used already by blockchain companies • Rapid iteration process to bring the best runtime EVER
  18. [email protected] @wasmerio github.com/wasmerio Recap • Fastest and modular WebAssembly runtime

    • Available in most popular languages (Rust, Go, Python…) • Adapted to work fast for blockchain use cases • Continuously improving