Skip to content

Commit 78e8a1f

Browse files
authored
feat: Context execution (#2013)
* feat: Context execute * all integrated * clippy * derive more no_std * add correct caller/target address * no std * remove std from derive_more * init first bench * init precompiles * rm comments
1 parent c3b6023 commit 78e8a1f

File tree

58 files changed

+1791
-1076
lines changed

Some content is hidden

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

58 files changed

+1791
-1076
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ handler-interface = { path = "crates/handler/interface", package = "revm-handler
6060
cfg-if = { version = "1.0", default-features = false }
6161
auto_impl = { version = "1.2.0" }
6262
derive-where = { version = "1.2.7", default-features = false }
63+
derive_more = { version = "1.0.0", default-features = false }
6364
criterion = { package = "codspeed-criterion-compat", version = "2.7" }
6465

6566
[workspace.package]

bins/revme/benches/evm.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use revme::cmd::{
55
};
66

77
fn evm(c: &mut Criterion) {
8+
// call analysis to init static data.
9+
revme::cmd::bench::analysis::run();
10+
811
for &bench_name in BenchName::ALL {
912
let cmd = MainCmd::Bench(bench::Cmd { name: bench_name });
1013
c.bench_function(bench_name.as_str(), |b| {
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
use database::BenchmarkDB;
1+
use std::time::Instant;
2+
3+
use database::{BenchmarkDB, BENCH_CALLER, BENCH_TARGET};
24
use revm::{
35
bytecode::Bytecode,
4-
primitives::{address, bytes, hex, Bytes, TxKind},
5-
transact_main, Context,
6+
primitives::{bytes, hex, Bytes, TxKind},
7+
Context, ExecuteEvm,
68
};
79

810
const BYTES: &str = include_str!("analysis.hex");
@@ -15,10 +17,17 @@ pub fn run() {
1517
.with_db(BenchmarkDB::new_bytecode(bytecode))
1618
.modify_tx_chained(|tx| {
1719
// Execution globals block hash/gas_limit/coinbase/timestamp..
18-
tx.caller = address!("1000000000000000000000000000000000000000");
19-
tx.kind = TxKind::Call(address!("0000000000000000000000000000000000000000"));
20+
tx.caller = BENCH_CALLER;
21+
tx.kind = TxKind::Call(BENCH_TARGET);
2022
//evm.env.tx.data = Bytes::from(hex::decode("30627b7c").unwrap());
2123
tx.data = bytes!("8035F0CE");
2224
});
23-
let _ = transact_main(&mut context);
25+
26+
let time = Instant::now();
27+
let _ = context.exec_previous();
28+
println!("First init: {:?}", time.elapsed());
29+
30+
let time = Instant::now();
31+
let _ = context.exec_previous();
32+
println!("Run: {:?}", time.elapsed());
2433
}

bins/revme/src/cmd/bench/burntpix.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use static_data::{
88

99
use alloy_sol_macro::sol;
1010
use alloy_sol_types::SolCall;
11-
use database::CacheDB;
11+
use database::{CacheDB, BENCH_CALLER};
1212
use revm::{
1313
context_interface::result::{ExecutionResult, Output},
1414
database_interface::EmptyDB,
15-
primitives::{address, hex, keccak256, Address, Bytes, TxKind, B256, U256},
15+
primitives::{hex, keccak256, Address, Bytes, TxKind, B256, U256},
1616
state::{AccountInfo, Bytecode},
1717
transact_main, Context,
1818
};
@@ -37,7 +37,7 @@ pub fn run() {
3737
let db = init_db();
3838

3939
let mut context = Context::builder().with_db(db).modify_tx_chained(|tx| {
40-
tx.caller = address!("1000000000000000000000000000000000000000");
40+
tx.caller = BENCH_CALLER;
4141
tx.kind = TxKind::Call(BURNTPIX_MAIN_ADDRESS);
4242
tx.data = run_call_data.clone().into();
4343
tx.gas_limit = u64::MAX;

bins/revme/src/cmd/bench/snailtracer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use database::BenchmarkDB;
1+
use database::{BenchmarkDB, BENCH_CALLER, BENCH_TARGET};
22
use revm::{
33
bytecode::Bytecode,
4-
primitives::{address, bytes, hex, Bytes, TxKind},
4+
primitives::{bytes, hex, Bytes, TxKind},
55
transact_main, Context,
66
};
77

@@ -10,8 +10,8 @@ pub fn simple_example(bytecode: Bytecode) {
1010
.with_db(BenchmarkDB::new_bytecode(bytecode.clone()))
1111
.modify_tx_chained(|tx| {
1212
// Execution globals block hash/gas_limit/coinbase/timestamp..
13-
tx.caller = address!("1000000000000000000000000000000000000000");
14-
tx.kind = TxKind::Call(address!("0000000000000000000000000000000000000000"));
13+
tx.caller = BENCH_CALLER;
14+
tx.kind = TxKind::Call(BENCH_TARGET);
1515
tx.data = bytes!("30627b7c");
1616
tx.gas_limit = 1_000_000_000;
1717
});
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
use database::BenchmarkDB;
1+
use std::time::Instant;
2+
3+
use database::{BenchmarkDB, BENCH_CALLER, BENCH_TARGET};
24
use revm::{
35
bytecode::Bytecode,
46
primitives::{TxKind, U256},
5-
transact_main, Context,
7+
Context, ExecuteEvm,
68
};
79

810
pub fn run() {
911
let mut context = Context::builder()
1012
.with_db(BenchmarkDB::new_bytecode(Bytecode::new()))
1113
.modify_tx_chained(|tx| {
1214
// Execution globals block hash/gas_limit/coinbase/timestamp..
13-
tx.caller = "0x0000000000000000000000000000000000000001"
14-
.parse()
15-
.unwrap();
15+
tx.caller = BENCH_CALLER;
16+
tx.kind = TxKind::Call(BENCH_TARGET);
1617
tx.value = U256::from(10);
17-
tx.kind = TxKind::Call(
18-
"0x0000000000000000000000000000000000000000"
19-
.parse()
20-
.unwrap(),
21-
);
2218
});
23-
let _ = transact_main(&mut context);
19+
let time = Instant::now();
20+
let _ = context.exec_previous();
21+
println!("First init: {:?}", time.elapsed());
22+
23+
let time = Instant::now();
24+
let _ = context.exec_previous();
25+
println!("Run: {:?}", time.elapsed());
2426
}

bins/revme/src/cmd/evmrunner.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use clap::Parser;
22
use database::BenchmarkDB;
3-
use inspector::{inspect_main, inspector_context::InspectorContext, inspectors::TracerEip3155};
3+
use inspector::{exec::InspectEvm, inspectors::TracerEip3155};
44
use revm::{
55
bytecode::{Bytecode, BytecodeDecodeError},
66
primitives::{address, hex, Address, TxKind},
7-
transact_main, Context, Database,
7+
transact_main, Context, Database, ExecuteEvm,
88
};
99
use std::io::Error as IoError;
1010
use std::path::PathBuf;
@@ -94,18 +94,16 @@ impl Cmd {
9494
let bench_options = microbench::Options::default().time(Duration::from_secs(3));
9595

9696
microbench::bench(&bench_options, "Run bytecode", || {
97-
let _ = transact_main(&mut ctx).unwrap();
97+
let _ = ctx.exec_previous().unwrap();
9898
});
9999

100100
return Ok(());
101101
}
102102

103103
let out = if self.trace {
104-
inspect_main(&mut InspectorContext::new(
105-
&mut ctx,
106-
TracerEip3155::new(Box::new(std::io::stdout())),
107-
))
108-
.map_err(|_| Errors::EVMError)?
104+
let inspector = TracerEip3155::new(Box::new(std::io::stdout()));
105+
ctx.inspect_previous(inspector)
106+
.map_err(|_| Errors::EVMError)?
109107
} else {
110108
let out = transact_main(&mut ctx).map_err(|_| Errors::EVMError)?;
111109
println!("Result: {:#?}", out.result);

bins/revme/src/cmd/statetest/runner.rs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use super::{
44
};
55
use database::State;
66
use indicatif::{ProgressBar, ProgressDrawTarget};
7-
use inspector::{
8-
inspect_main_commit, inspector_context::InspectorContext, inspectors::TracerEip3155,
9-
};
7+
use inspector::{exec::InspectCommitEvm, inspectors::TracerEip3155};
108
use revm::{
119
bytecode::Bytecode,
1210
context::{block::BlockEnv, cfg::CfgEnv, tx::TxEnv},
@@ -18,7 +16,7 @@ use revm::{
1816
database_interface::EmptyDB,
1917
primitives::{keccak256, Bytes, TxKind, B256},
2018
specification::{eip4844::TARGET_BLOB_GAS_PER_BLOCK_CANCUN, hardfork::SpecId},
21-
transact_main_commit, Context,
19+
Context, ExecuteCommitEvm,
2220
};
2321
use serde_json::json;
2422
use statetest_types::{SpecName, Test, TestSuite};
@@ -421,21 +419,20 @@ pub fn execute_test_suite(
421419

422420
// Do the deed
423421
let (e, exec_result) = if trace {
424-
let mut ctx = &mut InspectorContext::new(
425-
Context::builder()
426-
.with_block(&block)
427-
.with_tx(&tx)
428-
.with_cfg(&cfg)
429-
.with_db(&mut state),
430-
TracerEip3155::new(Box::new(stderr())).without_summary(),
431-
);
422+
let mut ctx = Context::builder()
423+
.with_block(&block)
424+
.with_tx(&tx)
425+
.with_cfg(&cfg)
426+
.with_db(&mut state);
432427

433428
let timer = Instant::now();
434-
let res = inspect_main_commit(&mut ctx);
429+
let res = ctx.inspect_commit_previous(
430+
TracerEip3155::new(Box::new(stderr())).without_summary(),
431+
);
435432
*elapsed.lock().unwrap() += timer.elapsed();
436433

437434
let spec = cfg.spec();
438-
let db = &mut ctx.inner.journaled_state.database;
435+
let db = &mut ctx.journaled_state.database;
439436
// Dump state and traces if test failed
440437
let output = check_evm_execution(
441438
&test,
@@ -452,7 +449,7 @@ pub fn execute_test_suite(
452449
(e, res)
453450
} else {
454451
let timer = Instant::now();
455-
let res = transact_main_commit(&mut ctx);
452+
let res = ctx.exec_commit_previous();
456453
*elapsed.lock().unwrap() += timer.elapsed();
457454

458455
let spec = cfg.spec();
@@ -494,24 +491,20 @@ pub fn execute_test_suite(
494491

495492
println!("\nTraces:");
496493

497-
let mut ctx = InspectorContext::new(
498-
Context::builder()
499-
.with_db(&mut state)
500-
.with_block(&block)
501-
.with_tx(&tx)
502-
.with_cfg(&cfg),
494+
let mut ctx = Context::builder()
495+
.with_db(&mut state)
496+
.with_block(&block)
497+
.with_tx(&tx)
498+
.with_cfg(&cfg);
499+
500+
let _ = ctx.inspect_commit_previous(
503501
TracerEip3155::new(Box::new(stderr())).without_summary(),
504502
);
505503

506-
let _ = inspect_main_commit(&mut ctx);
507-
508504
println!("\nExecution result: {exec_result:#?}");
509505
println!("\nExpected exception: {:?}", test.expect_exception);
510506
println!("\nState before: {cache_state:#?}");
511-
println!(
512-
"\nState after: {:#?}",
513-
ctx.inner.journaled_state.database.cache
514-
);
507+
println!("\nState after: {:#?}", ctx.journaled_state.database.cache);
515508
println!("\nSpecification: {:?}", cfg.spec);
516509
println!("\nTx: {tx:#?}");
517510
println!("Block: {block:#?}");

0 commit comments

Comments
 (0)