diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 34219472..73284bd6 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -33,3 +33,4 @@ rand = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true } +ethers-core = { workspace = true } diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index a147845a..8c45cbdb 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -1,6 +1,8 @@ use clap_cryo::Parser; use color_print::cstr; use colored::Colorize; +use cryo_freeze::ParseError; +use ethers_core::utils::keccak256; use serde::{Deserialize, Serialize}; use serde_json::Value; use std::{default::Default, path::PathBuf}; @@ -263,6 +265,28 @@ pub struct Args { } impl Args { + /// pass if it's hex, convert to hex if it's not + pub fn convert_to_selector_strings( + function_signatures: Vec, + ) -> Result, ParseError> { + let mut selectors = Vec::new(); + for signature in function_signatures { + if Args::is_hex_signature(&signature) { + // If it's already a hex string, use it directly + selectors.push(signature); + } else { + // Otherwise, hash and convert to hex + let hash = keccak256(&signature); + let selector_string = hex::encode(&hash[0..4]); // Convert to hex string + selectors.push(selector_string); + } + } + Ok(selectors) + } + // helper to check hex + fn is_hex_signature(signature: &str) -> bool { + signature.starts_with("0x") && signature.len() == 10 // 0x + 8 hex chars + } pub(crate) fn merge_with_precedence(self, other: Args) -> Self { let default_struct = Args::default(); diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 779d3b76..59d42e3b 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -15,6 +15,7 @@ use eyre::Result; #[allow(clippy::needless_return)] async fn main() -> Result<()> { let args = Args::parse(); + match run::run(args).await { Ok(Some(freeze_summary)) if freeze_summary.errored.is_empty() => Ok(()), Ok(Some(_freeze_summary)) => std::process::exit(1), diff --git a/crates/cli/src/parse/partitions.rs b/crates/cli/src/parse/partitions.rs index 4acaa920..48e939fd 100644 --- a/crates/cli/src/parse/partitions.rs +++ b/crates/cli/src/parse/partitions.rs @@ -139,10 +139,16 @@ fn parse_call_datas( function: &Option>, inputs: &Option>, ) -> Result>, ParseError> { - let call_datas = match (call_datas, function, inputs) { + let func = if let Some(function_signatures) = function { + let vec = function_signatures.clone(); + Some(Args::convert_to_selector_strings(vec)?) + } else { + None + }; + let call_datas = match (call_datas, &func, inputs) { (None, None, None) => return Ok(None), (Some(call_data), None, None) => hex_strings_to_binary(call_data)?, - (None, Some(function), None) => hex_strings_to_binary(function)?, + (None, Some(func), None) => hex_strings_to_binary(func)?, (None, Some(function), Some(inputs)) => { let mut call_datas = Vec::new(); for f in function.iter() {