Skip to content

Commit

Permalink
Optimization: Remove Less-performant Mutators (#447)
Browse files Browse the repository at this point in the history
* remove dbg

* optimizations

* fmt

* ooops
  • Loading branch information
shouc authored Apr 1, 2024
1 parent c769558 commit 714594e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 37 deletions.
4 changes: 3 additions & 1 deletion src/evm/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub enum EVMInputTy {
Liquidate,
}

const CALL_VALUE_MAX_BYTES: usize = 21; // 309M ether

/// EVM Input Trait
pub trait EVMInputT {
/// Set the contract and ABI
Expand Down Expand Up @@ -854,7 +856,7 @@ impl EVMInput {
return res;
}
// make set first 16 bytes to 0
(0..16).for_each(|i| {
(0..CALL_VALUE_MAX_BYTES).for_each(|i| {
input_vec[i] = 0;
});
input.set_txn_value(EVMU256::try_from_be_slice(input_vec.as_slice()).unwrap());
Expand Down
3 changes: 2 additions & 1 deletion src/evm/middlewares/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,10 @@ where
SourceCodeResult::SourceCode(source_code) => {
self.pc_info.insert((address, *pc), source_code.clone());
}
_ => {
SourceCodeResult::SourceCodeNoPcMatch(_) => {
skip_pcs.insert(*pc);
}
_ => {}
},
);

Expand Down
15 changes: 7 additions & 8 deletions src/evm/tokens/uniswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ pub fn fetch_uniswap_path(onchain: &mut OnChainConfig, token_address: EVMAddress

macro_rules! gen_v3_pair_context {
($pair: expr) => {{
println!("pair: {:?}", $pair);
let pair_address = EVMAddress::from_str($pair.pair.as_str()).expect("failed to parse pair");
let fee = onchain.get_v3_fee(pair_address);
let inner = _gen_v2_pair_context!($pair);
Expand Down Expand Up @@ -137,10 +136,10 @@ pub fn fetch_uniswap_path(onchain: &mut OnChainConfig, token_address: EVMAddress
});
for pair in &path_parsed.route {
if let super::PairContextTy::UniswapV3(inner) = pair {
println!(
"registering code for v3 pair: {:?}",
inner.borrow().inner.uniswap_info.router.unwrap()
);
// println!(
// "registering code for v3 pair: {:?}",
// inner.borrow().inner.uniswap_info.router.unwrap()
// );
register_code!(inner.borrow().inner.uniswap_info.router.unwrap());
}
}
Expand Down Expand Up @@ -235,8 +234,8 @@ fn get_pair(onchain: &mut OnChainConfig, token: &str, network: &str, is_pegged:
weth,
);

println!("original pairs: {:?}", pairs,);
println!("token: {:?}", token,);
// println!("original pairs: {:?}", pairs,);
// println!("token: {:?}", token,);

for pair in &mut pairs {
add_reserve_info(onchain, pair);
Expand All @@ -250,7 +249,7 @@ fn get_pair(onchain: &mut OnChainConfig, token: &str, network: &str, is_pegged:
if pairs.len() > 3 {
pairs = pairs[0..3].to_vec();
}
println!("pairs: {:?}", pairs);
// println!("pairs: {:?}", pairs);
pairs
}

Expand Down
29 changes: 2 additions & 27 deletions src/mutation_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,9 @@ where
{
let mutations = tuple_list!(
BitFlipMutator::new(),
ByteFlipMutator::new(),
ByteIncMutator::new(),
ByteDecMutator::new(),
ByteNegMutator::new(),
ByteRandMutator::new(),
ByteAddMutator::new(),
WordAddMutator::new(),
DwordAddMutator::new(),
QwordAddMutator::new(),
ByteInterestingMutator::new(),
WordInterestingMutator::new(),
DwordInterestingMutator::new(),
BytesSetMutator::new(),
BytesRandSetMutator::new(),
BytesSwapMutator::new(),
ConstantHintedMutator::new(),
);

Expand All @@ -210,30 +198,17 @@ pub fn byte_mutator_with_expansion<I, S>(
vm_slots: Option<HashMap<EVMU256, EVMU256>>,
) -> MutationResult
where
S: State + HasRand + HasMaxSize,
S: State + HasRand + HasMaxSize + HasMetadata,
I: HasBytesVec + Input,
{
let mutations = tuple_list!(
BitFlipMutator::new(),
ByteFlipMutator::new(),
ByteIncMutator::new(),
ByteDecMutator::new(),
ByteNegMutator::new(),
ByteRandMutator::new(),
ByteAddMutator::new(),
WordAddMutator::new(),
DwordAddMutator::new(),
QwordAddMutator::new(),
ByteInterestingMutator::new(),
WordInterestingMutator::new(),
DwordInterestingMutator::new(),
BytesExpandMutator::new(),
BytesInsertMutator::new(),
BytesRandInsertMutator::new(),
BytesSetMutator::new(),
BytesRandSetMutator::new(),
BytesCopyMutator::new(),
BytesSwapMutator::new(),
ConstantHintedMutator::new(),
);

if let Some(vm_slots) = vm_slots {
Expand Down

0 comments on commit 714594e

Please sign in to comment.