Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 2 additions & 7 deletions bins/revme/src/cmd/bench/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@ pub fn run(criterion: &mut Criterion) {
let mut evm = context.build_mainnet();
criterion.bench_function("analysis", |b| {
b.iter_batched(
|| {
// create a transaction input
tx.clone()
},
|input| {
let _ = evm.transact_one(input);
},
|| tx.clone(),
|input| evm.transact_one(input).unwrap(),
criterion::BatchSize::SmallInput,
);
});
Expand Down
9 changes: 2 additions & 7 deletions bins/revme/src/cmd/bench/burntpix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,8 @@ pub fn run(criterion: &mut Criterion) {

criterion.bench_function("burntpix", |b| {
b.iter_batched(
|| {
// create a transaction input
tx.clone()
},
|input| {
evm.transact_one(input).unwrap();
},
|| tx.clone(),
|input| evm.transact_one(input).unwrap(),
criterion::BatchSize::SmallInput,
);
});
Expand Down
4 changes: 1 addition & 3 deletions bins/revme/src/cmd/bench/evm_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use revm::{Context, MainBuilder, MainContext};

pub fn run(criterion: &mut Criterion) {
criterion.bench_function("evm-build", |b| {
b.iter(|| {
let _ = Context::mainnet().build_mainnet();
});
b.iter(|| Context::mainnet().build_mainnet());
});
}
9 changes: 2 additions & 7 deletions bins/revme/src/cmd/bench/gas_cost_estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,8 @@ pub fn run(criterion: &mut Criterion) {

criterion.bench_function(name, |b| {
b.iter_batched(
|| {
// create a transaction input
tx.clone()
},
|input| {
let _ = evm.transact_one(input).unwrap();
},
|| tx.clone(),
|input| evm.transact_one(input).unwrap(),
criterion::BatchSize::SmallInput,
);
});
Expand Down
18 changes: 4 additions & 14 deletions bins/revme/src/cmd/bench/snailtracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,16 @@ pub fn run(criterion: &mut Criterion) {

criterion.bench_function("snailtracer", |b| {
b.iter_batched(
|| {
// create a transaction input
tx.clone()
},
|input| {
let _ = evm.transact_one(input).unwrap();
},
|| tx.clone(),
|input| evm.transact_one(input).unwrap(),
criterion::BatchSize::SmallInput,
);
});

criterion.bench_function("analysis-inspector", |b| {
b.iter_batched(
|| {
// create a transaction input
tx.clone()
},
|input| {
let _ = evm.inspect_one_tx(input);
},
|| tx.clone(),
|input| evm.inspect_one_tx(input),
criterion::BatchSize::SmallInput,
);
});
Expand Down
13 changes: 3 additions & 10 deletions bins/revme/src/cmd/bench/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ pub fn run(criterion: &mut Criterion) {
let mut i = 0;
criterion.bench_function("transfer", |b| {
b.iter_batched(
|| {
// create a transfer input
tx.clone()
},
|| tx.clone(),
|input| {
i += 1;
evm.transact_one(input).unwrap();
evm.transact_one(input).unwrap()
},
criterion::BatchSize::SmallInput,
);
Expand All @@ -57,9 +54,5 @@ pub fn run(criterion: &mut Criterion) {

evm.modify_cfg(|cfg| cfg.disable_nonce_check = false);

criterion.bench_function("transfer_finalize", |b| {
b.iter(|| {
let _ = evm.replay().unwrap();
})
});
criterion.bench_function("transfer_finalize", |b| b.iter(|| evm.replay().unwrap()));
}
10 changes: 2 additions & 8 deletions bins/revme/src/cmd/bench/transfer_multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ pub fn run(criterion: &mut Criterion) {

criterion.bench_function("transact_commit_1000txs", |b| {
b.iter_batched(
|| {
// create transaction inputs
txs.clone()
},
|| txs.clone(),
|inputs| {
for tx in inputs {
let _ = evm.transact_commit(tx).unwrap();
Expand All @@ -66,10 +63,7 @@ pub fn run(criterion: &mut Criterion) {

criterion.bench_function("transact_1000tx_commit_inner_every_40", |b| {
b.iter_batched(
|| {
// create transaction inputs
txs.clone()
},
|| txs.clone(),
|inputs| {
for (i, tx) in inputs.into_iter().enumerate() {
let _ = evm.transact_one(tx).unwrap();
Expand Down
24 changes: 12 additions & 12 deletions bins/revme/src/cmd/evmrunner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,29 @@ impl Cmd {
.without_plots();
let mut criterion_group = criterion.benchmark_group("revme");
criterion_group.bench_function("evm", |b| {
b.iter(|| {
let _ = evm.transact(tx.clone()).unwrap();
})
b.iter_batched(
|| tx.clone(),
|input| evm.transact(input).unwrap(),
criterion::BatchSize::SmallInput,
);
});
criterion_group.finish();

return Ok(());
}

let time = Instant::now();
let state = if self.trace {
evm.inspect_tx(tx.clone())
.map_err(|_| Errors::EVMError)?
.state
let r = if self.trace {
evm.inspect_tx(tx)
} else {
let out = evm.transact(tx.clone()).map_err(|_| Errors::EVMError)?;
println!("Result: {:#?}", out.result);
out.state
};
evm.transact(tx)
}
.map_err(|_| Errors::EVMError)?;
let time = time.elapsed();

println!("Result: {:#?}", r.result);
if self.state {
println!("State: {state:#?}");
println!("State: {:#?}", r.state);
}

println!("Elapsed: {time:?}");
Expand Down
31 changes: 13 additions & 18 deletions bins/revme/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
use clap::Parser;
use revme::cmd::{Error, MainCmd};
use revme::cmd::MainCmd;
use std::process::ExitCode;

fn main() -> Result<(), Error> {
set_thread_panic_hook();
MainCmd::parse().run().inspect_err(|e| println!("{e:?}"))
}
fn main() -> ExitCode {
if std::env::var_os("RUST_BACKTRACE").is_none() {
unsafe { std::env::set_var("RUST_BACKTRACE", "1") };
}

/// Sets thread panic hook, useful for having tests that panic.
fn set_thread_panic_hook() {
use std::{
backtrace::Backtrace,
panic::{set_hook, take_hook},
process::exit,
};
let orig_hook = take_hook();
set_hook(Box::new(move |panic_info| {
println!("Custom backtrace: {}", Backtrace::capture());
orig_hook(panic_info);
exit(1);
}));
match MainCmd::parse().run() {
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
eprintln!("error:\n- {e}\n- {e:#?}");
ExitCode::FAILURE
}
}
}
20 changes: 9 additions & 11 deletions crates/bytecode/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use crate::{opcode, Bytecode, OpCode};
/// without dealing with the immediate values that follow instructions.
#[derive(Debug, Clone)]
pub struct BytecodeIterator<'a> {
/// Start pointer of the bytecode. Only used to calculate [`position`](Self::position).
start: *const u8,
/// Iterator over the bytecode bytes.
bytes: core::slice::Iter<'a, u8>,
/// Start pointer of the bytecode. Only used to calculate [`position`](Self::position).
start: *const u8,
}

impl<'a> BytecodeIterator<'a> {
Expand All @@ -21,8 +21,8 @@ impl<'a> BytecodeIterator<'a> {
Bytecode::Eip7702(_) => &[],
};
Self {
start: bytes.as_ptr(),
bytes: bytes.iter(),
start: bytes.as_ptr(),
}
}

Expand All @@ -40,15 +40,13 @@ impl<'a> BytecodeIterator<'a> {
/// Returns the current position in the bytecode.
#[inline]
pub fn position(&self) -> usize {
(self.bytes.as_slice().as_ptr() as usize) - (self.start as usize)
// TODO: Use the following on 1.87
// SAFETY: `start` always points to the start of the bytecode.
// unsafe {
// self.bytes
// .as_slice()
// .as_ptr()
// .offset_from_unsigned(self.start)
// }
unsafe {
self.bytes
.as_slice()
.as_ptr()
.offset_from_unsigned(self.start)
}
}

#[inline]
Expand Down
6 changes: 4 additions & 2 deletions crates/handler/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ where
Self::new(instruction_table::<WIRE, HOST>())
}

/// Rerurns new `EthInstructions` with custom instruction table.
/// Returns a new instance of `EthInstructions` with custom instruction table.
#[inline]
pub fn new(base_table: InstructionTable<WIRE, HOST>) -> Self {
Self {
instruction_table: Box::new(base_table),
}
}

/// Inserts a new instruction into the instruction table.s
/// Inserts a new instruction into the instruction table.
#[inline]
pub fn insert_instruction(&mut self, opcode: u8, instruction: Instruction<WIRE, HOST>) {
self.instruction_table[opcode as usize] = instruction;
}
Expand Down
Loading