From 00605ebde983a7c21097e0154b666742c41711dd Mon Sep 17 00:00:00 2001 From: Johann Date: Fri, 4 Mar 2022 19:09:12 -0700 Subject: [PATCH 01/11] Added Yul Support --- ethers-solc/src/artifacts/mod.rs | 4 +++ ethers-solc/src/compile/project.rs | 42 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/ethers-solc/src/artifacts/mod.rs b/ethers-solc/src/artifacts/mod.rs index 0d5038a4a..4cb3f0251 100644 --- a/ethers-solc/src/artifacts/mod.rs +++ b/ethers-solc/src/artifacts/mod.rs @@ -61,6 +61,10 @@ impl CompilerInput { Self { language: "Solidity".to_string(), sources, settings: Default::default() } } + pub fn with_yul_sources(sources: Sources) -> Self { + Self { language: "Yul".to_string(), sources, settings: Default::default() } + } + /// Sets the settings for compilation #[must_use] pub fn settings(mut self, settings: Settings) -> Self { diff --git a/ethers-solc/src/compile/project.rs b/ethers-solc/src/compile/project.rs index 6e1a9ac70..31935ec59 100644 --- a/ethers-solc/src/compile/project.rs +++ b/ethers-solc/src/compile/project.rs @@ -317,6 +317,48 @@ impl CompilerSources { } } +/// Compiles the input set sequentially and returns an aggregated set of the solc `CompilerOutput`s +fn compile_sequential_yul( + input: VersionedSources, + settings: &Settings, + paths: &ProjectPathsConfig, +) -> Result { + let mut aggregated = AggregatedCompilerOutput::default(); + tracing::trace!("compiling {} jobs sequentially", input.len()); + for (solc, (version, sources)) in input { + if sources.is_empty() { + // nothing to compile + continue + } + tracing::trace!( + "compiling {} sources with solc \"{}\" {:?}", + sources.len(), + solc.as_ref().display(), + solc.args + ); + + let input = CompilerInput::with_yul_sources(sources) + .settings(settings.clone()) + .normalize_evm_version(&version) + .with_remappings(paths.remappings.clone()); + + tracing::trace!( + "calling solc `{}` with {} sources {:?}", + version, + input.sources.len(), + input.sources.keys() + ); + + report::solc_spawn(&solc, &version, &input); + let output = solc.compile_exact(&input)?; + report::solc_success(&solc, &version, &output); + tracing::trace!("compiled input, output has error: {}", output.has_error()); + + aggregated.extend(version, output); + } + Ok(aggregated) +} + /// Compiles the input set sequentially and returns an aggregated set of the solc `CompilerOutput`s fn compile_sequential( input: VersionedSources, From 84df1bf498a0c877135d48d22997c66fe66aad21 Mon Sep 17 00:00:00 2001 From: DZuko Date: Fri, 4 Mar 2022 22:20:45 -0500 Subject: [PATCH 02/11] added example to compile yul, added new yul project and necessary struct parameters. Some struct parameters missing. --- examples/compile_yul.rs | 87 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 examples/compile_yul.rs diff --git a/examples/compile_yul.rs b/examples/compile_yul.rs new file mode 100644 index 000000000..ad2e1a274 --- /dev/null +++ b/examples/compile_yul.rs @@ -0,0 +1,87 @@ +use std::collections::BTreeMap; +use std::path::PathBuf; + +use ::ethers::solc::artifacts::{ + EvmVersion, Optimizer, OptimizerDetails, Settings, SettingsMetadata, YulDetails, +}; +use ::ethers::solc::{AllowedLibPaths, Project, ProjectPathsConfig, Solc, SolcConfig}; + +fn main() { + println!("Compiling Yul Contracts"); + + //initialize the solc settings + let solc_settings = Settings { + stop_after: Some("TODO:".to_string()), + remappings: vec![], + optimizer: Optimizer { + enabled: Some(false), + runs: Some(200), + details: Some(OptimizerDetails { + peephole: Some(false), + inliner: Some(false), + jumpdest_remover: Some(false), + order_literals: Some(false), + deduplicate: Some(false), + cse: Some(false), + constant_optimizer: Some(false), + yul: Some(true), + yul_details: Some(YulDetails { + stack_allocation: Some(false), + optimizer_steps: Some("TODO:".to_string()), + }), + }), + }, + metadata: Some(SettingsMetadata { + use_literal_content: Some(false), + bytecode_hash: Some("TODO:".to_string()), + }), + + //TODO: this needs to be BTreeMap>> + output_selection: BTreeMap::new(), + evm_version: Some(EvmVersion::Byzantium), + + //TODO: This also needs to be BTreeMap>> + libraries: BTreeMap::new(), + }; + + //create a new project + let yul_project = Project { + /// The layout of the project + paths: ProjectPathsConfig { + root: PathBuf::from("./"), + cache: PathBuf::from("./cache"), + artifacts: PathBuf::from("./artifacts"), + sources: PathBuf::from("./yul_contracts"), + tests: PathBuf::from("./tests"), + libraries: vec![], + remappings: vec![], + }, + /// Where to find solc + solc: Solc { + //TODO: pass in the path of solc + solc: PathBuf::from("TODO:"), + args: vec![], + }, + /// How solc invocation should be configured. + solc_config: SolcConfig { settings: solc_settings }, + /// Whether caching is enabled + cached: false, + /// Whether writing artifacts to disk is enabled + no_artifacts: false, + /// Whether writing artifacts to disk is enabled + auto_detect: false, + /// Handles all artifacts related tasks, reading and writing from the artifact dir. + // artifacts: //TODO: + /// Errors/Warnings which match these error codes are not going to be logged + ignored_error_codes: vec![], + /// The paths which will be allowed for library inclusion + allowed_lib_paths: AllowedLibPaths, + /// Maximum number of `solc` processes to run simultaneously. + solc_jobs: 1, + /// Offline mode, if set, network access (download solc) is disallowed + offline: true, + }; + + //compile the yul project + yul_project.svm_compile_yul(); +} From 0daccb3bce3d83726fdd4aafeea963499e645951 Mon Sep 17 00:00:00 2001 From: DZuko Date: Fri, 4 Mar 2022 22:25:28 -0500 Subject: [PATCH 03/11] added svm_compile_yul and added svm and aync to yul features in cargo.toml --- Cargo.toml | 3 +++ ethers-solc/src/lib.rs | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 10846f5d9..2ff7de10c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,6 +44,9 @@ rustdoc-args = ["--cfg", "docsrs"] features = ["full"] [features] + +yul=["svm", "async"] + celo = [ "ethers-core/celo", "ethers-providers/celo", diff --git a/ethers-solc/src/lib.rs b/ethers-solc/src/lib.rs index afc6821b2..df09dece8 100644 --- a/ethers-solc/src/lib.rs +++ b/ethers-solc/src/lib.rs @@ -199,7 +199,7 @@ impl Project { #[cfg(all(feature = "svm", feature = "async"))] if self.auto_detect { tracing::trace!("using solc auto detection to compile sources"); - return self.svm_compile(sources) + return self.svm_compile(sources); } let solc = self.configure_solc(self.solc.clone()); @@ -235,6 +235,11 @@ impl Project { project::ProjectCompiler::with_sources(self, sources)?.compile() } + #[cfg(all(feature = "svm", feature = "async"))] + pub fn svm_compile_yul(&self, sources: Sources) -> Result> { + project::ProjectCompiler::with_yul_sources(self, sources)?.compile() + } + /// Convenience function to compile a single solidity file with the project's settings. /// Same as [`Self::svm_compile()`] but with the given `file` as input. /// From 82d1d6236d026f1bc0006d27af9773c181941073 Mon Sep 17 00:00:00 2001 From: ControlCplusControlV <44706811+ControlCplusControlV@users.noreply.github.com> Date: Sun, 6 Mar 2022 19:21:09 -0700 Subject: [PATCH 04/11] Update Cargo.toml --- Cargo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2ff7de10c..61f4f8f24 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,8 +45,6 @@ features = ["full"] [features] -yul=["svm", "async"] - celo = [ "ethers-core/celo", "ethers-providers/celo", From b5bb844ecbbbfd0df946f71505844a83a587dc46 Mon Sep 17 00:00:00 2001 From: ControlCplusControlV <44706811+ControlCplusControlV@users.noreply.github.com> Date: Sun, 6 Mar 2022 19:21:41 -0700 Subject: [PATCH 05/11] Delete compile_yul.rs --- examples/compile_yul.rs | 87 ----------------------------------------- 1 file changed, 87 deletions(-) delete mode 100644 examples/compile_yul.rs diff --git a/examples/compile_yul.rs b/examples/compile_yul.rs deleted file mode 100644 index ad2e1a274..000000000 --- a/examples/compile_yul.rs +++ /dev/null @@ -1,87 +0,0 @@ -use std::collections::BTreeMap; -use std::path::PathBuf; - -use ::ethers::solc::artifacts::{ - EvmVersion, Optimizer, OptimizerDetails, Settings, SettingsMetadata, YulDetails, -}; -use ::ethers::solc::{AllowedLibPaths, Project, ProjectPathsConfig, Solc, SolcConfig}; - -fn main() { - println!("Compiling Yul Contracts"); - - //initialize the solc settings - let solc_settings = Settings { - stop_after: Some("TODO:".to_string()), - remappings: vec![], - optimizer: Optimizer { - enabled: Some(false), - runs: Some(200), - details: Some(OptimizerDetails { - peephole: Some(false), - inliner: Some(false), - jumpdest_remover: Some(false), - order_literals: Some(false), - deduplicate: Some(false), - cse: Some(false), - constant_optimizer: Some(false), - yul: Some(true), - yul_details: Some(YulDetails { - stack_allocation: Some(false), - optimizer_steps: Some("TODO:".to_string()), - }), - }), - }, - metadata: Some(SettingsMetadata { - use_literal_content: Some(false), - bytecode_hash: Some("TODO:".to_string()), - }), - - //TODO: this needs to be BTreeMap>> - output_selection: BTreeMap::new(), - evm_version: Some(EvmVersion::Byzantium), - - //TODO: This also needs to be BTreeMap>> - libraries: BTreeMap::new(), - }; - - //create a new project - let yul_project = Project { - /// The layout of the project - paths: ProjectPathsConfig { - root: PathBuf::from("./"), - cache: PathBuf::from("./cache"), - artifacts: PathBuf::from("./artifacts"), - sources: PathBuf::from("./yul_contracts"), - tests: PathBuf::from("./tests"), - libraries: vec![], - remappings: vec![], - }, - /// Where to find solc - solc: Solc { - //TODO: pass in the path of solc - solc: PathBuf::from("TODO:"), - args: vec![], - }, - /// How solc invocation should be configured. - solc_config: SolcConfig { settings: solc_settings }, - /// Whether caching is enabled - cached: false, - /// Whether writing artifacts to disk is enabled - no_artifacts: false, - /// Whether writing artifacts to disk is enabled - auto_detect: false, - /// Handles all artifacts related tasks, reading and writing from the artifact dir. - // artifacts: //TODO: - /// Errors/Warnings which match these error codes are not going to be logged - ignored_error_codes: vec![], - /// The paths which will be allowed for library inclusion - allowed_lib_paths: AllowedLibPaths, - /// Maximum number of `solc` processes to run simultaneously. - solc_jobs: 1, - /// Offline mode, if set, network access (download solc) is disallowed - offline: true, - }; - - //compile the yul project - yul_project.svm_compile_yul(); -} From ef318674f31949b8f579116077f9867ab4a8247a Mon Sep 17 00:00:00 2001 From: ControlCplusControlV <44706811+ControlCplusControlV@users.noreply.github.com> Date: Sun, 6 Mar 2022 19:39:55 -0700 Subject: [PATCH 06/11] Update project.rs --- ethers-solc/tests/project.rs | 80 ++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/ethers-solc/tests/project.rs b/ethers-solc/tests/project.rs index 4777c041e..77947b322 100644 --- a/ethers-solc/tests/project.rs +++ b/ethers-solc/tests/project.rs @@ -116,6 +116,86 @@ fn can_compile_configured() { assert!(artifact.ir_optimized.is_some()); } +#[test] +fn can_compile_yul() { + let mut project = TempProject::::dapptools().unwrap(); + + // Really have to make this example smaller + let src = project + .add_source( + "Foo", + r#" + object "SimpleStore" { + code { + datacopy(0, dataoffset("Runtime"), datasize("Runtime")) + return(0, datasize("Runtime")) + } + object "Runtime" { + code { + function mslice(position, length) -> result { + result := div(mload(position), exp(2, sub(256, mul(length, 8)))) + } + + function StoreCalldata.sig(pos) -> res { + res := mslice(StoreCalldata.sig.position(pos), 4) + } + + function StoreCalldata.sig.position(_pos) -> _offset { + function StoreCalldata.sig.position._chunk0(pos) -> __r { + __r := 0x00 + } + function StoreCalldata.sig.position._chunk1(pos) -> __r { + __r := pos + } + _offset := add(StoreCalldata.sig.position._chunk0(_pos), add(StoreCalldata.sig.position._chunk1(_pos), 0)) + + } + function StoreCalldata.val(pos) -> res { + res := mslice(StoreCalldata.val.position(pos), 32) + } + function StoreCalldata.val.position(_pos) -> _offset { + function StoreCalldata.val.position._chunk0(pos) -> __r { + __r := 0x04 + } + + function StoreCalldata.val.position._chunk1(pos) -> __r { + __r := pos + } + + + _offset := add(StoreCalldata.val.position._chunk0(_pos), add(StoreCalldata.val.position._chunk1(_pos), 0)) + } + calldatacopy(0, 0, 36) // write calldata to memory + switch StoreCalldata.sig(0) // select signature from memory (at position 0) + + case 0x6057361d { // new signature method + sstore(0, StoreCalldata.val(0)) // sstore calldata value + log2(0, 0, 0x69404ebde4a368ae324ed310becfefc3edfe9e5ebca74464e37ffffd8309a3c1, StoreCalldata.val(0)) + } + + case 0x6d4ce63c { + mstore(100, sload(0)) + return (100, 32) + } + } + } + } + "#, + ) + .unwrap(); + + let graph = Graph::resolve(project.paths()).unwrap(); + + let compiled = project.compile().unwrap(); + + + let contract = compiled.find("SimpleStore").unwrap(); + let bytecode = &contract.bytecode.as_ref().unwrap().object; + assert!(!compiled.has_compiler_errors()); + println!("{}", bytecode); + +} + #[test] fn can_compile_dapp_detect_changes_in_libs() { let mut project = TempProject::::dapptools().unwrap(); From ec8d64da58c5b70677b9b5b55539990e9932c0b3 Mon Sep 17 00:00:00 2001 From: ControlCplusControlV <44706811+ControlCplusControlV@users.noreply.github.com> Date: Sun, 6 Mar 2022 19:41:03 -0700 Subject: [PATCH 07/11] Update project.rs --- ethers-solc/tests/project.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethers-solc/tests/project.rs b/ethers-solc/tests/project.rs index 77947b322..4a9ecc1a3 100644 --- a/ethers-solc/tests/project.rs +++ b/ethers-solc/tests/project.rs @@ -186,9 +186,9 @@ fn can_compile_yul() { let graph = Graph::resolve(project.paths()).unwrap(); - let compiled = project.compile().unwrap(); + let compiled = project.svm_compile_yul().unwrap(); - + let contract = compiled.find("SimpleStore").unwrap(); let bytecode = &contract.bytecode.as_ref().unwrap().object; assert!(!compiled.has_compiler_errors()); From 900981ed41dabdc87d0becf2253e627a46f7af7f Mon Sep 17 00:00:00 2001 From: Johann Date: Sun, 6 Mar 2022 20:20:48 -0700 Subject: [PATCH 08/11] Added More Yul Functions --- ethers-solc/src/compile/project.rs | 116 +++++++++++++++++++---------- ethers-solc/src/lib.rs | 18 ++++- ethers-solc/src/project_util.rs | 4 + ethers-solc/tests/project.rs | 7 +- 4 files changed, 102 insertions(+), 43 deletions(-) diff --git a/ethers-solc/src/compile/project.rs b/ethers-solc/src/compile/project.rs index 31935ec59..056e59bf1 100644 --- a/ethers-solc/src/compile/project.rs +++ b/ethers-solc/src/compile/project.rs @@ -138,6 +138,18 @@ impl<'a, T: ArtifactOutput> ProjectCompiler<'a, T> { Ok(Self { edges, project, sources }) } + /// Since Yul only compiles sequentially atm + #[cfg(all(feature = "svm", feature = "async"))] + pub fn with_yul_sources(project: &'a Project, sources: Sources) -> Result { + let graph = Graph::resolve_sources(&project.paths, sources)?; + let (versions, edges) = graph.into_sources_by_version(project.offline)?; + let sources_by_version = versions.get(&project.allowed_lib_paths)?; + + let sources = CompilerSources::Sequential(sources_by_version); + + Ok(Self { edges, project, sources }) + } + /// Compiles the sources with a pinned `Solc` instance pub fn with_sources_and_solc( project: &'a Project, @@ -172,6 +184,11 @@ impl<'a, T: ArtifactOutput> ProjectCompiler<'a, T> { self.preprocess()?.compile()?.write_artifacts()?.write_cache() } + pub fn compile_yul(self) -> Result> { + // drive the compiler statemachine to completion + self.preprocess()?.compile_yul()?.write_artifacts()?.write_cache() + } + /// Does basic preprocessing /// - sets proper source unit names /// - check cache @@ -204,6 +221,15 @@ impl<'a, T: ArtifactOutput> PreprocessedState<'a, T> { Ok(CompiledState { output, cache }) } + + /// advance to the next state by compiling all sources + fn compile_yul(self) -> Result> { + let PreprocessedState { sources, cache } = self; + let output = + sources.compile_yul(&cache.project().solc_config.settings, &cache.project().paths)?; + + Ok(CompiledState { output, cache }) + } } /// Represents the state after `solc` was successfully invoked @@ -307,6 +333,18 @@ impl CompilerSources { } } + /// Compiles all the files with `Solc` + fn compile_yul( + self, + settings: &Settings, + paths: &ProjectPathsConfig, + ) -> Result { + match self { + CompilerSources::Sequential(input) => compile_sequential_yul(input, settings, paths), + CompilerSources::Parallel(input, _j) => compile_sequential_yul(input, settings, paths), + } + } + #[cfg(test)] #[allow(unused)] fn sources(&self) -> &VersionedSources { @@ -317,47 +355,47 @@ impl CompilerSources { } } -/// Compiles the input set sequentially and returns an aggregated set of the solc `CompilerOutput`s -fn compile_sequential_yul( - input: VersionedSources, - settings: &Settings, - paths: &ProjectPathsConfig, -) -> Result { - let mut aggregated = AggregatedCompilerOutput::default(); - tracing::trace!("compiling {} jobs sequentially", input.len()); - for (solc, (version, sources)) in input { - if sources.is_empty() { - // nothing to compile - continue + /// Compiles the input set sequentially and returns an aggregated set of the solc `CompilerOutput`s + fn compile_sequential_yul( + input: VersionedSources, + settings: &Settings, + paths: &ProjectPathsConfig, + ) -> Result { + let mut aggregated = AggregatedCompilerOutput::default(); + tracing::trace!("compiling {} jobs sequentially", input.len()); + for (solc, (version, sources)) in input { + if sources.is_empty() { + // nothing to compile + continue + } + tracing::trace!( + "compiling {} sources with solc \"{}\" {:?}", + sources.len(), + solc.as_ref().display(), + solc.args + ); + + let input = CompilerInput::with_yul_sources(sources) + .settings(settings.clone()) + .normalize_evm_version(&version) + .with_remappings(paths.remappings.clone()); + + tracing::trace!( + "calling solc `{}` with {} sources {:?}", + version, + input.sources.len(), + input.sources.keys() + ); + + report::solc_spawn(&solc, &version, &input); + let output = solc.compile_exact(&input)?; + report::solc_success(&solc, &version, &output); + tracing::trace!("compiled input, output has error: {}", output.has_error()); + + aggregated.extend(version, output); } - tracing::trace!( - "compiling {} sources with solc \"{}\" {:?}", - sources.len(), - solc.as_ref().display(), - solc.args - ); - - let input = CompilerInput::with_yul_sources(sources) - .settings(settings.clone()) - .normalize_evm_version(&version) - .with_remappings(paths.remappings.clone()); - - tracing::trace!( - "calling solc `{}` with {} sources {:?}", - version, - input.sources.len(), - input.sources.keys() - ); - - report::solc_spawn(&solc, &version, &input); - let output = solc.compile_exact(&input)?; - report::solc_success(&solc, &version, &output); - tracing::trace!("compiled input, output has error: {}", output.has_error()); - - aggregated.extend(version, output); + Ok(aggregated) } - Ok(aggregated) -} /// Compiles the input set sequentially and returns an aggregated set of the solc `CompilerOutput`s fn compile_sequential( diff --git a/ethers-solc/src/lib.rs b/ethers-solc/src/lib.rs index df09dece8..e6640ef78 100644 --- a/ethers-solc/src/lib.rs +++ b/ethers-solc/src/lib.rs @@ -207,6 +207,22 @@ impl Project { self.compile_with_version(&solc, sources) } + #[tracing::instrument(skip_all, name = "compile")] + pub fn compile_yul_project(&self) -> Result> { + let sources = self.paths.read_input_files()?; + tracing::trace!("found {} sources to compile: {:?}", sources.len(), sources.keys()); + + #[cfg(all(feature = "svm", feature = "async"))] + if self.auto_detect { + tracing::trace!("using solc auto detection to compile sources"); + return self.svm_compile_yul(sources); + } + + let solc = self.configure_solc(self.solc.clone()); + + self.compile_with_version(&solc, sources) + } + /// Compiles a set of contracts using `svm` managed solc installs /// /// This will autodetect the appropriate `Solc` version(s) to use when compiling the provided @@ -237,7 +253,7 @@ impl Project { #[cfg(all(feature = "svm", feature = "async"))] pub fn svm_compile_yul(&self, sources: Sources) -> Result> { - project::ProjectCompiler::with_yul_sources(self, sources)?.compile() + project::ProjectCompiler::with_yul_sources(self, sources)?.compile_yul() } /// Convenience function to compile a single solidity file with the project's settings. diff --git a/ethers-solc/src/project_util.rs b/ethers-solc/src/project_util.rs index 8683f2643..96b0eff85 100644 --- a/ethers-solc/src/project_util.rs +++ b/ethers-solc/src/project_util.rs @@ -66,6 +66,10 @@ impl TempProject { self.project().compile() } + pub fn compile_yul(&self) -> Result> { + self.project().compile_yul_project() + } + pub fn flatten(&self, target: &Path) -> Result { self.project().flatten(target) } diff --git a/ethers-solc/tests/project.rs b/ethers-solc/tests/project.rs index 4a9ecc1a3..b80af4d9b 100644 --- a/ethers-solc/tests/project.rs +++ b/ethers-solc/tests/project.rs @@ -186,13 +186,14 @@ fn can_compile_yul() { let graph = Graph::resolve(project.paths()).unwrap(); - let compiled = project.svm_compile_yul().unwrap(); + let compiled = project.compile_yul().unwrap(); - let contract = compiled.find("SimpleStore").unwrap(); + let contract = compiled.find("Foo").unwrap(); let bytecode = &contract.bytecode.as_ref().unwrap().object; + assert!(!compiled.has_compiler_errors()); - println!("{}", bytecode); + println!("{}", bytecode.as_str().unwrap()); } From 0b0654ffe9a11020da728b6be9a5325bd28fea2d Mon Sep 17 00:00:00 2001 From: 0xKitsune <0xKitsune@protonmail.com> Date: Mon, 7 Mar 2022 00:15:34 -0500 Subject: [PATCH 09/11] Patched error on can_compile_yul test. When declaring the compiled variable, it was looking for the Foo contract but the contract was named SimpleStorage. I changed the contract name to Foo and it works now. I added logic to get the bytecode from the compiled yul contract, convert it to a hex string and print it out in the terminal as a str to check the output. Also added some assert!() checks. --- ethers-solc/tests/project.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ethers-solc/tests/project.rs b/ethers-solc/tests/project.rs index b80af4d9b..934ff7f3a 100644 --- a/ethers-solc/tests/project.rs +++ b/ethers-solc/tests/project.rs @@ -125,7 +125,7 @@ fn can_compile_yul() { .add_source( "Foo", r#" - object "SimpleStore" { + object "Foo" { code { datacopy(0, dataoffset("Runtime"), datasize("Runtime")) return(0, datasize("Runtime")) @@ -185,16 +185,14 @@ fn can_compile_yul() { .unwrap(); let graph = Graph::resolve(project.paths()).unwrap(); - let compiled = project.compile_yul().unwrap(); - + assert!(compiled.find("Foo").is_some()); let contract = compiled.find("Foo").unwrap(); let bytecode = &contract.bytecode.as_ref().unwrap().object; - - assert!(!compiled.has_compiler_errors()); - println!("{}", bytecode.as_str().unwrap()); + assert!(!compiled.has_compiler_errors()); + println!("{:?}", bytecode.as_bytes().unwrap().to_string()); } #[test] From 92129762630a77abf6d28d09edf15f8725e89745 Mon Sep 17 00:00:00 2001 From: 0xKitsune <0xKitsune@protonmail.com> Date: Mon, 7 Mar 2022 11:12:49 -0500 Subject: [PATCH 10/11] added assert_eq statement to the can_compile yul test to evaluate bytecode output from compilation. --- ethers-solc/tests/project.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ethers-solc/tests/project.rs b/ethers-solc/tests/project.rs index 934ff7f3a..7c2e535d6 100644 --- a/ethers-solc/tests/project.rs +++ b/ethers-solc/tests/project.rs @@ -192,7 +192,9 @@ fn can_compile_yul() { let bytecode = &contract.bytecode.as_ref().unwrap().object; assert!(!compiled.has_compiler_errors()); - println!("{:?}", bytecode.as_bytes().unwrap().to_string()); + + assert_eq!(bytecode.as_bytes().unwrap().to_string(), + "0x61013c61001060003961013c6000f3fe6100c2565b6000600883026101000360020a825104905092915050565b6000610031600461002c84610038565b610004565b9050919050565b6000610050565b6000919050565b6000819050919050565b600061005b83610046565b016100658361003f565b019050919050565b6000610082602061007d84610089565b610004565b9050919050565b60006100a5565b600060049050919050565b6000819050919050565b60006100b08361009b565b016100ba83610090565b019050919050565b6024600080376100d2600061001c565b636057361d81146100ed57636d4ce63c811461012e5761013a565b6100f7600061006d565b600055610104600061006d565b7f69404ebde4a368ae324ed310becfefc3edfe9e5ebca74464e37ffffd8309a3c1600080a261013a565b60005460645260206064f35b50"); } #[test] From d9f73c13fff7e0d5ff89f5ec90c01bfd9ac7400b Mon Sep 17 00:00:00 2001 From: 0xKitsune <0xKitsune@protonmail.com> Date: Mon, 7 Mar 2022 11:27:16 -0500 Subject: [PATCH 11/11] formatting changes for can_compile_yul test --- ethers-solc/tests/project.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ethers-solc/tests/project.rs b/ethers-solc/tests/project.rs index 7c2e535d6..72a884a98 100644 --- a/ethers-solc/tests/project.rs +++ b/ethers-solc/tests/project.rs @@ -189,12 +189,23 @@ fn can_compile_yul() { assert!(compiled.find("Foo").is_some()); let contract = compiled.find("Foo").unwrap(); - let bytecode = &contract.bytecode.as_ref().unwrap().object; - assert!(!compiled.has_compiler_errors()); - assert_eq!(bytecode.as_bytes().unwrap().to_string(), - "0x61013c61001060003961013c6000f3fe6100c2565b6000600883026101000360020a825104905092915050565b6000610031600461002c84610038565b610004565b9050919050565b6000610050565b6000919050565b6000819050919050565b600061005b83610046565b016100658361003f565b019050919050565b6000610082602061007d84610089565b610004565b9050919050565b60006100a5565b600060049050919050565b6000819050919050565b60006100b08361009b565b016100ba83610090565b019050919050565b6024600080376100d2600061001c565b636057361d81146100ed57636d4ce63c811461012e5761013a565b6100f7600061006d565b600055610104600061006d565b7f69404ebde4a368ae324ed310becfefc3edfe9e5ebca74464e37ffffd8309a3c1600080a261013a565b60005460645260206064f35b50"); + let bytecode = &contract.bytecode.as_ref().unwrap().object; + assert_eq!( + bytecode.as_bytes().unwrap().to_string(), + r#"0x61013c61001060003961013c6000f3fe6100c2565b6000600883026101000360020a82510490 + 5092915050565b6000610031600461002c84610038565b610004565b9050919050565b600061005056 + 5b6000919050565b6000819050919050565b600061005b83610046565b016100658361003f565b0190 + 50919050565b6000610082602061007d84610089565b610004565b9050919050565b60006100a5565b + 600060049050919050565b6000819050919050565b60006100b08361009b565b016100ba8361009056 + 5b019050919050565b6024600080376100d2600061001c565b636057361d81146100ed57636d4ce63c8 + 11461012e5761013a565b6100f7600061006d565b600055610104600061006d565b7f69404ebde4a368a + e324ed310becfefc3edfe9e5ebca74464e37ffffd8309a3c1600080a261013a565b600054606452 + 60206064f35b50"# + .replace("\n", "") + .replace(" ", "") + ); } #[test]