revme/cmd/bench/
snailtracer.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use database::BenchmarkDB;
use revm::{
    bytecode::Bytecode,
    handler::EthHandler,
    primitives::{address, bytes, hex, Bytes, TxKind},
    Context, MainEvm,
};

pub fn simple_example(bytecode: Bytecode) {
    let context = Context::builder()
        .with_db(BenchmarkDB::new_bytecode(bytecode.clone()))
        .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");
            tx.gas_limit = 1_000_000_000;
        });
    let mut evm = MainEvm::new(context, EthHandler::default());
    let _ = evm.transact().unwrap();
}

pub fn run() {
    println!("Running snailtracer example!");
    let bytecode = Bytecode::new_raw(Bytes::from(hex::decode(BYTES).unwrap()));
    let start = std::time::Instant::now();
    simple_example(bytecode);
    let elapsed = start.elapsed();
    println!("elapsed: {:?}", elapsed);
}

const BYTES: &str = include_str!("snailtracer.hex");