WASM in the wild

hot-upgradable runtime in substrate

thanks to Rust

benjamin kampmann

gnunicorn.org // ben@parity.io

cologne, nov 7th, 2018

@ Rust Cologne

Next-generation
Crypto-tech
Infrastructure

Polkadot is ...

... a protocol that allows independent blockchains to exchange information.

... an interoperability layer, that enforces order and the validity of the messages between the chains

but how?

Relay Chain, a blockchain which relays messages of other chains, at the core of network.

Parachains are separate chains run in and with direct knowledge of polkadot.

& bridges allow interactions with 3rd Party chains.

Varying degree of sovereignity

Pluralistic by design

Polkadot is an interoperability protocol with multi-chain collaboration at the core of its design

Polkadot Architecture

excerpt

Roadmap

Substrate ...

... is a Polkadot compatible, general purpose blockchain development kit in rust

... allows hot-upgrades of the internal runtime through WebAssembly ("WASM")

Blockchain ...

... is log of state transitions

... the specifics depend on that particular blockchain

... transitions are bundled in blocks, where every block references its parent ("chain")

e.g. which crypto, consensus, network protocol or transitions are available

How general is

substrate?

  • Abstract block format
  • Crypto Database(s) agnostict
  • Pluggable Consensus Engine
  • Extensible networking, CLI, RPC
  • Abstract "execute_block" function

This is where the magic happens

Sandboxed Chain

Substrate

Chain Runtime

execute_block

Block "flow"

Substrate

Chain

Runtime

execute_block
  1. generic checks e.g. hash
  2. execute_block(      )
  1. consensus check
  2. execute transitions
  3.  -> get_state
  4.  -> set_state
  5.  -> store block

Substrate provided Key-Value-Store

:code

WebAssembly ...

"wasm"

.. is a web standard for an assembly like compile-target to run code in Web Browsers as almost native speed

.. is execute in a sandboxed virtual environment

.. can be compiled to from many system languages (C, C++, rust, ...)

execute_block interna

  1. generic checks e.g. hash
  2.  
let code = get_state(":code");
let executor = {
  if native.can_call_with(code.runtime_version) {
    native::executor
  } else {
    in_wasm_module_executor(code)
  }
};

executor.execute_block(   );

 

let code = get_state(":code");
let executor = {
  if native.can_call_with(code.runtime_version) {
    native::executor
  } else {
    in_wasm_module_executor(code)
  }
};

executor.execute_block(   );

 

Runtime

Version

Simple check whether the native executor is running the same basic code

pub struct RuntimeVersion {
    /// chain name
    pub spec_name: String,
    /// specific implementation
    pub impl_name: String,

    /// spec version
    pub spec_version: u32,
    /// "minor", non-breaking version
    pub impl_version: u32
}
impl RuntimeVersion {
  pub fn can_call_with(&self, other: &RuntimeVersion) -> bool {
    self.spec_name == other.spec_name &&
    self.spec_version == other.spec_version    
  }
}

Chain upgrade

Substrate

Chain Runtime

execute_block
set_state(":code",    )

+1

Substrate Runtime Module Library (SRML)

Modular & pluggable: choose the features you want, snap together, you’re done!

What do I get with Substrate

  • Hot-upgradeable chain Runtime

  • (optional) SRML Modules for your chain

  • Interchain connectivity via Polkadot

  • Hot-swappable, pluggable consensus

  • Light client

  • Chain synchronisation

  • Pub/Sub WebSocket JSON-RPC

  • Transaction queue

  • secure networking

  • JS implementation

  • Telemetry

thanks!

Questions?

benjamin kampmann

gnunicorn.org

tw/gnunicornBen

t.me/gnunicorn

ben@parity.io

We're hiring!

@me