Skip to content

Commit

Permalink
Merge pull request #84 from Cloud10240/feature/remove_proxy
Browse files Browse the repository at this point in the history
Remove proxy from evm.
  • Loading branch information
shouc committed Jun 19, 2023
2 parents b14363a + bec726e commit b4f75d9
Show file tree
Hide file tree
Showing 8 changed files with 860 additions and 357 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/solutions
/*bench
bin
corpus
corpus
.vscode
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ move-core-types = { path = "./externals/move/language/move-core/types", features
move-stdlib = { path = "./externals/move/language/move-stdlib" }
move-vm-runtime = { path = "./externals/move/language/move-vm/runtime", features = ["lazy_natives"] }
move-vm-types = { path = "./externals/move/language/move-vm/types" }

retry = "2.0.0"
48 changes: 11 additions & 37 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ use crate::TargetType::{Address, Glob};
use clap::Parser;
use ityfuzz::evm::config::{Config, FuzzerTypes, StorageFetchingMode};
use ityfuzz::evm::contract_utils::{set_hash, ContractLoader};
use ityfuzz::evm::host::PANIC_ON_BUG;
use ityfuzz::evm::input::EVMInput;
use ityfuzz::evm::middlewares::middleware::Middleware;
use ityfuzz::evm::onchain::endpoints::{Chain, OnChainConfig};
use ityfuzz::evm::onchain::flashloan::{DummyPriceOracle, Flashloan};
use ityfuzz::evm::oracles::bug::BugOracle;
use ityfuzz::evm::oracles::erc20::IERC20OracleFlashloan;
use ityfuzz::evm::oracles::v2_pair::PairBalanceOracle;
use ityfuzz::evm::producers::erc20::ERC20Producer;
use ityfuzz::evm::producers::pair::PairProducer;
use ityfuzz::evm::types::EVMFuzzState;
use ityfuzz::evm::vm::EVMState;
Expand All @@ -17,13 +20,9 @@ use ityfuzz::state::FuzzState;
use primitive_types::{H160, U256};
use std::cell::RefCell;
use std::collections::HashSet;
use std::path::PathBuf;
use std::env;
use std::rc::Rc;
use std::str::FromStr;
use ityfuzz::evm::producers::erc20::ERC20Producer;
use std::env;
use ityfuzz::evm::host::PANIC_ON_BUG;
use ityfuzz::evm::oracles::bug::BugOracle;

pub fn init_sentry() {
let _guard = sentry::init(("https://96f3517bd77346ea835d28f956a84b9d@o4504503751344128.ingest.sentry.io/4504503752523776", sentry::ClientOptions {
Expand Down Expand Up @@ -131,10 +130,9 @@ struct Args {
#[arg(long, default_value = "corpus")]
corpus_path: String,

// random seed
// random seed
#[arg(long, default_value = "1667840158231589000")]
seed: u64,

}

enum TargetType {
Expand All @@ -145,10 +143,7 @@ enum TargetType {
fn main() {
init_sentry();
let args = Args::parse();
ityfuzz::telemetry::report_campaign(
args.onchain,
args.target.clone()
);
ityfuzz::telemetry::report_campaign(args.onchain, args.target.clone());
let target_type: TargetType = match args.target_type {
Some(v) => match v.as_str() {
"glob" => Glob,
Expand All @@ -166,22 +161,12 @@ fn main() {
}
};

let is_local_proxy = args.onchain_local_proxy_addr.is_some();

let mut onchain = if args.onchain {
match args.chain_type {
Some(chain_str) => {
let chain = Chain::from_str(&chain_str).expect("Invalid chain type");
let block_number = args.onchain_block_number.unwrap();
if is_local_proxy {
Some(OnChainConfig::new_local_proxy(
chain,
block_number,
args.onchain_local_proxy_addr.unwrap(),
))
} else {
Some(OnChainConfig::new(chain, block_number))
}
Some(OnChainConfig::new(chain, block_number))
}
None => Some(OnChainConfig::new_raw(
args.onchain_url
Expand All @@ -193,12 +178,6 @@ fn main() {
.expect("You need to either specify chain type or block explorer url"),
args.onchain_chain_name
.expect("You need to either specify chain type or chain name"),
is_local_proxy,
if is_local_proxy {
args.onchain_local_proxy_addr.unwrap()
} else {
"".to_string()
},
)),
}
} else {
Expand All @@ -218,10 +197,7 @@ fn main() {
let erc20_producer = Rc::new(RefCell::new(ERC20Producer::new()));

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

// let harness_code = "oracle_harness()";
Expand Down Expand Up @@ -276,9 +252,7 @@ fn main() {
let config = Config {
fuzzer_type: FuzzerTypes::from_str(args.fuzzer_type.as_str()).expect("unknown fuzzer"),
contract_info: match target_type {
Glob => {
ContractLoader::from_glob(args.target.as_str(), &mut state).contracts
}
Glob => ContractLoader::from_glob(args.target.as_str(), &mut state).contracts,
Address => {
if onchain.is_none() {
panic!("Onchain is required for address target type");
Expand All @@ -293,7 +267,7 @@ fn main() {
args_target.push_str(",");
args_target.push_str(BSC_ADDRESS);
}
}else if "eth" == onchain.as_ref().unwrap().chain_name {
} else if "eth" == onchain.as_ref().unwrap().chain_name {
if args_target.find(ETH_ADDRESS) == None {
args_target.push_str(",");
args_target.push_str(ETH_ADDRESS);
Expand Down Expand Up @@ -332,7 +306,7 @@ fn main() {
},
replay_file: args.replay_file,
flashloan_oracle,
corpus_path:args.corpus_path,
corpus_path: args.corpus_path,
};

match config.fuzzer_type {
Expand Down
67 changes: 67 additions & 0 deletions src/cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use serde_json::json;
use std::collections::HashMap;
use std::error::Error;
use std::fs::{self, File};
use std::io::prelude::*;
use std::path::Path;

pub trait Cache {
fn save(&self, key: &str, value: &str) -> Result<(), Box<dyn Error>>;
fn load(&self, key: &str) -> Result<String, Box<dyn Error>>;
}

#[derive(Clone, Debug)]
pub struct FileSystemCache {
file_path: String,
}

impl FileSystemCache {
pub fn new(file_path: &str) -> FileSystemCache {
let path = Path::new(file_path);
if !path.exists() {
let dir = path.parent().unwrap();
if !dir.exists() {
fs::create_dir_all(dir).expect("Failed to create directory");
}

fs::File::create(&path).expect("Failed to create file");
}

FileSystemCache {
file_path: file_path.to_string(),
}
}
}

impl Cache for FileSystemCache {
fn save(&self, key: &str, value: &str) -> Result<(), Box<dyn Error>> {
let mut file = File::open(&self.file_path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;

let mut json_data: HashMap<String, String> = match serde_json::from_str(&contents) {
Ok(data) => data,
Err(_) => HashMap::new(),
};

json_data.insert(key.to_string(), value.to_string());
let serialized_data = serde_json::to_string(&json_data)?;
fs::write(&self.file_path, serialized_data)?;
Ok(())
}

fn load(&self, key: &str) -> Result<String, Box<dyn Error>> {
let mut file = File::open(&self.file_path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;

let json_data: HashMap<String, String> = serde_json::from_str(&contents)?;
match json_data.get(key) {
Some(value) => Ok(value.clone()),
None => Err(Box::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
"Key not found",
))),
}
}
}
3 changes: 1 addition & 2 deletions src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ pub mod oracle;
pub mod oracles;
pub mod presets;
pub mod producers;
pub mod srcmap;
pub mod types;
pub mod uniswap;
pub mod vm;
pub mod srcmap;

Loading

0 comments on commit b4f75d9

Please sign in to comment.