Skip to content

Commit

Permalink
fix(decode): respect skip_resolving in inspect and decompile mo…
Browse files Browse the repository at this point in the history
…dules (#527)
  • Loading branch information
Jon-Becker authored Dec 7, 2024
1 parent 555f7a2 commit 2c6f2d6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
9 changes: 7 additions & 2 deletions crates/decompile/src/core/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub(crate) struct AnalyzerState {
pub conditional_stack: Vec<String>,
/// Tracks which analyzer type we are using
pub analyzer_type: AnalyzerType,
/// Whether to skip resolving internal calls
pub skip_resolving: bool,
}

/// The analyzer, which will analyze a [`VMTrace`] generated by symbolic execution and build an
Expand All @@ -66,6 +68,8 @@ pub(crate) struct AnalyzerState {
pub struct Analyzer {
/// The type of analyzer to use
typ: AnalyzerType,
/// Whether to skip resolving internal calls
skip_resolving: bool,
/// The function to build during analysis
function: AnalyzedFunction,
/// A list of registered heuristics with the Heuristic Trait
Expand All @@ -74,8 +78,8 @@ pub struct Analyzer {

impl Analyzer {
/// Build a new analyzer with the given type, function, and trace
pub fn new(typ: AnalyzerType, function: AnalyzedFunction) -> Self {
Self { typ, function, heuristics: Vec::new() }
pub fn new(typ: AnalyzerType, skip_resolving: bool, function: AnalyzedFunction) -> Self {
Self { typ, function, skip_resolving, heuristics: Vec::new() }
}

/// Register heuristics for the given function and trace
Expand Down Expand Up @@ -121,6 +125,7 @@ impl Analyzer {
jumped_conditional: None,
conditional_stack: Vec::new(),
analyzer_type: self.typ,
skip_resolving: self.skip_resolving,
};

// Perform analysis
Expand Down
1 change: 1 addition & 0 deletions crates/decompile/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pub async fn decompile(args: DecompilerArgs) -> Result<DecompileResult, Error> {
async move {
let mut analyzer = Analyzer::new(
analyzer_type,
args.skip_resolving,
AnalyzedFunction::new(&selector, selector == "fallback"),
);

Expand Down
6 changes: 3 additions & 3 deletions crates/decompile/src/utils/heuristics/extcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use heimdall_decoder::{decode, DecodeArgsBuilder};
pub fn extcall_heuristic<'a>(
function: &'a mut AnalyzedFunction,
state: &'a State,
_: &'a mut AnalyzerState,
analyzer_state: &'a mut AnalyzerState,
) -> BoxFuture<'a, Result<(), Error>> {
Box::pin(async move {
let instruction = &state.last_instruction;
Expand Down Expand Up @@ -66,6 +66,7 @@ pub fn extcall_heuristic<'a>(
DecodeArgsBuilder::new()
.target(extcalldata_clone)
.raw(true)
.skip_resolving(analyzer_state.skip_resolving)
.build()
.expect("Failed to build DecodeArgs"),
)
Expand Down Expand Up @@ -156,6 +157,7 @@ pub fn extcall_heuristic<'a>(
DecodeArgsBuilder::new()
.target(extcalldata_clone)
.raw(true)
.skip_resolving(analyzer_state.skip_resolving)
.build()
.expect("Failed to build DecodeArgs"),
)
Expand Down Expand Up @@ -219,5 +221,3 @@ pub fn extcall_heuristic<'a>(
Ok(())
})
}

// TODO: handle skip_resolving (need to fix in inspect mod too)
3 changes: 2 additions & 1 deletion crates/inspect/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use heimdall_common::{
rpc::{get_block_logs, get_trace, get_transaction},
signatures::cache_signatures_from_abi,
},
utils::{hex::ToLowerHex, io::logging::TraceFactory},
utils::{env::set_env, hex::ToLowerHex, io::logging::TraceFactory},
};

use crate::{
Expand All @@ -35,6 +35,7 @@ impl InspectResult {
pub async fn inspect(args: InspectArgs) -> Result<InspectResult, Error> {
// init
let start_time = Instant::now();
set_env("SKIP_RESOLVING", &args.skip_resolving.to_string());

// parse and cache signatures from the ABI, if provided
if let Some(abi_path) = args.abi.as_ref() {
Expand Down

0 comments on commit 2c6f2d6

Please sign in to comment.