Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(levm): replace specId with Fork #1762

Merged
merged 11 commits into from
Jan 28, 2025
105 changes: 52 additions & 53 deletions cmd/ef_tests/levm/report.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::runner::{EFTestRunnerError, InternalError};
use colored::Colorize;
use ethrex_core::{Address, H256};
use ethrex_core::{types::Fork, Address, H256};
use ethrex_levm::{
errors::{TransactionReport, TxResult, VMError},
Account, StorageSlot,
};
use ethrex_storage::{error::StoreError, AccountUpdate};
use ethrex_vm::SpecId;
use itertools::Itertools;
use revm::primitives::{EVMError, ExecutionResult as RevmExecutionResult};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -133,21 +132,21 @@ pub fn summary_for_slack(reports: &[EFTestReport]) -> String {
}}
]
}}"#,
fork_summary_for_slack(reports, SpecId::PRAGUE),
fork_summary_for_slack(reports, SpecId::CANCUN),
fork_summary_for_slack(reports, SpecId::SHANGHAI),
fork_summary_for_slack(reports, SpecId::HOMESTEAD),
fork_summary_for_slack(reports, SpecId::ISTANBUL),
fork_summary_for_slack(reports, SpecId::LONDON),
fork_summary_for_slack(reports, SpecId::BYZANTIUM),
fork_summary_for_slack(reports, SpecId::BERLIN),
fork_summary_for_slack(reports, SpecId::CONSTANTINOPLE),
fork_summary_for_slack(reports, SpecId::MERGE),
fork_summary_for_slack(reports, SpecId::FRONTIER),
fork_summary_for_slack(reports, Fork::Prague),
fork_summary_for_slack(reports, Fork::Cancun),
fork_summary_for_slack(reports, Fork::Shanghai),
fork_summary_for_slack(reports, Fork::Homestead),
fork_summary_for_slack(reports, Fork::Istanbul),
fork_summary_for_slack(reports, Fork::London),
fork_summary_for_slack(reports, Fork::Byzantium),
fork_summary_for_slack(reports, Fork::Berlin),
fork_summary_for_slack(reports, Fork::Constantinople),
fork_summary_for_slack(reports, Fork::Paris),
ilitteri marked this conversation as resolved.
Show resolved Hide resolved
fork_summary_for_slack(reports, Fork::Frontier),
)
}

