From 8ad421d4c8737301500d904a1f8391fd080b00cd Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Fri, 20 Dec 2024 14:44:44 -0600 Subject: [PATCH 1/2] docker workspace root --- Cargo.lock | 105 ++++++++++++++++++++++++++++++--------------- Cargo.toml | 1 + main/Cargo.toml | 1 + main/src/check.rs | 11 ++++- main/src/docker.rs | 27 +++++++++--- main/src/main.rs | 34 +++++++++++++-- main/src/verify.rs | 1 + 7 files changed, 134 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b36935..4032580 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -118,7 +118,7 @@ dependencies = [ "alloy-transport", "futures", "futures-util", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -185,7 +185,7 @@ dependencies = [ "alloy-sol-types", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "tracing", ] @@ -207,7 +207,7 @@ dependencies = [ "async-trait", "auto_impl", "futures-utils-wasm", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -374,7 +374,7 @@ dependencies = [ "itertools 0.13.0", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -399,7 +399,7 @@ dependencies = [ "auto_impl", "elliptic-curve", "k256", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -417,7 +417,7 @@ dependencies = [ "eth-keystore", "k256", "rand", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -501,7 +501,7 @@ dependencies = [ "futures-utils-wasm", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "tokio", "tower", "tracing", @@ -1051,6 +1051,7 @@ dependencies = [ "brotli2", "bytes", "bytesize", + "cargo_metadata 0.19.1", "clap", "ethers", "eyre", @@ -1066,7 +1067,7 @@ dependencies = [ "sneks", "sys-info", "tempfile", - "thiserror", + "thiserror 1.0.69", "tiny-keccak", "tokio", "toml", @@ -1095,7 +1096,21 @@ dependencies = [ "semver 1.0.23", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", +] + +[[package]] +name = "cargo_metadata" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8769706aad5d996120af43197bf46ef6ad0fda35216b4505f926a365a232d924" +dependencies = [ + "camino", + "cargo-platform", + "semver 1.0.23", + "serde", + "serde_json", + "thiserror 2.0.8", ] [[package]] @@ -1187,7 +1202,7 @@ dependencies = [ "k256", "serde", "sha2", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -1203,7 +1218,7 @@ dependencies = [ "pbkdf2 0.12.2", "rand", "sha2", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -1223,7 +1238,7 @@ dependencies = [ "serde_derive", "sha2", "sha3", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -1811,7 +1826,7 @@ dependencies = [ "serde_json", "sha2", "sha3", - "thiserror", + "thiserror 1.0.69", "uuid 0.8.2", ] @@ -1828,7 +1843,7 @@ dependencies = [ "serde", "serde_json", "sha3", - "thiserror", + "thiserror 1.0.69", "uint", ] @@ -1907,7 +1922,7 @@ dependencies = [ "pin-project", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -1958,7 +1973,7 @@ checksum = "82d80cc6ad30b14a48ab786523af33b37f28a8623fc06afd55324816ef18fb1f" dependencies = [ "arrayvec", "bytes", - "cargo_metadata", + "cargo_metadata 0.18.1", "chrono", "const-hex", "elliptic-curve", @@ -1975,7 +1990,7 @@ dependencies = [ "strum", "syn 2.0.87", "tempfile", - "thiserror", + "thiserror 1.0.69", "tiny-keccak", "unicode-xid", ] @@ -1992,7 +2007,7 @@ dependencies = [ "semver 1.0.23", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "tracing", ] @@ -2016,7 +2031,7 @@ dependencies = [ "reqwest 0.11.27", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "tokio", "tracing", "tracing-futures", @@ -2048,7 +2063,7 @@ dependencies = [ "reqwest 0.11.27", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", "tokio", "tokio-tungstenite", "tracing", @@ -2075,7 +2090,7 @@ dependencies = [ "ethers-core", "rand", "sha2", - "thiserror", + "thiserror 1.0.69", "tracing", ] @@ -2103,7 +2118,7 @@ dependencies = [ "serde_json", "solang-parser", "svm-rs", - "thiserror", + "thiserror 1.0.69", "tiny-keccak", "tokio", "tracing", @@ -3533,7 +3548,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879952a81a83930934cbf1786752d6dedc3b1f29e8f8fb2ad1d0a36f377cf442" dependencies = [ "memchr", - "thiserror", + "thiserror 1.0.69", "ucd-trie", ] @@ -3880,7 +3895,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom", "libredox", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -4174,7 +4189,7 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32cca3c284cc507e641638806e7d3f162814091e0122a5b9877063b6c9c7b9f2" dependencies = [ - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -4575,7 +4590,7 @@ checksum = "adc4e5204eb1910f40f9cfa375f6f05b68c3abac4b6fd879c8ff5e7ae8a0a085" dependencies = [ "num-bigint", "num-traits", - "thiserror", + "thiserror 1.0.69", "time", ] @@ -4637,7 +4652,7 @@ dependencies = [ "lalrpop", "lalrpop-util", "phf", - "thiserror", + "thiserror 1.0.69", "unicode-xid", ] @@ -4737,7 +4752,7 @@ dependencies = [ "serde", "serde_json", "sha2", - "thiserror", + "thiserror 1.0.69", "url", "zip", ] @@ -4884,7 +4899,16 @@ version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f5383f3e0071702bf93ab5ee99b52d26936be9dedd9413067cbdcddcb6141a" +dependencies = [ + "thiserror-impl 2.0.8", ] [[package]] @@ -4898,6 +4922,17 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "thiserror-impl" +version = "2.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f357fcec90b3caef6623a099691be676d033b40a058ac95d2a6ade6fa0c943" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "threadpool" version = "1.8.1" @@ -5183,7 +5218,7 @@ dependencies = [ "rand", "rustls", "sha1", - "thiserror", + "thiserror 1.0.69", "url", "utf-8", ] @@ -5492,7 +5527,7 @@ dependencies = [ "serde", "serde-wasm-bindgen", "target-lexicon", - "thiserror", + "thiserror 1.0.69", "wasm-bindgen", "wasm-bindgen-downcast", "wasmer-compiler", @@ -5520,7 +5555,7 @@ dependencies = [ "more-asserts", "region", "smallvec", - "thiserror", + "thiserror 1.0.69", "wasmer-types", "wasmer-vm", "wasmparser 0.95.0", @@ -5571,7 +5606,7 @@ dependencies = [ "more-asserts", "rkyv", "target-lexicon", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -5596,7 +5631,7 @@ dependencies = [ "more-asserts", "region", "scopeguard", - "thiserror", + "thiserror 1.0.69", "wasmer-types", "winapi", ] @@ -5991,7 +6026,7 @@ dependencies = [ "pharos", "rustc_version 0.4.1", "send_wrapper 0.6.0", - "thiserror", + "thiserror 1.0.69", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", diff --git a/Cargo.toml b/Cargo.toml index 9f5dd2b..5884be4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ eyre = "0.6.8" hex = "0.4.3" rustc-host = "0.1.7" serde_json = "1.0.103" +cargo_metadata = "0.19.1" tiny-keccak = { version = "2.0.2", features = ["keccak"] } tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread" ] } diff --git a/main/Cargo.toml b/main/Cargo.toml index 3701d43..4a1447a 100644 --- a/main/Cargo.toml +++ b/main/Cargo.toml @@ -24,6 +24,7 @@ function_name.workspace = true clap.workspace = true eyre.workspace = true hex.workspace = true +cargo_metadata.workspace = true lazy_static.workspace = true ethers.workspace = true tokio.workspace = true diff --git a/main/src/check.rs b/main/src/check.rs index b621cba..adc9933 100644 --- a/main/src/check.rs +++ b/main/src/check.rs @@ -4,6 +4,7 @@ use crate::{ check::ArbWasm::ArbWasmErrors, constants::{ARB_WASM_H160, ONE_ETH, TOOLCHAIN_FILE_NAME}, + docker::find_workspace_root, macros::*, project::{self, extract_toolchain_channel, BuildConfig}, util::{ @@ -117,7 +118,15 @@ impl CheckConfig { if let Some(wasm) = self.wasm_file.clone() { return Ok((wasm, [0u8; 32])); } - let toolchain_file_path = PathBuf::from(".").as_path().join(TOOLCHAIN_FILE_NAME); + let workspace_root = self.workspace_root.clone().map_or_else( + || find_workspace_root().map_err(|e| eyre!("failed to find workspace root: {e}")), + |s| Ok(PathBuf::from(s)), + )?; + println!( + "Found workspace root in check: {}", + workspace_root.to_str().unwrap() + ); + let toolchain_file_path = workspace_root.join(TOOLCHAIN_FILE_NAME); let toolchain_channel = extract_toolchain_channel(&toolchain_file_path)?; let rust_stable = !toolchain_channel.contains("nightly"); let mut cfg = BuildConfig::new(rust_stable); diff --git a/main/src/docker.rs b/main/src/docker.rs index c293727..d88945f 100644 --- a/main/src/docker.rs +++ b/main/src/docker.rs @@ -5,12 +5,13 @@ use std::io::Write; use std::path::PathBuf; use std::process::{Command, Stdio}; -use crate::util::color::Color; +use cargo_metadata::MetadataCommand; use eyre::{bail, eyre, Result}; use crate::constants::TOOLCHAIN_FILE_NAME; use crate::macros::greyln; use crate::project::extract_toolchain_channel; +use crate::util::color::Color; fn image_name(cargo_stylus_version: &str, toolchain_version: &str) -> String { format!( @@ -84,10 +85,9 @@ fn run_in_docker_container( cargo_stylus_version: &str, toolchain_version: &str, command_line: &[&str], + workspace_root: PathBuf, ) -> Result<()> { let image_name = image_name(cargo_stylus_version, toolchain_version); - let dir = - std::env::current_dir().map_err(|e| eyre!("failed to find current directory: {e}"))?; Command::new("docker") .arg("run") .arg("--network") @@ -95,7 +95,7 @@ fn run_in_docker_container( .arg("-w") .arg("/source") .arg("-v") - .arg(format!("{}:/source", dir.as_os_str().to_str().unwrap())) + .arg(format!("{}:/source", workspace_root.to_str().unwrap())) .arg(image_name) .args(command_line) .spawn() @@ -108,9 +108,14 @@ fn run_in_docker_container( pub fn run_reproducible( cargo_stylus_version: Option, command_line: &[String], + workspace_root: Option, ) -> Result<()> { verify_valid_host()?; - let toolchain_file_path = PathBuf::from(".").as_path().join(TOOLCHAIN_FILE_NAME); + let workspace_root = workspace_root.map_or_else( + || find_workspace_root().map_err(|e| eyre!("failed to find workspace root: {e}")), + |s| Ok(PathBuf::from(s)), + )?; + let toolchain_file_path = workspace_root.join(TOOLCHAIN_FILE_NAME); let toolchain_channel = extract_toolchain_channel(&toolchain_file_path)?; greyln!( "Running reproducible Stylus command with toolchain {}", @@ -123,7 +128,17 @@ pub fn run_reproducible( command.push(s); } create_image(&cargo_stylus_version, &toolchain_channel)?; - run_in_docker_container(&cargo_stylus_version, &toolchain_channel, &command) + run_in_docker_container( + &cargo_stylus_version, + &toolchain_channel, + &command, + workspace_root, + ) +} + +pub fn find_workspace_root() -> Result { + let metadata = MetadataCommand::new().no_deps().exec()?; + Ok(metadata.workspace_root.clone().into_std_path_buf()) } fn verify_valid_host() -> Result<()> { diff --git a/main/src/main.rs b/main/src/main.rs index b8bf51e..6cffead 100644 --- a/main/src/main.rs +++ b/main/src/main.rs @@ -212,6 +212,9 @@ pub struct CheckConfig { /// Where to deploy and activate the contract (defaults to a random address). #[arg(long)] contract_address: Option, + /// Workspace root directory. Will default to the current directory based on Cargo metadata. + #[arg(long)] + workspace_root: Option, } #[derive(Args, Clone, Debug)] @@ -252,6 +255,9 @@ pub struct VerifyConfig { /// If not set, uses the default version of the local cargo stylus binary. #[arg(long)] cargo_stylus_version: Option, + /// Workspace root directory. Will default to the current directory based on Cargo metadata. + #[arg(long)] + workspace_root: Option, } #[derive(Args, Clone, Debug)] @@ -382,8 +388,9 @@ impl fmt::Display for CheckConfig { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "{} {} {}", + "{} {} {} {}", self.common_cfg, + self.data_fee, match &self.wasm_file { Some(path) => format!("--wasm-file={}", path.display()), None => "".to_string(), @@ -396,6 +403,16 @@ impl fmt::Display for CheckConfig { } } +impl fmt::Display for DataFeeOpts { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!( + f, + "{}", + format!("--data-fee-bump-percent={}", self.data_fee_bump_percent), + ) + } +} + impl fmt::Display for DeployConfig { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( @@ -450,7 +467,7 @@ impl fmt::Display for VerifyConfig { match self.no_verify { true => "--no-verify".to_string(), false => "".to_string(), - } + }, ) } } @@ -589,8 +606,13 @@ async fn main_impl(args: Opts) -> Result<()> { .filter(|s| !s.is_empty()) .collect::>(); commands.extend(config_args); + println!("Running with commands: {:?}", &commands); run!( - docker::run_reproducible(config.cargo_stylus_version, &commands), + docker::run_reproducible( + config.cargo_stylus_version, + &commands, + config.check_config.workspace_root + ), "failed reproducible run" ); } @@ -612,7 +634,11 @@ async fn main_impl(args: Opts) -> Result<()> { .collect::>(); commands.extend(config_args); run!( - docker::run_reproducible(config.cargo_stylus_version, &commands), + docker::run_reproducible( + config.cargo_stylus_version, + &commands, + config.workspace_root + ), "failed reproducible run" ); } diff --git a/main/src/verify.rs b/main/src/verify.rs index 82165ae..506165f 100644 --- a/main/src/verify.rs +++ b/main/src/verify.rs @@ -57,6 +57,7 @@ pub async fn verify(cfg: VerifyConfig) -> eyre::Result<()> { }, wasm_file: None, contract_address: None, + workspace_root: cfg.workspace_root, }; let _ = check::check(&check_cfg) .await From 0c37ef8865885a2a7171b9481ce3f6bd324e2bcd Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Fri, 20 Dec 2024 14:45:16 -0600 Subject: [PATCH 2/2] rm print --- main/src/check.rs | 4 ---- main/src/main.rs | 1 - 2 files changed, 5 deletions(-) diff --git a/main/src/check.rs b/main/src/check.rs index adc9933..631ab68 100644 --- a/main/src/check.rs +++ b/main/src/check.rs @@ -122,10 +122,6 @@ impl CheckConfig { || find_workspace_root().map_err(|e| eyre!("failed to find workspace root: {e}")), |s| Ok(PathBuf::from(s)), )?; - println!( - "Found workspace root in check: {}", - workspace_root.to_str().unwrap() - ); let toolchain_file_path = workspace_root.join(TOOLCHAIN_FILE_NAME); let toolchain_channel = extract_toolchain_channel(&toolchain_file_path)?; let rust_stable = !toolchain_channel.contains("nightly"); diff --git a/main/src/main.rs b/main/src/main.rs index 6cffead..1cbf8bc 100644 --- a/main/src/main.rs +++ b/main/src/main.rs @@ -606,7 +606,6 @@ async fn main_impl(args: Opts) -> Result<()> { .filter(|s| !s.is_empty()) .collect::>(); commands.extend(config_args); - println!("Running with commands: {:?}", &commands); run!( docker::run_reproducible( config.cargo_stylus_version,