Skip to content

Commit

Permalink
Feat: spport tload, tstore, and mcopy (#468)
Browse files Browse the repository at this point in the history
* support-tload-tstore-mcopy

* temporarily enable onchain-test on feat-tload-tstore-mcopy

* revert ci/rust.yml
  • Loading branch information
jacob-chia authored Apr 18, 2024
1 parent 64af36d commit 1393626
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ typetag = "0.2.13"
lazy_static = "1.4.0"
num_cpus = "1.0"

revm = { git = "https://github.com/fuzzland/revm", rev = "33b46b9", features = [
revm = { git = "https://github.com/fuzzland/revm", rev = "1dead51", features = [
"no_gas_measuring",
"serde",
"memory_limit",
] }
revm-primitives = { git = "https://github.com/fuzzland/revm", rev = "33b46b9", features = [
revm-primitives = { git = "https://github.com/fuzzland/revm", rev = "1dead51", features = [
"no_gas_measuring",
"serde",
"memory_limit",
] }
revm-interpreter = { git = "https://github.com/fuzzland/revm", rev = "33b46b9", features = [
revm-interpreter = { git = "https://github.com/fuzzland/revm", rev = "1dead51", features = [
"no_gas_measuring",
"serde",
"memory_limit",
Expand Down
19 changes: 19 additions & 0 deletions src/evm/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use revm_primitives::{
BerlinSpec,
Bytecode,
ByzantiumSpec,
CancunSpec,
Env,
FrontierSpec,
HomesteadSpec,
Expand Down Expand Up @@ -164,6 +165,8 @@ where
SC: Scheduler<State = EVMFuzzState> + Clone,
{
pub evmstate: EVMState,
/// [EIP-1153[(https://eips.ethereum.org/EIPS/eip-1153) transient storage that is discarded after every transactions
pub transient_storage: HashMap<(EVMAddress, EVMU256), EVMU256>,
// these are internal to the host
pub env: Env,
pub code: HashMap<EVMAddress, Arc<BytecodeLocked>>,
Expand Down Expand Up @@ -270,6 +273,7 @@ where
fn clone(&self) -> Self {
Self {
evmstate: self.evmstate.clone(),
transient_storage: self.transient_storage.clone(),
env: self.env.clone(),
code: self.code.clone(),
hash_to_address: self.hash_to_address.clone(),
Expand Down Expand Up @@ -331,6 +335,7 @@ where
pub fn new(scheduler: SC, workdir: String) -> Self {
Self {
evmstate: EVMState::new(),
transient_storage: HashMap::new(),
env: Env::default(),
code: HashMap::new(),
hash_to_address: HashMap::new(),
Expand Down Expand Up @@ -400,6 +405,7 @@ where
SpecId::LONDON => interp.run_inspect::<EVMFuzzState, FuzzHost<SC>, LondonSpec>(self, state),
SpecId::MERGE => interp.run_inspect::<EVMFuzzState, FuzzHost<SC>, MergeSpec>(self, state),
SpecId::SHANGHAI => interp.run_inspect::<EVMFuzzState, FuzzHost<SC>, ShanghaiSpec>(self, state),
SpecId::CANCUN => interp.run_inspect::<EVMFuzzState, FuzzHost<SC>, CancunSpec>(self, state),
_ => interp.run_inspect::<EVMFuzzState, FuzzHost<SC>, LatestSpec>(self, state),
}
}
Expand Down Expand Up @@ -1269,6 +1275,19 @@ where
Some((EVMU256::from(0), EVMU256::from(0), EVMU256::from(0), true))
}

fn tload(&mut self, address: EVMAddress, index: EVMU256) -> EVMU256 {
if let Some(slot) = self.transient_storage.get(&(address, index)) {
*slot
} else {
self.transient_storage.insert((address, index), self.next_slot);
self.next_slot
}
}

fn tstore(&mut self, address: EVMAddress, index: EVMU256, value: EVMU256) {
self.transient_storage.insert((address, index), value);
}

fn log(&mut self, _address: EVMAddress, _topics: Vec<B256>, _data: Bytes) {
// flag check
if _topics.len() == 1 {
Expand Down
3 changes: 3 additions & 0 deletions src/evm/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ macro_rules! init_host {
$host.jumpi_trace = 37;
$host.current_typed_bug = vec![];
$host.randomness = vec![9];
$host.transient_storage = HashMap::new();
// Uncomment the next line if middleware is needed.
// $host.add_middlewares(middleware.clone());
};
Expand Down Expand Up @@ -556,6 +557,7 @@ where
self.host.jumpi_trace = 37;
self.host.current_self_destructs = vec![];
self.host.current_arbitrary_calls = vec![];
self.host.transient_storage = HashMap::new();
// Initially, there is no state change
unsafe {
STATE_CHANGE = false;
Expand Down Expand Up @@ -1058,6 +1060,7 @@ where
unsafe {
IS_FAST_CALL_STATIC = true;
self.host.evmstate = vm_state.as_any().downcast_ref_unchecked::<EVMState>().clone();
self.host.transient_storage = HashMap::new();
self.host.current_self_destructs = vec![];
self.host.current_arbitrary_calls = vec![];
self.host.call_count = 0;
Expand Down

0 comments on commit 1393626

Please sign in to comment.