Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ABI Dump #400

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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