From 01893c4db9afd03ea94b86ec8c0573cf3315253a Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Tue, 19 Sep 2023 12:31:41 +0300 Subject: [PATCH 01/54] move SCs directly under contracts dir & replace benchmarks SCs with a single one --- .../EXTCODESIZE100.sol => BENCHMARKS.sol} | 39 +++++++++++++++++-- .../contracts/{greeter => }/Greeter.sol | 0 integration-tests/contracts/MLOAD/MLOAD.sol | 24 ------------ .../OpenZeppelinERC20TestToken.sol | 2 +- integration-tests/contracts/SDIV/SDIV.sol | 24 ------------ 5 files changed, 37 insertions(+), 52 deletions(-) rename integration-tests/contracts/{EXTCODESIZE/EXTCODESIZE100.sol => BENCHMARKS.sol} (80%) rename integration-tests/contracts/{greeter => }/Greeter.sol (100%) delete mode 100644 integration-tests/contracts/MLOAD/MLOAD.sol rename integration-tests/contracts/{ERC20 => }/OpenZeppelinERC20TestToken.sol (76%) delete mode 100644 integration-tests/contracts/SDIV/SDIV.sol diff --git a/integration-tests/contracts/EXTCODESIZE/EXTCODESIZE100.sol b/integration-tests/contracts/BENCHMARKS.sol similarity index 80% rename from integration-tests/contracts/EXTCODESIZE/EXTCODESIZE100.sol rename to integration-tests/contracts/BENCHMARKS.sol index 96f32cb2eb..995874e4a2 100644 --- a/integration-tests/contracts/EXTCODESIZE/EXTCODESIZE100.sol +++ b/integration-tests/contracts/BENCHMARKS.sol @@ -2,9 +2,42 @@ pragma solidity >=0.7.0 <0.9.0; -contract CheckExtCodeSize100 { +contract Benchmarks { + struct Len { + uint32 l; + } + + function checkMload(Len calldata l) external returns (uint32 r) { + assembly { + let input := calldataload(4) + let len := div(input, 100) + let b := 77 + for { + let i := 0 + } lt(i, len) { + i := add(i, 1) + } { + r := mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(0)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) + } + } + } + + function checkSdiv(Len calldata l) external returns (uint32 r) { + assembly { + let input := calldataload(4) + let len := div(input, 100) + let b := 77 + for { + let i := 0 + } lt(i, len) { + i := add(i, 1) + } { + r := sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,r)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) + } + } + } - function checkBatchYul(address[] calldata addresses) external returns (uint256 length) { + function checkExtCodeSize(address[] calldata addresses) external returns (uint256 length) { uint256 ptr = 68; uint256 len = addresses.length/100; uint8 inc = 32; @@ -214,4 +247,4 @@ contract CheckExtCodeSize100 { } return length; } -} +} \ No newline at end of file diff --git a/integration-tests/contracts/greeter/Greeter.sol b/integration-tests/contracts/Greeter.sol similarity index 100% rename from integration-tests/contracts/greeter/Greeter.sol rename to integration-tests/contracts/Greeter.sol diff --git a/integration-tests/contracts/MLOAD/MLOAD.sol b/integration-tests/contracts/MLOAD/MLOAD.sol deleted file mode 100644 index cca9cb87fd..0000000000 --- a/integration-tests/contracts/MLOAD/MLOAD.sol +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity >=0.7.0 <0.9.0; - -contract CheckMload { - struct Len { - uint256 l; - } - - function checkBatchYul(Len calldata l) external returns (uint256 r) { - assembly { - let input := calldataload(4) - let len := div(input, 100) - let b := 77 - for { - let i := 0 - } lt(i, len) { - i := add(i, 1) - } { - r := mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(mload(0)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) - } - } - } -} \ No newline at end of file diff --git a/integration-tests/contracts/ERC20/OpenZeppelinERC20TestToken.sol b/integration-tests/contracts/OpenZeppelinERC20TestToken.sol similarity index 76% rename from integration-tests/contracts/ERC20/OpenZeppelinERC20TestToken.sol rename to integration-tests/contracts/OpenZeppelinERC20TestToken.sol index 941e13e937..d5500119e6 100644 --- a/integration-tests/contracts/ERC20/OpenZeppelinERC20TestToken.sol +++ b/integration-tests/contracts/OpenZeppelinERC20TestToken.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.4; // import "./ERC20.sol"; -import "../vendor/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; +import "./vendor/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; contract OpenZeppelinERC20TestToken is ERC20 { constructor(address owner) ERC20("TestToken1", "TT1") { diff --git a/integration-tests/contracts/SDIV/SDIV.sol b/integration-tests/contracts/SDIV/SDIV.sol deleted file mode 100644 index 954ca9458a..0000000000 --- a/integration-tests/contracts/SDIV/SDIV.sol +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity >=0.7.0 <0.9.0; - -contract CheckSdiv { - struct Len { - uint256 l; - } - - function checkBatchYul(Len calldata l) external returns (uint256 r) { - assembly { - let input := calldataload(4) - let len := div(input, 100) - let b := 77 - for { - let i := 0 - } lt(i, len) { - i := add(i, 1) - } { - r := sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,sdiv(b,r)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) - } - } - } -} \ No newline at end of file From bf234f9075a67386e140bc840a9595bbfe81498c Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Tue, 19 Sep 2023 12:36:33 +0300 Subject: [PATCH 02/54] add build-dependencies to Cargo --- integration-tests/Cargo.toml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index c0d1300f51..70641c079f 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -35,3 +35,13 @@ rpc = [] circuit_input_builder = [] circuits = [] mock_prover = [] + +[build-dependencies] +env = "0.0.0" +ethers = "2.0.7" +ethers-contract-abigen = "2.0.8" +glob = "0.3.1" +log = "0.4.14" +serde = "1.0.130" +serde_json = "1.0.66" +uneval = "0.2.4" \ No newline at end of file From 25b62b75d8d8f5ec817aa462d35336e226d51cd8 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Tue, 19 Sep 2023 12:39:16 +0300 Subject: [PATCH 03/54] create build script for SC compilation and generation of ruct contract bindings --- integration-tests/build.rs | 152 +++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 integration-tests/build.rs diff --git a/integration-tests/build.rs b/integration-tests/build.rs new file mode 100644 index 0000000000..0c4e34f166 --- /dev/null +++ b/integration-tests/build.rs @@ -0,0 +1,152 @@ +use ethers::{ + abi::Contract, + core::types::Bytes, + solc::{CompilerInput, CompilerOutput, EvmVersion, Solc}, +}; +use ethers_contract_abigen::Abigen; +use log::info; +use serde::{Deserialize, Serialize}; +use std::{ + fs::File, + path::{Path, PathBuf}, +}; + +#[derive(Serialize, Deserialize, Debug)] +pub struct CompiledContract { + /// Contract path + pub path: String, + /// Contract name + pub name: String, + /// ABI + pub abi: Contract, + /// Bytecode + pub bin: Bytes, + /// Runtime Bytecode + pub bin_runtime: Bytes, +} + +/// Path to the test contracts +const CONTRACTS_PATH: &str = "contracts"; +/// Solidity compilation warnings to ignore (by error code) +/// 2018: Warning - "Function state mutability can be restricted to pure" +/// 5667: Warning - "Unused function parameter. Remove or comment out the +/// variable name to silence this warning." +/// For smart contracts that are optimized for worst case block generation, we want to allow +/// contracts that do not interfere with state, without setting state mutability to view. otherwise +/// compiler optimizations will not allow recursive execution of targeted opcodes +const WARN: &[u64] = &[2018, 5667]; +/// List of contracts as (ContractName, ContractSolidityFile) +const CONTRACTS: &[(&str, &str)] = &[ + ("Greeter", "Greeter.sol"), + ( + "OpenZeppelinERC20TestToken", + "OpenZeppelinERC20TestToken.sol", + ), + // Contract to test worst-case usage of opcodes. + ("Benchmarks", "BENCHMARKS.sol"), +]; +/// Target directory for rust contract bingings +const BINDINGS_DR: &str = "src"; + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + + let solc: Solc = Solc::default(); + let _solc_version = solc.version().expect("Version Works"); + + for (name, contract_path) in CONTRACTS { + let path_sol = Path::new(CONTRACTS_PATH).join(contract_path); + let inputs = CompilerInput::new(&path_sol).expect("CompilerInput Created"); + // ethers-solc: explicitly indicate the EvmVersion that corresponds to the zkevm circuit's + // supported Upgrade, e.g. `London/Shanghai/...` specifications. + let input: CompilerInput = inputs + .clone() + .first_mut() + .expect("first exists") + .clone() + .evm_version(EvmVersion::London); + + // compilation will either fail with Err variant or return Ok(CompilerOutput) + // which may contain Errors or Warnings + let output: Vec = solc.compile_output(&input).unwrap(); + let mut deserializer: serde_json::Deserializer> = + serde_json::Deserializer::from_slice(&output); + // The contracts to test the worst-case usage of certain opcodes, such as SDIV, MLOAD, and + // EXTCODESIZE, generate big JSON compilation outputs. We disable the recursion limit to + // avoid parsing failure. + deserializer.disable_recursion_limit(); + let compiled = match CompilerOutput::deserialize(&mut deserializer) { + Err(error) => { + panic!("COMPILATION ERROR {:?}\n{:?}", &path_sol, error); + } + // CompilationOutput is succesfully created (might contain Errors or Warnings) + Ok(output) => { + info!("COMPILATION OK: {:?}", name); + output + } + }; + + if compiled.has_error() || compiled.has_warning(WARN) { + panic!( + "... but CompilerOutput contains errors/warnings: {:?}:\n{:#?}", + &path_sol, compiled.errors + ); + } + + let contract = compiled + .get(path_sol.to_str().expect("path is not a string"), name) + .expect("contract not found"); + let abi = contract.abi.expect("no abi found").clone(); + let bin = contract.bin.expect("no bin found").clone(); + let bin_runtime = contract.bin_runtime.expect("no bin_runtime found").clone(); + let compiled_contract = CompiledContract { + path: path_sol.to_str().expect("path is not str").to_string(), + name: name.to_string(), + abi, + bin: bin.into_bytes().expect("bin"), + bin_runtime: bin_runtime.into_bytes().expect("bin_runtime"), + }; + + // Save CompiledContract object to json files in "contracts" folder + let mut path_json = path_sol.clone(); + path_json.set_extension("json"); + serde_json::to_writer( + &File::create(&path_json).expect("cannot create file"), + &compiled_contract, + ) + .expect("cannot serialize json into file"); + } + // Generate contract binding for compiled contracts + for entry in glob::glob("./contracts/*.json").unwrap() { + match entry { + Ok(path) => { + let _g = generate_rust_contract_bindings(BINDINGS_DR, &path); + } + Err(e) => eprintln!("{:#?}", e), + } + } +} + +fn generate_rust_contract_bindings(bindings_dir: &str, file: &PathBuf) -> () { + let abi_source = file.clone(); + let tempbinding = file + .clone() + .into_os_string() + .into_string() + .expect("FAILED CONVERSION TO STRING"); + let filenamevec: Vec<&str> = tempbinding.split("/").collect(); + let filename = filenamevec[1]; + + let contractnamevector: Vec<&str> = filename.split(".").collect(); + let contractname = contractnamevector[0].to_lowercase(); + let destpath = + Path::new(&bindings_dir).join([contractname.clone(), "rs".to_string()].join(".")); + let _ = Abigen::new( + contractname, + abi_source.into_os_string().into_string().expect("error"), + ) + .expect("error") + .generate() + .expect("error") + .write_to_file(destpath); +} From d92a7af1e7be4b1d8b8a4b5c396dfbf0dcff6810 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Tue, 19 Sep 2023 12:47:48 +0300 Subject: [PATCH 04/54] update lib.rs --- integration-tests/src/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index dc49b6be4b..0d50552049 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -43,9 +43,7 @@ pub const CONTRACTS: &[(&str, &str)] = &[ "ERC20/OpenZeppelinERC20TestToken.sol", ), // Contracts to test worst-case usage of opcodes. - ("CheckMload", "MLOAD/MLOAD.sol"), - ("CheckExtCodeSize100", "EXTCODESIZE/EXTCODESIZE100.sol"), - ("CheckSdiv", "SDIV/SDIV.sol"), + ("Benchmarks", "BENCHMARKS.sol"), ]; /// Path to gen_blockchain_data output file pub const GENDATA_OUTPUT_PATH: &str = "gendata_output.json"; @@ -151,5 +149,11 @@ pub struct CompiledContract { pub bin_runtime: Bytes, } +#[allow(missing_docs)] +pub mod benchmarks; +#[allow(missing_docs)] +pub mod greeter; /// Common code for integration tests of circuits. pub mod integration_test_circuits; +#[allow(missing_docs)] +pub mod openzeppelinerc20testtoken; From da0d388885158b2613cce6c196d4a456c62836a5 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Tue, 19 Sep 2023 12:56:14 +0300 Subject: [PATCH 05/54] update Cargo dependenies --- Cargo.lock | 308 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 186 insertions(+), 122 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d905111ac3..aea19265d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -333,7 +333,7 @@ dependencies = [ "gadgets", "halo2_proofs", "hex", - "itertools", + "itertools 0.10.5", "lazy_static", "log", "mock", @@ -341,8 +341,8 @@ dependencies = [ "revm-precompile", "serde", "serde_json", - "strum", - "strum_macros", + "strum 0.24.1", + "strum_macros 0.24.3", "tokio", "url", ] @@ -415,9 +415,9 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.15.4" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eee4243f1f26fc7a42710e7439c149e2b10b05472f88090acce52632f231a73a" +checksum = "e7daec1a2a2129eeba1644b220b4647ec537b0b5d4bfd6876fcc5a540056b592" dependencies = [ "camino", "cargo-platform", @@ -472,7 +472,7 @@ dependencies = [ "eth-types", "ethers-signers", "halo2_proofs", - "itertools", + "itertools 0.10.5", "mock", "rand", "rand_chacha", @@ -611,6 +611,18 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "const-hex" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08849ed393c907c90016652a01465a12d86361cd38ad2a7de026c56a520cc259" +dependencies = [ + "cfg-if", + "cpufeatures", + "hex", + "serde", +] + [[package]] name = "const-oid" version = "0.9.3" @@ -874,6 +886,15 @@ dependencies = [ "subtle", ] +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + [[package]] name = "dirs-next" version = "2.0.0" @@ -884,6 +905,18 @@ dependencies = [ "dirs-sys-next", ] +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys", +] + [[package]] name = "dirs-sys-next" version = "0.1.2" @@ -1019,6 +1052,12 @@ dependencies = [ "syn 2.0.23", ] +[[package]] +name = "env" +version = "0.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876927d21ef1ae98001c8c35a1d8dfd682136914b23ef04276820fa6d43c3630" + [[package]] name = "env_logger" version = "0.9.3" @@ -1089,7 +1128,7 @@ dependencies = [ "ethers-signers", "halo2_proofs", "hex", - "itertools", + "itertools 0.10.5", "lazy_static", "libsecp256k1", "num", @@ -1098,8 +1137,8 @@ dependencies = [ "serde", "serde_json", "serde_with", - "strum", - "strum_macros", + "strum 0.24.1", + "strum_macros 0.24.3", "subtle", "uint", ] @@ -1201,16 +1240,16 @@ dependencies = [ [[package]] name = "ethers-contract-abigen" -version = "2.0.7" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c113e3e86b6bc16d98484b2c3bb2d01d6fed9f489fe2e592e5cc87c3024d616b" +checksum = "ce95a43c939b2e4e2f3191c5ad4a1f279780b8a39139c9905b43a7433531e2ab" dependencies = [ "Inflector", + "const-hex", "dunce", "ethers-core", "ethers-etherscan", "eyre", - "hex", "prettyplease", "proc-macro2", "quote", @@ -1241,27 +1280,27 @@ dependencies = [ [[package]] name = "ethers-core" -version = "2.0.7" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6da5fa198af0d3be20c19192df2bd9590b92ce09a8421e793bec8851270f1b05" +checksum = "c0a17f0708692024db9956b31d7a20163607d2745953f5ae8125ab368ba280ad" dependencies = [ "arrayvec", "bytes", "cargo_metadata", "chrono", + "const-hex", "elliptic-curve", "ethabi", "generic-array 0.14.7", - "hex", "k256", - "num_enum 0.6.1", + "num_enum 0.7.0", "once_cell", "open-fastrlp", "rand", "rlp", "serde", "serde_json", - "strum", + "strum 0.25.0", "syn 2.0.23", "tempfile", "thiserror", @@ -1271,9 +1310,9 @@ dependencies = [ [[package]] name = "ethers-etherscan" -version = "2.0.7" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84ebb401ba97c6f5af278c2c9936c4546cad75dec464b439ae6df249906f4caa" +checksum = "0e53451ea4a8128fbce33966da71132cf9e1040dcfd2a2084fd7733ada7b2045" dependencies = [ "ethers-core", "ethers-solc", @@ -1370,15 +1409,16 @@ dependencies = [ [[package]] name = "ethers-solc" -version = "2.0.7" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a81c89f121595cf8959e746045bb8b25a6a38d72588561e1a3b7992fc213f674" +checksum = "de34e484e7ae3cab99fbfd013d6c5dc7f9013676a4e0e414d8b12e1213e8b3ba" dependencies = [ "cfg-if", + "const-hex", + "dirs", "dunce", "ethers-core", "glob", - "hex", "home", "md-5", "num_cpus", @@ -1421,12 +1461,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "1.9.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] +checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" [[package]] name = "ff" @@ -1626,7 +1663,7 @@ dependencies = [ "rand", "rand_xorshift", "sha3 0.7.3", - "strum", + "strum 0.24.1", ] [[package]] @@ -1952,7 +1989,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.4.9", "tokio", "tower-service", "tracing", @@ -2089,9 +2126,12 @@ name = "integration-tests" version = "0.1.0" dependencies = [ "bus-mapping", + "env", "env_logger", "eth-types", "ethers", + "ethers-contract-abigen", + "glob", "halo2_proofs", "lazy_static", "log", @@ -2104,21 +2144,11 @@ dependencies = [ "serde", "serde_json", "tokio", + "uneval", "url", "zkevm-circuits", ] -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi 0.3.2", - "libc", - "windows-sys", -] - [[package]] name = "ipnet" version = "2.8.0" @@ -2132,7 +2162,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24fddda5af7e54bf7da53067d6e802dbcc381d0a8eef629df528e3ebf68755cb" dependencies = [ "hermit-abi 0.3.2", - "rustix 0.38.3", + "rustix", "windows-sys", ] @@ -2145,6 +2175,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.8" @@ -2194,20 +2233,20 @@ dependencies = [ [[package]] name = "lalrpop" -version = "0.19.12" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a1cbf952127589f2851ab2046af368fd20645491bb4b376f04b7f94d7a9837b" +checksum = "da4081d44f4611b66c6dd725e6de3169f9f63905421e8626fcb86b6a898998b8" dependencies = [ "ascii-canvas", "bit-set", "diff", "ena", "is-terminal", - "itertools", + "itertools 0.10.5", "lalrpop-util", "petgraph", "regex", - "regex-syntax 0.6.29", + "regex-syntax", "string_cache", "term", "tiny-keccak", @@ -2216,9 +2255,9 @@ dependencies = [ [[package]] name = "lalrpop-util" -version = "0.19.12" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3c48237b9604c5a4702de6b824e02006c3214327564636aef27c1028a8fa0ed" +checksum = "3f35c735096c0293d313e8f2a641627472b83d01b937177fe76e5e2708d31e0d" [[package]] name = "lazy_static" @@ -2289,12 +2328,6 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" -[[package]] -name = "linux-raw-sys" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" - [[package]] name = "linux-raw-sys" version = "0.4.3" @@ -2388,7 +2421,7 @@ dependencies = [ "ethers-core", "ethers-signers", "external-tracer", - "itertools", + "itertools 0.10.5", "lazy_static", "rand", "rand_chacha", @@ -2498,11 +2531,11 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" +checksum = "70bf6736f74634d299d00086f02986875b3c2d924781a6a2cb6c201e73da0ceb" dependencies = [ - "num_enum_derive 0.6.1", + "num_enum_derive 0.7.0", ] [[package]] @@ -2519,9 +2552,9 @@ dependencies = [ [[package]] name = "num_enum_derive" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" +checksum = "56ea360eafe1022f7cc56cd7b869ed57330fb2453d0c7831d99b74c65d2f5597" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2575,6 +2608,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "os_str_bytes" version = "6.5.1" @@ -2842,9 +2881,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.10" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -3102,7 +3141,7 @@ dependencies = [ "aho-corasick", "memchr", "regex-automata", - "regex-syntax 0.7.3", + "regex-syntax", ] [[package]] @@ -3113,15 +3152,9 @@ checksum = "fa250384981ea14565685dea16a9ccc4d1c541a13f82b9c168572264d1df8c56" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.3", + "regex-syntax", ] -[[package]] -name = "regex-syntax" -version = "0.6.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" - [[package]] name = "regex-syntax" version = "0.7.3" @@ -3130,9 +3163,9 @@ checksum = "2ab07dc67230e4a4718e70fd5c20055a4334b121f1f9db8fe63ef39ce9b8c846" [[package]] name = "reqwest" -version = "0.11.18" +version = "0.11.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" +checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" dependencies = [ "base64 0.21.2", "bytes", @@ -3163,7 +3196,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 0.22.6", + "webpki-roots 0.25.2", "winreg", ] @@ -3337,20 +3370,6 @@ dependencies = [ "semver", ] -[[package]] -name = "rustix" -version = "0.37.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d69718bf81c6127a49dc64e44a742e8bb9213c0ff8869a22c308f84c1d4ab06" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys 0.3.8", - "windows-sys", -] - [[package]] name = "rustix" version = "0.38.3" @@ -3360,7 +3379,7 @@ dependencies = [ "bitflags 2.3.3", "errno", "libc", - "linux-raw-sys 0.4.3", + "linux-raw-sys", "windows-sys", ] @@ -3376,13 +3395,13 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.2" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e32ca28af694bc1bbf399c33a516dbdf1c90090b8ab23c2bc24f834aa2247f5f" +checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" dependencies = [ "log", "ring", - "rustls-webpki", + "rustls-webpki 0.101.5", "sct", ] @@ -3405,6 +3424,16 @@ dependencies = [ "untrusted", ] +[[package]] +name = "rustls-webpki" +version = "0.101.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45a27e3b59326c16e23d30aeb7a36a24cc0d29e71d68ff611cdfb4a01d013bed" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.13" @@ -3742,7 +3771,7 @@ dependencies = [ "halo2_proofs", "halo2curves", "hex", - "itertools", + "itertools 0.10.5", "lazy_static", "num-bigint", "num-integer", @@ -3765,13 +3794,23 @@ dependencies = [ "winapi", ] +[[package]] +name = "socket2" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "solang-parser" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a94494913728908efa7a25a2dd2e4f037e714897985c24273c40596638ed909" +checksum = "7cb9fa2fa2fa6837be8a2495486ff92e3ffe68a99b6eeba288e139efdd842457" dependencies = [ - "itertools", + "itertools 0.11.0", "lalrpop", "lalrpop-util", "phf", @@ -3825,8 +3864,14 @@ name = "strum" version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" + +[[package]] +name = "strum" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" dependencies = [ - "strum_macros", + "strum_macros 0.25.2", ] [[package]] @@ -3842,6 +3887,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "strum_macros" +version = "0.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8d03b598d3d0fff69bf533ee3ef19b8eeb342729596df84bcc7e1f96ec4059" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.23", +] + [[package]] name = "substrate-bn" version = "0.6.0" @@ -3863,13 +3921,13 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "svm-rs" -version = "0.2.23" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a04fc4f5cd35c700153b233f5575ccb3237e0f941fa5049d9e98254d10bf2fe" +checksum = "597e3a746727984cb7ea2487b6a40726cad0dbe86628e7d429aa6b8c4c153db4" dependencies = [ + "dirs", "fs2", "hex", - "home", "once_cell", "reqwest", "semver", @@ -3911,15 +3969,14 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.6.0" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c0432476357e58790aaa47a8efb0c5138f137343f3b5f23bd36a27e3b0a6d6" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ - "autocfg", "cfg-if", "fastrand", "redox_syscall 0.3.5", - "rustix 0.37.23", + "rustix", "windows-sys", ] @@ -3969,8 +4026,8 @@ dependencies = [ "regex", "serde", "serde_json", - "strum", - "strum_macros", + "strum 0.24.1", + "strum_macros 0.24.3", "thiserror", "toml 0.5.11", "urlencoding", @@ -4046,18 +4103,17 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.29.1" +version = "1.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" +checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" dependencies = [ - "autocfg", "backtrace", "bytes", "libc", "mio", "num_cpus", "pin-project-lite", - "socket2", + "socket2 0.5.4", "tokio-macros", "windows-sys", ] @@ -4254,6 +4310,16 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "uneval" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63cc5d2fd8648d7e2be86098f60c9ece7045cc710b3c1e226910e2f37d11dc73" +dependencies = [ + "serde", + "thiserror", +] + [[package]] name = "unicode-bidi" version = "0.3.13" @@ -4445,21 +4511,18 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.6" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338" dependencies = [ - "webpki", + "rustls-webpki 0.100.1", ] [[package]] name = "webpki-roots" -version = "0.23.1" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338" -dependencies = [ - "rustls-webpki", -] +checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" [[package]] name = "winapi" @@ -4569,11 +4632,12 @@ dependencies = [ [[package]] name = "winreg" -version = "0.10.1" +version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ - "winapi", + "cfg-if", + "windows-sys", ] [[package]] @@ -4663,7 +4727,7 @@ dependencies = [ "halo2_proofs", "hex", "integer", - "itertools", + "itertools 0.10.5", "lazy_static", "libsecp256k1", "log", @@ -4680,8 +4744,8 @@ dependencies = [ "serde_json", "sha3 0.10.8", "snark-verifier", - "strum", - "strum_macros", + "strum 0.24.1", + "strum_macros 0.24.3", ] [[package]] From 4cad68ed25952abfb487a04f46a950f9e2263d99 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Tue, 19 Sep 2023 12:57:21 +0300 Subject: [PATCH 06/54] remove compilation step, new deploy fn based on SC rust bindings, add MLOAD and SDIV Txs --- .../src/bin/gen_blockchain_data.rs | 278 +++++++----------- 1 file changed, 114 insertions(+), 164 deletions(-) diff --git a/integration-tests/src/bin/gen_blockchain_data.rs b/integration-tests/src/bin/gen_blockchain_data.rs index 21d74e0a56..59898b882d 100644 --- a/integration-tests/src/bin/gen_blockchain_data.rs +++ b/integration-tests/src/bin/gen_blockchain_data.rs @@ -1,40 +1,66 @@ +use core::{borrow::Borrow, clone::Clone}; use ethers::{ - abi::{self, Tokenize}, - contract::{builders::ContractCall, Contract, ContractFactory}, + abi::{self, Abi}, + contract::{builders::ContractCall, Contract}, core::{ types::{ - transaction::eip2718::TypedTransaction, Address, TransactionReceipt, - TransactionRequest, U256, U64, + transaction::eip2718::TypedTransaction, Address, GethDebugTracingOptions, + TransactionReceipt, TransactionRequest, H160, U256, U64, }, utils::WEI_IN_ETHER, }, - middleware::SignerMiddleware, - providers::{Middleware, PendingTransaction}, + middleware::{ + contract::{ContractDeploymentTx, ContractInstance}, + SignerMiddleware, + }, + providers::{Http, Middleware, PendingTransaction, Provider}, signers::Signer, - solc::{CompilerInput, CompilerOutput, EvmVersion, Solc}, }; use integration_tests::{ - get_client, get_provider, get_wallet, log_init, CompiledContract, GenDataOutput, CONTRACTS, - CONTRACTS_PATH, WARN, + benchmarks::*, get_client, get_provider, get_wallet, greeter::*, log_init, + openzeppelinerc20testtoken::openzeppelinerc20testtoken as ozerc20tt, GenDataOutput, }; use log::{error, info}; -use serde::de::Deserialize; -use std::{collections::HashMap, fs::File, path::Path, sync::Arc, thread::sleep, time::Duration}; +use std::{collections::HashMap, fs::File, sync::Arc, thread::sleep, time::Duration}; -async fn deploy(prov: Arc, compiled: &CompiledContract, args: T) -> Contract +async fn deploy<'a, M, C, B>( + deployer_tx: ContractDeploymentTx, + name: &'a str, +) -> (Abi, H160, U64, C) where - T: Tokenize, - M: Middleware, + M: Middleware + 'a, + B: Borrow + Clone + 'a, + C: From> + 'a, { - info!("Deploying {}...", compiled.name); - let factory = ContractFactory::new(compiled.abi.clone(), compiled.bin.clone(), prov); - factory - .deploy(args) - .expect("cannot deploy") - .confirmations(0usize) - .send() + info!("Deploying {}...", name); + let binding = deployer_tx.clone(); + let contract_abi = binding.abi(); + let c_abi = contract_abi.clone(); + let contract_deployed = deployer_tx + .send_with_receipt() + .await + .expect("Could not confirm contract deployment"); + let contract_instance = contract_deployed.0; + let deploy_tx_receipt = contract_deployed.1; + let block_number = deploy_tx_receipt + .block_number + .expect("failed to get block number"); + let contract_address = deploy_tx_receipt + .contract_address + .expect("failed to get contract address"); + (c_abi, contract_address, block_number, contract_instance) +} + +async fn dump_tx_trace(prov: Provider, receipt: TransactionReceipt, name: &str) -> () +{ + let options = GethDebugTracingOptions::default(); + let trace = prov + .debug_trace_transaction(receipt.transaction_hash, options) .await - .expect("cannot confirm deploy") + .expect("SOME REASON"); + let filename = format!("{}_trace.json", name); + serde_json::to_writer(&File::create(filename).expect("cannot create file"), &trace) + .expect("reason"); } fn erc20_transfer( @@ -74,76 +100,8 @@ where async fn main() { log_init(); - // Compile contracts - info!("Compiling contracts..."); - let solc = Solc::default(); - info!("Solc version {}", solc.version().expect("version works")); - let mut contracts = HashMap::new(); - for (name, contract_path) in CONTRACTS { - let path_sol = Path::new(CONTRACTS_PATH).join(contract_path); - let inputs = CompilerInput::new(&path_sol).expect("Compile success"); - // ethers-solc: explicitly indicate the EvmVersion that corresponds to the zkevm circuit's - // supported Upgrade, e.g. `London/Shanghai/...` specifications. - let input = inputs - .clone() - .first_mut() - .expect("first exists") - .clone() - .evm_version(EvmVersion::London); - - // compilation will either fail with Err variant or return Ok(CompilerOutput) - // which may contain Errors or Warnings - let output = solc.compile_output(&input).unwrap(); - let mut deserializer: serde_json::Deserializer> = - serde_json::Deserializer::from_slice(&output); - // The contracts to test the worst-case usage of certain opcodes, such as SDIV, MLOAD, and - // EXTCODESIZE, generate big JSON compilation outputs. We disable the recursion limit to - // avoid parsing failure. - deserializer.disable_recursion_limit(); - let compiled = match CompilerOutput::deserialize(&mut deserializer) { - Err(error) => { - panic!("COMPILATION ERROR {:?}\n{:?}", &path_sol, error); - } - // CompilationOutput is succesfully created (might contain Errors or Warnings) - Ok(output) => { - info!("COMPILATION OK: {:?}", name); - output - } - }; - - if compiled.has_error() || compiled.has_warning(WARN) { - panic!( - "... but CompilerOutput contains errors/warnings: {:?}:\n{:#?}", - &path_sol, compiled.errors - ); - } - - let contract = compiled - .get(path_sol.to_str().expect("path is not str"), name) - .expect("contract not found"); - let abi = contract.abi.expect("no abi found").clone(); - let bin = contract.bin.expect("no bin found").clone(); - let bin_runtime = contract.bin_runtime.expect("no bin_runtime found").clone(); - let compiled_contract = CompiledContract { - path: path_sol.to_str().expect("path is not str").to_string(), - name: name.to_string(), - abi, - bin: bin.into_bytes().expect("bin"), - bin_runtime: bin_runtime.into_bytes().expect("bin_runtime"), - }; - - let mut path_json = path_sol.clone(); - path_json.set_extension("json"); - serde_json::to_writer( - &File::create(&path_json).expect("cannot create file"), - &compiled_contract, - ) - .expect("cannot serialize json into file"); - - contracts.insert(name.to_string(), compiled_contract); - } - let prov = get_provider(); + let mut contracts = HashMap::new(); // Wait for geth to be online. loop { @@ -200,83 +158,42 @@ async fn main() { let prov_wallet0 = Arc::new(SignerMiddleware::new(get_provider(), wallet0)); // Greeter - let contract = deploy( - prov_wallet0.clone(), - contracts.get("Greeter").expect("contract not found"), - U256::from(42), - ) - .await; - let block_num = prov.get_block_number().await.expect("cannot get block_num"); - blocks.insert("Deploy Greeter".to_string(), block_num.as_u64()); + let greeter_deployer = greeter::greeter::deploy(prov_wallet0.clone(), U256::from(42)) + .expect("Error building deployment Transaction"); + let (contract_abi, contract_address, block_number, _greeter_instance) = + deploy(greeter_deployer, "Greeter").await; + + contracts.insert("greeter".to_string(), contract_abi.clone()); deployments.insert( - "Greeter".to_string(), - (block_num.as_u64(), contract.address()), + "greeter".to_string(), + (block_number.as_u64(), contract_address), ); // OpenZeppelinERC20TestToken - let contract = deploy( - prov_wallet0.clone(), - contracts - .get("OpenZeppelinERC20TestToken") - .expect("contract not found"), - prov_wallet0.address(), - ) - .await; - let block_num = prov.get_block_number().await.expect("cannot get block_num"); - blocks.insert( - "Deploy OpenZeppelinERC20TestToken".to_string(), - block_num.as_u64(), - ); + let ozerc20tt_deployer = ozerc20tt::deploy(prov_wallet0.clone(), prov_wallet0.address()) + .expect("Error building deployment Transaction"); + let (contract_abi, contract_address, block_number, _ozerc20tt_instance) = + deploy(ozerc20tt_deployer, "OpenZeppelinERC20TestToken").await; + + contracts.insert("ozerc20tt".to_string(), contract_abi); deployments.insert( - "OpenZeppelinERC20TestToken".to_string(), - (block_num.as_u64(), contract.address()), + "ozerc20tt".to_string(), + (block_number.as_u64(), contract_address), ); // Deploy smart contracts for worst case block benches // - // CheckMload - let contract = deploy( - prov_wallet0.clone(), - contracts.get("CheckMload").expect("contract not found"), - (), - ) - .await; - let block_num = prov.get_block_number().await.expect("cannot get block_num"); - blocks.insert("Deploy CheckMload".to_string(), block_num.as_u64()); - deployments.insert( - "CheckMload".to_string(), - (block_num.as_u64(), contract.address()), - ); - - // CheckSdiv - let contract = deploy( - prov_wallet0.clone(), - contracts.get("CheckSdiv").expect("contract not found"), - (), - ) - .await; - let block_num = prov.get_block_number().await.expect("cannot get block_num"); - blocks.insert("Deploy CheckSdiv".to_string(), block_num.as_u64()); - deployments.insert( - "CheckSdiv".to_string(), - (block_num.as_u64(), contract.address()), - ); + // Benchmarks + let benchmarks_deployer = benchmarks::benchmarks::deploy(prov_wallet0.clone(), ()) + .expect("Error building deployment Transaction"); + let (contract_abi, contract_address, block_number, benchmarks_instance) = + deploy(benchmarks_deployer, "Benchmarks").await; - // CheckExtCodeSize100 - let contract = deploy( - prov_wallet0.clone(), - contracts - .get("CheckExtCodeSize100") - .expect("contract not found"), - (), - ) - .await; - let block_num = prov.get_block_number().await.expect("cannot get block_num"); - blocks.insert("Deploy CheckExtCodeSize100".to_string(), block_num.as_u64()); + contracts.insert("benchmarks".to_string(), contract_abi); deployments.insert( - "CheckExtCodeSize100".to_string(), - (block_num.as_u64(), contract.address()), + "benchmarks".to_string(), + (block_number.as_u64(), contract_address), ); // ETH transfers: Generate a block with multiple transfers @@ -338,14 +255,9 @@ async fn main() { info!("Generating ERC20 calls..."); - let contract_address = deployments - .get("OpenZeppelinERC20TestToken") - .expect("contract not found") - .1; - let contract_abi = &contracts - .get("OpenZeppelinERC20TestToken") - .expect("contract not found") - .abi; + let contract_address = deployments.get("ozerc20tt").expect("contract not found").1; + let contract_abi = &contracts.get("ozerc20tt").expect("contract not found"); + // .abi; // OpenZeppelin ERC20 single failed transfer (wallet2 sends 345.67 Tokens to // wallet3, but wallet2 has 0 Tokens) @@ -429,6 +341,44 @@ async fn main() { block_num.as_u64(), ); + // Create Transactions optimized for circuit benchmarks + // + // MLOAD (EVM) + info!("Sending Tx optimized for maximum MLOAD opcode calls up to 300k gas"); + cli.miner_start().await.expect("cannot start miner"); + let bench_tx = benchmarks_instance.check_mload(benchmarks::Len(77500)); + let tx_call = bench_tx + .send() + .await + .expect("Could not confirm transaction"); + let tx_receipt = tx_call + .await + .expect("failed to fetch the transaction receipt") + .unwrap(); + blocks.insert( + "MLOAD".to_string(), + tx_receipt.block_number.unwrap().as_u64(), + ); + // dump_tx_trace(get_provider(), tx_receipt, "mload").await; + + // SDIV (STATE) + info!("Sending Tx optimized for maximum SDIV opcode calls up to 300k gas"); + cli.miner_start().await.expect("cannot start miner"); + let bench_tx = benchmarks_instance.check_sdiv(benchmarks::Len(32400)); + let tx_call = bench_tx + .send() + .await + .expect("Could not confirm transaction"); + let tx_receipt = tx_call + .await + .expect("failed to fetch the transaction receipt") + .unwrap(); + blocks.insert( + "SDIV".to_string(), + tx_receipt.block_number.unwrap().as_u64(), + ); + // dump_tx_trace(get_provider(), tx_receipt, "sdiv").await; + let gen_data = GenDataOutput { coinbase: accounts[0], wallets: wallets.iter().map(|w| w.address()).collect(), From aaaef53291ee1b43412709e2ccc2b304cfdcfd12 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Tue, 19 Sep 2023 12:57:54 +0300 Subject: [PATCH 07/54] formatting --- integration-tests/src/bin/gen_blockchain_data.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/integration-tests/src/bin/gen_blockchain_data.rs b/integration-tests/src/bin/gen_blockchain_data.rs index 59898b882d..ac60de4049 100644 --- a/integration-tests/src/bin/gen_blockchain_data.rs +++ b/integration-tests/src/bin/gen_blockchain_data.rs @@ -51,8 +51,7 @@ where (c_abi, contract_address, block_number, contract_instance) } -async fn dump_tx_trace(prov: Provider, receipt: TransactionReceipt, name: &str) -> () -{ +async fn dump_tx_trace(prov: Provider, receipt: TransactionReceipt, name: &str) -> () { let options = GethDebugTracingOptions::default(); let trace = prov .debug_trace_transaction(receipt.transaction_hash, options) From 1d32a9a1bad9466af883386464a4c20eff121204 Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Thu, 21 Sep 2023 13:44:22 +0300 Subject: [PATCH 08/54] add git submodule update step in action workflow yml --- .github/workflows/integration.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 2ae9f72139..bfd299550e 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -93,6 +93,8 @@ jobs: ~/.cargo/git/db/ target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Update git submodule + run: git submodule update --init --recursive --checkout contracts/vendor # Run an initial build in a separate step to split the build time from execution time - name: Build bins run: cargo build --bin gen_blockchain_data From 86427459b6e94985e15052c646930c67fc4ac9e9 Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Thu, 21 Sep 2023 14:00:03 +0300 Subject: [PATCH 09/54] Update integration.yml --- .github/workflows/integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index bfd299550e..6954385f0e 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -94,7 +94,7 @@ jobs: target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Update git submodule - run: git submodule update --init --recursive --checkout contracts/vendor + run: git submodule update --init --recursive --checkout integration-tests/contracts/vendor/openzeppelin-contracts # Run an initial build in a separate step to split the build time from execution time - name: Build bins run: cargo build --bin gen_blockchain_data From 6d20243d5398de33e5c091c3460960d9d601edab Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Thu, 21 Sep 2023 14:14:16 +0300 Subject: [PATCH 10/54] remove git submodule update step from run.sh >> now a step of workflow yaml --- integration-tests/run.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/integration-tests/run.sh b/integration-tests/run.sh index 974af3e14b..88fef4f70c 100755 --- a/integration-tests/run.sh +++ b/integration-tests/run.sh @@ -91,7 +91,6 @@ fi if [ -n "$STEP_GENDATA" ]; then echo "+ Gen blockchain data..." - git submodule update --init --recursive --checkout contracts/vendor rm gendata_output.json > /dev/null 2>&1 || true cargo run --bin gen_blockchain_data fi From a19b745d775fcde43d004698f625cc2bfc824810 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Thu, 21 Sep 2023 16:17:57 +0300 Subject: [PATCH 11/54] fix contract path/name --- integration-tests/tests/rpc.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/integration-tests/tests/rpc.rs b/integration-tests/tests/rpc.rs index 9285c9b411..bcdc0e0869 100644 --- a/integration-tests/tests/rpc.rs +++ b/integration-tests/tests/rpc.rs @@ -41,7 +41,7 @@ async fn test_get_block_by_number_by_hash() { #[tokio::test] async fn test_trace_block_by_number_by_hash() { - let block_num = GEN_DATA.deployments.get("Greeter").unwrap().0; + let block_num = GEN_DATA.deployments.get("greeter").unwrap().0; let cli = get_client(); let block = cli.get_block_by_number(block_num.into()).await.unwrap(); @@ -53,8 +53,8 @@ async fn test_trace_block_by_number_by_hash() { #[tokio::test] async fn test_get_contract_code() { - let contract_name = "Greeter"; - let contract_path_json = "greeter/Greeter.json"; + let contract_name = "greeter"; + let contract_path_json = "Greeter.json"; let (block_num, address) = GEN_DATA.deployments.get(contract_name).unwrap(); let path_json = Path::new(CONTRACTS_PATH).join(contract_path_json); @@ -69,7 +69,7 @@ async fn test_get_contract_code() { #[tokio::test] async fn test_get_proof() { - let (block_num, address) = GEN_DATA.deployments.get("Greeter").unwrap(); + let (block_num, address) = GEN_DATA.deployments.get("greeter").unwrap(); // Key 0 corresponds to `Greeter.number`, which is initialized with 0x2a. let expected_storage_proof_json = r#"{ "key": "0x0", From c0c5118df9b56e668b7e6d5355ccbd6b801478f0 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Thu, 21 Sep 2023 19:25:53 +0300 Subject: [PATCH 12/54] add an entry in blocks hashmap for Deploy Greeter (to be consumend by declare_tests macro --- integration-tests/src/bin/gen_blockchain_data.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integration-tests/src/bin/gen_blockchain_data.rs b/integration-tests/src/bin/gen_blockchain_data.rs index ac60de4049..de877b9fb9 100644 --- a/integration-tests/src/bin/gen_blockchain_data.rs +++ b/integration-tests/src/bin/gen_blockchain_data.rs @@ -167,6 +167,8 @@ async fn main() { "greeter".to_string(), (block_number.as_u64(), contract_address), ); + blocks.insert("Deploy Greeter".to_string(), block_num.as_u64()); + // OpenZeppelinERC20TestToken let ozerc20tt_deployer = ozerc20tt::deploy(prov_wallet0.clone(), prov_wallet0.address()) From 1fe5cac54982b58746cf9561a09f48a0e80bc0bb Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Fri, 22 Sep 2023 06:47:50 +0300 Subject: [PATCH 13/54] add submodule update back in run.sh. otherwise tests do not run locally --- integration-tests/run.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/integration-tests/run.sh b/integration-tests/run.sh index 88fef4f70c..974af3e14b 100755 --- a/integration-tests/run.sh +++ b/integration-tests/run.sh @@ -91,6 +91,7 @@ fi if [ -n "$STEP_GENDATA" ]; then echo "+ Gen blockchain data..." + git submodule update --init --recursive --checkout contracts/vendor rm gendata_output.json > /dev/null 2>&1 || true cargo run --bin gen_blockchain_data fi From e37265e86d8cafd62b00c09f69433df3f1e1f0fb Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Fri, 22 Sep 2023 06:50:21 +0300 Subject: [PATCH 14/54] formatting --- integration-tests/src/bin/gen_blockchain_data.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/integration-tests/src/bin/gen_blockchain_data.rs b/integration-tests/src/bin/gen_blockchain_data.rs index de877b9fb9..e44c123f2e 100644 --- a/integration-tests/src/bin/gen_blockchain_data.rs +++ b/integration-tests/src/bin/gen_blockchain_data.rs @@ -168,7 +168,6 @@ async fn main() { (block_number.as_u64(), contract_address), ); blocks.insert("Deploy Greeter".to_string(), block_num.as_u64()); - // OpenZeppelinERC20TestToken let ozerc20tt_deployer = ozerc20tt::deploy(prov_wallet0.clone(), prov_wallet0.address()) From 6342b4887feaf9cf5ab424a87f195fc7535242ff Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Fri, 22 Sep 2023 13:45:43 +0300 Subject: [PATCH 15/54] modify lints.yml workflow to run cargo build before fmt checks --- .github/workflows/lints.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml index 78d8c137aa..18ea7c62f6 100644 --- a/.github/workflows/lints.yml +++ b/.github/workflows/lints.yml @@ -59,6 +59,12 @@ jobs: target/ key: lint-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Update ERC20 git submodule + run: git submodule update --init --recursive --checkout integration-tests/contracts/vendor/openzeppelin-contracts + - name: Cargo Build + uses: actions-rs/cargo@v1 + with: + command: build - name: Check code format uses: actions-rs/cargo@v1 with: From 05611d130a85fecfefeb9263e8c5947f442e8542 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Fri, 22 Sep 2023 14:23:13 +0300 Subject: [PATCH 16/54] lints.tml fix typos --- .github/workflows/lints.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml index 18ea7c62f6..5290132917 100644 --- a/.github/workflows/lints.yml +++ b/.github/workflows/lints.yml @@ -60,7 +60,7 @@ jobs: key: lint-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Update ERC20 git submodule - run: git submodule update --init --recursive --checkout integration-tests/contracts/vendor/openzeppelin-contracts + run: git submodule update --init --recursive --checkout integration-tests/contracts/vendor/openzeppelin-contracts - name: Cargo Build uses: actions-rs/cargo@v1 with: From 20382f0b6b4da3d0b8473586a5c988518979b571 Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Fri, 22 Sep 2023 14:26:35 +0300 Subject: [PATCH 17/54] typos lints.yml --- .github/workflows/lints.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml index 5290132917..d62e0741a6 100644 --- a/.github/workflows/lints.yml +++ b/.github/workflows/lints.yml @@ -60,8 +60,8 @@ jobs: key: lint-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Update ERC20 git submodule - run: git submodule update --init --recursive --checkout integration-tests/contracts/vendor/openzeppelin-contracts - - name: Cargo Build + run: git submodule update --init --recursive --checkout integration-tests/contracts/vendor/openzeppelin-contracts + - name: Cargo build uses: actions-rs/cargo@v1 with: command: build From 5284fff25bdd6e70574d3839a644dd4f503b3d03 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 26 Sep 2023 15:54:53 +0300 Subject: [PATCH 18/54] Install solc --- .github/workflows/lints.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml index d62e0741a6..102a1eba0f 100644 --- a/.github/workflows/lints.yml +++ b/.github/workflows/lints.yml @@ -59,6 +59,10 @@ jobs: target/ key: lint-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Install solc + run: | + wget -O /usr/bin/solc https://github.com/ethereum/solidity/releases/download/v0.8.21/solc-static-linux + chmod +x /usr/bin/solc - name: Update ERC20 git submodule run: git submodule update --init --recursive --checkout integration-tests/contracts/vendor/openzeppelin-contracts - name: Cargo build From db90c4a1a3aff5321f7802ebede7c32b8aa7a291 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 26 Sep 2023 15:57:04 +0300 Subject: [PATCH 19/54] Add sudo to command --- .github/workflows/lints.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml index 102a1eba0f..ad1f9c938d 100644 --- a/.github/workflows/lints.yml +++ b/.github/workflows/lints.yml @@ -61,8 +61,8 @@ jobs: - name: Install solc run: | - wget -O /usr/bin/solc https://github.com/ethereum/solidity/releases/download/v0.8.21/solc-static-linux - chmod +x /usr/bin/solc + sudo wget -O /usr/bin/solc https://github.com/ethereum/solidity/releases/download/v0.8.21/solc-static-linux + sudo chmod +x /usr/bin/solc - name: Update ERC20 git submodule run: git submodule update --init --recursive --checkout integration-tests/contracts/vendor/openzeppelin-contracts - name: Cargo build From 377faa2ba3a28bbb76af20f83f080983b3114cea Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 26 Sep 2023 16:33:00 +0300 Subject: [PATCH 20/54] Build bin gen_blockchain_data --- .github/workflows/lints.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml index ad1f9c938d..a05b19d144 100644 --- a/.github/workflows/lints.yml +++ b/.github/workflows/lints.yml @@ -68,7 +68,7 @@ jobs: - name: Cargo build uses: actions-rs/cargo@v1 with: - command: build + command: build --bin gen_blockchain_data - name: Check code format uses: actions-rs/cargo@v1 with: From b68677d0199465a9fb7bbd458f908ccc185a0738 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 26 Sep 2023 16:36:05 +0300 Subject: [PATCH 21/54] Fix cargo args --- .github/workflows/lints.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml index a05b19d144..cfaea3d443 100644 --- a/.github/workflows/lints.yml +++ b/.github/workflows/lints.yml @@ -68,7 +68,8 @@ jobs: - name: Cargo build uses: actions-rs/cargo@v1 with: - command: build --bin gen_blockchain_data + command: build + args: --bin gen_blockchain_data - name: Check code format uses: actions-rs/cargo@v1 with: From 79ca544668c320682f849542c75d807befb98b8b Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Wed, 27 Sep 2023 12:03:52 +0300 Subject: [PATCH 22/54] fix clippy errors on build script --- integration-tests/build.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/integration-tests/build.rs b/integration-tests/build.rs index 0c4e34f166..db655b8c09 100644 --- a/integration-tests/build.rs +++ b/integration-tests/build.rs @@ -6,10 +6,7 @@ use ethers::{ use ethers_contract_abigen::Abigen; use log::info; use serde::{Deserialize, Serialize}; -use std::{ - fs::File, - path::{Path, PathBuf}, -}; +use std::{fs::File, path::Path}; #[derive(Serialize, Deserialize, Debug)] pub struct CompiledContract { @@ -120,24 +117,27 @@ fn main() { for entry in glob::glob("./contracts/*.json").unwrap() { match entry { Ok(path) => { - let _g = generate_rust_contract_bindings(BINDINGS_DR, &path); + generate_rust_contract_bindings(BINDINGS_DR, &path); } Err(e) => eprintln!("{:#?}", e), } } } -fn generate_rust_contract_bindings(bindings_dir: &str, file: &PathBuf) -> () { - let abi_source = file.clone(); +fn generate_rust_contract_bindings(bindings_dir: &str, file: &Path) { + const SLASH: char = '/'; + const DOT: char = '.'; + + let abi_source = file.to_path_buf(); let tempbinding = file - .clone() + .to_path_buf() .into_os_string() .into_string() .expect("FAILED CONVERSION TO STRING"); - let filenamevec: Vec<&str> = tempbinding.split("/").collect(); + let filenamevec: Vec<&str> = tempbinding.split(SLASH).collect(); let filename = filenamevec[1]; - let contractnamevector: Vec<&str> = filename.split(".").collect(); + let contractnamevector: Vec<&str> = filename.split(DOT).collect(); let contractname = contractnamevector[0].to_lowercase(); let destpath = Path::new(&bindings_dir).join([contractname.clone(), "rs".to_string()].join(".")); From 3b928d211b5f83456fcc21ba23c9959fca5f5520 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Fri, 29 Sep 2023 16:13:55 +0300 Subject: [PATCH 23/54] exclude generated code from cargo fmt checks --- integration-tests/rustfmt.toml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 integration-tests/rustfmt.toml diff --git a/integration-tests/rustfmt.toml b/integration-tests/rustfmt.toml new file mode 100644 index 0000000000..0851690ba5 --- /dev/null +++ b/integration-tests/rustfmt.toml @@ -0,0 +1,5 @@ +ignore = [ + "src/benchmarks.rs", + "src/greeter.rs", + "src/openzeppelinerc20testtoken.rs" +] \ No newline at end of file From 6a9f10fea1484c13f61a5382bf47ca8a1f01c5b6 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Thu, 5 Oct 2023 23:38:14 +0300 Subject: [PATCH 24/54] git ignore generated bindings and exclule from fmt check --- integration-tests/.gitignore | 3 +++ integration-tests/rustfmt.toml | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/integration-tests/.gitignore b/integration-tests/.gitignore index bbcc9ac930..2f86c1ca28 100644 --- a/integration-tests/.gitignore +++ b/integration-tests/.gitignore @@ -1 +1,4 @@ gendata_output.json +src/benchmarks.rs +src/greeter.rs +src/openzeppelinerc20testtoken.rs \ No newline at end of file diff --git a/integration-tests/rustfmt.toml b/integration-tests/rustfmt.toml index 0851690ba5..f33334a768 100644 --- a/integration-tests/rustfmt.toml +++ b/integration-tests/rustfmt.toml @@ -1,5 +1,5 @@ ignore = [ - "src/benchmarks.rs", - "src/greeter.rs", - "src/openzeppelinerc20testtoken.rs" + "./src/benchmarks.rs", + "./src/greeter.rs", + "./src/openzeppelinerc20testtoken.rs" ] \ No newline at end of file From 756fdcd516dbd42e3af9bd5d6a03351d12a263f7 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Thu, 5 Oct 2023 23:56:01 +0300 Subject: [PATCH 25/54] git ignore generated bindings --- integration-tests/.gitignore | 6 +++--- integration-tests/rustfmt.toml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/integration-tests/.gitignore b/integration-tests/.gitignore index 2f86c1ca28..aa2b364dcf 100644 --- a/integration-tests/.gitignore +++ b/integration-tests/.gitignore @@ -1,4 +1,4 @@ gendata_output.json -src/benchmarks.rs -src/greeter.rs -src/openzeppelinerc20testtoken.rs \ No newline at end of file +src/bindings_benchmarks.rs +src/bindings_greeter.rs +src/bindings_openzeppelinerc20testtoken.rs \ No newline at end of file diff --git a/integration-tests/rustfmt.toml b/integration-tests/rustfmt.toml index f33334a768..eba3a948d9 100644 --- a/integration-tests/rustfmt.toml +++ b/integration-tests/rustfmt.toml @@ -1,5 +1,5 @@ ignore = [ - "./src/benchmarks.rs", - "./src/greeter.rs", - "./src/openzeppelinerc20testtoken.rs" + "src/bindings_benchmarks.rs", + "src/bindings_greeter.rs", + "src/bindings_openzeppelinerc20testtoken.rs" ] \ No newline at end of file From cf3e5a0c98b2599ac2fb608026d5fc047ab7d8f7 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Thu, 5 Oct 2023 23:56:44 +0300 Subject: [PATCH 26/54] fix clippy error: module inception --- integration-tests/build.rs | 4 +++- .../src/bin/gen_blockchain_data.rs | 17 ++++++++++------- integration-tests/src/lib.rs | 8 ++++---- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/integration-tests/build.rs b/integration-tests/build.rs index db655b8c09..637b9e9062 100644 --- a/integration-tests/build.rs +++ b/integration-tests/build.rs @@ -139,8 +139,10 @@ fn generate_rust_contract_bindings(bindings_dir: &str, file: &Path) { let contractnamevector: Vec<&str> = filename.split(DOT).collect(); let contractname = contractnamevector[0].to_lowercase(); + let destpath = format!("{}{}{}", "bindings_", contractname, ".rs"); let destpath = - Path::new(&bindings_dir).join([contractname.clone(), "rs".to_string()].join(".")); + // Path::new(&bindings_dir).join([contractname.clone(), "rs".to_string()].join(".")); + Path::new(&bindings_dir).join(destpath); let _ = Abigen::new( contractname, abi_source.into_os_string().into_string().expect("error"), diff --git a/integration-tests/src/bin/gen_blockchain_data.rs b/integration-tests/src/bin/gen_blockchain_data.rs index e44c123f2e..bc761980dc 100644 --- a/integration-tests/src/bin/gen_blockchain_data.rs +++ b/integration-tests/src/bin/gen_blockchain_data.rs @@ -17,9 +17,12 @@ use ethers::{ signers::Signer, }; use integration_tests::{ - benchmarks::*, get_client, get_provider, get_wallet, greeter::*, log_init, - openzeppelinerc20testtoken::openzeppelinerc20testtoken as ozerc20tt, GenDataOutput, + bindings_benchmarks::{benchmarks::benchmarks, Len}, + bindings_greeter::greeter::greeter, + bindings_openzeppelinerc20testtoken::openzeppelinerc_2_0testtoken::openzeppelinerc20testtoken as ozerc20tt, + get_client, get_provider, get_wallet, log_init, GenDataOutput, }; + use log::{error, info}; use std::{collections::HashMap, fs::File, sync::Arc, thread::sleep, time::Duration}; @@ -51,7 +54,7 @@ where (c_abi, contract_address, block_number, contract_instance) } -async fn dump_tx_trace(prov: Provider, receipt: TransactionReceipt, name: &str) -> () { +async fn dump_tx_trace(prov: Provider, receipt: TransactionReceipt, name: &str) { let options = GethDebugTracingOptions::default(); let trace = prov .debug_trace_transaction(receipt.transaction_hash, options) @@ -157,7 +160,7 @@ async fn main() { let prov_wallet0 = Arc::new(SignerMiddleware::new(get_provider(), wallet0)); // Greeter - let greeter_deployer = greeter::greeter::deploy(prov_wallet0.clone(), U256::from(42)) + let greeter_deployer = greeter::deploy(prov_wallet0.clone(), U256::from(42)) .expect("Error building deployment Transaction"); let (contract_abi, contract_address, block_number, _greeter_instance) = deploy(greeter_deployer, "Greeter").await; @@ -185,7 +188,7 @@ async fn main() { // // Benchmarks - let benchmarks_deployer = benchmarks::benchmarks::deploy(prov_wallet0.clone(), ()) + let benchmarks_deployer = benchmarks::deploy(prov_wallet0.clone(), ()) .expect("Error building deployment Transaction"); let (contract_abi, contract_address, block_number, benchmarks_instance) = deploy(benchmarks_deployer, "Benchmarks").await; @@ -346,7 +349,7 @@ async fn main() { // MLOAD (EVM) info!("Sending Tx optimized for maximum MLOAD opcode calls up to 300k gas"); cli.miner_start().await.expect("cannot start miner"); - let bench_tx = benchmarks_instance.check_mload(benchmarks::Len(77500)); + let bench_tx = benchmarks_instance.check_mload(Len(77500)); let tx_call = bench_tx .send() .await @@ -364,7 +367,7 @@ async fn main() { // SDIV (STATE) info!("Sending Tx optimized for maximum SDIV opcode calls up to 300k gas"); cli.miner_start().await.expect("cannot start miner"); - let bench_tx = benchmarks_instance.check_sdiv(benchmarks::Len(32400)); + let bench_tx = benchmarks_instance.check_sdiv(Len(32400)); let tx_call = bench_tx .send() .await diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 0d50552049..cd3e0ec0f2 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -150,10 +150,10 @@ pub struct CompiledContract { } #[allow(missing_docs)] -pub mod benchmarks; +pub mod bindings_benchmarks; #[allow(missing_docs)] -pub mod greeter; +pub mod bindings_greeter; +#[allow(missing_docs)] +pub mod bindings_openzeppelinerc20testtoken; /// Common code for integration tests of circuits. pub mod integration_test_circuits; -#[allow(missing_docs)] -pub mod openzeppelinerc20testtoken; From 0929b7c03468e51f435c0a8edb87f05247c5b025 Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Fri, 6 Oct 2023 00:07:30 +0300 Subject: [PATCH 27/54] add "install solc" and update erc20 submodule steps in wf main-tests --- .github/workflows/main-tests.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/main-tests.yml b/.github/workflows/main-tests.yml index 9d58eb2794..60bb6ada75 100644 --- a/.github/workflows/main-tests.yml +++ b/.github/workflows/main-tests.yml @@ -66,6 +66,13 @@ jobs: ~/.cargo/git/db/ target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Install solc + run: | + sudo wget -O /usr/bin/solc https://github.com/ethereum/solidity/releases/download/v0.8.21/solc-static-linux + sudo chmod +x /usr/bin/solc + - name: Update ERC20 git submodule + run: git submodule update --init --recursive --checkout integration-tests/contracts/vendor/openzeppelin-contracts + - name: Cargo build - name: Run light tests # light tests are run in parallel uses: actions-rs/cargo@v1 with: From fcd0d7ca0812a14ce02019b2c6997e4d3c4de901 Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Fri, 6 Oct 2023 00:20:39 +0300 Subject: [PATCH 28/54] remove incorrent line --- .github/workflows/main-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main-tests.yml b/.github/workflows/main-tests.yml index 60bb6ada75..df57c5d0a6 100644 --- a/.github/workflows/main-tests.yml +++ b/.github/workflows/main-tests.yml @@ -72,7 +72,6 @@ jobs: sudo chmod +x /usr/bin/solc - name: Update ERC20 git submodule run: git submodule update --init --recursive --checkout integration-tests/contracts/vendor/openzeppelin-contracts - - name: Cargo build - name: Run light tests # light tests are run in parallel uses: actions-rs/cargo@v1 with: From 5be6c47cf2fdb95c80f749861e57814d3f5a3381 Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Fri, 6 Oct 2023 00:55:00 +0300 Subject: [PATCH 29/54] Update main-tests.yml --- .github/workflows/main-tests.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/main-tests.yml b/.github/workflows/main-tests.yml index df57c5d0a6..be112286dc 100644 --- a/.github/workflows/main-tests.yml +++ b/.github/workflows/main-tests.yml @@ -121,6 +121,12 @@ jobs: ~/.cargo/git/db/ target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Install solc + run: | + sudo wget -O /usr/bin/solc https://github.com/ethereum/solidity/releases/download/v0.8.21/solc-static-linux + sudo chmod +x /usr/bin/solc + - name: Update ERC20 git submodule + run: git submodule update --init --recursive --checkout integration-tests/contracts/vendor/openzeppelin-contracts - name: Run heavy tests # heavy tests are run serially to avoid OOM uses: actions-rs/cargo@v1 with: @@ -163,6 +169,12 @@ jobs: ~/.cargo/git/db/ target/ key: build-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Install solc + run: | + sudo wget -O /usr/bin/solc https://github.com/ethereum/solidity/releases/download/v0.8.21/solc-static-linux + sudo chmod +x /usr/bin/solc + - name: Update ERC20 git submodule + run: git submodule update --init --recursive --checkout integration-tests/contracts/vendor/openzeppelin-contracts - name: cargo build uses: actions-rs/cargo@v1 with: From 8e224aa46b05f0368144eab39bc4f5a985ce06da Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Fri, 6 Oct 2023 01:41:01 +0300 Subject: [PATCH 30/54] indentation main-tests.yml --- .github/workflows/main-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main-tests.yml b/.github/workflows/main-tests.yml index be112286dc..8298724130 100644 --- a/.github/workflows/main-tests.yml +++ b/.github/workflows/main-tests.yml @@ -169,7 +169,7 @@ jobs: ~/.cargo/git/db/ target/ key: build-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Install solc + - name: Install solc run: | sudo wget -O /usr/bin/solc https://github.com/ethereum/solidity/releases/download/v0.8.21/solc-static-linux sudo chmod +x /usr/bin/solc From 323209f0c6946efa1cd3d0da13455f5268299c56 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Fri, 6 Oct 2023 01:56:54 +0300 Subject: [PATCH 31/54] move rustfmt.toml ignore block to project root --- integration-tests/rustfmt.toml | 5 ----- rustfmt.toml | 8 +++++++- 2 files changed, 7 insertions(+), 6 deletions(-) delete mode 100644 integration-tests/rustfmt.toml diff --git a/integration-tests/rustfmt.toml b/integration-tests/rustfmt.toml deleted file mode 100644 index eba3a948d9..0000000000 --- a/integration-tests/rustfmt.toml +++ /dev/null @@ -1,5 +0,0 @@ -ignore = [ - "src/bindings_benchmarks.rs", - "src/bindings_greeter.rs", - "src/bindings_openzeppelinerc20testtoken.rs" -] \ No newline at end of file diff --git a/rustfmt.toml b/rustfmt.toml index 526145466c..e19636a84f 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -6,4 +6,10 @@ max_width = 100 newline_style = "Unix" normalize_comments = true reorder_imports = true -wrap_comments = true \ No newline at end of file +wrap_comments = true + +ignore = [ + "integration-tests/src/bindings_benchmarks.rs", + "integration-tests/src/bindings_greeter.rs", + "integration-tests/src/bindings_openzeppelinerc20testtoken.rs" +] \ No newline at end of file From 92c2457cd9866aa3d73ea1122f3cdde8dd757169 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Fri, 6 Oct 2023 02:27:02 +0300 Subject: [PATCH 32/54] add #[allow(clippy::all)] to lib.rs for generated modules --- integration-tests/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index cd3e0ec0f2..d710b91911 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -150,10 +150,13 @@ pub struct CompiledContract { } #[allow(missing_docs)] +#[allow(clippy::all)] pub mod bindings_benchmarks; #[allow(missing_docs)] +#[allow(clippy::all)] pub mod bindings_greeter; #[allow(missing_docs)] +#[allow(clippy::all)] pub mod bindings_openzeppelinerc20testtoken; /// Common code for integration tests of circuits. pub mod integration_test_circuits; From ca1199fd4ea0e907792d9977e0bd6b42bc0a6b7a Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Fri, 6 Oct 2023 02:39:33 +0300 Subject: [PATCH 33/54] remove --args from build command --- .github/workflows/lints.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml index cfaea3d443..ad1f9c938d 100644 --- a/.github/workflows/lints.yml +++ b/.github/workflows/lints.yml @@ -69,7 +69,6 @@ jobs: uses: actions-rs/cargo@v1 with: command: build - args: --bin gen_blockchain_data - name: Check code format uses: actions-rs/cargo@v1 with: From accd9e5b9d7bee6665bec928cb78f3a22427d7e6 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Mon, 9 Oct 2023 13:19:02 +0300 Subject: [PATCH 34/54] use EnumString macro from from strum_macros --- testool/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testool/src/main.rs b/testool/src/main.rs index e521420ec6..e94bffff9d 100644 --- a/testool/src/main.rs +++ b/testool/src/main.rs @@ -16,7 +16,7 @@ use statetest::{ StateTest, }; use std::{collections::HashSet, path::PathBuf, time::SystemTime}; -use strum::EnumString; +use strum_macros::EnumString; const REPORT_FOLDER: &str = "report"; const CODEHASH_FILE: &str = "./codehash.txt"; From cd607d7e2b1cf7838426309fccb132f578ced22e Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Mon, 9 Oct 2023 13:33:15 +0300 Subject: [PATCH 35/54] allow unused function dump_tx_trace --- integration-tests/src/bin/gen_blockchain_data.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/integration-tests/src/bin/gen_blockchain_data.rs b/integration-tests/src/bin/gen_blockchain_data.rs index bc761980dc..d96f25a217 100644 --- a/integration-tests/src/bin/gen_blockchain_data.rs +++ b/integration-tests/src/bin/gen_blockchain_data.rs @@ -54,6 +54,7 @@ where (c_abi, contract_address, block_number, contract_instance) } +#[allow(dead_code)] async fn dump_tx_trace(prov: Provider, receipt: TransactionReceipt, name: &str) { let options = GethDebugTracingOptions::default(); let trace = prov From 28f6ffca5fa3bfd8b10c582bc7bc4367a517fb04 Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:48:18 +0300 Subject: [PATCH 36/54] Update integration-tests/src/bin/gen_blockchain_data.rs Co-authored-by: Chih Cheng Liang --- integration-tests/src/bin/gen_blockchain_data.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/integration-tests/src/bin/gen_blockchain_data.rs b/integration-tests/src/bin/gen_blockchain_data.rs index d96f25a217..38b2b39725 100644 --- a/integration-tests/src/bin/gen_blockchain_data.rs +++ b/integration-tests/src/bin/gen_blockchain_data.rs @@ -381,7 +381,6 @@ async fn main() { "SDIV".to_string(), tx_receipt.block_number.unwrap().as_u64(), ); - // dump_tx_trace(get_provider(), tx_receipt, "sdiv").await; let gen_data = GenDataOutput { coinbase: accounts[0], From 46137bd907047a390c11088dc537023404b4c1da Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:49:13 +0300 Subject: [PATCH 37/54] Update integration-tests/build.rs Co-authored-by: Chih Cheng Liang --- integration-tests/build.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/integration-tests/build.rs b/integration-tests/build.rs index 637b9e9062..4ff7d593b4 100644 --- a/integration-tests/build.rs +++ b/integration-tests/build.rs @@ -141,7 +141,6 @@ fn generate_rust_contract_bindings(bindings_dir: &str, file: &Path) { let contractname = contractnamevector[0].to_lowercase(); let destpath = format!("{}{}{}", "bindings_", contractname, ".rs"); let destpath = - // Path::new(&bindings_dir).join([contractname.clone(), "rs".to_string()].join(".")); Path::new(&bindings_dir).join(destpath); let _ = Abigen::new( contractname, From 758d9f8ff4867739308e0aa8a2f752de0013b204 Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:49:26 +0300 Subject: [PATCH 38/54] Update integration-tests/src/bin/gen_blockchain_data.rs Co-authored-by: Chih Cheng Liang --- integration-tests/src/bin/gen_blockchain_data.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/integration-tests/src/bin/gen_blockchain_data.rs b/integration-tests/src/bin/gen_blockchain_data.rs index 38b2b39725..0dd4a1af08 100644 --- a/integration-tests/src/bin/gen_blockchain_data.rs +++ b/integration-tests/src/bin/gen_blockchain_data.rs @@ -363,7 +363,6 @@ async fn main() { "MLOAD".to_string(), tx_receipt.block_number.unwrap().as_u64(), ); - // dump_tx_trace(get_provider(), tx_receipt, "mload").await; // SDIV (STATE) info!("Sending Tx optimized for maximum SDIV opcode calls up to 300k gas"); From 098234571345b20cb239b34439aa1b6f4787c425 Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:49:43 +0300 Subject: [PATCH 39/54] Update integration-tests/src/bin/gen_blockchain_data.rs Co-authored-by: Chih Cheng Liang --- integration-tests/src/bin/gen_blockchain_data.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/integration-tests/src/bin/gen_blockchain_data.rs b/integration-tests/src/bin/gen_blockchain_data.rs index 0dd4a1af08..bb18a07741 100644 --- a/integration-tests/src/bin/gen_blockchain_data.rs +++ b/integration-tests/src/bin/gen_blockchain_data.rs @@ -261,7 +261,6 @@ async fn main() { let contract_address = deployments.get("ozerc20tt").expect("contract not found").1; let contract_abi = &contracts.get("ozerc20tt").expect("contract not found"); - // .abi; // OpenZeppelin ERC20 single failed transfer (wallet2 sends 345.67 Tokens to // wallet3, but wallet2 has 0 Tokens) From 6422b8cd24d756a81902936de73aa460162fda37 Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Tue, 10 Oct 2023 22:38:03 +0300 Subject: [PATCH 40/54] Update build.rs fmt --- integration-tests/build.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/integration-tests/build.rs b/integration-tests/build.rs index 4ff7d593b4..0e67b37f67 100644 --- a/integration-tests/build.rs +++ b/integration-tests/build.rs @@ -140,8 +140,7 @@ fn generate_rust_contract_bindings(bindings_dir: &str, file: &Path) { let contractnamevector: Vec<&str> = filename.split(DOT).collect(); let contractname = contractnamevector[0].to_lowercase(); let destpath = format!("{}{}{}", "bindings_", contractname, ".rs"); - let destpath = - Path::new(&bindings_dir).join(destpath); + let destpath = Path::new(&bindings_dir).join(destpath); let _ = Abigen::new( contractname, abi_source.into_os_string().into_string().expect("error"), From 2c61487b7c595f300929f52b756b2c635cf14b30 Mon Sep 17 00:00:00 2001 From: testuser-at-490752553772 Date: Fri, 13 Oct 2023 11:23:54 +0300 Subject: [PATCH 41/54] error handling for build script --- Cargo.lock | 43 +++++++-- integration-tests/Cargo.toml | 5 +- integration-tests/build.rs | 181 ++++++++++++++++++++++++++--------- 3 files changed, 179 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f3d95dcd21..1828190b5b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1098,6 +1098,16 @@ dependencies = [ "libc", ] +[[package]] +name = "error" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6e606f14042bb87cc02ef6a14db6c90ab92ed6f62d87e69377bc759fd7987cc" +dependencies = [ + "traitobject", + "typeable", +] + [[package]] name = "eth-keystore" version = "0.5.0" @@ -2128,6 +2138,7 @@ dependencies = [ "bus-mapping", "env", "env_logger", + "error", "eth-types", "ethers", "ethers-contract-abigen", @@ -2143,6 +2154,8 @@ dependencies = [ "rand_xorshift", "serde", "serde_json", + "this", + "thiserror", "tokio", "uneval", "url", @@ -4041,20 +4054,26 @@ version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" +[[package]] +name = "this" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e044516ef2cdfc2f4426e8f7c4d115a77a2235700b918411482bba13d528d518" + [[package]] name = "thiserror" -version = "1.0.44" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.44" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", @@ -4259,6 +4278,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "traitobject" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" + [[package]] name = "try-lock" version = "0.2.4" @@ -4286,6 +4311,12 @@ dependencies = [ "webpki", ] +[[package]] +name = "typeable" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" + [[package]] name = "typenum" version = "1.16.0" @@ -4744,8 +4775,8 @@ dependencies = [ "serde_json", "sha3 0.10.8", "snark-verifier", - "strum", - "strum_macros", + "strum 0.24.1", + "strum_macros 0.24.3", "thiserror", ] diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 70641c079f..ed2c692516 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -25,6 +25,8 @@ paste = "1.0" rand_xorshift = "0.3.0" rand_core = "0.6.4" mock = { path = "../mock" } +this = "0.3.0" +error = "0.1.9" [dev-dependencies] pretty_assertions = "1.0.0" @@ -44,4 +46,5 @@ glob = "0.3.1" log = "0.4.14" serde = "1.0.130" serde_json = "1.0.66" -uneval = "0.2.4" \ No newline at end of file +uneval = "0.2.4" +thiserror = "1.0.49" \ No newline at end of file diff --git a/integration-tests/build.rs b/integration-tests/build.rs index 0e67b37f67..42c4d6709c 100644 --- a/integration-tests/build.rs +++ b/integration-tests/build.rs @@ -1,12 +1,15 @@ use ethers::{ abi::Contract, core::types::Bytes, - solc::{CompilerInput, CompilerOutput, EvmVersion, Solc}, + solc::{ + artifacts::{CompactContractRef, Error as SolcArtifactError}, + CompilerInput, CompilerOutput, EvmVersion, Solc, + }, }; use ethers_contract_abigen::Abigen; -use log::info; use serde::{Deserialize, Serialize}; use std::{fs::File, path::Path}; +use thiserror::Error; #[derive(Serialize, Deserialize, Debug)] pub struct CompiledContract { @@ -22,6 +25,55 @@ pub struct CompiledContract { pub bin_runtime: Bytes, } +#[derive(Error, Debug)] +enum BuildError { + /// Failed to detect solidity compiler or compiler version. + #[error("FailedToGetSolidity({0:})")] + FailedToGetSolidity(String), + /// Failed to create CompilerInput artifact for given contract + #[error("FailedToComposeCompilerInputs(path: {path:}, {reason:}))")] + FailedToComposeCompilerInputs { path: String, reason: String }, + /// Errors or non-ignored warnings exist in the CompilerOutpu struct + #[error("CompilerOutputContainsErrors(path: {path:}, errors: {errors:#?})")] + CompilerOutputContainsErrors { + path: String, + errors: Vec, + }, + /// Vec is empty + #[error("ArtifactError({0:})")] + ArtifactError(String), + /// Functon compile_output failed to encode CompilerInput to Vec + #[error("CompileOutputFailure({0:})")] + CompileOutputFailure(String), + /// Could not convert Vec to CompilerOutput + #[error("CompilerOutputDeSerError({0:})")] + CompilerOutputDeSerError(String), + /// Failed loading Abi from CompactContractRef + #[error("ErrorLoadingContractAbi({0:})")] + ErrorLoadingContractAbi(String), + /// Failed loading Bin from CompactContractRef + #[error("ErrorLoadingContractBin({0:})")] + ErrorLoadingContractBin(String), + /// Failed loading BinRuntime from CompactContractRef + #[error("ErrorLoadingContractBinRuntime({0:})")] + ErrorLoadingContractBinRuntime(String), + /// Failed to convert PathBuff to String + #[error("StringConversionError({0:})")] + StringConversionError(String), + /// Failed to create CompactContractRef from path + name + #[error("FailedToLoadCompactContractRef({0:})")] + FailedToLoadCompactContractRef(String), + /// Failed Bytecode to Bytes conversion + #[error("ByteCodeToBytesError({0:})")] + ByteCodeToBytesError(String), + /// Error serializing json to file + #[error("JsonSerializatonError({0:})")] + JsonSerializatonError(String), + /// Errors from Abigen + #[error("GenerateContractBindingsError({0:})")] + GenerateContractBindingsError(String), +} + /// Path to the test contracts const CONTRACTS_PATH: &str = "contracts"; /// Solidity compilation warnings to ignore (by error code) @@ -45,63 +97,101 @@ const CONTRACTS: &[(&str, &str)] = &[ /// Target directory for rust contract bingings const BINDINGS_DR: &str = "src"; -fn main() { +fn main() -> Result<(), BuildError> { println!("cargo:rerun-if-changed=build.rs"); let solc: Solc = Solc::default(); - let _solc_version = solc.version().expect("Version Works"); + let _solc_version = solc + .version() + .map_err(|err| BuildError::FailedToGetSolidity(err.to_string()))?; for (name, contract_path) in CONTRACTS { let path_sol = Path::new(CONTRACTS_PATH).join(contract_path); - let inputs = CompilerInput::new(&path_sol).expect("CompilerInput Created"); - // ethers-solc: explicitly indicate the EvmVersion that corresponds to the zkevm circuit's - // supported Upgrade, e.g. `London/Shanghai/...` specifications. - let input: CompilerInput = inputs - .clone() - .first_mut() - .expect("first exists") - .clone() + let input = CompilerInput::new(&path_sol) + .map_err(|err| BuildError::FailedToComposeCompilerInputs { + path: path_sol.to_string_lossy().to_string(), + reason: err.to_string(), + })? + .pop() + .ok_or_else(|| BuildError::ArtifactError("No Artifact Found".to_string()))? + // ethers-solc: explicitly indicate the EvmVersion that corresponds to the zkevm + // circuit's supported Upgrade, e.g. `London/Shanghai/...` specifications. .evm_version(EvmVersion::London); // compilation will either fail with Err variant or return Ok(CompilerOutput) // which may contain Errors or Warnings - let output: Vec = solc.compile_output(&input).unwrap(); + let output: Vec = solc + .compile_output(&input) + .map_err(|err| BuildError::CompileOutputFailure(err.to_string()))?; let mut deserializer: serde_json::Deserializer> = serde_json::Deserializer::from_slice(&output); // The contracts to test the worst-case usage of certain opcodes, such as SDIV, MLOAD, and // EXTCODESIZE, generate big JSON compilation outputs. We disable the recursion limit to // avoid parsing failure. deserializer.disable_recursion_limit(); - let compiled = match CompilerOutput::deserialize(&mut deserializer) { - Err(error) => { - panic!("COMPILATION ERROR {:?}\n{:?}", &path_sol, error); - } - // CompilationOutput is succesfully created (might contain Errors or Warnings) - Ok(output) => { - info!("COMPILATION OK: {:?}", name); - output + + let p = path_sol.to_str().ok_or_else(|| { + BuildError::StringConversionError( + "Failed to convert provided path to string".to_string(), + ) + })?; + + let compiled = CompilerOutput::deserialize(&mut deserializer) + .map_err(|err| BuildError::CompilerOutputDeSerError(err.to_string()))?; + let compiled_binding = compiled.clone(); + + let error_free = !{ compiled.has_error() || compiled.has_warning(WARN) }; + + let _ = error_free.then_some(|| ()).ok_or_else(|| { + BuildError::CompilerOutputContainsErrors { + path: p.to_string(), + errors: compiled.errors, } - }; + })?; - if compiled.has_error() || compiled.has_warning(WARN) { - panic!( - "... but CompilerOutput contains errors/warnings: {:?}:\n{:#?}", - &path_sol, compiled.errors - ); - } + let contract: CompactContractRef = compiled_binding.get(p, name).ok_or_else(|| { + BuildError::FailedToLoadCompactContractRef("FailedToLoadCompactContractRef".to_string()) + })?; + + let abi = contract + .abi + .ok_or_else(|| { + BuildError::ErrorLoadingContractAbi("Failed to get contract Abi".to_string()) + })? + .clone(); + + let bin = contract + .bin + .ok_or_else(|| { + BuildError::ErrorLoadingContractBin("Failed to get contract Bin".to_string()) + })? + .clone() + .into_bytes() + .ok_or_else(|| { + BuildError::ByteCodeToBytesError("Could not convert bin to bytes".to_string()) + })?; + + let bin_runtime = contract + .bin_runtime + .ok_or_else(|| { + BuildError::ErrorLoadingContractBinRuntime( + "Failed to get contract bin-runtime".to_string(), + ) + })? + .clone() + .into_bytes() + .ok_or_else(|| { + BuildError::ByteCodeToBytesError( + "Could not convert bin-runtime to bytes".to_string(), + ) + })?; - let contract = compiled - .get(path_sol.to_str().expect("path is not a string"), name) - .expect("contract not found"); - let abi = contract.abi.expect("no abi found").clone(); - let bin = contract.bin.expect("no bin found").clone(); - let bin_runtime = contract.bin_runtime.expect("no bin_runtime found").clone(); let compiled_contract = CompiledContract { - path: path_sol.to_str().expect("path is not str").to_string(), + path: p.to_string(), name: name.to_string(), abi, - bin: bin.into_bytes().expect("bin"), - bin_runtime: bin_runtime.into_bytes().expect("bin_runtime"), + bin, + bin_runtime, }; // Save CompiledContract object to json files in "contracts" folder @@ -111,20 +201,21 @@ fn main() { &File::create(&path_json).expect("cannot create file"), &compiled_contract, ) - .expect("cannot serialize json into file"); + .map_err(|err| BuildError::JsonSerializatonError(err.to_string()))?; } // Generate contract binding for compiled contracts for entry in glob::glob("./contracts/*.json").unwrap() { match entry { Ok(path) => { - generate_rust_contract_bindings(BINDINGS_DR, &path); + let _ = generate_rust_contract_bindings(BINDINGS_DR, &path); } Err(e) => eprintln!("{:#?}", e), } } + Ok(()) } -fn generate_rust_contract_bindings(bindings_dir: &str, file: &Path) { +fn generate_rust_contract_bindings(bindings_dir: &str, file: &Path) -> Result<(), BuildError> { const SLASH: char = '/'; const DOT: char = '.'; @@ -143,10 +234,14 @@ fn generate_rust_contract_bindings(bindings_dir: &str, file: &Path) { let destpath = Path::new(&bindings_dir).join(destpath); let _ = Abigen::new( contractname, - abi_source.into_os_string().into_string().expect("error"), + abi_source + .into_os_string() + .into_string() + .expect("FAILED CONVERSION TO STRING"), ) - .expect("error") + .map_err(|err| BuildError::GenerateContractBindingsError(err.to_string()))? .generate() - .expect("error") + .map_err(|err| BuildError::GenerateContractBindingsError(err.to_string()))? .write_to_file(destpath); + Ok(()) } From 2dda50415dd015e919a6f523159a54094871f3db Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Wed, 8 Nov 2023 22:11:22 +0200 Subject: [PATCH 42/54] remove necessary string argument from error types Co-authored-by: Chih Cheng Liang --- integration-tests/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/build.rs b/integration-tests/build.rs index 42c4d6709c..b7af53e88e 100644 --- a/integration-tests/build.rs +++ b/integration-tests/build.rs @@ -113,7 +113,7 @@ fn main() -> Result<(), BuildError> { reason: err.to_string(), })? .pop() - .ok_or_else(|| BuildError::ArtifactError("No Artifact Found".to_string()))? + .ok_or_else(|| BuildError::ArtifactError)? // ethers-solc: explicitly indicate the EvmVersion that corresponds to the zkevm // circuit's supported Upgrade, e.g. `London/Shanghai/...` specifications. .evm_version(EvmVersion::London); From 9bf9c1ca6e400b990dd9d6f1c2e283b218b12c92 Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Wed, 8 Nov 2023 22:13:07 +0200 Subject: [PATCH 43/54] remove unnecessary string argument from build error Co-authored-by: Chih Cheng Liang --- integration-tests/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/build.rs b/integration-tests/build.rs index b7af53e88e..5eb2ddea4c 100644 --- a/integration-tests/build.rs +++ b/integration-tests/build.rs @@ -150,7 +150,7 @@ fn main() -> Result<(), BuildError> { })?; let contract: CompactContractRef = compiled_binding.get(p, name).ok_or_else(|| { - BuildError::FailedToLoadCompactContractRef("FailedToLoadCompactContractRef".to_string()) + BuildError::FailedToLoadCompactContractRef })?; let abi = contract From 43ee65c78bde086726e115076ec41405dd9bd93a Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Wed, 8 Nov 2023 22:13:49 +0200 Subject: [PATCH 44/54] remove unnecessary string argument from build error Co-authored-by: Chih Cheng Liang --- integration-tests/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/build.rs b/integration-tests/build.rs index 5eb2ddea4c..bc2ccfa5b3 100644 --- a/integration-tests/build.rs +++ b/integration-tests/build.rs @@ -156,7 +156,7 @@ fn main() -> Result<(), BuildError> { let abi = contract .abi .ok_or_else(|| { - BuildError::ErrorLoadingContractAbi("Failed to get contract Abi".to_string()) + BuildError::ErrorLoadingContractAbi })? .clone(); From d80a1b4dc0964765527b7816fc5654baf11c9c1c Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Fri, 10 Nov 2023 20:27:54 +0200 Subject: [PATCH 45/54] modify BuildError variants when no need to return a string --- integration-tests/build.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/integration-tests/build.rs b/integration-tests/build.rs index bc2ccfa5b3..8c41978ed7 100644 --- a/integration-tests/build.rs +++ b/integration-tests/build.rs @@ -40,8 +40,8 @@ enum BuildError { errors: Vec, }, /// Vec is empty - #[error("ArtifactError({0:})")] - ArtifactError(String), + #[error("ArtifactError")] + ArtifactError, /// Functon compile_output failed to encode CompilerInput to Vec #[error("CompileOutputFailure({0:})")] CompileOutputFailure(String), @@ -49,8 +49,8 @@ enum BuildError { #[error("CompilerOutputDeSerError({0:})")] CompilerOutputDeSerError(String), /// Failed loading Abi from CompactContractRef - #[error("ErrorLoadingContractAbi({0:})")] - ErrorLoadingContractAbi(String), + #[error("ErrorLoadingContractAbi")] + ErrorLoadingContractAbi, /// Failed loading Bin from CompactContractRef #[error("ErrorLoadingContractBin({0:})")] ErrorLoadingContractBin(String), @@ -61,8 +61,8 @@ enum BuildError { #[error("StringConversionError({0:})")] StringConversionError(String), /// Failed to create CompactContractRef from path + name - #[error("FailedToLoadCompactContractRef({0:})")] - FailedToLoadCompactContractRef(String), + #[error("FailedToLoadCompactContractRef")] + FailedToLoadCompactContractRef, /// Failed Bytecode to Bytes conversion #[error("ByteCodeToBytesError({0:})")] ByteCodeToBytesError(String), From 3a0a27f1d40300340eae7bf345853fb6c2306361 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Fri, 10 Nov 2023 20:36:08 +0200 Subject: [PATCH 46/54] replace ok_or_else() with ok_or() when first one not necessary --- integration-tests/build.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/integration-tests/build.rs b/integration-tests/build.rs index 8c41978ed7..bf3c80d39e 100644 --- a/integration-tests/build.rs +++ b/integration-tests/build.rs @@ -113,7 +113,7 @@ fn main() -> Result<(), BuildError> { reason: err.to_string(), })? .pop() - .ok_or_else(|| BuildError::ArtifactError)? + .ok_or(BuildError::ArtifactError)? // ethers-solc: explicitly indicate the EvmVersion that corresponds to the zkevm // circuit's supported Upgrade, e.g. `London/Shanghai/...` specifications. .evm_version(EvmVersion::London); @@ -149,15 +149,15 @@ fn main() -> Result<(), BuildError> { } })?; - let contract: CompactContractRef = compiled_binding.get(p, name).ok_or_else(|| { + let contract: CompactContractRef = compiled_binding.get(p, name).ok_or( BuildError::FailedToLoadCompactContractRef - })?; + )?; let abi = contract .abi - .ok_or_else(|| { + .ok_or( BuildError::ErrorLoadingContractAbi - })? + )? .clone(); let bin = contract From 954ef898e781657b4a5a95bcae71bbd346d4acde Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Fri, 10 Nov 2023 21:03:56 +0200 Subject: [PATCH 47/54] fmt --- integration-tests/build.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/integration-tests/build.rs b/integration-tests/build.rs index bf3c80d39e..72c783203f 100644 --- a/integration-tests/build.rs +++ b/integration-tests/build.rs @@ -149,15 +149,13 @@ fn main() -> Result<(), BuildError> { } })?; - let contract: CompactContractRef = compiled_binding.get(p, name).ok_or( - BuildError::FailedToLoadCompactContractRef - )?; + let contract: CompactContractRef = compiled_binding + .get(p, name) + .ok_or(BuildError::FailedToLoadCompactContractRef)?; let abi = contract .abi - .ok_or( - BuildError::ErrorLoadingContractAbi - )? + .ok_or(BuildError::ErrorLoadingContractAbi)? .clone(); let bin = contract From 64785e1c56b1c48c37d222dd4dcf9edc2d1612c1 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Fri, 10 Nov 2023 21:32:29 +0200 Subject: [PATCH 48/54] fix cargo.lock parsing error: remove duplicate pkg declarations for num_enum and num_enum_derive --- Cargo.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5fdc475475..29a06c9808 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2695,11 +2695,11 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.7.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70bf6736f74634d299d00086f02986875b3c2d924781a6a2cb6c201e73da0ceb" +checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" dependencies = [ - "num_enum_derive 0.7.0", + "num_enum_derive 0.6.1", ] [[package]] @@ -2725,9 +2725,9 @@ dependencies = [ [[package]] name = "num_enum_derive" -version = "0.7.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56ea360eafe1022f7cc56cd7b869ed57330fb2453d0c7831d99b74c65d2f5597" +checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" dependencies = [ "proc-macro-crate", "proc-macro2", From 8b9fe66b639ef65bf8811f7d9511fd05b521af57 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Fri, 10 Nov 2023 22:30:31 +0200 Subject: [PATCH 49/54] declare path to solidity file as and catch conversion error --- integration-tests/build.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/integration-tests/build.rs b/integration-tests/build.rs index 72c783203f..14d5a6c171 100644 --- a/integration-tests/build.rs +++ b/integration-tests/build.rs @@ -107,9 +107,12 @@ fn main() -> Result<(), BuildError> { for (name, contract_path) in CONTRACTS { let path_sol = Path::new(CONTRACTS_PATH).join(contract_path); + let p = path_sol.to_str().ok_or_else(|| { + BuildError::StringConversionError("Failed to convert provided path to &str".to_string()) + })?; let input = CompilerInput::new(&path_sol) .map_err(|err| BuildError::FailedToComposeCompilerInputs { - path: path_sol.to_string_lossy().to_string(), + path: p.to_string(), reason: err.to_string(), })? .pop() @@ -130,12 +133,6 @@ fn main() -> Result<(), BuildError> { // avoid parsing failure. deserializer.disable_recursion_limit(); - let p = path_sol.to_str().ok_or_else(|| { - BuildError::StringConversionError( - "Failed to convert provided path to string".to_string(), - ) - })?; - let compiled = CompilerOutput::deserialize(&mut deserializer) .map_err(|err| BuildError::CompilerOutputDeSerError(err.to_string()))?; let compiled_binding = compiled.clone(); @@ -150,7 +147,7 @@ fn main() -> Result<(), BuildError> { })?; let contract: CompactContractRef = compiled_binding - .get(p, name) + .get(&p, name) .ok_or(BuildError::FailedToLoadCompactContractRef)?; let abi = contract From ec58e85648a03bde654bfcd98555279b119e9d30 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Fri, 10 Nov 2023 22:59:12 +0200 Subject: [PATCH 50/54] simplify compilation error check as per review proposal --- integration-tests/build.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/integration-tests/build.rs b/integration-tests/build.rs index 14d5a6c171..dbb1b1fd1f 100644 --- a/integration-tests/build.rs +++ b/integration-tests/build.rs @@ -139,6 +139,13 @@ fn main() -> Result<(), BuildError> { let error_free = !{ compiled.has_error() || compiled.has_warning(WARN) }; + if !error_free { + return Err(BuildError::CompilerOutputContainsErrors { + path: p.to_string(), + errors: compiled.errors, + }); + } + let _ = error_free.then_some(|| ()).ok_or_else(|| { BuildError::CompilerOutputContainsErrors { path: p.to_string(), @@ -147,7 +154,7 @@ fn main() -> Result<(), BuildError> { })?; let contract: CompactContractRef = compiled_binding - .get(&p, name) + .get(p, name) .ok_or(BuildError::FailedToLoadCompactContractRef)?; let abi = contract From 62ff0cd50292b33acea92552dba594b64d034269 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Fri, 10 Nov 2023 23:00:02 +0200 Subject: [PATCH 51/54] add error msg to .expect blocks --- integration-tests/src/bin/gen_blockchain_data.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration-tests/src/bin/gen_blockchain_data.rs b/integration-tests/src/bin/gen_blockchain_data.rs index bb18a07741..e9eac2682a 100644 --- a/integration-tests/src/bin/gen_blockchain_data.rs +++ b/integration-tests/src/bin/gen_blockchain_data.rs @@ -60,10 +60,10 @@ async fn dump_tx_trace(prov: Provider, receipt: TransactionReceipt, name: let trace = prov .debug_trace_transaction(receipt.transaction_hash, options) .await - .expect("SOME REASON"); + .expect("Failed to get transaction debug trace"); let filename = format!("{}_trace.json", name); serde_json::to_writer(&File::create(filename).expect("cannot create file"), &trace) - .expect("reason"); + .expect("Could not seralize trace as json data"); } fn erc20_transfer( From 8c61fd3cd7563827af6b8009d53f0af20b7debf6 Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Sat, 11 Nov 2023 00:39:47 +0200 Subject: [PATCH 52/54] use PathBuff methods to derive solidity file base --- integration-tests/build.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/integration-tests/build.rs b/integration-tests/build.rs index dbb1b1fd1f..1492a0c58b 100644 --- a/integration-tests/build.rs +++ b/integration-tests/build.rs @@ -218,20 +218,18 @@ fn main() -> Result<(), BuildError> { } fn generate_rust_contract_bindings(bindings_dir: &str, file: &Path) -> Result<(), BuildError> { - const SLASH: char = '/'; - const DOT: char = '.'; - let abi_source = file.to_path_buf(); - let tempbinding = file - .to_path_buf() - .into_os_string() - .into_string() - .expect("FAILED CONVERSION TO STRING"); - let filenamevec: Vec<&str> = tempbinding.split(SLASH).collect(); - let filename = filenamevec[1]; - - let contractnamevector: Vec<&str> = filename.split(DOT).collect(); - let contractname = contractnamevector[0].to_lowercase(); + let tempbinding = abi_source.clone(); + + let contractname = tempbinding + .file_stem() + .ok_or(BuildError::ArtifactError)? + .to_str() + .ok_or(BuildError::StringConversionError( + "Could not convert &OsStr to &str".to_string(), + ))? + .to_lowercase(); + let destpath = format!("{}{}{}", "bindings_", contractname, ".rs"); let destpath = Path::new(&bindings_dir).join(destpath); let _ = Abigen::new( From a286505f728620fa26375917e83f889cb44d455d Mon Sep 17 00:00:00 2001 From: AronisAt79 Date: Sat, 11 Nov 2023 01:23:35 +0200 Subject: [PATCH 53/54] install openssl on runner --- .github/workflows/integration.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 6954385f0e..b802408bd7 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -95,6 +95,8 @@ jobs: key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Update git submodule run: git submodule update --init --recursive --checkout integration-tests/contracts/vendor/openzeppelin-contracts + - name: Install openssl + run: sudo apt-get install -y openssl # Run an initial build in a separate step to split the build time from execution time - name: Build bins run: cargo build --bin gen_blockchain_data From 1181ccd4de0e6a2d128330f65546cb07722df252 Mon Sep 17 00:00:00 2001 From: AronisAt79 <45406504+AronisAt79@users.noreply.github.com> Date: Sat, 11 Nov 2023 01:33:41 +0200 Subject: [PATCH 54/54] Update integration.yml libssl-dev --- .github/workflows/integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index b802408bd7..bdfb6b546f 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -96,7 +96,7 @@ jobs: - name: Update git submodule run: git submodule update --init --recursive --checkout integration-tests/contracts/vendor/openzeppelin-contracts - name: Install openssl - run: sudo apt-get install -y openssl + run: sudo apt-get install -y pkg-config libssl-dev # Run an initial build in a separate step to split the build time from execution time - name: Build bins run: cargo build --bin gen_blockchain_data