Skip to content

Commit

Permalink
Fix swap reverted but state after swap committed (#413)
Browse files Browse the repository at this point in the history
* fix swap reverted but committed

* fix libafl
  • Loading branch information
shouc authored Dec 25, 2023
1 parent a5032dc commit fc8236d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/evm/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub struct EVMInput {
pub repeat: usize,

/// Swap data
#[serde(skip_deserializing)]
pub swap_data: HashMap<String, SwapInfo>,
}

Expand Down Expand Up @@ -193,6 +194,7 @@ pub struct ConciseEVMInput {
pub return_data: Option<Vec<u8>>,

/// Swap data
#[serde(skip_deserializing)]
pub swap_data: HashMap<String, SwapInfo>,
}

Expand Down
13 changes: 8 additions & 5 deletions src/evm/oracles/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,16 @@ impl

let (_out, mut state) = ctx.call_post_batch_dyn(&liquidation_txs);

let is_reverted = _out.iter().any(|(_, is_success)| *is_success == false);

// Record the swap info for generating foundry in the future.
state.swap_data = ctx.fuzz_state.get_execution_result().new_state.state.swap_data.clone();
for (target, mut abi, _) in swap_infos {
state.swap_data.push(&target, &mut abi);
if !is_reverted {
state.swap_data = ctx.fuzz_state.get_execution_result().new_state.state.swap_data.clone();
for (target, mut abi, _) in swap_infos {
state.swap_data.push(&target, &mut abi);
}
ctx.fuzz_state.get_execution_result_mut().new_state.state = state;
}

ctx.fuzz_state.get_execution_result_mut().new_state.state = state;
}

let exec_res = ctx.fuzz_state.get_execution_result_mut();
Expand Down

0 comments on commit fc8236d

Please sign in to comment.