Skip to content

Commit

Permalink
remvme bench, builder for context
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita committed Nov 28, 2024
1 parent a4fa635 commit f38aae6
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 108 deletions.
25 changes: 13 additions & 12 deletions bins/revme/src/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// pub mod bench;
pub mod bench;
pub mod bytecode;
// pub mod eofvalidation;
// pub mod evmrunner;
pub mod eofvalidation;
//pub mod evmrunner;
pub mod statetest;

use clap::Parser;
Expand All @@ -12,14 +12,14 @@ use clap::Parser;
pub enum MainCmd {
/// Execute Ethereum state tests.
Statetest(statetest::Cmd),
// /// Execute eof validation tests.
// EofValidation(eofvalidation::Cmd),
/// Execute eof validation tests.
EofValidation(eofvalidation::Cmd),
// /// Run arbitrary EVM bytecode.
// Evm(evmrunner::Cmd),
/// Print the structure of an EVM bytecode.
Bytecode(bytecode::Cmd),
// /// Run bench from specified list.
// Bench(bench::Cmd),
/// Run bench from specified list.
Bench(bench::Cmd),
}

#[derive(Debug, thiserror::Error)]
Expand All @@ -41,15 +41,16 @@ impl MainCmd {
pub fn run(&self) -> Result<(), Error> {
match self {
Self::Statetest(cmd) => cmd.run().map_err(Into::into),
// Self::EofValidation(cmd) => cmd.run().map_err(Into::into),
Self::EofValidation(cmd) => cmd.run().map_err(Into::into),
// Self::Evm(cmd) => cmd.run().map_err(Into::into),
Self::Bytecode(cmd) => {
cmd.run();
Ok(())
} // Self::Bench(cmd) => {
// cmd.run();
// Ok(())
// }
}
Self::Bench(cmd) => {
cmd.run();
Ok(())
}
}
}
}
23 changes: 10 additions & 13 deletions bins/revme/src/cmd/bench/analysis.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use database::{BenchmarkDB, EthereumBenchmarkWiring};
use database::BenchmarkDB;
use revm::{
bytecode::Bytecode,
handler::EthHandler,
primitives::{address, bytes, hex, Bytes, TxKind},
Evm,
Context, MainEvm,
};
use std::time::Instant;

