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

feat: inspect transaction inspection module #221

Merged
merged 17 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ keywords = ["ethereum", "web3", "decompiler", "evm", "crypto"]
clap = { version = "3.1.18", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
bincode = "1.3.3"
serde_json = "1.0.108"
20 changes: 12 additions & 8 deletions cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,9 @@ where
None => return None,
};

let binary_vec = decode_hex(&binary_string);
let binary_vec = decode_hex(&binary_string).ok()?;

if binary_vec.is_err() {
return None;
}

let cache: Cache<T> = match bincode::deserialize::<Cache<T>>(&binary_vec.unwrap()) {
let cache: Cache<T> = match bincode::deserialize::<Cache<T>>(&binary_vec) {
Ok(c) => {
// check if the cache has expired, if so, delete it and return None
if c.expiry <
Expand Down Expand Up @@ -233,7 +229,11 @@ where
/// store_cache("store_cache_key2", "value", Some(60 * 60 * 24));
/// ```
#[allow(deprecated)]
pub fn store_cache<T>(key: &str, value: T, expiry: Option<u64>)
pub fn store_cache<T>(
key: &str,
value: T,
expiry: Option<u64>,
) -> Result<(), Box<dyn std::error::Error>>
where
T: Serialize, {
let home = home_dir().unwrap();
Expand All @@ -247,9 +247,12 @@ where
);

let cache = Cache { value, expiry };
let encoded: Vec<u8> = bincode::serialize(&cache).unwrap();
let encoded: Vec<u8> = bincode::serialize(&cache)
.map_err(|e| format!("Failed to serialize cache object: {:?}", e))?;
let binary_string = encode_hex(encoded);
write_file(cache_file.to_str().unwrap(), &binary_string);

Ok(())
}

/// Cache subcommand handler
Expand Down Expand Up @@ -289,6 +292,7 @@ pub fn cache(args: CacheArgs) -> Result<(), Box<dyn std::error::Error>> {
}

#[allow(deprecated)]
#[allow(unused_must_use)]
#[cfg(test)]
mod tests {
use crate::{delete_cache, exists, keys, read_cache, store_cache};
Expand Down
22 changes: 22 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use heimdall_core::{
decompile::{decompile, out::abi::ABIStructure, DecompilerArgs},
disassemble::{disassemble, DisassemblerArgs},
dump::{dump, DumpArgs},
inspect::{inspect, InspectArgs},
snapshot::{snapshot, util::csv::generate_csv, SnapshotArgs},
};
use tui::{backend::CrosstermBackend, Terminal};
Expand Down Expand Up @@ -65,6 +66,13 @@ pub enum Subcommands {

#[clap(name = "dump", about = "Dump the value of all storage slots accessed by a contract")]
Dump(DumpArgs),

#[clap(
name = "inspect",
about = "Detailed inspection of Ethereum transactions, including calldata & trace decoding, log visualization, and more"
)]
Inspect(InspectArgs),

#[clap(
name = "snapshot",
about = "Infer functiogn information from bytecode, including access control, gas
Expand Down Expand Up @@ -330,6 +338,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}

Subcommands::Inspect(mut cmd) => {
// if the user has not specified a rpc url, use the default
if cmd.rpc_url.as_str() == "" {
cmd.rpc_url = configuration.rpc_url;
}

// if the user has not specified a transpose api key, use the default
if cmd.transpose_api_key.is_none() {
cmd.transpose_api_key = Some(configuration.transpose_api_key);
}

inspect(cmd).await?;
}

Subcommands::Config(cmd) => {
config(cmd);
}
Expand Down
Loading
Loading