Skip to content

Commit

Permalink
add real balance for onchain && handle call transfer (#198)
Browse files Browse the repository at this point in the history
* add debug info for contract init && clippy

* clippy host.rs

* clippy onchain/vm.rs

* add real balance for onchain && handle call transfer

* clean debug code

* skip to deploy FuzzLand helper contract

* add test

* Fix force_cache macro

* real_balance as a feature

---------

Co-authored-by: Chaofan Shou <[email protected]>
  • Loading branch information
0xAWM and shouc authored Sep 29, 2023
1 parent b208152 commit cb50da1
Show file tree
Hide file tree
Showing 13 changed files with 780 additions and 617 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ print_infant_corpus = []
print_txn_corpus = []
fuzz_static = []
flashloan_v2 = []
real_balance = []
full_trace = []
force_cache = []
use_presets = []
Expand Down
65 changes: 37 additions & 28 deletions cli/src/evm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use clap::Parser;
use ethers::types::Transaction;
use hex::{decode, encode};
use ityfuzz::evm::blaz::builder::{BuildJob, BuildJobResult};
use ityfuzz::evm::blaz::offchain_artifacts::OffChainArtifact;
use ityfuzz::evm::blaz::offchain_config::OffchainConfig;
use ityfuzz::evm::config::{Config, FuzzerTypes, StorageFetchingMode};
use ityfuzz::evm::contract_utils::{set_hash, ContractLoader};
use ityfuzz::evm::host::PANIC_ON_BUG;
Expand Down Expand Up @@ -29,10 +32,6 @@ use std::collections::HashSet;
use std::env;
use std::rc::Rc;
use std::str::FromStr;
use ityfuzz::evm::blaz::builder::{BuildJob, BuildJobResult};
use ityfuzz::evm::blaz::offchain_artifacts::OffChainArtifact;
use ityfuzz::evm::blaz::offchain_config::OffchainConfig;


pub fn parse_constructor_args_string(input: String) -> HashMap<String, Vec<String>> {
let mut map = HashMap::new();
Expand Down Expand Up @@ -263,7 +262,7 @@ enum EVMTargetType {
Glob,
Address,
ArtifactAndProxy,
Config
Config,
}

pub fn evm_main(args: EvmArgs) {
Expand Down Expand Up @@ -342,7 +341,7 @@ pub fn evm_main(args: EvmArgs) {
Vec<u8>,
EVMInput,
EVMFuzzState,
ConciseEVMInput
ConciseEVMInput,
>,
>,
>,
Expand All @@ -361,7 +360,7 @@ pub fn evm_main(args: EvmArgs) {
Vec<u8>,
EVMInput,
EVMFuzzState,
ConciseEVMInput
ConciseEVMInput,
>,
>,
>,
Expand Down Expand Up @@ -426,7 +425,6 @@ pub fn evm_main(args: EvmArgs) {

let constructor_args_map = parse_constructor_args_string(args.constructor_args);


let onchain_replacements = if args.onchain_replacements_file.len() > 0 {
BuildJobResult::from_multi_file(args.onchain_replacements_file)
} else {
Expand All @@ -441,40 +439,48 @@ pub fn evm_main(args: EvmArgs) {

let offchain_artifacts = if args.builder_artifacts_url.len() > 0 {
target_type = EVMTargetType::ArtifactAndProxy;
Some(OffChainArtifact::from_json_url(args.builder_artifacts_url).expect("failed to parse builder artifacts"))
Some(
OffChainArtifact::from_json_url(args.builder_artifacts_url)
.expect("failed to parse builder artifacts"),
)
} else if args.builder_artifacts_file.len() > 0 {
target_type = EVMTargetType::ArtifactAndProxy;
Some(OffChainArtifact::from_file(args.builder_artifacts_file).expect("failed to parse builder artifacts"))
Some(
OffChainArtifact::from_file(args.builder_artifacts_file)
.expect("failed to parse builder artifacts"),
)
} else {
None
};
let offchain_config = if args.offchain_config_url.len() > 0 {
target_type = EVMTargetType::Config;
Some(OffchainConfig::from_json_url(args.offchain_config_url).expect("failed to parse offchain config"))
Some(
OffchainConfig::from_json_url(args.offchain_config_url)
.expect("failed to parse offchain config"),
)
} else if args.offchain_config_file.len() > 0 {
target_type = EVMTargetType::Config;
Some(OffchainConfig::from_file(args.offchain_config_file).expect("failed to parse offchain config"))
Some(
OffchainConfig::from_file(args.offchain_config_file)
.expect("failed to parse offchain config"),
)
} else {
None
};

let config = Config {
fuzzer_type: FuzzerTypes::from_str(args.fuzzer_type.as_str()).expect("unknown fuzzer"),
contract_loader: match target_type {
EVMTargetType::Glob => {
ContractLoader::from_glob(
args.target.as_str(),
&mut state,
&proxy_deploy_codes,
&constructor_args_map,
)
}
EVMTargetType::Config => {
ContractLoader::from_config(
&offchain_artifacts.expect("offchain artifacts is required for config target type"),
&offchain_config.expect("offchain config is required for config target type"),
)
}
EVMTargetType::Glob => ContractLoader::from_glob(
args.target.as_str(),
&mut state,
&proxy_deploy_codes,
&constructor_args_map,
),
EVMTargetType::Config => ContractLoader::from_config(
&offchain_artifacts.expect("offchain artifacts is required for config target type"),
&offchain_config.expect("offchain config is required for config target type"),
),

EVMTargetType::ArtifactAndProxy => {
// ContractLoader::from_artifacts_and_proxy(
Expand Down Expand Up @@ -511,12 +517,15 @@ pub fn evm_main(args: EvmArgs) {
ContractLoader::from_address(
&mut onchain.as_mut().unwrap(),
HashSet::from_iter(addresses),
builder.clone(),
builder.clone(),
)
}
},
only_fuzz: if args.only_fuzz.len() > 0 {
args.only_fuzz.split(",").map(|s| EVMAddress::from_str(s).expect("failed to parse only fuzz")).collect()
args.only_fuzz
.split(",")
.map(|s| EVMAddress::from_str(s).expect("failed to parse only fuzz"))
.collect()
} else {
HashSet::new()
},
Expand Down
Loading

0 comments on commit cb50da1

Please sign in to comment.