Skip to content

Commit

Permalink
feat(snapshot): use run_with_timeout for symbolic execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-Becker committed Dec 30, 2023
1 parent feb7834 commit cb6cdeb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
25 changes: 22 additions & 3 deletions core/src/snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub mod menus;
pub mod resolve;
pub mod structures;
pub mod util;
use heimdall_common::debug_max;
use heimdall_common::{debug_max, utils::threading::run_with_timeout};

use std::{
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -76,6 +76,10 @@ pub struct SnapshotArgs {
/// The output directory to write the output to, or 'print' to print to the console.
#[clap(long = "output", short = 'o', default_value = "output", hide_default_value = true)]
pub output: String,

/// The timeout for each function's symbolic execution in milliseconds.
#[clap(long, short, default_value = "10000", hide_default_value = true)]
pub timeout: u64,
}

impl SnapshotArgsBuilder {
Expand All @@ -89,6 +93,7 @@ impl SnapshotArgsBuilder {
no_tui: Some(true),
name: Some(String::new()),
output: Some(String::new()),
timeout: Some(10000),
}
}
}
Expand Down Expand Up @@ -257,8 +262,22 @@ async fn get_snapshots(
);

// get a map of possible jump destinations
let (map, jumpdest_count) =
evm.clone().symbolic_exec_selector(&selector, function_entry_point);
let mut evm_clone = evm.clone();
let selector_clone = selector.clone();
let (map, jumpdest_count) = match run_with_timeout(
move || evm_clone.symbolic_exec_selector(&selector_clone, function_entry_point),
Duration::from_millis(args.timeout),
) {
Some(map) => map,
None => {
trace.add_error(
func_analysis_trace,
line!(),
&format!("symbolic execution timed out, skipping snapshotting."),
);
continue
}
};

trace.add_debug(
func_analysis_trace,
Expand Down
5 changes: 5 additions & 0 deletions core/tests/test_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod benchmark {
no_tui: true,
name: String::from(""),
output: String::from(""),
timeout: 10000,
};
let _ = heimdall_core::snapshot::snapshot(args).await.unwrap();
}
Expand All @@ -36,6 +37,7 @@ mod benchmark {
no_tui: true,
name: String::from(""),
output: String::from(""),
timeout: 10000,
};
let _ = heimdall_core::snapshot::snapshot(args).await.unwrap();
}
Expand All @@ -61,6 +63,7 @@ mod integration_tests {
no_tui: true,
name: String::from(""),
output: String::from(""),
timeout: 10000,
};

let _ = heimdall_core::snapshot::snapshot(args).await.unwrap();
Expand All @@ -77,6 +80,7 @@ mod integration_tests {
no_tui: true,
name: String::from(""),
output: String::from(""),
timeout: 10000,
};

let _ = heimdall_core::snapshot::snapshot(args).await.unwrap();
Expand Down Expand Up @@ -167,6 +171,7 @@ mod integration_tests {
no_tui: true,
name: String::from(""),
output: String::from(""),
timeout: 10000,
};
let _ = heimdall_core::snapshot::snapshot(args).await.unwrap();
}
Expand Down

0 comments on commit cb6cdeb

Please sign in to comment.