From 30e73310900e9cf633ce39851680462340f0ba71 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Sat, 11 Sep 2021 19:38:25 +0300 Subject: [PATCH 1/9] chore: use ethabi with bumped ethereum-types --- Cargo.lock | 11 +++++------ Cargo.toml | 3 +++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 24dec85d5..530109c3a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -805,8 +805,7 @@ dependencies = [ [[package]] name = "ethabi" version = "14.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01317735d563b3bad2d5f90d2e1799f414165408251abb762510f40e790e69a" +source = "git+https://github.com/gakonst/ethabi/?branch=patch-1#01763cdf2446a5bf3a2b0065c364e672a45d391b" dependencies = [ "anyhow", "ethereum-types", @@ -833,9 +832,9 @@ dependencies = [ [[package]] name = "ethereum-types" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f64b5df66a228d85e4b17e5d6c6aa43b0310898ffe8a85988c4c032357aaabfd" +checksum = "0dd6bde671199089e601e8d47e153368b893ef885f11f365a3261ec58153c211" dependencies = [ "ethbloom", "fixed-hash", @@ -1946,9 +1945,9 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "primitive-types" -version = "0.9.1" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06345ee39fbccfb06ab45f3a1a5798d9dafa04cb8921a76d227040003a234b0e" +checksum = "05e4722c697a58a99d5d06a08c30821d7c082a4632198de1eaa5a6c22ef42373" dependencies = [ "fixed-hash", "impl-codec", diff --git a/Cargo.toml b/Cargo.toml index 200eb6059..0a301644e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,3 +86,6 @@ rand = "0.8.4" serde = { version = "1.0.124", features = ["derive"] } serde_json = "1.0.64" tokio = { version = "1.5", features = ["macros", "rt-multi-thread"] } + +[patch.'crates-io'] +ethabi = { git = "https://github.com/gakonst/ethabi/", branch = "patch-1" } From d9fb11e324ff7e4820f6d580a6d0db93d55e8adc Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Sat, 11 Sep 2021 19:39:44 +0300 Subject: [PATCH 2/9] fix: do not use internal type in human readable abi --- ethers-core/src/abi/human_readable.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/ethers-core/src/abi/human_readable.rs b/ethers-core/src/abi/human_readable.rs index 2a08fc5bd..11f41a638 100644 --- a/ethers-core/src/abi/human_readable.rs +++ b/ethers-core/src/abi/human_readable.rs @@ -364,6 +364,7 @@ impl AbiParser { Ok(Param { name: name.to_string(), kind: self.parse_type(type_str)?, + internal_type: None, }) } } From 5135f9f76d5632c2c65c8d8d86423d6b6435173b Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Sat, 11 Sep 2021 19:58:26 +0300 Subject: [PATCH 3/9] fix: do not use internal type in abigen --- ethers-contract/ethers-contract-derive/src/abigen.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/ethers-contract/ethers-contract-derive/src/abigen.rs b/ethers-contract/ethers-contract-derive/src/abigen.rs index ac718a884..f0cfc2e35 100644 --- a/ethers-contract/ethers-contract-derive/src/abigen.rs +++ b/ethers-contract/ethers-contract-derive/src/abigen.rs @@ -169,6 +169,7 @@ impl Parse for Method { Ok(Param { name: "".into(), kind, + internal_type: None, }) }) .collect::>>()?; From b1f9e8349b308edd52263f7b9cb89820fed1473a Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Sat, 11 Sep 2021 22:31:05 +0300 Subject: [PATCH 4/9] feat(solc): save the runtime bytecode --- ethers-core/src/utils/solc.rs | 36 ++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/ethers-core/src/utils/solc.rs b/ethers-core/src/utils/solc.rs index da4692e7d..e1d933ab0 100644 --- a/ethers-core/src/utils/solc.rs +++ b/ethers-core/src/utils/solc.rs @@ -28,6 +28,8 @@ pub struct CompiledContract { pub abi: Abi, /// The contract's bytecode pub bytecode: Bytes, + /// The contract's runtime bytecode + pub runtime_bytecode: Bytes, } /// Solidity Compiler Bindings @@ -98,7 +100,7 @@ impl Solc { .arg("--evm-version") .arg(self.evm_version.to_string()) .arg("--combined-json") - .arg("abi,bin"); + .arg("abi,bin,bin-runtime"); if let Some(runs) = self.optimizer { command @@ -148,7 +150,21 @@ impl Solc { ))) } }; - contracts.insert(name, CompiledContractStr { abi, bin }); + + let runtime_bin = + if let serde_json::Value::String(bin) = contract["bin-runtime"].take() { + bin + } else { + panic!("no runtime bytecode found") + }; + contracts.insert( + name, + CompiledContractStr { + abi, + bin, + runtime_bin, + }, + ); } else { return Err(SolcError::SolcError( "could not find `bin` in solc output".to_string(), @@ -174,7 +190,19 @@ impl Solc { let bytecode = hex::decode(contract.bin) .expect("solc did not produce valid bytecode") .into(); - (name, CompiledContract { abi, bytecode }) + + // parse the runtime bytecode + let runtime_bytecode = hex::decode(contract.runtime_bin) + .expect("solc did not produce valid runtime-bytecode") + .into(); + ( + name, + CompiledContract { + abi, + bytecode, + runtime_bytecode, + }, + ) }) .collect::>(); @@ -297,4 +325,6 @@ pub struct CompiledContractStr { pub abi: String, /// The contract's bytecode in hex pub bin: String, + /// The contract's runtime bytecode in hex + pub runtime_bin: String, } From 614ebcd4a7082a2dd71e8773a622e55203f063e7 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Mon, 13 Sep 2021 01:26:47 +0300 Subject: [PATCH 5/9] feat: implement serde for CompiledContract --- ethers-core/src/utils/solc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethers-core/src/utils/solc.rs b/ethers-core/src/utils/solc.rs index e1d933ab0..62632e0c9 100644 --- a/ethers-core/src/utils/solc.rs +++ b/ethers-core/src/utils/solc.rs @@ -21,7 +21,7 @@ pub enum SolcError { SerdeJson(#[from] serde_json::Error), } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Serialize, Deserialize)] /// The result of a solc compilation pub struct CompiledContract { /// The contract's ABI From 9af13a9a0d0cc9c287fd3caa134468e5da605c97 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Mon, 13 Sep 2021 03:55:57 +0300 Subject: [PATCH 6/9] feat: allow overriding solc binary path --- ethers-core/src/utils/solc.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ethers-core/src/utils/solc.rs b/ethers-core/src/utils/solc.rs index 62632e0c9..447501d3a 100644 --- a/ethers-core/src/utils/solc.rs +++ b/ethers-core/src/utils/solc.rs @@ -57,6 +57,9 @@ pub struct CompiledContract { /// # } /// ``` pub struct Solc { + /// The path to the Solc binary + pub solc_path: Option, + /// The path where contracts will be read from pub paths: Vec, @@ -85,6 +88,7 @@ impl Solc { Self { paths, + solc_path: None, optimizer: Some(200), // default optimizer runs = 200 evm_version: EvmVersion::Istanbul, allowed_paths: Vec::new(), @@ -94,7 +98,7 @@ impl Solc { /// Gets the ABI for the contracts pub fn build_raw(self) -> Result> { - let mut command = Command::new(SOLC); + let mut command = Command::new(self.solc_path.unwrap_or_else(|| PathBuf::from(SOLC))); command .arg("--evm-version") @@ -237,6 +241,12 @@ impl Solc { self } + /// Sets the path to the solc binary + pub fn solc_path(mut self, path: PathBuf) -> Self { + self.solc_path = Some(std::fs::canonicalize(path).unwrap()); + self + } + /// Sets the optimizer runs (default = 200). None indicates no optimization /// /// ```rust,no_run From 6a356c279cee21866dfa5b3cbffca89e50847549 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Mon, 13 Sep 2021 05:53:25 +0300 Subject: [PATCH 7/9] feat: expose providing raw file paths --- ethers-core/src/utils/solc.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ethers-core/src/utils/solc.rs b/ethers-core/src/utils/solc.rs index 447501d3a..ba2f51e37 100644 --- a/ethers-core/src/utils/solc.rs +++ b/ethers-core/src/utils/solc.rs @@ -77,7 +77,7 @@ pub struct Solc { } impl Solc { - /// Instantiates the Solc builder for the provided paths + /// Instantiates The Solc builder with the provided glob of Solidity files pub fn new(path: &str) -> Self { // Convert the glob to a vector of string paths // TODO: This might not be the most robust way to do this @@ -85,7 +85,11 @@ impl Solc { .expect("could not get glob") .map(|path| path.expect("path not found").to_string_lossy().to_string()) .collect::>(); + Self::new_with_paths(paths) + } + /// Instantiates the Solc builder for the provided paths + pub fn new_with_paths(paths: Vec) -> Self { Self { paths, solc_path: None, From c3f805d907ec7ab40c63a48e1c074b606924d299 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Mon, 13 Sep 2021 15:03:24 +0300 Subject: [PATCH 8/9] feat: do not set evm versions on old solc --- ethers-core/src/utils/solc.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ethers-core/src/utils/solc.rs b/ethers-core/src/utils/solc.rs index ba2f51e37..9c36e1ec8 100644 --- a/ethers-core/src/utils/solc.rs +++ b/ethers-core/src/utils/solc.rs @@ -102,13 +102,19 @@ impl Solc { /// Gets the ABI for the contracts pub fn build_raw(self) -> Result> { - let mut command = Command::new(self.solc_path.unwrap_or_else(|| PathBuf::from(SOLC))); + let path = self.solc_path.unwrap_or_else(|| PathBuf::from(SOLC)); + let mut command = Command::new(&path); + let version = Solc::version(Some(path)); - command - .arg("--evm-version") - .arg(self.evm_version.to_string()) - .arg("--combined-json") - .arg("abi,bin,bin-runtime"); + command.arg("--combined-json").arg("abi,bin,bin-runtime"); + + if (version.starts_with("0.5") && self.evm_version < EvmVersion::Istanbul) + || !version.starts_with("0.4") + { + command + .arg("--evm-version") + .arg(self.evm_version.to_string()); + } if let Some(runs) = self.optimizer { command @@ -222,8 +228,8 @@ impl Solc { /// # Panics /// /// If `solc` is not in the user's $PATH - pub fn version() -> String { - let command_output = Command::new(SOLC) + pub fn version(solc_path: Option) -> String { + let command_output = Command::new(solc_path.unwrap_or_else(|| PathBuf::from(SOLC))) .arg("--version") .output() .unwrap_or_else(|_| panic!("`{}` not in user's $PATH", SOLC)); @@ -299,7 +305,7 @@ impl Solc { } } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum EvmVersion { Homestead, TangerineWhistle, From 8b7349dac2e9f2eeed06088075b361cb8a0965a0 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Mon, 13 Sep 2021 15:09:36 +0300 Subject: [PATCH 9/9] chore: use upstream ethabi --- Cargo.lock | 2 +- Cargo.toml | 2 -- ethers-core/Cargo.toml | 3 ++- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 530109c3a..c0ba7feeb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -805,7 +805,7 @@ dependencies = [ [[package]] name = "ethabi" version = "14.1.0" -source = "git+https://github.com/gakonst/ethabi/?branch=patch-1#01763cdf2446a5bf3a2b0065c364e672a45d391b" +source = "git+https://github.com/rust-ethereum/ethabi/?branch=master#506f6cc364cdb458ac09f2be4f300779da256b08" dependencies = [ "anyhow", "ethereum-types", diff --git a/Cargo.toml b/Cargo.toml index 0a301644e..8463a5a75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -87,5 +87,3 @@ serde = { version = "1.0.124", features = ["derive"] } serde_json = "1.0.64" tokio = { version = "1.5", features = ["macros", "rt-multi-thread"] } -[patch.'crates-io'] -ethabi = { git = "https://github.com/gakonst/ethabi/", branch = "patch-1" } diff --git a/ethers-core/Cargo.toml b/ethers-core/Cargo.toml index 726add54f..0ed84d52d 100644 --- a/ethers-core/Cargo.toml +++ b/ethers-core/Cargo.toml @@ -11,7 +11,8 @@ keywords = ["ethereum", "web3", "celo", "ethers"] [dependencies] rlp = { version = "0.5.0", default-features = false } -ethabi = { version = "14.1.0", default-features = false } +# ethabi = { version = "14.1.0", default-features = false } +ethabi = { git = "https://github.com/rust-ethereum/ethabi/", branch = "master" } arrayvec = { version = "0.7.1", default-features = false } rlp-derive = { version = "0.1.0", default-features = false }