Skip to content

Commit

Permalink
chore(sym-exec): convert tuple to JumpFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-Becker committed Dec 26, 2023
1 parent 769a33f commit 7b8f539
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
15 changes: 15 additions & 0 deletions common/src/ether/evm/ext/exec/jump_frame.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use ethers::types::U256;

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct JumpFrame {
pub pc: u128,
pub jumpdest: U256,
pub stack_depth: usize,
pub jump_taken: bool,
}

impl JumpFrame {
pub fn new(pc: u128, jumpdest: U256, stack_depth: usize, jump_taken: bool) -> Self {
Self { pc, jumpdest, stack_depth, jump_taken }
}
}
27 changes: 13 additions & 14 deletions common/src/ether/evm/ext/exec/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
mod jump_frame;
mod util;

use self::util::{
jump_condition_appears_recursive, jump_condition_contains_mutated_memory_access,
jump_condition_contains_mutated_storage_access,
jump_condition_historical_diffs_approximately_equal, stack_contains_too_many_of_the_same_item,
stack_diff, stack_item_source_depth_too_deep,
use self::{
jump_frame::JumpFrame,
util::{
jump_condition_appears_recursive, jump_condition_contains_mutated_memory_access,
jump_condition_contains_mutated_storage_access,
jump_condition_historical_diffs_approximately_equal,
stack_contains_too_many_of_the_same_item, stack_diff, stack_item_source_depth_too_deep,
},
};
use crate::{
debug_max,
Expand All @@ -14,7 +18,6 @@ use crate::{
},
utils::{io::logging::Logger, strings::decode_hex},
};
use ethers::types::U256;
use std::collections::HashMap;

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -66,7 +69,7 @@ impl VM {
fn recursive_map(
&mut self,
branch_count: &mut u32,
handled_jumps: &mut HashMap<(u128, U256, usize, bool), Vec<Stack>>,
handled_jumps: &mut HashMap<JumpFrame, Vec<Stack>>,
logger: &Logger,
) -> VMTrace {
let mut vm = self.clone();
Expand Down Expand Up @@ -96,16 +99,12 @@ impl VM {
state.last_instruction.instruction
);

// jump frame contains:
// 1. the instruction (PC) of the JUMPI
// 2. the jump destination
// 3. the stack size at the time of the JUMPI
// 4. whether the jump condition is zero
let jump_frame: (u128, U256, usize, bool) = (
// build hashable jump frame
let jump_frame = JumpFrame::new(
state.last_instruction.instruction,
state.last_instruction.inputs[0],
vm.stack.size(),
state.last_instruction.inputs[1].is_zero(),
!state.last_instruction.inputs[1].is_zero(),
);

// if the stack has over 16 items of the same source, it's probably a loop
Expand Down
6 changes: 1 addition & 5 deletions common/src/utils/range_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ impl RangeMap {
}

fn affected_ranges(&self, range: Range<usize>) -> Vec<Range<usize>> {
self.0
.keys()
.filter(|incumbent| Self::range_collides(&range, *incumbent))
.cloned()
.collect()
self.0.keys().filter(|incumbent| Self::range_collides(&range, incumbent)).cloned().collect()
}

fn range_collides(incoming: &Range<usize>, incumbent: &Range<usize>) -> bool {
Expand Down

0 comments on commit 7b8f539

Please sign in to comment.