Profile picture
Sina Habibian @sinahab
, 17 tweets, 4 min read Read on Twitter
1) The Truebit virtual machine spec is up!

github.com/TrueBitFoundat…
2) The Truebit VM is based on WebAssembly, because:
• WASM is portable.
• WASM is designed to be sandboxed and secure.
• WASM is a compilation target for C, C++, Rust, ...
• WASM values map directly to 32/64 bit architectures.
• ...
3) The Truebit VM is fully deterministic.

• Resource limits (memory, native call stack limit) are fixed across the system.

• Floating point can be either canonicalized, emulated as integers (current impl), or disallowed in the system.
4) Tasks are priced using a similar mechanism to Ethereum:

The Task Giver sets a gasPrice and a gasLimit.
5) Instructions and memory are metered ––

Metering instructions are injected per block of code.

The VM keeps track of gas used in a counter, and terminates if the value exceeds the gasLimit.
6) The offchain interpreter can create state snapshots ––

A merkle tree including every part of the VM:
• the code
• the stack
• the linear memory
• the globals
• the calltable
• pc, stack_ptr, call_ptr
• …
7) TaskGiver creates a task by declaring:
• the program (a WebAssembly module),
• the inputs

And attaching some reward
• gas price
• gas limit
8) Solver runs the task locally:

Step 1) download program and inputs from decentralized filesystem
Step 2) inject metering instructions into the code
Step 3) perform pre-processing & instantiate the VM
Step 4) run the code
Step 5) submit solution to the contract
9) Disputes in step 4 result in a Truebit verification game.

The challenger forces a binary search arriving at the first disputed step in O(log(n)) time, with n being the number of instructions
10) Disputes in step 2 or 3 also result in a verification game! Metering, pre-processing, and instantiation are implemented as deterministic WASM modules.
11) But.. disputed instructions are not actually run fully onchain.

Instead, the Truebit VM breaks each instructions into multiple *phases*.

E.g. i32.add has phases for popping the first stack item, the second stack item, summing them, and pushing the result onto the stack
12) The Truebit WebAssembly interpreter (written in Solidity) runs only *one phase* on chain.

github.com/TrueBitFoundat…
13) Truebit tasks can read inputs directly (as in the interactive Scrypt verification for the Doge-Ethereum bridge).

They can also read inputs from a decentralized filesystem (e.g. IPFS).
14) We have the following short & long-term avenues for data availability:
• store data on the blockchain –– contract storage, logs, or contract code.
• Jason Teutsch decentralized oracles: people.cs.uchicago.edu/~teutsch/paper…
• Ethereum sharding – consensus on data.
• Filecoin and Swarm
15) Truebit tasks execute efficiently because:

• the original run by Solver/Verifier uses a JIT, without the need for snapshots.
• the follow-up runs during verification games use the interpreter, with state snapshots.
16) The JIT is fast. (Shout-out to @Sunfishcode and Cretonne).
The interpreter is slow(er), but is only ever used in case of disputes.
17) Check it out and let us know if you have any feedback.

Thanks to @mrsmkl , @ethchris , and others for massive contributions to the Truebit VM!
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Sina Habibian
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member and get exclusive features!

Premium member ($3.00/month or $30.00/year)

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!