Expand All @@ -13,17 +14,16 @@ pub fn run() {
let bytecode_analysed = Bytecode::new_raw(contract_data).into_analyzed();

// BenchmarkDB is dummy state that implements Database trait.
let mut evm = Evm::<EthereumBenchmarkWiring>::builder()
.modify_tx_env(|tx| {
let context = Context::default()
.with_db(BenchmarkDB::new_bytecode(bytecode_raw))
.modify_tx_chained(|tx| {
// execution globals block hash/gas_limit/coinbase/timestamp..
tx.caller = address!("1000000000000000000000000000000000000000");
tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000"));
//evm.env.tx.data = Bytes::from(hex::decode("30627b7c").unwrap());
tx.data = bytes!("8035F0CE");
})
.with_db(BenchmarkDB::new_bytecode(bytecode_raw))
.with_default_ext_ctx()
.build();
});
let mut evm = MainEvm::new(context, EthHandler::default());

// Just to warm up the processor.
for _ in 0..10000 {
Expand All @@ -36,11 +36,8 @@ pub fn run() {
}
println!("Raw elapsed time: {:?}", timer.elapsed());

let mut evm = evm
.modify()
.with_db(BenchmarkDB::new_bytecode(bytecode_analysed))
.with_default_ext_ctx()
.build();
evm.context
.modify_db(|db| *db = BenchmarkDB::new_bytecode(bytecode_analysed));

let timer = Instant::now();
for _ in 0..30000 {
Expand Down
25 changes: 9 additions & 16 deletions bins/revme/src/cmd/bench/burntpix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ use alloy_sol_macro::sol;
use alloy_sol_types::SolCall;
use database::CacheDB;
use revm::{
context_interface::result::{ExecutionResult, Output},
database_interface::EmptyDB,
handler::EthHandler,
primitives::{address, hex, keccak256, Address, Bytes, TxKind, B256, U256},
state::{AccountInfo, Bytecode},
context_interface::{
result::{ExecutionResult, Output},
EthereumWiring,
},
Evm,
Context, MainEvm,
};

use std::fs::File;
Expand All @@ -32,24 +30,19 @@ sol! {
}
}

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

pub fn run() {
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::<EthereumCacheDbWiring>::builder()
.modify_tx_env(|tx| {
tx.caller = address!("1000000000000000000000000000000000000000");
tx.transact_to = TxKind::Call(BURNTPIX_MAIN_ADDRESS);
tx.data = run_call_data.clone().into();
})
.with_db(db)
.with_default_ext_ctx()
.build();
let context = Context::default().with_db(db).modify_tx_chained(|tx| {
tx.caller = address!("1000000000000000000000000000000000000000");
tx.transact_to = TxKind::Call(BURNTPIX_MAIN_ADDRESS);
tx.data = run_call_data.clone().into();
});
let mut evm = MainEvm::new(context, EthHandler::default());

let started = Instant::now();
let tx_result = evm.transact().unwrap().result;
Expand Down
15 changes: 7 additions & 8 deletions bins/revme/src/cmd/bench/snailtracer.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
use database::{BenchmarkDB, EthereumBenchmarkWiring};
use database::BenchmarkDB;
use revm::{
bytecode::Bytecode,
handler::EthHandler,
primitives::{address, bytes, Bytes, TxKind},
Evm,
Context, MainEvm,
};

pub fn simple_example() {
let bytecode = Bytecode::new_raw(CONTRACT_DATA.clone()).into_analyzed();

// BenchmarkDB is dummy state that implements Database trait.
let mut evm = Evm::<EthereumBenchmarkWiring>::builder()
let context = Context::default()
.with_db(BenchmarkDB::new_bytecode(bytecode.clone()))
.with_default_ext_ctx()
.modify_tx_env(|tx| {
.modify_tx_chained(|tx| {
// execution globals block hash/gas_limit/coinbase/timestamp..
tx.caller = address!("1000000000000000000000000000000000000000");
tx.transact_to = TxKind::Call(address!("0000000000000000000000000000000000000000"));
tx.data = bytes!("30627b7c");
})
.build();
});
let mut evm = MainEvm::new(context, EthHandler::default());

let _ = evm.transact().unwrap();
}
Expand Down
15 changes: 7 additions & 8 deletions bins/revme/src/cmd/bench/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use database::{BenchmarkDB, EthereumBenchmarkWiring};
use database::BenchmarkDB;
use revm::{
bytecode::Bytecode,
handler::EthHandler,
primitives::{TxKind, U256},
Evm,
Context, MainEvm,
};
use std::time::Duration;

pub fn run() {
// BenchmarkDB is dummy state that implements Database trait.
let mut evm = Evm::<EthereumBenchmarkWiring>::builder()
let context = Context::default()
.with_db(BenchmarkDB::new_bytecode(Bytecode::new()))
.with_default_ext_ctx()
.modify_tx_env(|tx| {
.modify_tx_chained(|tx| {
// execution globals block hash/gas_limit/coinbase/timestamp..
tx.caller = "0x0000000000000000000000000000000000000001"
.parse()
Expand All @@ -22,8 +21,8 @@ pub fn run() {
.parse()
.unwrap(),
);
})
.build();
});
let mut evm = MainEvm::new(context, EthHandler::default());

// Microbenchmark
let bench_options = microbench::Options::default().time(Duration::from_secs(3));
Expand Down
3 changes: 1 addition & 2 deletions bins/revme/src/cmd/evmrunner.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use clap::Parser;
use database::BenchmarkDB;
use inspector::{inspector_handle_register, inspectors::TracerEip3155};
use inspector::{inspectors::TracerEip3155, InspectorMainEvm};
use revm::{
bytecode::{Bytecode, BytecodeDecodeError},
primitives::{address, hex, Address, TxKind},
context_interface::EthereumWiring,
Database, Evm,
};
use std::io::Error as IoError;
Expand Down
47 changes: 12 additions & 35 deletions bins/revme/src/cmd/statetest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,43 +408,24 @@ pub fn execute_test_suite(
.with_bundle_update()
.build();
let mut evm = MainEvm {
context: Context {
block: block.clone(),
tx: tx.clone(),
cfg: cfg.clone(),
journaled_state: JournaledState::new(
cfg.spec().into(),
&mut state,
Default::default(),
),
chain: (),
error: Ok(()),
},
handler: EthHandler::new(
EthValidation::new(),
EthPreExecution::new(),
EthExecution::new(),
EthPostExecution::new(),
),
context: Context::default()
.with_block(block.clone())
.with_tx(tx.clone())
.with_cfg(cfg.clone())
.with_db(&mut state),
handler: EthHandler::default(),
_error: core::marker::PhantomData,
};

// do the deed
let (e, exec_result) = if trace {
let mut evm = InspectorMainEvm {
context: InspectorContext {
inner: Context {
block: block.clone(),
tx: tx.clone(),
cfg: cfg.clone(),
journaled_state: JournaledState::new(
cfg.spec().into(),
&mut state,
Default::default(),
),
chain: (),
error: Ok(()),
},
inner: Context::default()
.with_block(block.clone())
.with_tx(tx.clone())
.with_cfg(cfg.clone())
.with_db(&mut state),
inspector: TracerEip3155::new(Box::new(stdout())),
frame_input_stack: Vec::new(),
},
Expand Down Expand Up @@ -542,11 +523,7 @@ pub fn execute_test_suite(
block: block.clone(),
tx: tx.clone(),
cfg: cfg.clone(),
journaled_state: JournaledState::new(
cfg.spec().into(),
&mut state,
Default::default(),
),
journaled_state: JournaledState::new(cfg.spec().into(), &mut state),
chain: (),
error: Ok(()),
},
Expand Down
Loading

0 comments on commit f38aae6

Please sign in to comment.