Skip to content

Commit

Permalink
Merge pull request #4 from GatewayLabs/feat/garbled-stack
Browse files Browse the repository at this point in the history
Implement stack as enum and enhance stack value handling
  • Loading branch information
boscocg authored Jan 9, 2025
2 parents 46a2768 + 58da1d6 commit 4f5ba26
Show file tree
Hide file tree
Showing 26 changed files with 2,141 additions and 849 deletions.
1,244 changes: 759 additions & 485 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ members = [
"examples/database_ref",
"examples/uniswap_get_reserves",
"examples/uniswap_v2_usdc_swap",
"examples/add_example",
#"examples/custom_opcodes",
]

Expand All @@ -45,11 +46,11 @@ specification = { path = "crates/specification", package = "revm-specification",
state = { path = "crates/state", package = "revm-state", version = "1.0.0", default-features = false }
wiring = { path = "crates/wiring", package = "revm-wiring", version = "1.0.0", default-features = false }
transaction = { path = "crates/wiring/transaction", package = "revm-transaction", version = "1.0.0", default-features = false }
interpreter = { path = "crates/interpreter", package = "revm-interpreter", version = "10.0.1", default-features = false }
interpreter = { path = "crates/interpreter", package = "revm-interpreter", version = "10.0.1", features = ["serde"] }
inspector = { path = "crates/inspector", package = "revm-inspector", version = "1.0.0", default-features = false }
precompile = { path = "crates/precompile", package = "revm-precompile", version = "11.0.1", default-features = false }
statetest-types = { path = "crates/statetest-types", package = "revm-statetest-types", version = "1.0.0", default-features = false }
compute = { package = "compute", git = "https://github.com/Gateway-DAO/circuit-sdk", branch = "main" }
compute = { path = "../circuit-sdk/compute" }

[workspace.package]
license = "MIT"
Expand All @@ -72,4 +73,4 @@ debug = true

[profile.ethtests]
inherits = "test"
opt-level = 3
opt-level = 3
130 changes: 25 additions & 105 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,140 +1,60 @@
# revm

[![CI](https://github.com/bluealloy/revm/actions/workflows/ci.yml/badge.svg)][gh-ci]
[![License](https://img.shields.io/badge/License-MIT-orange.svg)][mit-license]
[![Chat][tg-badge]][tg-url]

[mit-license]: https://opensource.org/license/mit/
[gh-ci]: https://github.com/bluealloy/revm/actions/workflows/ci.yml
[tg-url]: https://t.me/+Ig4WDWOzikA3MzA0
[tg-badge]: https://img.shields.io/badge/chat-telegram-blue
# REVM Gateway

**Rust Ethereum Virtual Machine**

![](./assets/logo/revm-banner.png)

Revm is an EVM written in Rust that is focused on **speed** and **simplicity**.
It has a fast and flexible implementation with a simple interface and embedded Host.
It passes all `ethereum/tests` test suites.

Here is a list of guiding principles that Revm follows.

* **EVM compatibility and stability** - this goes without saying but it is nice to put it here. In the blockchain industry, stability is the most desired attribute of any system.
* **Speed** - is one of the most important things and most decisions are made to complement this.
* **Simplicity** - simplification of internals so that it can be easily understood and extended, and interface that can be easily used or integrated into other projects.
* **interfacing** - `[no_std]` so that it can be used as wasm lib and integrate with JavaScript and cpp binding if needed.
- **EVM compatibility and stability** - this goes without saying but it is nice to put it here. In the blockchain industry, stability is the most desired attribute of any system.
- **Speed** - is one of the most important things and most decisions are made to complement this.
- **Simplicity** - simplification of internals so that it can be easily understood and extended, and interface that can be easily used or integrated into other projects.
- **interfacing** - `[no_std]` so that it can be used as wasm lib and integrate with JavaScript and cpp binding if needed.

# Project
## Project

Structure:

* crates
* revm -> main EVM library.
* revm-primitives -> Primitive data types.
* revm-interpreter -> Execution loop with instructions
* revm-precompile -> EVM precompiles
* bins:
* revme: cli binary, used for running state test jsons
- crates
- revm -> main EVM library.
- revm-primitives -> Primitive data types.
- revm-interpreter -> Execution loop with instructions
- revm-precompile -> EVM precompiles
- bins:
- revme: cli binary, used for running state test jsons

This project tends to use the newest rust version, so if you're encountering a build error try running `rustup update` first.

There were some big efforts on optimization of revm:

* Optimizing interpreter loop: https://github.com/bluealloy/revm/issues/7
* Introducing Bytecode format (and better bytecode analysis): https://github.com/bluealloy/revm/issues/121
* Unification of instruction signatures: https://github.com/bluealloy/revm/pull/283

# Building from source

```shell
git clone https://github.com/bluealloy/revm.git
cd revm
cargo build --release
```

**_Note:_** `clang` is required for building revm with `c-kzg` or `secp256k1` feature flags as they depend on `C` libraries. If you don't have it installed, you can install it with `apt install clang`.

# Running eth tests

go to `cd bins/revme/`

Download eth tests from (this will take some time): `git clone https://github.com/ethereum/tests`

run tests with command: `cargo run --release -- statetest tests/GeneralStateTests/ tests/LegacyTests/Constantinople/GeneralStateTests`

`GeneralStateTests` contains all tests related to EVM.

## Running benchmarks

Benches can be found in [`crates/revm/benches`](./crates/revm/benches).
## Running the project

Currently, available benches include the following.
- *analysis*
- *snailtracer*
- *transfer*
### Dependencies

To run the `snailtracer` bench, execute the `cargo bench` subcommand below.
- [Gateway Circuit SDK](https://github.com/GatewayLabs/circuit-sdk)
In in the same work directory as you cloned this repository, you have to clone the `Gateway Circuit SDK`.

```shell
cargo bench --package revm --profile release -- snailtracer
git clone [email protected]:GatewayLabs/circuit-sdk.git
```

Using [flamegraph][flamegraph], you can create a visualization breaking down the runtime of various
sections of the bench execution - a flame graph. Executing the `cargo flamegraph` subcommand requires
installing [flamegraph][flamegraph] by running `cargo install flamegraph`.
### Building the project

```shell
cargo flamegraph --root --freq 4000 --min-width 0.001 --package revm --bench bench -- snailtracer
cargo build --release
```

This command will produce a flamegraph image output to `flamegraph.svg`.
Flamegraph also requires sudo mode to run (hence the `--root` cli arg) and will prompt you for your password if not in sudo mode already.

[flamegraph]: https://docs.rs/crate/flamegraph/0.1.6

## Running examples
### Running an example

```shell
cargo run -p revm --features ethersdb --example fork_ref_transact
cargo run -p add-example (for instance)
```

Generate block traces and write them to json files in a new `traces/` directory.
Each file corresponds to a transaction in the block and is named as such: `<tx index>.json`.

```shell
cargo run -p revm --features std,serde-json,ethersdb --example generate_block_traces
cargo run
```

# Used by:

* [Foundry](https://github.com/foundry-rs/foundry) is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
* [Helios](https://github.com/a16z/helios) is a fully trustless, efficient, and portable Ethereum light client written in Rust.
* [Reth](https://github.com/paradigmxyz/reth) Modular, contributor-friendly and blazing-fast implementation of the Ethereum protocol
* [Arbiter](https://github.com/primitivefinance/arbiter) is a framework for stateful Ethereum smart-contract simulation
* [Zeth](https://github.com/risc0/zeth) is an open-source ZK block prover for Ethereum built on the RISC Zero zkVM.
* [VERBS](https://github.com/simtopia/verbs) an open-source Ethereum agent-based modelling and simulation library with a Python API.
* [Hardhat](https://github.com/NomicFoundation/hardhat) is a development environment to compile, deploy, test, and debug your Ethereum software.
* [Trin](https://github.com/ethereum/trin) is Portal Network client. An execution and consensus layer Ethereum light client written in Rust. Portal Network client's provide complete, provable, and distributed execution archival access.
* [Simular](https://github.com/simular-fi/simular/) is a Python smart-contract API with a fast, embedded, Ethereum Virtual Machine.
* [rbuilder](https://github.com/flashbots/rbuilder) is a state of the art Ethereum MEV-Boost block builder written in Rust and designed to work with Reth.
* ...

(If you want to add project to the list, ping me or open the PR)

# Documentation

The book can be found at github page here: https://bluealloy.github.io/revm/

The documentation (alas needs some love) can be found here: https://bluealloy.github.io/revm/docs/

To serve the mdbook documentation in a local environment, ensure you have mdbook installed (if not install it with cargo) and then run:

```shell
mdbook serve documentation
```

# Contact

There is public telegram group: https://t.me/+Ig4WDWOzikA3MzA0
## Important considerations

Or if you want to contact me directly, here is my email: [email protected] and telegram: https://t.me/draganrakita
This is a very volatile project, and it is under heavy development. Expect constant changes in the code and the documentation.
2 changes: 1 addition & 1 deletion crates/inspector/src/eip3155.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<EvmWiringT: EvmWiring> Inspector<EvmWiringT> for TracerEip3155 {

fn step(&mut self, interp: &mut Interpreter, context: &mut EvmContext<EvmWiringT>) {
self.gas_inspector.step(interp, context);
self.stack.clone_from(interp.stack.data());
self.stack = interp.stack.data().iter().map(|v| v.to_u256()).collect();
self.memory = if self.include_memory {
Some(hex::encode_prefixed(interp.shared_memory.context_memory()))
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ serde_json = "1.0"
bincode = "1.3"

[features]
default = ["std"]
default = ["std", "serde"]
std = ["serde?/std", "primitives/std", "wiring/std"]
hashbrown = ["primitives/hashbrown"]
serde = ["dep:serde", "primitives/serde", "bytecode/serde", "wiring/serde"]
Expand Down
Loading

0 comments on commit 4f5ba26

Please sign in to comment.