fn fork_summary_for_slack(reports: &[EFTestReport], fork: SpecId) -> String {
fn fork_summary_for_slack(reports: &[EFTestReport], fork: Fork) -> String {
let fork_str: &str = fork.into();
let (fork_tests, fork_passed_tests, fork_success_percentage) = fork_statistics(reports, fork);
format!(r#"*{fork_str}:* {fork_passed_tests}/{fork_tests} ({fork_success_percentage:.2}%)"#)
Expand All @@ -173,22 +172,22 @@ pub fn summary_for_github(reports: &[EFTestReport]) -> String {
let success_percentage = (total_passed as f64 / total_run as f64) * 100.0;
format!(
r#"Summary: {total_passed}/{total_run} ({success_percentage:.2}%)\n\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n"#,
fork_summary_for_github(reports, SpecId::PRAGUE),
fork_summary_for_github(reports, SpecId::CANCUN),
fork_summary_for_github(reports, SpecId::SHANGHAI),
fork_summary_for_github(reports, SpecId::HOMESTEAD),
fork_summary_for_github(reports, SpecId::ISTANBUL),
fork_summary_for_github(reports, SpecId::LONDON),
fork_summary_for_github(reports, SpecId::BYZANTIUM),
fork_summary_for_github(reports, SpecId::BERLIN),
fork_summary_for_github(reports, SpecId::CONSTANTINOPLE),
fork_summary_for_github(reports, SpecId::MERGE),
fork_summary_for_github(reports, SpecId::FRONTIER),
fork_summary_for_github(reports, Fork::Prague),
fork_summary_for_github(reports, Fork::Cancun),
fork_summary_for_github(reports, Fork::Shanghai),
fork_summary_for_github(reports, Fork::Homestead),
fork_summary_for_github(reports, Fork::Istanbul),
fork_summary_for_github(reports, Fork::London),
fork_summary_for_github(reports, Fork::Byzantium),
fork_summary_for_github(reports, Fork::Berlin),
fork_summary_for_github(reports, Fork::Constantinople),
fork_summary_for_github(reports, Fork::Paris),
ilitteri marked this conversation as resolved.
Show resolved Hide resolved
fork_summary_for_github(reports, Fork::Frontier),
)
}

fn fork_summary_for_github(reports: &[EFTestReport], fork: SpecId) -> String {
let fork_str: &str = fork.into();
fn fork_summary_for_github(reports: &[EFTestReport], fork: Fork) -> String {
let fork_str:&str = fork.into();
let (fork_tests, fork_passed_tests, fork_success_percentage) = fork_statistics(reports, fork);
format!("{fork_str}: {fork_passed_tests}/{fork_tests} ({fork_success_percentage:.2}%)")
}
Expand Down Expand Up @@ -221,22 +220,22 @@ pub fn summary_for_shell(reports: &[EFTestReport]) -> String {
} else {
format!("{}", total_passed).red()
},
fork_summary_shell(reports, SpecId::PRAGUE),
fork_summary_shell(reports, SpecId::CANCUN),
fork_summary_shell(reports, SpecId::SHANGHAI),
fork_summary_shell(reports, SpecId::MERGE),
fork_summary_shell(reports, SpecId::LONDON),
fork_summary_shell(reports, SpecId::BERLIN),
fork_summary_shell(reports, SpecId::ISTANBUL),
fork_summary_shell(reports, SpecId::CONSTANTINOPLE),
fork_summary_shell(reports, SpecId::BYZANTIUM),
fork_summary_shell(reports, SpecId::HOMESTEAD),
fork_summary_shell(reports, SpecId::FRONTIER),
fork_summary_shell(reports, Fork::Prague),
fork_summary_shell(reports, Fork::Cancun),
fork_summary_shell(reports, Fork::Shanghai),
fork_summary_shell(reports, Fork::Paris),
fork_summary_shell(reports, Fork::London),
fork_summary_shell(reports, Fork::Berlin),
fork_summary_shell(reports, Fork::Istanbul),
fork_summary_shell(reports, Fork::Constantinople),
fork_summary_shell(reports, Fork::Byzantium),
fork_summary_shell(reports, Fork::Homestead),
fork_summary_shell(reports, Fork::Frontier),
test_dir_summary_for_shell(reports),
)
}

fn fork_summary_shell(reports: &[EFTestReport], fork: SpecId) -> String {
fn fork_summary_shell(reports: &[EFTestReport], fork: Fork) -> String {
let fork_str: &str = fork.into();
let (fork_tests, fork_passed_tests, fork_success_percentage) = fork_statistics(reports, fork);
format!(
Expand All @@ -252,7 +251,7 @@ fn fork_summary_shell(reports: &[EFTestReport], fork: SpecId) -> String {
)
}

fn fork_statistics(reports: &[EFTestReport], fork: SpecId) -> (usize, usize, f64) {
fn fork_statistics(reports: &[EFTestReport], fork: Fork) -> (usize, usize, f64) {
let fork_tests = reports.iter().filter(|report| report.fork == fork).count();
let fork_passed_tests = reports
.iter()
Expand Down Expand Up @@ -312,17 +311,17 @@ impl Display for EFTestsReport {
let total_run = self.0.len();
writeln!(f, "Summary: {total_passed}/{total_run}",)?;
writeln!(f)?;
writeln!(f, "{}", fork_summary_shell(&self.0, SpecId::PRAGUE))?;
writeln!(f, "{}", fork_summary_shell(&self.0, SpecId::CANCUN))?;
writeln!(f, "{}", fork_summary_shell(&self.0, SpecId::SHANGHAI))?;
writeln!(f, "{}", fork_summary_shell(&self.0, SpecId::HOMESTEAD))?;
writeln!(f, "{}", fork_summary_shell(&self.0, SpecId::ISTANBUL))?;
writeln!(f, "{}", fork_summary_shell(&self.0, SpecId::LONDON))?;
writeln!(f, "{}", fork_summary_shell(&self.0, SpecId::BYZANTIUM))?;
writeln!(f, "{}", fork_summary_shell(&self.0, SpecId::BERLIN))?;
writeln!(f, "{}", fork_summary_shell(&self.0, SpecId::CONSTANTINOPLE))?;
writeln!(f, "{}", fork_summary_shell(&self.0, SpecId::MERGE))?;
writeln!(f, "{}", fork_summary_shell(&self.0, SpecId::FRONTIER))?;
writeln!(f, "{}", fork_summary_shell(&self.0, Fork::Prague))?;
writeln!(f, "{}", fork_summary_shell(&self.0, Fork::Cancun))?;
writeln!(f, "{}", fork_summary_shell(&self.0, Fork::Shanghai))?;
writeln!(f, "{}", fork_summary_shell(&self.0, Fork::Homestead))?;
writeln!(f, "{}", fork_summary_shell(&self.0, Fork::Istanbul))?;
writeln!(f, "{}", fork_summary_shell(&self.0, Fork::London))?;
writeln!(f, "{}", fork_summary_shell(&self.0, Fork::Byzantium))?;
writeln!(f, "{}", fork_summary_shell(&self.0, Fork::Berlin))?;
writeln!(f, "{}", fork_summary_shell(&self.0, Fork::Constantinople))?;
writeln!(f, "{}", fork_summary_shell(&self.0, Fork::Paris))?;
ilitteri marked this conversation as resolved.
Show resolved Hide resolved
writeln!(f, "{}", fork_summary_shell(&self.0, Fork::Frontier))?;
writeln!(f)?;
writeln!(f, "Failed tests:")?;
writeln!(f)?;
Expand Down Expand Up @@ -397,14 +396,14 @@ pub struct EFTestReport {
pub name: String,
pub dir: String,
pub test_hash: H256,
pub fork: SpecId,
pub fork: Fork,
pub skipped: bool,
pub failed_vectors: HashMap<TestVector, EFTestRunnerError>,
pub re_run_report: Option<TestReRunReport>,
}

impl EFTestReport {
pub fn new(name: String, dir: String, test_hash: H256, fork: SpecId) -> Self {
pub fn new(name: String, dir: String, test_hash: H256, fork: Fork) -> Self {
EFTestReport {
name,
dir,
Expand Down
2 changes: 1 addition & 1 deletion cmd/ef_tests/levm/runner/levm_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn prepare_vm_for_tx(vector: &TestVector, test: &EFTest) -> Result<VM, EFTes
origin: tx.sender,
refunded_gas: 0,
gas_limit: tx.gas_limit,
spec_id: test.fork(),
fork: test.fork(),
block_number: test.env.current_number,
coinbase: test.env.current_coinbase,
timestamp: test.env.current_timestamp,
Expand Down
4 changes: 2 additions & 2 deletions cmd/ef_tests/levm/runner/revm_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ethrex_levm::{
Account, StorageSlot,
};
use ethrex_storage::{error::StoreError, AccountUpdate};
use ethrex_vm::{db::StoreWrapper, EvmState, RevmAddress, RevmU256};
use ethrex_vm::{db::StoreWrapper, fork_to_spec_id, EvmState, RevmAddress, RevmU256};
use revm::{
db::State,
inspectors::TracerEip3155 as RevmTracerEip3155,
Expand Down Expand Up @@ -194,7 +194,7 @@ pub fn prepare_revm_for_tx<'state>(
.with_block_env(block_env)
.with_tx_env(tx_env)
.modify_cfg_env(|cfg| cfg.chain_id = chain_spec.chain_id)
.with_spec_id(test.fork())
.with_spec_id(fork_to_spec_id(test.fork()))
.with_external_context(
RevmTracerEip3155::new(Box::new(std::io::stderr())).without_summary(),
);
Expand Down
27 changes: 13 additions & 14 deletions cmd/ef_tests/levm/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ use crate::{
};
use bytes::Bytes;
use ethrex_core::{
types::{Genesis, GenesisAccount, TxKind},
types::{Fork, Genesis, GenesisAccount, TxKind},
Address, H256, U256,
};
use ethrex_vm::SpecId;
use serde::Deserialize;
use std::collections::HashMap;

Expand All @@ -33,21 +32,21 @@ pub struct EFTest {
}

impl EFTest {
pub fn fork(&self) -> SpecId {
pub fn fork(&self) -> Fork {
match &self.post {
EFTestPost::Prague(_) => SpecId::PRAGUE,
EFTestPost::Cancun(_) => SpecId::CANCUN,
EFTestPost::Shanghai(_) => SpecId::SHANGHAI,
EFTestPost::Homestead(_) => SpecId::HOMESTEAD,
EFTestPost::Istanbul(_) => SpecId::ISTANBUL,
EFTestPost::London(_) => SpecId::LONDON,
EFTestPost::Byzantium(_) => SpecId::BYZANTIUM,
EFTestPost::Berlin(_) => SpecId::BERLIN,
EFTestPost::Prague(_) => Fork::Prague,
EFTestPost::Cancun(_) => Fork::Cancun,
EFTestPost::Shanghai(_) => Fork::Shanghai,
EFTestPost::Homestead(_) => Fork::Homestead,
EFTestPost::Istanbul(_) => Fork::Istanbul,
EFTestPost::London(_) => Fork::London,
EFTestPost::Byzantium(_) => Fork::Byzantium,
EFTestPost::Berlin(_) => Fork::Berlin,
EFTestPost::Constantinople(_) | EFTestPost::ConstantinopleFix(_) => {
SpecId::CONSTANTINOPLE
Fork::Constantinople
}
EFTestPost::Paris(_) => SpecId::MERGE,
EFTestPost::Frontier(_) => SpecId::FRONTIER,
EFTestPost::Paris(_) => Fork::Paris,
EFTestPost::Frontier(_) => Fork::Frontier,
}
}
}
Expand Down
83 changes: 79 additions & 4 deletions crates/common/types/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,82 @@ pub struct ChainConfig {
pub terminal_total_difficulty_passed: bool,
}

#[derive(Debug, PartialEq, PartialOrd)]
#[repr(u8)]
#[derive(Debug, PartialEq, PartialOrd, Default, Clone, Copy, Serialize, Deserialize)]
ilitteri marked this conversation as resolved.
Show resolved Hide resolved
pub enum Fork {
Paris = 0,
Shanghai = 1,
Cancun = 2,
Frontier = 0,
FrontierThawing = 1,
Homestead = 2,
DaoFork = 3,
Tangerine = 4,
SpuriousDragon = 5,
Byzantium = 6,
Constantinople = 7,
Petersburg = 8,
Istanbul = 9,
MuirGlacier = 10,
Berlin = 11,
London = 12,
ArrowGlacier = 13,
GrayGlacier = 14,
Paris = 15,
Shanghai = 16,
#[default]
Cancun = 17,
Prague = 18,
}

impl From<Fork> for &str {
ilitteri marked this conversation as resolved.
Show resolved Hide resolved
fn from(fork: Fork) -> Self {
match fork {
Fork::Frontier => "Frontier",
Fork::FrontierThawing => "FrontierThawing",
Fork::Homestead => "Homestead",
Fork::DaoFork => "DaoFork",
Fork::Tangerine => "Tangerine",
Fork::SpuriousDragon => "SpuriousDragon",
Fork::Byzantium => "Byzantium",
Fork::Constantinople => "Constantinople",
Fork::Petersburg => "Petersburg",
Fork::Istanbul => "Istanbul",
Fork::MuirGlacier => "MuirGlacier",
Fork::Berlin => "Berlin",
Fork::London => "London",
Fork::ArrowGlacier => "ArrowGlacier",
Fork::GrayGlacier => "GrayGlacier",
Fork::Paris => "Paris",
Fork::Shanghai => "Shanghai",
Fork::Cancun => "Cancun",
Fork::Prague => "Prague",
}
}
}

impl From<&str> for Fork {
fn from(s: &str) -> Self {
match s {
"Frontier" => Fork::Frontier,
"FrontierThawing" => Fork::FrontierThawing,
"Homestead" => Fork::Homestead,
"DaoFork" => Fork::DaoFork,
"Tangerine" => Fork::Tangerine,
"SpuriousDragon" => Fork::SpuriousDragon,
"Byzantium" => Fork::Byzantium,
"Constantinople" => Fork::Constantinople,
"Petersburg" => Fork::Petersburg,
"Istanbul" => Fork::Istanbul,
"MuirGlacier" => Fork::MuirGlacier,
"Berlin" => Fork::Berlin,
"London" => Fork::London,
"ArrowGlacier" => Fork::ArrowGlacier,
"GrayGlacier" => Fork::GrayGlacier,
"Paris" => Fork::Paris,
"Shanghai" => Fork::Shanghai,
"Cancun" => Fork::Cancun,
"Prague" => Fork::Prague,
_ => Fork::Cancun,
ilitteri marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

impl ChainConfig {
Expand Down Expand Up @@ -122,6 +193,10 @@ impl ChainConfig {
}
}

pub fn fork(&self, block_timestamp: u64) -> Fork {
self.get_fork(block_timestamp)
}

pub fn gather_forks(&self) -> (Vec<Option<u64>>, Vec<Option<u64>>) {
let block_number_based_forks: Vec<Option<u64>> = vec![
self.homestead_block,
Expand Down
4 changes: 2 additions & 2 deletions crates/vm/levm/src/environment.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ethrex_core::{Address, H256, U256};
use ethrex_core::{types::Fork, Address, H256, U256};
pub use revm_primitives::SpecId;

use std::collections::HashMap;
Expand All @@ -12,7 +12,7 @@ pub struct Environment {
pub origin: Address,
pub refunded_gas: u64,
pub gas_limit: u64,
pub spec_id: SpecId,
pub fork: Fork,
pub block_number: U256,
pub coinbase: Address,
pub timestamp: U256,
Expand Down
Loading