• This repository has been archived on 05/Jan/2019
  • Stars
    star
    107
  • Rank 323,506 (Top 7 %)
  • Language
    C++
  • License
    Mozilla Public Li...
  • Created over 8 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[ORPHANED] Transcompiles EVM code to eWASM

Note: this project is not actively maintained. See RuneVM and yevm for replacement candidates.

SYNOPSIS

CircleCI js-standard-style

EVM (Ethereum VM 1.0) to eWASM transcompiler. Here is a online frontend.

INSTALL

Clone the repository and run npm install

USE

There is a commandline tool to transcompile EVM input:

Transcompile EVM to WASM

$ bin/evm2wasm.js -e `evm_bytecode_file` -o `wasm_output_file`

Transcompile EVM to WAST

$ bin/evm2wasm.js -e `evm_bytecode_file` -o `wasm_output_file` --wast

Transcompile EVM to WAST with embedded EVM trace statements for each transpiled EVM opcode

$ bin/evm2wasm.js -e `evm_bytecode_file` -o `wasm_output_file` --wast --trace

Transcompile EVM to WAST with gas metering per transpiled EVM opcode (not per branch segment)

$ bin/evm2wasm.js -e `evm_bytecode_file` -o `wasm_output_file` --wast --charge-per-op

DEVELOP

  • After any changes to .wast file, npm run build needs to be run to compile the files into a .json file
  • To rebuild the documentation run npm run build:docs
  • To lint run npm run lint
  • And make sure you test with npm test and npm run vmTests which runs the offical Ethereum test suite

The above build command will invoke wasm/generateInterface.js which generates wasm/wast.json and include/wast.h containing a Webassembly function corresponding to each EVM opcode.

The core logic of the evm2wasm compiler is in index.js (Javascript frontend) or libs/evm2wasm/evm2wasm.cpp (C++ fronetend), which iterates the input EMV bytecode and generates a Webassembly output by invoking each of the above generated Webassembly functions and concatenating them into the output.

To build the C++ frontend:

$ mkdir build
$ cd build
$ cmake ..
$ make

API

./docs/

TECHNICAL NOTES

EVM is stack based and offers access to memory, storage and state via special instructions.
Here we replicate the stack layout in WebAssembly (WASM) and implement each operation working on this stack.

OPCODES

Every opcode (bar some special instructions) receives the current stack pointer ($sp) as i32 and must return the adjusted stack pointer.

STACK LAYOUT

The stack grows from memory location 0, where 256 bit values are stored linearly in LSB byteorder.
The $sp points to the starting position of the top stack entry (and not the next free stack position). If the stack is empty, it is set to -32.

MEMORY LAYOUT

The resulting (after transpilation) contract memory layout is currently as follows:

.---------------------------------------------------
| Reserved space for the stack (32768 bytes)
| - each stack entry is 256 bits
| - the stack is limited to 1024 entries
+---------------------------------------------------
| Word count (4 bytes)
| (Number of 256 bit words stored in memory)
+---------------------------------------------------
| Previous memory cost in word count (4 bytes)
| (The cost charged for the last memory allocation)
+---------------------------------------------------
| Scratch space (32 bytes)
+---------------------------------------------------
| Reserved space for the Keccak-256 context (1024 bytes)
+---------------------------------------------------
| "EVM 1.0" contract memory starts here ("unlimited" in size)
`---------------------------------------------------

METERING

The generated eWASM contract contains gas metering. It is assumed evm2wasm will become a deployed trusted contract, which returns eWASM code that does not need to be run through the gas injector contract.

LICENSE

MPL-2.0

More Repositories

1

design

Ewasm Design Overview and Specification
1,015
star
2

hera

Hera: Ewasm virtual machine conforming to the EVMC API
C++
180
star
3

ewasm-rust-api

Ewasm API for Rust
Rust
102
star
4

scout

Scout is a Ethereum 2.0 Phase 2 execution prototyping engine.
Rust
89
star
5

wasm-metering

[ORPHANED] Injects metering into webassembly binaries
JavaScript
68
star
6

testnet

Testnet planning & documentation
Dockerfile
64
star
7

ewasm-precompiles

Implementation of the Ethereum precompiled contracts in Rust.
Rust
45
star
8

wasm-json-toolkit

[ORPHANED] A small toolkit for converting wasm binaries into json and back.
JavaScript
32
star
9

ewasm-kernel

[ORPHANE] Javascript implementation of an eWASM VM
JavaScript
24
star
10

assemblyscript-ewasm-api

Ewasm API for AssemblyScript
TypeScript
21
star
11

biturbo

Eth1 EE using Turboproofs
TypeScript
20
star
12

rust-ewasm

[ORPHANE] Examples of compiling Rust code to ewasm contracts
WebAssembly
20
star
13

wast2wasm

[OBSOLETE] converts .wast files -> .wasm
JavaScript
20
star
14

benchmarking

Instructions for benchmarking Ewasm precompiles. (And results.)
Python
18
star
15

ewasm-studio

A lightweight development environment for eWASM
JavaScript
16
star
16

wrc20-examples

This repository contains examples of WRC20 tokens written in different languages.
12
star
17

sentinel-rs

Validator and metering injector for Ewasm
Rust
11
star
18

pm

Ewasm project management repository
11
star
19

ethereum-bls12.rs

Ethereum serialisation for BLS12-381 operations in Rust.
Rust
10
star
20

eth1x64

Description and examples for different variants under the Eth1x64 experiment.
8
star
21

scout.ts

TypeScript port of Scout
TypeScript
7
star
22

ethereum-bn128.rs

Ethereum's BN128 helpers for Rust.
Rust
7
star
23

scoutone

ScoutOne is a C++ library implementing the Eth 2 Phase 2 execution environment on top of wabt.
CMake
6
star
24

evm2wasm-frontend

[ORPHANE] an html front-end for evm2wasm
JavaScript
5
star
25

ewasm-cleanup

[OBSOLETE] Cleanup eWASM contracts to satisfy the specification
JavaScript
4
star
26

sentinel-governance

Governance prototype for the Sentinel contract
JavaScript
4
star
27

ewasm-explorer

[ORPHANE] Minimal account explorer for ewasm testnet.
JavaScript
2
star
28

hera.rs

Rust
2
star
29

ewasm-testgen

Random test case generator for Ewasm.
JavaScript
2
star
30

wasm-metering-old

[OBSOLETE] This is a prototype to inject metering into wasm code.
JavaScript
2
star
31

awesome-phase2

A curated list of awesome things related to Eth2 Phase2
2
star
32

ce-playground

This is a loose collection of Eth 2.0 Phase 2 Computational Environments (CE).
1
star
33

evm384_f6m_mul

Shell
1
star
34

docker

Docker sources useful for Ewasm
Dockerfile
1
star
35

ewasm-libc

1
star
36

ewasm-tests

[OBSOLETE] Tests.
1
star