From 3d720273d29357c43c7d5a4c264b245b984b7d3c Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Tue, 16 Apr 2024 13:54:35 +0000 Subject: [PATCH 1/3] add `no_metadata`, equivalent to adding `bytecode_hash = "none" and cbor_metadata = false` --- crates/cli/src/opts/build/core.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/cli/src/opts/build/core.rs b/crates/cli/src/opts/build/core.rs index 9ed8f98b3330..1c585cfd6049 100644 --- a/crates/cli/src/opts/build/core.rs +++ b/crates/cli/src/opts/build/core.rs @@ -70,6 +70,13 @@ pub struct CoreBuildArgs { #[serde(skip)] pub via_ir: bool, + /// Whether to append the metadata hash to the bytecode. + /// This is equivalent to setting [Config::bytecode_hash] to `none` and + /// [Config::cbor_metadata] to `false`. + #[arg(long, help_heading = "Compiler options")] + #[serde(skip)] + pub no_metadata: bool, + /// The path to the contract artifacts folder. #[arg( long = "out", @@ -204,9 +211,15 @@ impl Provider for CoreBuildArgs { dict.insert("via_ir".to_string(), true.into()); } + if self.no_metadata { + dict.insert("bytecode_hash".to_string(), "none".into()); + dict.insert("cbor_metadata".to_string(), false.into()); + } + if self.force { dict.insert("force".to_string(), self.force.into()); } + // we need to ensure no_cache set accordingly if self.no_cache { dict.insert("cache".to_string(), false.into()); From 90052bb4c7ab9255ed454cef6c3f19ed8c7ab2ee Mon Sep 17 00:00:00 2001 From: zerosnacks Date: Tue, 16 Apr 2024 14:12:04 +0000 Subject: [PATCH 2/3] add basic smoke test for --no-metadata setting cbor_metadata to false, bytecode_hash to none --- crates/forge/tests/cli/config.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/forge/tests/cli/config.rs b/crates/forge/tests/cli/config.rs index 22d885af4931..8c69fcc4f84e 100644 --- a/crates/forge/tests/cli/config.rs +++ b/crates/forge/tests/cli/config.rs @@ -2,7 +2,7 @@ use alloy_primitives::{Address, B256, U256}; use foundry_cli::utils as forge_utils; -use foundry_compilers::artifacts::{OptimizerDetails, RevertStrings, YulDetails}; +use foundry_compilers::artifacts::{BytecodeHash, OptimizerDetails, RevertStrings, YulDetails}; use foundry_config::{ cache::{CachedChains, CachedEndpoints, StorageCachingConfig}, fs_permissions::{FsAccessPermission, PathPermission}, @@ -305,8 +305,10 @@ forgetest_init!(can_get_evm_opts, |prj, _cmd| { // checks that we can set various config values forgetest_init!(can_set_config_values, |prj, _cmd| { - let config = prj.config_from_output(["--via-ir"]); + let config = prj.config_from_output(["--via-ir", "--no-metadata"]); assert!(config.via_ir); + assert_eq!(config.cbor_metadata, false); + assert_eq!(config.bytecode_hash, BytecodeHash::None); }); // tests that solc can be explicitly set From f3b57845dcacbc12d11f5b0a85762de7788cc738 Mon Sep 17 00:00:00 2001 From: zerosnacks <95942363+zerosnacks@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:09:28 +0200 Subject: [PATCH 3/3] Update core.rs Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com> --- crates/cli/src/opts/build/core.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/cli/src/opts/build/core.rs b/crates/cli/src/opts/build/core.rs index 1c585cfd6049..99caaea35454 100644 --- a/crates/cli/src/opts/build/core.rs +++ b/crates/cli/src/opts/build/core.rs @@ -70,9 +70,9 @@ pub struct CoreBuildArgs { #[serde(skip)] pub via_ir: bool, - /// Whether to append the metadata hash to the bytecode. - /// This is equivalent to setting [Config::bytecode_hash] to `none` and - /// [Config::cbor_metadata] to `false`. + /// Do not append any metadata to the bytecode. + /// + /// This is equivalent to setting `bytecode_hash` to `none` and `cbor_metadata` to `false`. #[arg(long, help_heading = "Compiler options")] #[serde(skip)] pub no_metadata: bool,