Skip to content

Commit

Permalink
Support ABI Dump (#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
shouc authored Dec 5, 2023
1 parent ac365e5 commit 57515a2
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion src/evm/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,55 @@ pub struct ConciseEVMInput {
pub return_data: Option<Vec<u8>>,
}

/// EVM Input Minimum for Deserializing with human readable ABI
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct ConciseEVMInputReadable {
/// Input type
pub input_type: EVMInputTy,

/// Caller address
pub caller: EVMAddress,

/// Contract address
pub contract: EVMAddress,

/// Input data in ABI format
#[cfg(not(feature = "debug"))]
pub data: Option<BoxedABI>,
#[cfg(not(feature = "debug"))]
pub data_readable: Option<String>,

#[cfg(feature = "debug")]
pub direct_data: String,

/// Transaction value in wei
pub txn_value: Option<EVMU256>,

/// Whether to resume execution from the last control leak
pub step: bool,

/// Environment (block, timestamp, etc.)
pub env: Env,

/// Percentage of the token amount in all callers' account to liquidate
pub liquidation_percent: u8,

/// Additional random bytes for mutator
pub randomness: Vec<u8>,

/// Execute the transaction multiple times
pub repeat: usize,

/// How many post execution steps to take
pub layer: usize,

/// When to control leak, after `call_leak` number of calls
pub call_leak: u32,

/// return data
pub return_data: Option<Vec<u8>>,
}

impl ConciseEVMInput {
pub fn from_input<I, Out>(
input: &I,
Expand Down Expand Up @@ -280,6 +329,29 @@ impl ConciseEVMInput {
)
}

pub fn to_readable(&self) -> ConciseEVMInputReadable {
ConciseEVMInputReadable {
input_type: self.input_type.clone(),
caller: self.caller,
contract: self.contract,
#[cfg(not(feature = "debug"))]
data: self.data.clone(),
#[cfg(not(feature = "debug"))]
data_readable: self.data.clone().map(|d| format!("{}", d)),
#[cfg(feature = "debug")]
direct_data: self.direct_data.clone(),
txn_value: self.txn_value,
step: self.step,
env: self.env.clone(),
liquidation_percent: self.liquidation_percent,
randomness: self.randomness.clone(),
repeat: self.repeat,
layer: self.layer,
call_leak: self.call_leak,
return_data: self.return_data.clone(),
}
}

// Variable `liq` is used when `debug` feature is disabled
#[allow(unused_variables)]
fn pretty_txn(&self) -> Option<String> {
Expand Down Expand Up @@ -770,7 +842,7 @@ impl EVMInput {

impl ConciseSerde for ConciseEVMInput {
fn serialize_concise(&self) -> Vec<u8> {
serde_json::to_vec(self).expect("Failed to deserialize concise input")
serde_json::to_vec(&self.to_readable()).expect("Failed to deserialize concise input")
}

fn deserialize_concise(data: &[u8]) -> Self {
Expand Down

0 comments on commit 57515a2

Please sign in to comment.