Writing Ewasm in Rust
Antonio Yang
yanganto@github
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
WebAssembly is an open standard that defines a portable binary-code format for executable programs, and a corresponding textual assembly language.
Ethereum is a decentralized, open-source blockchain with smart contract (web3) functionality.
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
Any language with HTTP protocol
Web2 Server
API
EVM
Web3 Blockchain
Restricted
Any language compile to EWasm format
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
Rust is a multi-paradigm, high-level, general-purpose programming language designed for performance and safety, especially safe concurrency.
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
Web3 Blockchain
Talk to contract in Binary over the blockchain network
Web2 Server
API
Talk to API in Hyper Text Markup Language over the internet
API
API
API
API
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
Handler(s)
Main entry
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
In web2, Uniform Resource Identifier(URI) for routing
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
In web3, functional signature for routing
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
Handlers
Main function
(entry point)
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
.rs
Executor
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
Result
Option
operate on Bytes32
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
pub enum CallResult { Successful, Failure, Revert, Unknown, }
pub enum CallError { Failure, Revert, Unknown, }
fn call() -> CallResult;
fn call() -> Result<(), CallError>;
Please read things behind the wordings!
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
Constructor
Handlers
Main function
(entry point)
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
ewasm-rust-api
.rs
Web3 Blockchain
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
Tests
Create WasmEdge runtime,
Add _compile_constructor_test,
Add _compile_runtime_test
Run each test in runtime
Use macro to add common test utilities,
then just cargo test
第六届中国开源年会 COSCon'21 开心开源 Happy Hacking
扫码关注
开源社公众号
Let's meet on github or hackthon,
issue, PR are welcome