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


  1. 6. @wasmerio How to execute
 outside of the

    Browser? • Interpreter • Compile Ahead of Time / Just in Time (AOT / JIT)
  2. 8. @wasmerio How to execute
 WebAssembly performantly
 outside of

    the Browser? • Interpreter • Compile Ahead of Time / Just in Time (AOT / JIT)
  3. 12. @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. 13. @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. 21. @wasmerio Singlepass is a backend for the WebAssembly

    runtime focused on compilation speed. It emits machine code as the module is being parsed
  6. 31. @wasmerio But we have embeddings for almost any

    other language • Go: Perlin, Cosmos, Ethereum • Rust: Polkadot, EVM • Python • …and many more!
  7. 33. @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. 36. @wasmerio How metering is done today • Transforms

    the WebAssembly module, injecting the calls to the gas meter
  9. 38. @wasmerio This is the best strategy if you

    can’t access the VM directly (e.g. browser environments)
  10. 43. @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. 44. @wasmerio Metering in Numbers 0us 1.75us 3.5us 5.25us

    7us Not metered Middleware WASM Transforms Baseline Time spent on metering
  12. 45. @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. 48. @wasmerio A contract is a set of imports

    and exports that must be fulfilled in the module
  14. 58. @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
  15. 61. @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
  16. 68. @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.
  17. 70. @wasmerio But wait, there is more! • Preparing

    support for AArch64 (ARM) coming in the next months • More languages! • Tiering!
  18. 71. @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
  19. 72. @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