Skip to content

Commit

Permalink
Feat #319: callprinter better output format (#341)
Browse files Browse the repository at this point in the history
* Add tree

* Handle stepping with return

* add [layer -> CALL]

* transfer, borrow

* liquidation

* tune abi_call

* EVMU256::unwrap_or_default()

* handle U256

* colored call

* colored function

* fine-tune colors

* colorize solution

* fine-tune the color of call

* remove

* colored address

* fn args

* colored address

* pretty return data

* pretty value

* fine-tune sender

* Add warning log when there is unknown VmCalls

* remove <- ()

* stepping with return

* fine-tune indent

* fine-tune liquidation

* fine-tune borrow

* abi.encodeWithSelector

* prettify trace tree

* add layer

* add layer

* fine-tune tree
  • Loading branch information
iamjacobjia authored Nov 12, 2023
1 parent 80c2adb commit 93f943e
Show file tree
Hide file tree
Showing 9 changed files with 365 additions and 110 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@ alloy-primitives = "0.4.1"
# logging
tracing = "0.1"
tracing-subscriber = "0.3"
colored = "2.0"
39 changes: 36 additions & 3 deletions src/evm/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ use revm_primitives::U256;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use tracing::debug;

use super::types::checksum;
use super::{
types::checksum,
utils::{colored_address, prettify_value},
};
/// Definition of ABI types and their encoding, decoding, mutating methods
use crate::evm::abi::ABILossyType::{TArray, TDynamic, TEmpty, TUnknown, T256};
use crate::{
Expand Down Expand Up @@ -140,6 +143,11 @@ pub trait ABI: CloneABI {
fn get_concolic(&self) -> Vec<Box<Expr>>;
/// Get the size of args
fn get_size(&self) -> usize;

/// Convert args to colored string
fn to_colored_string(&self) -> String {
self.to_string()
}
}

impl Default for Box<dyn ABI> {
Expand Down Expand Up @@ -283,6 +291,14 @@ impl BoxedABI {
pub fn set_bytes(&mut self, bytes: Vec<u8>) -> bool {
self.b.set_bytes(bytes[4..].to_vec())
}

pub fn to_colored_string(&self) -> String {
if self.function == [0; 4] {
self.to_string()
} else {
format!("{}{}", self.get_func_name(), self.b.to_colored_string())
}
}
}

/// Randomly sample an args with any type with size `size`
Expand Down Expand Up @@ -613,7 +629,10 @@ impl ABI for A256 {
A256InnerType::Int => I256::from_hex_str(&vec_to_hex(&self.data))
.unwrap_or_default()
.to_string(),
A256InnerType::Uint => U256::try_from_be_slice(&self.data).unwrap_or_default().to_string(),
A256InnerType::Uint => {
let value = U256::try_from_be_slice(&self.data).unwrap_or_default();
prettify_value(value)
}
A256InnerType::Bool => {
if self.data == [0] {
"false".to_string()
Expand All @@ -632,6 +651,13 @@ impl ABI for A256 {
}
}

fn to_colored_string(&self) -> String {
match self.inner_type {
A256InnerType::Address => colored_address(&self.to_string()),
_ => self.to_string(),
}
}

fn get_concolic(&self) -> Vec<Box<Expr>> {
let mut bytes = vec![Expr::const_byte(0u8); 32];
let data_len = self.data.len();
Expand Down Expand Up @@ -848,7 +874,14 @@ impl ABI for AArray {
}

fn to_string(&self) -> String {
format!("({})", self.data.iter().map(|x| x.b.deref().to_string()).join(","))
format!("({})", self.data.iter().map(|x| x.b.deref().to_string()).join(", "))
}

fn to_colored_string(&self) -> String {
format!(
"({})",
self.data.iter().map(|x| x.b.deref().to_colored_string()).join(", ")
)
}

fn as_any(&mut self) -> &mut dyn Any {
Expand Down
Loading

0 comments on commit 93f943e

Please sign in to comment.