You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
REVM is a flexible implementation of the Ethereum Virtual Machine (EVM). It follows the rules of the Ethereum mainnet and stays up to date with changes through hardforks as defined in the official [Ethereum
@@ -7,26 +7,45 @@ You can use REVM in two main ways:
7
7
1. Run regular Ethereum transactions using a Execution API
8
8
2. Create your own custom version of the EVM (for Layer 2 solutions or other chains) using EVM framework
9
9
10
-
The main `revm` library combines all the different crates into one package and reexports them. You can see overview revm crates in [crates folder](https://github.com/bluealloy/revm/tree/main/crates) and overview of examples in [examples folder](https://github.com/bluealloy/revm/tree/main/examples).
10
+
To see usage examples you can check the [examples folder](https://github.com/bluealloy/revm/tree/main/examples). Other than documentation, examples are main resource to see and learn about Revm.
11
11
12
-
REVM works in no_std environments which means it can be used in zero-knowledge virtual machines (zkVMs). It also has very few external dependencies, which you can read more about in the [dev section](./dev.md).
12
+
The main `revm` library combines all crates into one package and reexports them, standalone library are useful if there is need to import functionality with smaller scope. You can see overview of revm crates in [crates folder](https://github.com/bluealloy/revm/tree/main/crates).
13
+
14
+
REVM works in `no_std` environments which means it can be used in zero-knowledge virtual machines (zkVMs) and it is the standard library in that use case. It also has very few external dependencies.
13
15
14
16
# Execution API
15
17
16
-
REVM provides four ways to execute transactions through traits (interfaces).
18
+
`Evm` the main structure for executing mainnet ethereum transaction is build with a `Context` and a builder, code for it looks like this:
19
+
20
+
```rust,ignore
21
+
let mut evm = Context::mainnet().with_block(block).build_mainnet();
The State system builds on the `Database` trait and handles:
19
-
- Getting data from external storage
20
-
- Managing the EVM's output
21
-
- Caching changes when running multiple transactions
31
+
And `Context` contains data used in execution:
32
+
* Environment data, the data that is known before execution starts are `Transaction`, `Block`, `Cfg`.
33
+
*`Journal` is place where internal state is stored. Internal state is returned after execution ends.
34
+
* And `Database` is a interface that allows fetching external data that is needed in runtime. That data are account, storage and bytecode. When loaded they are stored in `Journal`
22
35
23
-
You can implement one of three database interfaces depending on what you need:
36
+
REVM provides four ways to execute transactions through traits (API):
24
37
25
-
-`Database`: Uses a mutable reference (`&mut self`). This is useful when you want to update a cache or track statistics while getting data. Enables basic transaction functions like `transact` and `inspect`.
38
+
*`transact(tx)` and `replay()` are function of `ExecuteEvm` trait that allow execution transactions. They return the status of execution with reason, changed state and in of case of failed execution a error.
39
+
*`transact_commit(tx)` and `replay_commit()` are part of `ExecuteCommitEvm` that internally commits the state diff to the database and returns status of execution. Database is requires to support `DatabaseCommit` trait.
40
+
*`inspect()`, `inspect_replay(tx)` and few others are part of `InspectEvm` trait that allow execution with inspection. This is how tracers are called.
41
+
*`inspect_commit()`,`inspect_replay_commit(tx)` that are part of `InspectCommitEvm` trait that extends `InspectEvm` to allow committing state diff after tracing.
26
42
27
-
-`DatabaseRef`: Uses a regular reference (`&self`). Good for when you only need to read data without making changes. Enables reference-based functions like `transact_ref`.
43
+
For inspection API to be enabled `Evm` needs to be create with inspector.
28
44
29
-
-`Database + DatabaseCommit`: Adds the ability to save transaction changes directly. Enables commit functions like `transact_commit`.
45
+
```rust,ignore
46
+
let mut evm = Context::mainnet().with_block(block).build_mainnet().with_inspector(inspector);
47
+
let _ = evm.inspect_with_tx(tx);
48
+
```
30
49
31
50
# EVM Framework
32
51
@@ -38,16 +57,12 @@ Each trait needed to build custom EVM has detailed documentation explaining how
38
57
39
58
In summary, REVM is built around several key traits that enable customizable EVM functionality. The core traits include:
40
59
41
-
***EvmTr**: The core EVM trait that provides access to the main EVM components:
42
-
- Context - Environment and state access
43
-
- Instructions - EVM opcode implementations
44
-
- Precompiles - Built-in contract implementations
45
-
- Inspector - Used for tracing, only enabled with `InspectorEvmTr` trait.
46
-
***ContextTr**: Accessed through EvmTr, defines the execution environment including Tx/Block/Journal/Db:
60
+
***EvmTr**: The core EVM trait that provides access to `Context`, `Instruction`, `Precompiles`:
61
+
***ContextTr**: Accessed through EvmTr, defines the execution environment including Tx/Block/Journal/Db.
47
62
***Handler**: Implements the core execution logic, taking an EvmTr implementation. The default implementation follows Ethereum consensus.
48
63
49
64
And traits that provide support for inspection and tracing:
50
65
51
-
***InspectorEvmTr**: Extends EvmTr to enable inspection mode execution with an associated Inspector type
52
-
***InspectorHandler**: Extends Handler with inspection-enabled execution paths that make Inspector callbacks
66
+
***InspectorEvmTr**: Extends EvmTr to enable inspection mode execution with an associated `Inspector` type
67
+
***InspectorHandler**: Extends Handler with inspection-enabled execution paths that make `Inspector` callbacks
53
68
***Inspector**: User-implementable trait for EVM inspection/tracing
Copy file name to clipboardexpand all lines: book/src/dev.md
+1-26
Original file line number
Diff line number
Diff line change
@@ -9,29 +9,4 @@ cargo build --release
9
9
10
10
**_Note:_** This project tends to use the newest rust version, so if you're encountering a build error try running rustup update first.
11
11
12
-
**_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`.
13
-
14
-
# External core dependencies
15
-
16
-
REVM relies on several key external dependencies to provide its core functionality:
17
-
18
-
* The `alloy-primitives` crate provides essential native types including:
19
-
-`ruint` U256 big number type
20
-
- Address, Bytes, and B256 types
21
-
-`hashbrown` implementations of HashMap/HashSet with custom hashing algorithms
22
-
* For broad compatibility, REVM is `no_std` compliant and uses the `alloc` crate for heap allocation needs.
23
-
* Precompile functionality requires several cryptography and math libraries:
24
-
-`c-kzg`: Implements Polynomial Commitments API for EIP-4844 (C implementation with Rust bindings)
25
-
-`modexp`: Handles big integer modular exponentiation
26
-
-`secp256k1`: Provides ECDSA public key recovery based on secp256k1 curves
27
-
-`k256`: Serves as a no_std compatible fallback for secp256k1
28
-
* Transaction environment AccessList and AuthorizationList come from:
29
-
-`alloy-eip7702`
30
-
-`alloy-eip2930`
31
-
* Optional serialization support through feature-flagged:
32
-
-`serde`
33
-
-`serde-json`
34
-
* Various utility crates enhance development:
35
-
-`auto_impl`
36
-
-`derive_more`
37
-
- Specialized libraries like `nnum` for specific use cases
12
+
**_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`.
0 commit comments