Skip to content

Commit

Permalink
Upgrade heimdall (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-chia authored Oct 13, 2023
1 parent 9fa074c commit 45ec9d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ revm-interpreter = { git = "https://github.com/fuzzland/revm", rev = "f9fdf3e66f
"memory_limit",
] }
# external fuzzing-based abi decompiler
heimdall = { git = "https://github.com/fuzzland/heimdall-rs", rev = "32363c9c59cf14c6839e48e5548cc862dfc54842" }
heimdall_core = { git = "https://github.com/fuzzland/heimdall-rs.git", package = "heimdall-core"}
# heimdall_core relies on an async runtime
tokio = {version = "1.0", features = ["full"]}


move-binary-format = { git = "https://github.com/fuzzland/ityfuzz-sui-fork.git", package = "move-binary-format", optional = true }
move-core-types = { git = "https://github.com/fuzzland/ityfuzz-sui-fork.git", package = "move-core-types", features = [
Expand Down
20 changes: 15 additions & 5 deletions src/evm/onchain/abi_decompiler.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use crate::cache::{Cache, FileSystemCache};
use crate::evm::contract_utils::ABIConfig;
use heimdall::decompile::decompile_with_bytecode;
use heimdall::decompile::out::solidity::ABIStructure;
use heimdall_core::decompile::{decompile, DecompilerArgsBuilder, out::abi::ABIStructure};
use std::collections::hash_map::DefaultHasher;
use std::error::Error;
use std::fs;
use std::hash::{Hash, Hasher};
use std::path::Path;

pub fn fetch_abi_heimdall(bytecode: String) -> Vec<ABIConfig> {
let mut hasher = DefaultHasher::new();
Expand All @@ -21,7 +18,7 @@ pub fn fetch_abi_heimdall(bytecode: String) -> Vec<ABIConfig> {
}
Err(_) => {}
}
let heimdall_result = decompile_with_bytecode(bytecode, "".to_string());
let heimdall_result = decompile_with_bytecode(bytecode).expect("unable to decompile contract");
let mut result = vec![];
for heimdall_abi in heimdall_result {
match heimdall_abi {
Expand Down Expand Up @@ -64,6 +61,19 @@ pub fn fetch_abi_heimdall(bytecode: String) -> Vec<ABIConfig> {
result
}

fn decompile_with_bytecode(contract_bytecode: String) -> Result<Vec<ABIStructure>, Box<dyn Error>>{
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?;

let args = DecompilerArgsBuilder::new()
.target(contract_bytecode)
.build()?;

let res = rt.block_on(decompile(args))?;
res.abi.ok_or("unable to decompile contract".into())
}

mod tests {
use super::*;

Expand Down

0 comments on commit 45ec9d5

Please sign in to comment.