From 15d2baba12fe89fc693ece2926f285f4b88855c8 Mon Sep 17 00:00:00 2001 From: mandreyel Date: Tue, 28 Mar 2023 15:16:47 +0400 Subject: [PATCH] sync with upstream for shanghai changes --- ethjson/src/spec/spec.rs | 18 +++++++++++++++++- jsontests/src/state.rs | 16 +++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/ethjson/src/spec/spec.rs b/ethjson/src/spec/spec.rs index 634c1dd..e215344 100644 --- a/ethjson/src/spec/spec.rs +++ b/ethjson/src/spec/spec.rs @@ -42,8 +42,13 @@ pub enum ForkSpec { Istanbul, /// Berlin (#12,244,000, 2021-04-15) Berlin, - /// London (To be announced) + /// London (12,965,000, 2021-08-05) London, + /// Paris - The Merge (15,537,394, 2022-09-15) + Merge, + /// Shanghai (To be announced) + Shanghai, + /// Byzantium transition test-net EIP158ToByzantiumAt5, /// Homestead transition test-net @@ -58,6 +63,17 @@ pub enum ForkSpec { ConstantinopleFixToIstanbulAt5, } +impl ForkSpec { + /// Returns true if the fork is at or after the merge. + pub fn is_eth2(&self) -> bool { + // NOTE: Include new forks in this match arm. + matches!( + *self, + ForkSpec::London | ForkSpec::Merge | ForkSpec::Shanghai + ) + } +} + /// Spec deserialization. #[derive(Debug, PartialEq, Deserialize)] #[serde(deny_unknown_fields)] diff --git a/jsontests/src/state.rs b/jsontests/src/state.rs index 760b8a1..0dadddb 100644 --- a/jsontests/src/state.rs +++ b/jsontests/src/state.rs @@ -139,6 +139,11 @@ impl JsonPrecompile { } // precompiles for London and Berlin are the same ForkSpec::London => Self::precompile(&ForkSpec::Berlin), + // TODO: true? + // precompiles for Merge and Berlin are the same + ForkSpec::Merge => Self::precompile(&ForkSpec::Berlin), + // precompiles for Shanghai and Berlin are the same + ForkSpec::Shanghai => Self::precompile(&ForkSpec::Berlin), _ => None, } } @@ -287,9 +292,11 @@ fn test_run(name: &str, test: Test) { } } + let actual_fee = executor.fee(vicinity.gas_price); - let mniner_reward = if let ForkSpec::London = spec { - // see EIP-1559 + // Forks after London burn miner rewards and thus have different gas fee + // calculation (see EIP-1559) + let miner_reward = if spec.is_eth2() { let max_priority_fee_per_gas = test.0.transaction.max_priority_fee_per_gas(); let max_fee_per_gas = test.0.transaction.max_fee_per_gas(); let base_fee_per_gas = vicinity.block_base_fee_per_gas; @@ -299,11 +306,14 @@ fn test_run(name: &str, test: Test) { } else { actual_fee }; + executor .state_mut() - .deposit(vicinity.block_coinbase, mniner_reward); + .deposit(vicinity.block_coinbase, miner_reward); executor.state_mut().deposit(caller, total_fee - actual_fee); + let (values, logs) = executor.into_state().deconstruct(); + backend.apply(values, logs, delete_empty); }