Skip to content

Commit 9dff3b0

Browse files
committed
all integrated
1 parent 2f3f98f commit 9dff3b0

File tree

48 files changed

+1636
-865
lines changed

Some content is hidden

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

48 files changed

+1636
-865
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.

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:#?}");

crates/context/interface/src/host.rs

Lines changed: 106 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,87 @@
11
mod dummy;
22

33
pub use crate::journaled_state::StateLoad;
4+
use database_interface::Database;
45
pub use dummy::DummyHost;
56

6-
use crate::{journaled_state::AccountLoad, BlockGetter, CfgGetter, TransactionGetter};
7-
use auto_impl::auto_impl;
8-
use primitives::{Address, Bytes, Log, B256, U256};
7+
use crate::{
8+
journaled_state::AccountLoad, Block, BlockGetter, CfgGetter, Journal, JournalGetter,
9+
TransactionGetter,
10+
};
11+
use primitives::{Address, Bytes, Log, B256, BLOCK_HASH_HISTORY, U256};
12+
use std::boxed::Box;
913

1014
/// EVM context host.
11-
#[auto_impl(&mut, Box)]
12-
pub trait Host: TransactionGetter + BlockGetter + CfgGetter {
13-
/// Load an account code.
14-
fn load_account_delegated(&mut self, address: Address) -> Option<StateLoad<AccountLoad>>;
15+
pub trait Host: JournalGetter + TransactionGetter + BlockGetter + CfgGetter {
16+
fn set_error(
17+
&mut self,
18+
error: <<<Self as JournalGetter>::Journal as Journal>::Database as Database>::Error,
19+
);
1520

1621
/// Gets the block hash of the given block `number`.
17-
fn block_hash(&mut self, number: u64) -> Option<B256>;
22+
fn block_hash(&mut self, requested_number: u64) -> Option<B256> {
23+
let block_number = self.block().number();
24+
25+
let Some(diff) = block_number.checked_sub(requested_number) else {
26+
return Some(B256::ZERO);
27+
};
28+
29+
// blockhash should push zero if number is same as current block number.
30+
if diff == 0 {
31+
return Some(B256::ZERO);
32+
}
33+
34+
if diff <= BLOCK_HASH_HISTORY {
35+
return self
36+
.journal()
37+
.db()
38+
.block_hash(requested_number)
39+
.map_err(|e| self.set_error(e))
40+
.ok();
41+
}
42+
43+
Some(B256::ZERO)
44+
}
45+
46+
fn load_account_delegated(&mut self, address: Address) -> Option<StateLoad<AccountLoad>> {
47+
self.journal()
48+
.load_account_delegated(address)
49+
.map_err(|e| self.set_error(e))
50+
.ok()
51+
}
1852

1953
/// Gets balance of `address` and if the account is cold.
20-
fn balance(&mut self, address: Address) -> Option<StateLoad<U256>>;
54+
fn balance(&mut self, address: Address) -> Option<StateLoad<U256>> {
55+
self.journal()
56+
.load_account(address)
57+
.map(|acc| acc.map(|a| a.info.balance))
58+
.map_err(|e| self.set_error(e))
59+
.ok()
60+
}
2161

2262
/// Gets code of `address` and if the account is cold.
23-
fn code(&mut self, address: Address) -> Option<StateLoad<Bytes>>;
63+
fn code(&mut self, address: Address) -> Option<StateLoad<Bytes>> {
64+
self.journal()
65+
.code(address)
66+
.map_err(|e| self.set_error(e))
67+
.ok()
68+
}
2469

2570
/// Gets code hash of `address` and if the account is cold.
26-
fn code_hash(&mut self, address: Address) -> Option<StateLoad<B256>>;
71+
fn code_hash(&mut self, address: Address) -> Option<StateLoad<B256>> {
72+
self.journal()
73+
.code_hash(address)
74+
.map_err(|e| self.set_error(e))
75+
.ok()
76+
}
2777

2878
/// Gets storage value of `address` at `index` and if the account is cold.
29-
fn sload(&mut self, address: Address, index: U256) -> Option<StateLoad<U256>>;
79+
fn sload(&mut self, address: Address, index: U256) -> Option<StateLoad<U256>> {
80+
self.journal()
81+
.sload(address, index)
82+
.map_err(|e| self.set_error(e))
83+
.ok()
84+
}
3085

3186
/// Sets storage value of account address at index.
3287
///
@@ -36,23 +91,57 @@ pub trait Host: TransactionGetter + BlockGetter + CfgGetter {
3691
address: Address,
3792
index: U256,
3893
value: U256,
39-
) -> Option<StateLoad<SStoreResult>>;
94+
) -> Option<StateLoad<SStoreResult>> {
95+
self.journal()
96+
.sstore(address, index, value)
97+
.map_err(|e| self.set_error(e))
98+
.ok()
99+
}
40100

41101
/// Gets the transient storage value of `address` at `index`.
42-
fn tload(&mut self, address: Address, index: U256) -> U256;
102+
fn tload(&mut self, address: Address, index: U256) -> U256 {
103+
self.journal().tload(address, index)
104+
}
43105

44106
/// Sets the transient storage value of `address` at `index`.
45-
fn tstore(&mut self, address: Address, index: U256, value: U256);
107+
fn tstore(&mut self, address: Address, index: U256, value: U256) {
108+
self.journal().tstore(address, index, value)
109+
}
46110

47111
/// Emits a log owned by `address` with given `LogData`.
48-
fn log(&mut self, log: Log);
112+
fn log(&mut self, log: Log) {
113+
self.journal().log(log);
114+
}
49115

50116
/// Marks `address` to be deleted, with funds transferred to `target`.
51117
fn selfdestruct(
52118
&mut self,
53119
address: Address,
54120
target: Address,
55-
) -> Option<StateLoad<SelfDestructResult>>;
121+
) -> Option<StateLoad<SelfDestructResult>> {
122+
self.journal()
123+
.selfdestruct(address, target)
124+
.map_err(|e| self.set_error(e))
125+
.ok()
126+
}
127+
}
128+
129+
impl<T: Host> Host for &mut T {
130+
fn set_error(
131+
&mut self,
132+
error: <<<Self as JournalGetter>::Journal as Journal>::Database as Database>::Error,
133+
) {
134+
(**self).set_error(error)
135+
}
136+
}
137+
138+
impl<T: Host> Host for Box<T> {
139+
fn set_error(
140+
&mut self,
141+
error: <<<Self as JournalGetter>::Journal as Journal>::Database as Database>::Error,
142+
) {
143+
(**self).set_error(error)
144+
}
56145
}
57146

58147
/// Represents the result of an `sstore` operation.

0 commit comments

Comments
 (0)