Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introducing EvmWiring, a chain-specific configuration #1672

Merged
merged 64 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
f8fcaa7
refactor: allow chain-specific configuration of Evm
Wodann May 1, 2024
6145d39
refactor: rename Transaction::transact_to and clarify docs
Wodann Jun 18, 2024
7b950c7
refactor: remove trait bounds on Transaction super trait
Wodann Jun 18, 2024
caaf05d
refactor: remove trait bounds from Block supertrait
Wodann Jun 18, 2024
72272c9
fix: clippy warnings
Wodann Jun 19, 2024
0723ff0
fix: cargo doc
Wodann Jun 19, 2024
f5ccf54
refactor: limit trait bounds on HaltReason
Wodann Jun 19, 2024
6a881fa
refactor: allow moving of kind
Wodann Jun 19, 2024
dab9e20
refactor: rename Transaction::nonce to nonce_opt to signal that it's …
Wodann Jun 19, 2024
214c1d5
refactor: replace AccessList with alloy version
Wodann Jun 19, 2024
7303587
refactor: rename gas_priority_fee to max_priority_fee_per_gas
Wodann Jun 20, 2024
a8227c0
refactor: correct trait bound on ExecutionResult::clone
Wodann Jun 20, 2024
fe1ab43
Clone
Wodann Jun 20, 2024
373e197
refactor: only allow optional nonce check via CfgEnv
Wodann Jun 20, 2024
689be7f
fix: revme
Wodann Jun 24, 2024
f53a2a9
refactor: derive DummyHost
Wodann Jun 24, 2024
dbe9e3a
refactor: derive Clone for ExecutionResult
Wodann Jun 24, 2024
77e19ce
refactor: remove EVMErrorForChain
Wodann Jun 24, 2024
6c16bef
refactor: derive Clone for CfgEnvWithChainSpec
Wodann Jun 24, 2024
145a4ce
refactor: use EVMResultGeneric
Wodann Jun 24, 2024
3f29a23
refactor: add convenience EVMErrorForChain type alias
Wodann Jun 24, 2024
3c6c4d3
feat: export OptimismBlock
Wodann Jul 8, 2024
4856bea
refactor: add handler constructor and Context to revm::ChainSpec
Wodann Jul 22, 2024
93089c3
refactor: generalise optimism implementation using traits
Wodann Jul 22, 2024
da8175a
fix: no-default-features
Wodann Jul 23, 2024
0f052b5
fix: CI
Wodann Jul 29, 2024
69e7304
chore: Add default fn to Tx/Block traits
rakita Jul 31, 2024
946d404
Chore: rename ChainSpec to EvmWiring
rakita Jul 31, 2024
57a3feb
chore: clippy comments fix
rakita Jul 31, 2024
b6e90b6
chore: rename EthEvmWiring to EthereumWiring
rakita Jul 31, 2024
69890ae
chore: re add serde, restring HaltReasonTrait
rakita Jul 31, 2024
9a6d2e6
chore: move custom opcode to examples
rakita Jul 31, 2024
da81d97
chore: remove op feature from test wiring
rakita Jul 31, 2024
1ad97fd
nit use Self::EvmWiringT
rakita Jul 31, 2024
6d479da
nit indents
rakita Jul 31, 2024
1bce037
feat(Wiring): Add Database and EXT to EvmWiring
rakita Aug 1, 2024
1c660da
some fixes
rakita Aug 1, 2024
ed99ce9
temp
rakita Aug 5, 2024
45c07c5
feat: make builder compile. EnvWiring and Result Halt
rakita Aug 5, 2024
d73f96c
chore: cleanup rename
rakita Aug 6, 2024
763ba26
nit
rakita Aug 6, 2024
b96b397
fix: make string conversion complete
Wodann Aug 28, 2024
62b45b7
Merge remote-tracking branch 'origin/main' into wiring
rakita Sep 2, 2024
65d4f26
fix compile
rakita Sep 2, 2024
83a0803
Merge remote-tracking branch 'wodann/refactor/opt-spec-id' into wiring
rakita Sep 2, 2024
917a753
compiles
rakita Sep 4, 2024
28ac623
Merge remote-tracking branch 'origin/main' into wiring
rakita Sep 4, 2024
897f8ed
wip builder
rakita Sep 4, 2024
6528d3b
wip
rakita Sep 4, 2024
321972c
Merge remote-tracking branch 'origin/main' into wiring
rakita Sep 5, 2024
0462c5b
fix compile
rakita Sep 5, 2024
c1c57ab
wip
rakita Sep 5, 2024
c4845c2
fix optimism test
rakita Sep 5, 2024
de4e89c
fix docs ci
rakita Sep 5, 2024
492c27a
cleanup
rakita Sep 6, 2024
f1faa47
cleanup
rakita Sep 6, 2024
f97ce47
use core::error::Error
rakita Sep 6, 2024
d64f624
cleanup
rakita Sep 6, 2024
4a7e6e3
use core error
rakita Sep 6, 2024
d51cc59
fix builer
rakita Sep 6, 2024
e7d78ca
fix docs
rakita Sep 6, 2024
763592a
final doc fix
rakita Sep 6, 2024
5fef8e2
rm alloy provider
rakita Sep 6, 2024
1383df7
Merge remote-tracking branch 'origin/main' into wiring
rakita Sep 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ jobs:
strategy:
fail-fast: false
matrix:
features: ["", "optimism,kzg-rs"]
features: ["", "kzg-rs"]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: riscv32imac-unknown-none-elf
- run: cargo check --target riscv32imac-unknown-none-elf --no-default-features --features=${{ matrix.features }}
- run: |
cargo check --target riscv32imac-unknown-none-elf --no-default-features --features=${{ matrix.features }}
cargo check --target riscv32imac-unknown-none-elf -p revm-optimism --no-default-features --features=${{ matrix.features }}

