Skip to content

Commit 3c11ded

Browse files
authored
feat: book structure (#2082)
* book: wip * wip book * structure of the book * ci book, note about wip book * git ignore * rm generated book * fix book links * ignore incomplete codes * Change perm for readme.md * fix * test * test * chmod 777 * 777 folder * 777 folder * change mod of root folder * move file for mdbook test * base link * base link
1 parent dd63090 commit 3c11ded

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+374
-1276
lines changed

.github/workflows/book.yml

+8-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ jobs:
3232
echo `pwd`/mdbook-template >> $GITHUB_PATH
3333
3434
- name: Run tests
35-
run: mdbook test
35+
run: |
36+
cp README.md book/src/README.md
37+
sed -i -e 's|../../README.md|README.md|g' book/src/SUMMARY.md
38+
mdbook test
3639
3740
lint:
3841
runs-on: ubuntu-latest
@@ -78,26 +81,26 @@ jobs:
7881
echo `pwd`/mdbook-template >> $GITHUB_PATH
7982
8083
- name: Build book
81-
run: mdbook build documentation
84+
run: mdbook build book
8285

8386
- name: Build docs
8487
run: RUSTDOCFLAGS="--enable-index-page -Zunstable-options" cargo doc --all --no-deps
8588

8689
- name: Move docs to book folder
8790
run: |
8891
mkdir -p target/book/docs
89-
mv target/doc documentation/book/docs
92+
mv target/doc book/book/docs
9093
9194
- name: Archive artifact
9295
shell: sh
9396
run: |
94-
chmod -c -R +rX "documentation/book" |
97+
chmod -c -R +rX "book/book" |
9598
while read line; do
9699
echo "::warning title=Invalid file permissions automatically fixed::$line"
97100
done
98101
tar \
99102
--dereference --hard-dereference \
100-
--directory "documentation/book" \
103+
--directory "book/book" \
101104
-cvf "$RUNNER_TEMP/artifact.tar" \
102105
--exclude=.git \
103106
--exclude=.github \

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pkg/
1010
bins/revme/temp_folder
1111
bins/revme/tests
1212
ethereumjs-util.js
13-
book
1413

1514
# Generated by the block traces example
1615
traces
@@ -19,3 +18,8 @@ burntpix/svgs
1918

2019
# Rust bug report
2120
rustc-ice-*
21+
22+
# book output of README.md generated by `mdbook serve book`
23+
/book/book
24+
/book/cache.json
25+
/index.html

README.md

+43-127
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,73 @@
1-
# revm
1+
### Revm
22

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

7+
Revm is a highly efficient and stable implementation of the Ethereum Virtual Machine (EVM) written in Rust.
8+
9+
![banner](https://raw.githubusercontent.com/bluealloy/revm/refs/heads/main/assets/logo/revm-banner.png)
10+
711
[mit-license]: https://opensource.org/license/mit/
812
[gh-ci]: https://github.com/bluealloy/revm/actions/workflows/ci.yml
913
[tg-url]: https://t.me/+Ig4WDWOzikA3MzA0
1014
[tg-badge]: https://img.shields.io/badge/chat-telegram-blue
1115

12-
**Rust Ethereum Virtual Machine**
13-
14-
![](./assets/logo/revm-banner.png)
15-
16-
Revm is an EVM written in Rust that is focused on **speed** and **simplicity**.
17-
It has a fast and flexible implementation with a simple interface and embedded Host.
18-
It passes all `ethereum/tests` test suites.
19-
20-
Here is a list of guiding principles that Revm follows.
21-
22-
* **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.
23-
* **Speed** - is one of the most important things and most decisions are made to complement this.
24-
* **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.
25-
* **interfacing** - `[no_std]` so that it can be used as wasm lib and integrate with JavaScript and cpp binding if needed.
26-
27-
# Project
28-
29-
Structure:
30-
31-
* crates
32-
* revm -> main EVM library.
33-
* revm-primitives -> Primitive data types.
34-
* revm-interpreter -> Execution loop with instructions
35-
* revm-precompile -> EVM precompiles
36-
* bins:
37-
* revme: cli binary, used for running state test jsons
16+
Known for its robustness, it stands as one of the most popular libraries and critical component of the Ethereum ecosystem. Revm plays a crucial role across various projects, being widely utilized by almost all tooling and block builders. It is integrated into Reth, multiple Layer 2 variants and other clients and serving as a standard for zkVMs.
3817

39-
This project tends to use the newest rust version, so if you're encountering a build error try running `rustup update` first.
18+
Revm offers two primary applications: firstly, it functions as an executor where users can set up block info and process mainnet transactions; secondly, it acts as a framework that facilitates the extension and support of different EVM variants such as revm-optimism.
4019

41-
There were some big efforts on optimization of revm:
20+
### How to use:
4221

43-
* Optimizing interpreter loop: https://github.com/bluealloy/revm/issues/7
44-
* Introducing Bytecode format (and better bytecode analysis): https://github.com/bluealloy/revm/issues/121
45-
* Unification of instruction signatures: https://github.com/bluealloy/revm/pull/283
22+
Here is a straightforward example of using the Execution API: It allows us to create an Ethereum Virtual Machine (EVM) and execute transactions. Additionally, it can be utilized to generate traces with the inspector or more complex example of foundry cheatcodes.
4623

47-
# Building from source
24+
```rust,ignore
25+
let mut evm = Context::mainnet().with_block(block).build_mainnet();
26+
let out = evm.transact(tx);
4827
49-
```shell
50-
git clone https://github.com/bluealloy/revm.git
51-
cd revm
52-
cargo build --release
28+
// or you can use powerful inspection tool to trace it
29+
let mut evm = evm.with_inspector(tracer);
30+
let out = evm.inspect_with_tx(tx);
5331
```
5432

55-
**_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`.
33+
The Evm Framework API is somewhat complex to use, but this document provides a detailed explanation. It enables users to extend logic, incorporate various context types, and offers built-in support for inspection. For a practical example, you can refer to the revm-optimism crate.
5634

57-
# Running eth tests
35+
### Users:
5836

59-
go to `cd bins/revme/`
37+
As previously noted, there are several groups of projects that utilize this technology:
6038

61-
Download eth tests from (this will take some time): `git clone https://github.com/ethereum/tests`
39+
* **Major block builders**.
40+
* **Clients**: [Reth](https://github.com/paradigmxyz/reth), [Helios](https://github.com/a16z/helios), [Trin](https://github.com/ethereum/trin),..
41+
* **Tooling**: [Foundry](https://github.com/foundry-rs/foundry/), [Hardhat](https://github.com/NomicFoundation/hardhat),..
42+
* **L2s**: [Optimism](https://github.com/bluealloy/revm/tree/main/crates/optimism), [Coinbase](https://www.base.org/), [Scroll](https://github.com/scroll-tech/revm),..
43+
* **zkVM**: [Risc0](https://github.com/risc0/risc0-ethereum), [Succinct](https://github.com/succinctlabs/sp1-reth),..
6244

63-
run tests with command: `cargo run --release -- statetest tests/GeneralStateTests/ tests/LegacyTests/Constantinople/GeneralStateTests`
45+
The full list of projects that use Revm is available in the awesome-revm section of the book.
6446

65-
`GeneralStateTests` contains all tests related to EVM.
47+
### How to, dev section
6648

67-
## Running benchmarks
68-
69-
Benches can be found in [`crates/revm/benches`](./crates/revm/benches).
70-
71-
Currently, available benches include the following.
72-
- *analysis*
73-
- *snailtracer*
74-
- *transfer*
75-
76-
To run the `snailtracer` bench, execute the `cargo bench` subcommand below.
77-
78-
```shell
79-
cargo bench --package revm --profile release -- snailtracer
80-
```
81-
82-
Using [flamegraph][flamegraph], you can create a visualization breaking down the runtime of various
83-
sections of the bench execution - a flame graph. Executing the `cargo flamegraph` subcommand requires
84-
installing [flamegraph][flamegraph] by running `cargo install flamegraph`.
85-
86-
```shell
87-
cargo flamegraph --root --freq 4000 --min-width 0.001 --package revm --bench bench -- snailtracer
88-
```
49+
Note that book and code docs are still in WIP stage and they are being updated!
8950

90-
This command will produce a flamegraph image output to `flamegraph.svg`.
91-
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.
51+
Part of the links point to the code documentation or the book. code docs are there to explain usage of particular part of the code where book is to get more of the overview on architecture or how components/projects fit toggether.
9252

93-
[flamegraph]: https://docs.rs/crate/flamegraph/0.1.6
53+
* How to build and use revm can be found here. (code)
54+
* Architecture overview can be seen here. (book)
55+
* Structure of the project (list of crates) can be seen here. (book)
56+
* How to use Revm Framework can be found here. (book)
57+
* Release procedure and changelogs explanation. (book)
58+
* How to use revme (Revm binary with few commands) can be found here. (code)
59+
* How to run Ethereum test can be found here: (book)
60+
* How to run examples and benchmark with `samply` to check performance. (book)
61+
* If there is more explanations please open PR request for it.
9462

95-
## Running Examples
63+
### Community:
64+
For questions please open an github issue or join public telegram group: [https://t.me/+Ig4WDWOzikA3MzA0](https://t.me/+Ig4WDWOzikA3MzA0)
9665

97-
```shell
98-
# Run database reference example
99-
cargo run -p example-database-ref
100-
101-
# Run contract deployment example
102-
cargo run -p example-contract-deployment
103-
104-
# Query Uniswap V2 pool reserves
105-
cargo run -p example-uniswap-get-reserves
106-
107-
# Execute USDC swap on Uniswap V2
108-
cargo run -p example-uniswap-v2-usdc-swap
109-
110-
# Generate block traces
111-
cargo run -p example-block-traces
112-
113-
# Run database reference example
114-
cargo run -p example-database-ref
115-
```
116-
117-
All examples can be found in the `examples/` directory. Each example demonstrates different aspects of revm:
118-
- `block_traces`: Generating execution traces for entire blocks
119-
- `contract_deployment`: Deploying and interacting with smart contracts
120-
- `database_ref`: Using database references for state access
121-
- `uniswap_get_reserves`: Reading state from Uniswap contracts
122-
- `uniswap_v2_usdc_swap`: Executing swaps on Uniswap V2
123-
124-
# Used by:
125-
126-
* [Foundry](https://github.com/foundry-rs/foundry) is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
127-
* [Helios](https://github.com/a16z/helios) is a fully trustless, efficient, and portable Ethereum light client written in Rust.
128-
* [Reth](https://github.com/paradigmxyz/reth) Modular, contributor-friendly and blazing-fast implementation of the Ethereum protocol
129-
* [Arbiter](https://github.com/primitivefinance/arbiter) is a framework for stateful Ethereum smart-contract simulation
130-
* [Zeth](https://github.com/risc0/zeth) is an open-source ZK block prover for Ethereum built on the RISC Zero zkVM.
131-
* [VERBS](https://github.com/simtopia/verbs) an open-source Ethereum agent-based modelling and simulation library with a Python API.
132-
* [Hardhat](https://github.com/NomicFoundation/hardhat) is a development environment to compile, deploy, test, and debug your Ethereum software.
133-
* [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.
134-
* [Simular](https://github.com/simular-fi/simular/) is a Python smart-contract API with a fast, embedded, Ethereum Virtual Machine.
135-
* [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.
136-
* [Tycho-simulation](https://github.com/propeller-heads/tycho-simulation) is a local simulation toolkit that lets you simulate any DEX pool in a revm environment without worrying about protocol internals.
137-
* ...
138-
139-
(If you want to add project to the list, ping me or open the PR)
140-
141-
# Documentation
142-
143-
The book can be found at github page here: https://bluealloy.github.io/revm/
144-
145-
The documentation (alas needs some love) can be found here: https://bluealloy.github.io/revm/docs/
146-
147-
To serve the mdbook documentation in a local environment, ensure you have mdbook installed (if not install it with cargo) and then run:
148-
149-
```shell
150-
mdbook serve documentation
151-
```
66+
### Licence
67+
Revm is licensed under MIT Licence.
15268

153-
# Contact
69+
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in these crates by you, shall be licensed as above, without any additional terms or conditions.
15470

155-
There is public telegram group: https://t.me/+Ig4WDWOzikA3MzA0
71+
### Security
15672

157-
Or if you want to contact me directly, here is my email: [email protected] and telegram: https://t.me/draganrakita
73+
For any security questions or findings, please reach out to me directly via email at [email protected] or contact me on Keybase under the username [draganrakita](https://keybase.io/draganrakita/).

book.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[book]
2-
authors = ["Colin Roberts, Waylon Jepsen", "Dragan Rakita"]
2+
authors = ["Dragan Rakita"]
33
language = "en"
44
multilingual = false
5-
src = "documentation/src"
6-
title = "Rust EVM"
5+
src = "book/src"
6+
title = "Revm - Rust Ethereum Virtual Machine"
77

88
[output.linkcheck]
99
optional = true

book/src/SUMMARY.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Summary
2+
3+
- [Introduction](./../../README.md)
4+
- [Awesome Revm](./awesome.md)
5+
- [Architecture](./architecture.md)
6+
- [Dependencies](./architecture/dependencies.md)
7+
- [Crates](./architecture/crates.md)
8+
- [Framework](./framework.md)
9+
- [Dev section](./dev.md)
10+
- [Examples](./examples.md)
11+
- [Release procedure](./release_procedure.md)
12+
- [Testing](./testing.md)
13+
- [Contact](./contact.md)

book/src/architecture.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Architecture
2+
3+
List of crates can be found in [Crates](./architecture/crates.md) section of the book.
4+
5+
REVM as any EVM implement a list of [EIP's (Ethereum Improvement Protocol)](https://github.com/ethereum/EIPs) changes over time. Those changes are shipped in the form of hardforks. List of hardforks can be found here [Ethereum Hardforks]() and repository that contains all EIPs can be found here [EIPs](https://eips.ethereum.org/).
6+
7+
### Main components/traits:
8+
9+
Revm consist of few traits that implement functionality of the EVM. The main traits are:
10+
* **EvmTrait**: This trait allows as to access main EVM fields and to run interpreter. It defines **Context**, **Precompiles**, **Instructions**. Docs
11+
* **ContextTrait**: is gained from EvmTrait and consist of types needed for execution. It defines environment such as block and transaction, database for runtime fetching of accounts and storage, journal for status changes and revert handling and few more fields. Docs
12+
* **EthHandler**: is a trait that by default implements Ethereum logic, it takes EvmTrait as a input. Entry point is a `run` function. Docs
13+
* **Frame**: is a associate type of EthHandler and contains runtime data of the call and logic of executing the call, default impl is a type is EthFrame. Docs
14+
15+
Inspection for tracing is extensing above traits with:
16+
* **InspectorEvmTrait** is derived from EvmTrait and allows running Evm in Inspection mode. It contains **Inspector** associate type. Docs
17+
* **EthInspectorHandler** is derived from EthHandler and allows running Evm in Inspection mode. Entry point is `inspect_run` function and it calls a alternative functions for execution loop that includes inspector calls. Docs
18+
* **Inspector** is a a user oriented trait that is used for inspection of the EVM. It is used for tracing. It is part of Evm struct and it is called from EthInspectorHandler and InspectorEvmTrait. Docs
19+
20+
21+
### Simplified code
22+
23+
```rust,ignore
24+
pub trait EvmTrait {
25+
type Context: ContextTrait;
26+
...
27+
fn execute_interpreter(..);
28+
}
29+
30+
pub trait EthHandler {
31+
type Evm: EvmTrait;
32+
type Frame: Frame;
33+
...
34+
fn run(evm);
35+
}
36+
```
37+
38+
### flow of execution
39+
Execution flow can be found here (TODO Move to codebase to EthHandler trait):
40+
* It starts with creation of new EVM instance
41+
* Building of the Context
42+
* Building of the EVM. Inspector/Precompiles are created.
43+
* Adding of the Inspector if needed.
44+
* transact/inspect. Both inspection and transaction have same flow where the only difference is that inspection includes calls to the inspector.
45+
* validation of transaction and doing balance gas limit check.
46+
* pre execution loads all warm accounts and deducts the caller.
47+
* Execution :
48+
* Creates first frame with Interpreter or executes precompile.
49+
* run the frame loop:
50+
* Calls Evm to exec interpreter with the frame. Interpreter loops is called here
51+
* Output of Interpreter loop is NextAction that can be a Return of Call.
52+
* If Return, then the frame is popped and the return value is pushed to the parent frame. If it is new call, then a new frame is created and pushed to the call stack.
53+
* If call stack is empty the execution loop is done.
54+
* handles the result of execution.s
55+
* Post execution deals with halt and revert handling redistribution of rewards and reimbursement of unspend gas.

book/src/architecture/crates.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
Revm project is split in multiple crates, each crate is responsible for different part of the project. The main crates are:
3+
4+
There is one binary crate `revme`. It is used for running Ethereum state tests json.
5+
6+
### Library crates
7+
* revm:
8+
* primitives:
9+
* interpreter:
10+
* precompile:
11+
* database:
12+
* database/interface:
13+
* bytecode:
14+
* state:
15+
* specification:
16+
* context:
17+
* context/interface:
18+
* handler:
19+
20+
### variants
21+
* optimism
22+
* inspector
23+
24+
### utility
25+
* statetest-types:
26+
27+
### examples
28+
* block_traces:
29+
* cheatcode_inspector:
30+
* contract_deployment:
31+
* database_components:
32+
* uniswap_get_reserves:
33+
* uniswap_v2_usdc_swap:
34+
* erc20_gas:
35+
36+
37+
# Dependency of library crates can be seen here
38+
39+
TODO Add dependency graph here

0 commit comments

Comments
 (0)