Skip to content

Commit

Permalink
etherscan_key as env (#255)
Browse files Browse the repository at this point in the history
* etherscan_key as env

* allow multi etherscan key
  • Loading branch information
0xAWM authored Oct 15, 2023
1 parent 20c10b3 commit 6c9d013
Showing 1 changed file with 27 additions and 36 deletions.
63 changes: 27 additions & 36 deletions src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ use blaz::offchain_artifacts::OffChainArtifact;
use blaz::offchain_config::OffchainConfig;
use clap::Parser;
use config::{Config, FuzzerTypes, StorageFetchingMode};
use contract_utils::{set_hash, ContractLoader};
use contract_utils::ContractLoader;
use ethers::types::Transaction;
use hex::{decode, encode};
use host::PANIC_ON_BUG;
use input::{ConciseEVMInput, EVMInput};
use middlewares::middleware::Middleware;
use onchain::endpoints::{Chain, OnChainConfig};
use onchain::flashloan::{DummyPriceOracle, Flashloan};
use onchain::flashloan::DummyPriceOracle;
use oracles::erc20::IERC20OracleFlashloan;
use oracles::v2_pair::PairBalanceOracle;
use producers::erc20::ERC20Producer;
Expand All @@ -54,7 +51,7 @@ use vm::EVMState;
pub fn parse_constructor_args_string(input: String) -> HashMap<String, Vec<String>> {
let mut map = HashMap::new();

if input.len() == 0 {
if input.is_empty() {
return map;
}

Expand All @@ -73,7 +70,6 @@ pub fn parse_constructor_args_string(input: String) -> HashMap<String, Vec<Strin
#[derive(Deserialize)]
struct Data {
body: RPCCall,
response: serde_json::Value,
}

#[derive(Deserialize)]
Expand All @@ -82,22 +78,6 @@ struct RPCCall {
params: Option<serde_json::Value>,
}

#[derive(Deserialize)]
struct Response {
data: ResponseData,
}

#[derive(Deserialize)]
struct ResponseData {
id: u16,
result: TXResult,
}

#[derive(Deserialize)]
struct TXResult {
input: String,
}

/// CLI for ItyFuzz for EVM smart contracts
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand Down Expand Up @@ -336,17 +316,21 @@ pub fn evm_main(args: EvmArgs) {

let onchain_clone = onchain.clone();

if onchain.is_some() && args.onchain_etherscan_api_key.is_some() {
onchain
.as_mut()
.unwrap()
.etherscan_api_key
.push(args.onchain_etherscan_api_key.unwrap());
let etherscan_api_key = match args.onchain_etherscan_api_key {
Some(v) => v,
None => std::env::var("ETHERSCAN_API_KEY").unwrap_or_default(),
};

if onchain.is_some() && !etherscan_api_key.is_empty() {
onchain.as_mut().unwrap().etherscan_api_key = etherscan_api_key
.split(',')
.map(|s| s.to_string())
.collect();
}
let pair_producer = Rc::new(RefCell::new(PairProducer::new()));
let erc20_producer = Rc::new(RefCell::new(ERC20Producer::new()));

let mut flashloan_oracle = Rc::new(RefCell::new({
let flashloan_oracle = Rc::new(RefCell::new({
IERC20OracleFlashloan::new(pair_producer.clone(), erc20_producer.clone())
}));

Expand All @@ -361,14 +345,21 @@ pub fn evm_main(args: EvmArgs) {
RefCell<
dyn Oracle<
EVMState,
EVMAddress,
_,
_,
EVMAddress,
EVMU256,
revm_primitives::B160,
revm_primitives::Bytecode,
bytes::Bytes,
revm_primitives::B160,
revm_primitives::ruint::Uint<256, 4>,
Vec<u8>,
EVMInput,
EVMFuzzState,
FuzzState<
EVMInput,
EVMState,
revm_primitives::B160,
revm_primitives::B160,
Vec<u8>,
ConciseEVMInput,
>,
ConciseEVMInput,
>,
>,
Expand Down

0 comments on commit 6c9d013

Please sign in to comment.