check:
name: check ${{ matrix.features }}
Expand Down
29 changes: 28 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"crates/primitives",
"crates/interpreter",
"crates/precompile",
"crates/optimism",
]
resolver = "2"
default-members = ["crates/revm"]
Expand Down
6 changes: 3 additions & 3 deletions bins/revm-test/src/bin/analysis.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use revm::{
db::BenchmarkDB,
db::{BenchmarkDB, EthereumBenchmarkWiring},
interpreter::analysis::to_analysed,
primitives::{address, bytes, Bytecode, Bytes, TxKind},
Evm,
Expand All @@ -13,7 +13,7 @@ fn main() {
let bytecode_analysed = to_analysed(Bytecode::new_raw(contract_data));

// BenchmarkDB is dummy state that implements Database trait.
let mut evm = Evm::builder()
let mut evm = Evm::<EthereumBenchmarkWiring>::builder()
.modify_tx_env(|tx| {
// execution globals block hash/gas_limit/coinbase/timestamp..
tx.caller = address!("1000000000000000000000000000000000000000");
Expand All @@ -37,7 +37,7 @@ fn main() {

let mut evm = evm
.modify()
.reset_handler_with_db(BenchmarkDB::new_bytecode(bytecode_analysed))
.with_db(BenchmarkDB::new_bytecode(bytecode_analysed))
.build();

let timer = Instant::now();
Expand Down
8 changes: 5 additions & 3 deletions bins/revm-test/src/bin/burntpix/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use regex::bytes::Regex;
use revm::{
db::{CacheDB, EmptyDB},
primitives::{
address, hex, keccak256, AccountInfo, Address, Bytecode, Bytes, ExecutionResult, Output,
TxKind, B256, U256,
address, hex, keccak256, AccountInfo, Address, Bytecode, Bytes, EthereumWiring,
ExecutionResult, Output, TxKind, B256, U256,
},
Evm,
};
Expand All @@ -28,14 +28,16 @@ sol! {
}
}

type EthereumCacheDbWiring = EthereumWiring<CacheDB<EmptyDB>, ()>;

fn main() {
let (seed, iterations) = try_init_env_vars().expect("Failed to parse env vars");

let run_call_data = IBURNTPIX::runCall { seed, iterations }.abi_encode();

let db = init_db();

let mut evm = Evm::builder()
let mut evm = Evm::<EthereumCacheDbWiring>::builder()
.modify_tx_env(|tx| {
tx.caller = address!("1000000000000000000000000000000000000000");
tx.transact_to = TxKind::Call(BURNTPIX_MAIN_ADDRESS);
Expand Down
4 changes: 2 additions & 2 deletions bins/revm-test/src/bin/snailtracer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use revm::{
db::BenchmarkDB,
db::{BenchmarkDB, EthereumBenchmarkWiring},
interpreter::analysis::to_analysed,
primitives::{address, bytes, Bytecode, Bytes, TxKind},
Evm,
Expand All @@ -9,7 +9,7 @@ pub fn simple_example() {
let bytecode = to_analysed(Bytecode::new_raw(CONTRACT_DATA.clone()));

// BenchmarkDB is dummy state that implements Database trait.
let mut evm = Evm::builder()
let mut evm = Evm::<EthereumBenchmarkWiring>::builder()
.with_db(BenchmarkDB::new_bytecode(bytecode.clone()))
.modify_tx_env(|tx| {
// execution globals block hash/gas_limit/coinbase/timestamp..
Expand Down
5 changes: 2 additions & 3 deletions bins/revm-test/src/bin/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use revm::{
db::BenchmarkDB,
db::{BenchmarkDB, EthereumBenchmarkWiring},
primitives::{Bytecode, TxKind, U256},
Evm,
};

use std::time::Duration;

fn main() {
// BenchmarkDB is dummy state that implements Database trait.
let mut evm = Evm::builder()
let mut evm = Evm::<EthereumBenchmarkWiring>::builder()
.with_db(BenchmarkDB::new_bytecode(Bytecode::new()))
.modify_tx_env(|tx| {
// execution globals block hash/gas_limit/coinbase/timestamp..
Expand Down
26 changes: 14 additions & 12 deletions bins/revme/src/cmd/evmrunner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use revm::{
db::BenchmarkDB,
inspector_handle_register,
inspectors::TracerEip3155,
primitives::{Address, Bytecode, BytecodeDecodeError, TxKind},
Evm,
primitives::{address, Address, Bytecode, BytecodeDecodeError, EthereumWiring, TxKind},
Database, Evm,
};
use std::io::Error as IoError;
use std::path::PathBuf;
Expand Down Expand Up @@ -57,6 +57,8 @@ pub struct Cmd {
impl Cmd {
/// Run evm runner command.
pub fn run(&self) -> Result<(), Errors> {
const CALLER: Address = address!("0000000000000000000000000000000000000001");

let bytecode_str: Cow<'_, str> = if let Some(path) = &self.path {
// check if path exists.
if !path.exists() {
Expand All @@ -71,19 +73,21 @@ impl Cmd {
let input = hex::decode(self.input.trim())
.map_err(|_| Errors::InvalidInput)?
.into();

let mut db = BenchmarkDB::new_bytecode(Bytecode::new_raw_checked(bytecode.into())?);

let nonce = db.basic(CALLER).unwrap().map_or(0, |account| account.nonce);

// BenchmarkDB is dummy state that implements Database trait.
// the bytecode is deployed at zero address.
let mut evm = Evm::builder()
.with_db(BenchmarkDB::new_bytecode(Bytecode::new_raw_checked(
bytecode.into(),
)?))
let mut evm = Evm::<EthereumWiring<BenchmarkDB, TracerEip3155>>::builder()
.with_db(db)
.modify_tx_env(|tx| {
// execution globals block hash/gas_limit/coinbase/timestamp..
tx.caller = "0x0000000000000000000000000000000000000001"
.parse()
.unwrap();
tx.caller = CALLER;
tx.transact_to = TxKind::Call(Address::ZERO);
tx.data = input;
tx.nonce = nonce;
})
.build();

Expand All @@ -101,9 +105,7 @@ impl Cmd {
let out = if self.trace {
let mut evm = evm
.modify()
.reset_handler_with_external_context(TracerEip3155::new(
Box::new(std::io::stdout()),
))
.with_external_context(TracerEip3155::new(Box::new(std::io::stdout())))
.append_handler_register(inspector_handle_register)
.build();

Expand Down
51 changes: 28 additions & 23 deletions bins/revme/src/cmd/statetest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ use super::{
};
use indicatif::{ProgressBar, ProgressDrawTarget};
use revm::{
db::EmptyDB,
db::{EmptyDB, State},
inspector_handle_register,
inspectors::TracerEip3155,
interpreter::analysis::to_analysed,
primitives::{
calc_excess_blob_gas, keccak256, Bytecode, Bytes, EVMResultGeneric, Env, ExecutionResult,
SpecId, TxKind, B256,
calc_excess_blob_gas, keccak256, Bytecode, Bytes, EVMResultGeneric, EnvWiring,
EthereumWiring, ExecutionResult, HaltReason, SpecId, TxKind, B256,
},
Evm, State,
Evm,
};
use serde_json::json;
use std::{
convert::Infallible,
fmt::Debug,
io::{stderr, stdout},
path::{Path, PathBuf},
sync::{
Expand All @@ -29,6 +29,9 @@ use std::{
use thiserror::Error;
use walkdir::{DirEntry, WalkDir};

type ExecEvmWiring<'a> = EthereumWiring<&'a mut State<EmptyDB>, ()>;
type TraceEvmWiring<'a> = EthereumWiring<&'a mut State<EmptyDB>, TracerEip3155>;

#[derive(Debug, Error)]
#[error("Test {name} failed: {kind}")]
pub struct TestError {
Expand Down Expand Up @@ -135,12 +138,15 @@ fn skip_test(path: &Path) -> bool {
)
}

fn check_evm_execution<EXT>(
fn check_evm_execution<EXT: Debug>(
test: &Test,
expected_output: Option<&Bytes>,
test_name: &str,
exec_result: &EVMResultGeneric<ExecutionResult, Infallible>,
evm: &Evm<'_, EXT, &mut State<EmptyDB>>,
exec_result: &EVMResultGeneric<
ExecutionResult<HaltReason>,
EthereumWiring<&mut State<EmptyDB>, EXT>,
>,
evm: &Evm<'_, EthereumWiring<&mut State<EmptyDB>, EXT>>,
print_json_outcome: bool,
) -> Result<(), TestError> {
let logs_root = log_rlp_hash(exec_result.as_ref().map(|r| r.logs()).unwrap_or_default());
Expand All @@ -164,7 +170,7 @@ fn check_evm_execution<EXT>(
Err(e) => e.to_string(),
},
"postLogsHash": logs_root,
"fork": evm.handler.cfg().spec_id,
"fork": evm.handler.spec_id(),
"test": test_name,
"d": test.indexes.data,
"g": test.indexes.gas,
Expand Down Expand Up @@ -277,7 +283,7 @@ pub fn execute_test_suite(
cache_state.insert_account_with_storage(address, acc_info, info.storage);
}

let mut env = Box::<Env>::default();
let mut env = Box::<EnvWiring<ExecEvmWiring>>::default();
// for mainnet
env.cfg.chain_id = 1;
// env.cfg.spec_id is set down the road
Expand Down Expand Up @@ -355,6 +361,8 @@ pub fn execute_test_suite(
.get(test.indexes.data)
.unwrap()
.clone();

env.tx.nonce = u64::try_from(unit.transaction.nonce).unwrap();
env.tx.value = unit.transaction.value[test.indexes.value];

env.tx.access_list = unit
Expand All @@ -376,16 +384,14 @@ pub fn execute_test_suite(
env.tx.transact_to = to;

let mut cache = cache_state.clone();
cache.set_state_clear_flag(SpecId::enabled(
spec_id,
revm::primitives::SpecId::SPURIOUS_DRAGON,
));
cache.set_state_clear_flag(SpecId::enabled(spec_id, SpecId::SPURIOUS_DRAGON));
let mut state = revm::db::State::builder()
.with_cached_prestate(cache)
.with_bundle_update()
.build();
let mut evm = Evm::builder()
let mut evm = Evm::<ExecEvmWiring>::builder()
.with_db(&mut state)
.with_default_ext_ctx()
.modify_env(|e| e.clone_from(&env))
.with_spec_id(spec_id)
.build();
Expand All @@ -394,7 +400,8 @@ pub fn execute_test_suite(
let (e, exec_result) = if trace {
let mut evm = evm
.modify()
.reset_handler_with_external_context(
.reset_handler_with_external_context::<EthereumWiring<_, TracerEip3155>>()
.with_external_context(
TracerEip3155::new(Box::new(stderr())).without_summary(),
)
.append_handler_register(inspector_handle_register)
Expand Down Expand Up @@ -445,21 +452,19 @@ pub fn execute_test_suite(

// re build to run with tracing
let mut cache = cache_state.clone();
cache.set_state_clear_flag(SpecId::enabled(
spec_id,
revm::primitives::SpecId::SPURIOUS_DRAGON,
));
let state = revm::db::State::builder()
cache.set_state_clear_flag(SpecId::enabled(spec_id, SpecId::SPURIOUS_DRAGON));
let mut state = revm::db::State::builder()
.with_cached_prestate(cache)
.with_bundle_update()
.build();

let path = path.display();
println!("\nTraces:");
let mut evm = Evm::builder()
let mut evm = Evm::<TraceEvmWiring>::builder()
.with_db(&mut state)
.with_spec_id(spec_id)
.with_db(state)
.with_env(env.clone())
.reset_handler_with_external_context::<EthereumWiring<_, TracerEip3155>>()
.with_external_context(TracerEip3155::new(Box::new(stdout())).without_summary())
.append_handler_register(inspector_handle_register)
.build();
Expand Down
11 changes: 1 addition & 10 deletions crates/interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ all = "warn"
[dependencies]
revm-primitives = { path = "../primitives", version = "9.0.1", default-features = false }

derive-where = { version = "1.2.7", default-features = false }
paste = { version = "1.0", optional = true }
phf = { version = "0.11", default-features = false, optional = true, features = [
"macros",
Expand All @@ -50,16 +51,6 @@ asm-keccak = ["revm-primitives/asm-keccak"]
portable = ["revm-primitives/portable"]
parse = ["dep:paste", "dep:phf"]

optimism = ["revm-primitives/optimism"]
# Optimism default handler enabled Optimism handler register by default in EvmBuilder.
optimism-default-handler = [
"optimism",
"revm-primitives/optimism-default-handler",
]
negate-optimism-default-handler = [
"revm-primitives/negate-optimism-default-handler",
]

dev = [
"memory_limit",
"optional_balance_check",
Expand Down
Loading
Loading