Skip to content

Commit

Permalink
replace unused heimdall function names with evmole
Browse files Browse the repository at this point in the history
  • Loading branch information
cdump committed Jul 25, 2024
1 parent e1e592c commit 7611137
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 51 deletions.
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
8 changes: 4 additions & 4 deletions src/evm/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ use crate::{
middlewares::middleware::{add_corpus, CallMiddlewareReturn, Middleware, MiddlewareType},
mutator::AccessPattern,
onchain::{
abi_decompiler::fetch_abi_heimdall,
abi_decompiler::fetch_abi_evmole,
flashloan::{register_borrow_txn, Flashloan},
},
types::{as_u64, generate_random_address, is_zero, EVMAddress, EVMU256},
Expand Down Expand Up @@ -1379,7 +1379,7 @@ where
self.set_code(r_addr, Bytecode::new_raw(runtime_code.clone()), state);
if !unsafe { SETCODE_ONLY } {
// now we build & insert abi
let contract_code_str = hex::encode(runtime_code.clone());
let contract_code_str = hex::encode(&runtime_code);
let sigs = extract_sig_from_contract(&contract_code_str);
let mut unknown_sigs: usize = 0;
let mut parsed_abi = vec![];
Expand All @@ -1392,8 +1392,8 @@ where
}

if unknown_sigs >= sigs.len() / 30 {
debug!("Too many unknown function signature for newly created contract, we are going to decompile this contract using Heimdall");
let abis = fetch_abi_heimdall(contract_code_str)
debug!("Too many unknown function signature for newly created contract, we are going to decompile this contract using EVMole");
let abis = fetch_abi_evmole(&runtime_code)
.iter()
.map(|abi| {
if let Some(known_abi) =
Expand Down
45 changes: 14 additions & 31 deletions src/evm/onchain/abi_decompiler.rs

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions src/evm/onchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::{
middleware::{add_corpus, Middleware, MiddlewareType},
},
mutator::AccessPattern,
onchain::{abi_decompiler::fetch_abi_heimdall, endpoints::OnChainConfig, flashloan::register_borrow_txn},
onchain::{abi_decompiler::fetch_abi_evmole, endpoints::OnChainConfig, flashloan::register_borrow_txn},
types::{convert_u256_to_h160, EVMAddress, EVMU256},
vm::IS_FAST_CALL,
},
Expand Down Expand Up @@ -377,10 +377,11 @@ impl OnChain {
None => {
// 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
debug!("Contract {:?} has no abi", address_h160);
let contract_code_str = hex::encode(contract_code.bytes());
let contract_code = contract_code.bytes();
let contract_code_str = hex::encode(contract_code);
let sigs = extract_sig_from_contract(&contract_code_str);
let mut unknown_sigs: usize = 0;
for sig in &sigs {
Expand All @@ -399,8 +400,8 @@ impl OnChain {
}

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

0 comments on commit 7611137

Please sign in to comment.