From bfe2fd622155ecd21f0368fcec89fbe6e3e3e556 Mon Sep 17 00:00:00 2001 From: rakita Date: Mon, 26 Dec 2022 22:55:46 +0100 Subject: [PATCH] ci: add eth chain test. Set prevrandao after merge (#621) * Small changes * feat: Add eth chain test to ci. Set prevrandao after merge * Update .github/workflows/ci.yml Co-authored-by: Bjerg * move env Co-authored-by: Bjerg --- .github/workflows/ci.yml | 29 +++++++++++++++++++++++++++ bin/reth/src/test_eth_chain/mod.rs | 7 ++++++- bin/reth/src/test_eth_chain/runner.rs | 7 +++++-- crates/executor/src/config.rs | 12 +++++------ crates/executor/src/executor.rs | 5 +++-- crates/executor/src/revm_wrap.rs | 10 +++++++-- 6 files changed, 57 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8d3895f9..6d470cab4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,35 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} files: lcov.info flags: unit-tests + eth-blockchain: + name: Ethereum blockchain Tests (Stable) + runs-on: ubuntu-latest + env: + RUST_LOG: info,sync=error + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Checkout ethereum/tests + uses: actions/checkout@v2 + with: + repository: ethereum/tests + path: ethtests + submodules: recursive + + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - uses: Swatinem/rust-cache@v1 + with: + cache-on-failure: true + + - name: Run Ethereum tests + run: cargo run --release -- test-chain ethtests/BlockchainTests/GeneralStateTests/ fuzz: # Skip the Fuzzing Jobs until we make them run fast and reliably. Currently they will diff --git a/bin/reth/src/test_eth_chain/mod.rs b/bin/reth/src/test_eth_chain/mod.rs index 38b7ab878..5714d210d 100644 --- a/bin/reth/src/test_eth_chain/mod.rs +++ b/bin/reth/src/test_eth_chain/mod.rs @@ -2,6 +2,7 @@ use crate::util; use clap::Parser; +use eyre::eyre; use std::path::PathBuf; use tracing::{error, info}; /// Models for parsing JSON blockchain tests @@ -45,6 +46,10 @@ impl Command { info!("\nPASSED {num_of_passed}/{} tests\n", num_of_passed + num_of_failed); - Ok(()) + if num_of_failed != 0 { + Err(eyre!("Failed {num_of_failed} tests")) + } else { + Ok(()) + } } } diff --git a/bin/reth/src/test_eth_chain/runner.rs b/bin/reth/src/test_eth_chain/runner.rs index ff71da0f2..6e715b1a7 100644 --- a/bin/reth/src/test_eth_chain/runner.rs +++ b/bin/reth/src/test_eth_chain/runner.rs @@ -63,7 +63,8 @@ pub fn should_skip(path: &Path) -> bool { path.file_name() == Some(OsStr::new("Call50000_sha256.json")) || path.file_name() == Some(OsStr::new("static_Call50000_sha256.json")) || path.file_name() == Some(OsStr::new("loopMul.json")) || - path.file_name() == Some(OsStr::new("CALLBlake2f_MaxRounds.json")) + path.file_name() == Some(OsStr::new("CALLBlake2f_MaxRounds.json")) || + path.file_name() == Some(OsStr::new("shiftCombinations.json")) { return true } @@ -79,12 +80,14 @@ pub async fn run_test(path: PathBuf) -> eyre::Result<()> { if should_skip(path) { return Ok(()) } + info!("Executing test from path: {path:?}"); for (name, suite) in suites.0 { if matches!( suite.network, ForkSpec::ByzantiumToConstantinopleAt5 | ForkSpec::Constantinople | + ForkSpec::ConstantinopleFix | ForkSpec::MergeEOF | ForkSpec::MergeMeterInitCode | ForkSpec::MergePush0, @@ -96,7 +99,7 @@ pub async fn run_test(path: PathBuf) -> eyre::Result<()> { let pre_state = suite.pre.0; - debug!("Executing test: {name} for spec: {:?}", suite.network); + debug!("Executing {:?} spec: {:?}", name, suite.network); let spec_upgrades: SpecUpgrades = suite.network.into(); // if paris aka merge is not activated we dont have block rewards; diff --git a/crates/executor/src/config.rs b/crates/executor/src/config.rs index 29648a49d..c66526d31 100644 --- a/crates/executor/src/config.rs +++ b/crates/executor/src/config.rs @@ -77,11 +77,11 @@ impl SpecUpgrades { } } - /// New homestead enabled spec - pub fn new_homestead_activated() -> Self { + /// New frontier enabled spec + pub fn new_frontier_activated() -> Self { Self { - homestead: 0, - frontier: u64::MAX, + frontier: 0, + homestead: u64::MAX, tangerine_whistle: u64::MAX, spurious_dragon: u64::MAX, byzantium: u64::MAX, @@ -95,8 +95,8 @@ impl SpecUpgrades { } /// New homestead enabled spec - pub fn new_frontier_activated() -> Self { - Self { frontier: 0, ..Self::new_ethereum() } + pub fn new_homestead_activated() -> Self { + Self { homestead: 0, ..Self::new_frontier_activated() } } /// New tangerine enabled spec diff --git a/crates/executor/src/executor.rs b/crates/executor/src/executor.rs index 877b6d967..2dcd256e1 100644 --- a/crates/executor/src/executor.rs +++ b/crates/executor/src/executor.rs @@ -13,7 +13,7 @@ use reth_primitives::{ use reth_provider::StateProvider; use revm::{ db::AccountState, Account as RevmAccount, AccountInfo, AnalysisKind, Bytecode, Database, - Return, B160, EVM, U256 as evmU256, + Return, SpecId, B160, EVM, U256 as evmU256, }; use std::collections::BTreeMap; @@ -312,12 +312,13 @@ pub fn execute( let mut evm = EVM::new(); evm.database(db); + let spec_id = config.spec_upgrades.revm_spec(header.number); evm.env.cfg.chain_id = evmU256::from_limbs(config.chain_id.0); evm.env.cfg.spec_id = config.spec_upgrades.revm_spec(header.number); evm.env.cfg.perf_all_precompiles_have_balance = false; evm.env.cfg.perf_analyse_created_bytecodes = AnalysisKind::Raw; - revm_wrap::fill_block_env(&mut evm.env.block, header); + revm_wrap::fill_block_env(&mut evm.env.block, header, spec_id >= SpecId::MERGE); let mut cumulative_gas_used = 0; // output of verification let mut changesets = Vec::with_capacity(transactions.len()); diff --git a/crates/executor/src/revm_wrap.rs b/crates/executor/src/revm_wrap.rs index 906af68a9..d2988d392 100644 --- a/crates/executor/src/revm_wrap.rs +++ b/crates/executor/src/revm_wrap.rs @@ -67,11 +67,17 @@ impl DatabaseRef for State { } /// Fill block environment from Block. -pub fn fill_block_env(block_env: &mut BlockEnv, header: &Header) { +pub fn fill_block_env(block_env: &mut BlockEnv, header: &Header, after_merge: bool) { block_env.number = evmU256::from(header.number); block_env.coinbase = B160(header.beneficiary.0); block_env.timestamp = evmU256::from(header.timestamp); - block_env.difficulty = evmU256::from_limbs(header.difficulty.0); + if after_merge { + block_env.prevrandao = Some(B256(header.mix_hash.0)); + block_env.difficulty = evmU256::ZERO; + } else { + block_env.difficulty = evmU256::from_limbs(header.difficulty.0); + block_env.prevrandao = None; + } block_env.basefee = evmU256::from(header.base_fee_per_gas.unwrap_or_default()); block_env.gas_limit = evmU256::from(header.gas_limit); }