Skip to content

Commit

Permalink
Merge pull request #525 from cdump/evmole
Browse files Browse the repository at this point in the history
upgrade EVMole to 0.3.6
  • Loading branch information
publicqi authored Jul 25, 2024
2 parents 03d3303 + 7611137 commit 02f0ea8
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 237 deletions.
184 changes: 4 additions & 180 deletions Cargo.lock

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

7 changes: 1 addition & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ revm-interpreter = { git = "https://github.com/fuzzland/revm", rev = "1dead51",
"serde",
"memory_limit",
] }
# external fuzzing-based abi decompiler
heimdall-core = { git = "https://github.com/Jon-Becker/heimdall-rs.git", rev = "256973b58370e05aed1536d1cfe44add20805ea4" }
# heimdall_core relies on an async runtime
tokio = { version = "1.34.0", features = ["full"] }


move-binary-format = { git = "https://github.com/fuzzland/ityfuzz-sui-fork.git", optional = true }
move-core-types = { git = "https://github.com/fuzzland/ityfuzz-sui-fork.git", features = [
Expand Down Expand Up @@ -131,5 +126,5 @@ thiserror = "1.0"
tracing = "0.1"
tracing-subscriber = "0.3"
colored = "2.0"
evmole = "0.3.2"
evmole = "0.3.6"
semver = "1.0.22"
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ ityfuzz evm -o -t 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 --onchain-block-num
```

ItyFuzz 将从 Etherscan 拉取合约的 ABI 并 fuzz 它。如果 ItyFuzz 遇到 Storage 中未知的槽,它将从 RPC 同步槽。
如果 ItyFuzz 遇到对外部未知合约的调用,它将拉取该合约的字节码和 ABI。 如果它的 ABI 不可用,ItyFuzz 将使用 heimdall 对字节码进行反编译分析 ABI。
如果 ItyFuzz 遇到对外部未知合约的调用,它将拉取该合约的字节码和 ABI。 如果它的 ABI 不可用,ItyFuzz 将使用 EVMole 对字节码进行反编译分析 ABI。

### Onchain 获取

Expand Down
2 changes: 1 addition & 1 deletion src/const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub const RANDOM_ADDRESS_CHOICE: u64 = 90;

// src/evm/corpus_initializer.rs
/// If there are more than 1/UNKNOWN_SIGS_DIVISOR unknown sigs, we will
/// decompile with heimdall
/// decompile with EVMole
pub const UNKNOWN_SIGS_DIVISOR: usize = 30;

// src/evm/mutator.rs
Expand Down
5 changes: 3 additions & 2 deletions src/evm/contract_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,14 +872,15 @@ impl ContractLoader {
error!("Failed to get code for contract at address {:?}", addr);
continue;
}
let code_bytes = hex::decode(&code).expect("code is not hex");
let abi = match onchain_config.fetch_abi(addr) {
Some(abi_str) => Self::parse_abi_str(&abi_str),
None => fetch_abi_evmole(code.clone()),
None => fetch_abi_evmole(&code_bytes),
};

contracts.push(ContractInfo {
name: format!("{}", addr),
code: hex::decode(&code).expect("code is not hex"),
code: code_bytes,
abi: abi.clone(),
is_code_deployed: true,
constructor_args: vec![],
Expand Down
12 changes: 6 additions & 6 deletions src/evm/corpus_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::{
input::{ConciseEVMInput, EVMInput, EVMInputTy},
middlewares::cheatcode::CHEATCODE_ADDRESS,
mutator::AccessPattern,
onchain::{abi_decompiler::fetch_abi_heimdall, flashloan::register_borrow_txn, BLACKLIST_ADDR},
onchain::{abi_decompiler::fetch_abi_evmole, flashloan::register_borrow_txn, BLACKLIST_ADDR},
presets::Preset,
types::{
fixed_address,
Expand Down Expand Up @@ -315,10 +315,10 @@ where
// this contract's abi is not available, we will use 3 layers to handle this
// 1. Extract abi from bytecode, and see do we have any function sig available
// in state
// 2. Use Heimdall to extract abi
// 3. Reconfirm on failures of heimdall
// 2. Use EVMole to extract abi
// 3. Reconfirm on failures of EVMole
info!("Contract {} has no abi", contract.name);
let contract_code = hex::encode(contract.code.clone());
let contract_code = hex::encode(&contract.code);
let sigs = extract_sig_from_contract(&contract_code);
let mut unknown_sigs: usize = 0;
for sig in &sigs {
Expand All @@ -330,8 +330,8 @@ where
}

if unknown_sigs >= sigs.len() / UNKNOWN_SIGS_DIVISOR {
info!("Too many unknown function signature for {:?}, we are going to decompile this contract using Heimdall", contract.name);
let abis = fetch_abi_heimdall(contract_code)
info!("Too many unknown function signature for {:?}, we are going to decompile this contract using EVMole", contract.name);
let abis = fetch_abi_evmole(&contract.code)
.iter()
.map(|abi| {
if let Some(known_abi) =
Expand Down
Loading

0 comments on commit 02f0ea8

Please sign in to comment.