Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add real balance for onchain && handle call transfer #198

Merged
merged 12 commits into from
Sep 29, 2023
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