From d41c311a7e5df566927cc109becc7936187539f2 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 21 Apr 2022 14:52:15 +0200 Subject: [PATCH 1/3] feat: add support for revert strings --- cli/src/cmd/forge/build.rs | 15 ++++++++++++++- cli/src/cmd/forge/flatten.rs | 1 + cli/src/cmd/forge/verify.rs | 1 + cli/tests/it/config.rs | 2 ++ config/README.md | 7 +++++++ config/src/lib.rs | 15 ++++++++++++++- 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/cli/src/cmd/forge/build.rs b/cli/src/cmd/forge/build.rs index b8050246bf5d..9f766ab10565 100644 --- a/cli/src/cmd/forge/build.rs +++ b/cli/src/cmd/forge/build.rs @@ -9,7 +9,7 @@ use crate::{ opts::forge::CompilerArgs, }; use clap::{Parser, ValueHint}; -use ethers::solc::{remappings::Remapping, utils::canonicalized}; +use ethers::solc::{artifacts::RevertStrings, remappings::Remapping, utils::canonicalized}; use foundry_config::{ figment::{ self, @@ -138,6 +138,15 @@ pub struct CoreBuildArgs { )] #[serde(skip)] pub config_path: Option, + + #[clap( + help_heading = "PROJECT OPTIONS", + help = r#"How to treat revert (and require) reason strings. Possible values are "default", "strip", "debug" and "verboseDebug""#, + long = "revert-strings", + value_name = "revert" + )] + #[serde(skip)] + pub revert_strings: Option, } impl CoreBuildArgs { @@ -202,6 +211,10 @@ impl Provider for CoreBuildArgs { dict.insert("extra_output_files".to_string(), selection.into()); } + if let Some(ref revert) = self.revert_strings { + dict.insert("revert_strings".to_string(), revert.to_string().into()); + } + Ok(Map::from([(Config::selected_profile(), dict)])) } } diff --git a/cli/src/cmd/forge/flatten.rs b/cli/src/cmd/forge/flatten.rs index 27f2cd9f7ca4..bbcf4efd344d 100644 --- a/cli/src/cmd/forge/flatten.rs +++ b/cli/src/cmd/forge/flatten.rs @@ -40,6 +40,7 @@ impl Cmd for FlattenArgs { libraries: vec![], via_ir: false, config_path: None, + revert_strings: None, }; let config = Config::from(&build_args); diff --git a/cli/src/cmd/forge/verify.rs b/cli/src/cmd/forge/verify.rs index 4b01217d82ca..3669c532fc48 100644 --- a/cli/src/cmd/forge/verify.rs +++ b/cli/src/cmd/forge/verify.rs @@ -136,6 +136,7 @@ impl VerifyArgs { libraries: vec![], via_ir: false, config_path: None, + revert_strings: None, }; let project = build_args.project()?; diff --git a/cli/tests/it/config.rs b/cli/tests/it/config.rs index 930bd1966ea9..a44b17ab38ff 100644 --- a/cli/tests/it/config.rs +++ b/cli/tests/it/config.rs @@ -1,6 +1,7 @@ //! Contains various tests for checking forge commands related to config values use ethers::{ prelude::artifacts::YulDetails, + solc::artifacts::RevertStrings, types::{Address, U256}, }; use forge::executor::opts::EvmOpts; @@ -83,6 +84,7 @@ forgetest!(can_extract_config_values, |prj: TestProject, mut cmd: TestCommand| { }, no_storage_caching: true, bytecode_hash: Default::default(), + revert_strings: Some(RevertStrings::Strip), sparse_mode: true, __non_exhaustive: (), }; diff --git a/config/README.md b/config/README.md index fce72a8f776f..b2dd243537d6 100644 --- a/config/README.md +++ b/config/README.md @@ -94,6 +94,13 @@ block_base_fee_per_gas = 0 block_coinbase = '0x0000000000000000000000000000000000000000' block_timestamp = 0 block_difficulty = 0 +# How to treat revert (and require) reason strings. +# Possible values are: "default", "strip", "debug" and "verboseDebug". +# "default" does not inject compiler-generated revert strings and keeps user-supplied ones. +# "strip" removes all revert strings (if possible, i.e. if literals are used) keeping side-effects +# "debug" injects strings for compiler-generated internal reverts, implemented for ABI encoders V1 and V2 for now. +# "verboseDebug" even appends further information to user-supplied revert strings (not yet implemented) +revert_strings = "default" # caches storage retrieved locally for certain chains and endpoints # can also be restrictied to `chains = ["optimism", "mainnet"]` # by default all endpoints will be cached, alternative options are "remote" for only caching non localhost endpoints and "" diff --git a/config/src/lib.rs b/config/src/lib.rs index d918c9e21db7..22fe760e1ef5 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -11,7 +11,10 @@ use crate::caching::StorageCachingConfig; use ethers_core::types::{Address, U256}; pub use ethers_solc::artifacts::OptimizerDetails; use ethers_solc::{ - artifacts::{output_selection::ContractOutputSelection, BytecodeHash, Optimizer, Settings}, + artifacts::{ + output_selection::ContractOutputSelection, serde_helpers, BytecodeHash, DebuggingSettings, + Optimizer, RevertStrings, Settings, + }, cache::SOLIDITY_FILES_CACHE_FILENAME, error::SolcError, remappings::{RelativeRemapping, Remapping}, @@ -221,6 +224,9 @@ pub struct Config { /// The metadata hash is machine dependent. By default, this is set to [BytecodeHash::None] to allow for deterministic code, See: #[serde(with = "from_str_lowercase")] pub bytecode_hash: BytecodeHash, + /// How to treat revert (and require) reason strings. + #[serde(with = "serde_helpers::display_from_str_opt")] + pub revert_strings: Option, /// Whether to compile in sparse mode /// /// If this option is enabled, only the required contracts/files will be selected to be @@ -567,6 +573,10 @@ impl Config { evm_version: Some(self.evm_version), libraries, metadata: Some(self.bytecode_hash.into()), + debug: self.revert_strings.map(|revert_strings| DebuggingSettings { + revert_strings: Some(revert_strings), + debug_info: Vec::new(), + }), ..Default::default() } .with_extra_output(self.configured_artifacts_handler().output_selection()) @@ -939,6 +949,7 @@ impl Default for Config { rpc_storage_caching: Default::default(), no_storage_caching: false, bytecode_hash: BytecodeHash::Ipfs, + revert_strings: None, sparse_mode: false, } } @@ -1643,6 +1654,7 @@ mod tests { via_ir = true rpc_storage_caching = { chains = [1, "optimism", 999999], endpoints = "all"} bytecode_hash = "ipfs" + revert_strings = "strip" "#, )?; @@ -1666,6 +1678,7 @@ mod tests { endpoints: CachedEndpoints::All }, bytecode_hash: BytecodeHash::Ipfs, + revert_strings: Some(RevertStrings::Strip), ..Config::default() } ); From 2e5a35e39a7c589c123c04d1011b81ed55bb4ab6 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 21 Apr 2022 19:30:34 +0200 Subject: [PATCH 2/3] bump ethers --- Cargo.lock | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ed6df183466b..fe363e44e1b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1283,7 +1283,7 @@ dependencies = [ [[package]] name = "ethers" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#8dd553a5ebbc19846fcd2d5a037c4f044f51c430" +source = "git+https://github.com/gakonst/ethers-rs#35c29c82c6f3f7f13280b576ca2397c41f517d06" dependencies = [ "ethers-addressbook", "ethers-contract", @@ -1298,7 +1298,7 @@ dependencies = [ [[package]] name = "ethers-addressbook" version = "0.1.0" -source = "git+https://github.com/gakonst/ethers-rs#8dd553a5ebbc19846fcd2d5a037c4f044f51c430" +source = "git+https://github.com/gakonst/ethers-rs#35c29c82c6f3f7f13280b576ca2397c41f517d06" dependencies = [ "ethers-core", "once_cell", @@ -1309,7 +1309,7 @@ dependencies = [ [[package]] name = "ethers-contract" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#8dd553a5ebbc19846fcd2d5a037c4f044f51c430" +source = "git+https://github.com/gakonst/ethers-rs#35c29c82c6f3f7f13280b576ca2397c41f517d06" dependencies = [ "ethers-contract-abigen", "ethers-contract-derive", @@ -1327,7 +1327,7 @@ dependencies = [ [[package]] name = "ethers-contract-abigen" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#8dd553a5ebbc19846fcd2d5a037c4f044f51c430" +source = "git+https://github.com/gakonst/ethers-rs#35c29c82c6f3f7f13280b576ca2397c41f517d06" dependencies = [ "Inflector", "cfg-if 1.0.0", @@ -1349,7 +1349,7 @@ dependencies = [ [[package]] name = "ethers-contract-derive" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#8dd553a5ebbc19846fcd2d5a037c4f044f51c430" +source = "git+https://github.com/gakonst/ethers-rs#35c29c82c6f3f7f13280b576ca2397c41f517d06" dependencies = [ "ethers-contract-abigen", "ethers-core", @@ -1363,7 +1363,7 @@ dependencies = [ [[package]] name = "ethers-core" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#8dd553a5ebbc19846fcd2d5a037c4f044f51c430" +source = "git+https://github.com/gakonst/ethers-rs#35c29c82c6f3f7f13280b576ca2397c41f517d06" dependencies = [ "arrayvec 0.7.2", "bytes", @@ -1389,7 +1389,7 @@ dependencies = [ [[package]] name = "ethers-etherscan" version = "0.2.0" -source = "git+https://github.com/gakonst/ethers-rs#8dd553a5ebbc19846fcd2d5a037c4f044f51c430" +source = "git+https://github.com/gakonst/ethers-rs#35c29c82c6f3f7f13280b576ca2397c41f517d06" dependencies = [ "ethers-core", "ethers-solc", @@ -1403,7 +1403,7 @@ dependencies = [ [[package]] name = "ethers-middleware" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#8dd553a5ebbc19846fcd2d5a037c4f044f51c430" +source = "git+https://github.com/gakonst/ethers-rs#35c29c82c6f3f7f13280b576ca2397c41f517d06" dependencies = [ "async-trait", "ethers-contract", @@ -1426,7 +1426,7 @@ dependencies = [ [[package]] name = "ethers-providers" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#8dd553a5ebbc19846fcd2d5a037c4f044f51c430" +source = "git+https://github.com/gakonst/ethers-rs#35c29c82c6f3f7f13280b576ca2397c41f517d06" dependencies = [ "async-trait", "auto_impl", @@ -1458,7 +1458,7 @@ dependencies = [ [[package]] name = "ethers-signers" version = "0.6.0" -source = "git+https://github.com/gakonst/ethers-rs#8dd553a5ebbc19846fcd2d5a037c4f044f51c430" +source = "git+https://github.com/gakonst/ethers-rs#35c29c82c6f3f7f13280b576ca2397c41f517d06" dependencies = [ "async-trait", "coins-bip32", @@ -1481,7 +1481,7 @@ dependencies = [ [[package]] name = "ethers-solc" version = "0.3.0" -source = "git+https://github.com/gakonst/ethers-rs#8dd553a5ebbc19846fcd2d5a037c4f044f51c430" +source = "git+https://github.com/gakonst/ethers-rs#35c29c82c6f3f7f13280b576ca2397c41f517d06" dependencies = [ "colored", "dunce", @@ -3613,9 +3613,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.5.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" +checksum = "fd249e82c21598a9a426a4e00dd7adc1d640b22445ec8545feef801d1a74c221" dependencies = [ "autocfg", "crossbeam-deque", @@ -3625,14 +3625,13 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.9.1" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" +checksum = "9f51245e1e62e1f1629cbfec37b5793bbabcaeb90f30e94d2ba03564687353e4" dependencies = [ "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "lazy_static", "num_cpus", ] @@ -4648,9 +4647,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.33" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80b9fa4360528139bc96100c160b7ae879f5567f49f1782b0b02035b0358ebf3" +checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" dependencies = [ "cfg-if 1.0.0", "pin-project-lite", From 2dc546d79abdc0f31250283d3eaa6b8a83c7b234 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 22 Apr 2022 12:14:49 +0200 Subject: [PATCH 3/3] Update cli/src/cmd/forge/build.rs Co-authored-by: Bjerg --- cli/src/cmd/forge/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/cmd/forge/build.rs b/cli/src/cmd/forge/build.rs index 9f766ab10565..b60cdc92840e 100644 --- a/cli/src/cmd/forge/build.rs +++ b/cli/src/cmd/forge/build.rs @@ -141,7 +141,7 @@ pub struct CoreBuildArgs { #[clap( help_heading = "PROJECT OPTIONS", - help = r#"How to treat revert (and require) reason strings. Possible values are "default", "strip", "debug" and "verboseDebug""#, + help = r#"Revert string configuration. Possible values are "default", "strip" (remove), "debug" (Solidity-generated revert strings) and "verboseDebug""#, long = "revert-strings", value_name = "revert" )]