From 1e318692de81bec946662dac4ccf438220787c51 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Fri, 19 Apr 2024 09:35:59 +0100 Subject: [PATCH 1/7] burn base fee after eip-1559 included in london fork --- jsontests/src/run.rs | 4 ++-- jsontests/src/types.rs | 7 ++++++- src/standard/config.rs | 11 +++++++++++ src/standard/invoker/mod.rs | 21 +++++++++++++++++---- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/jsontests/src/run.rs b/jsontests/src/run.rs index 5fa6e8c6a..9ee310990 100644 --- a/jsontests/src/run.rs +++ b/jsontests/src/run.rs @@ -115,8 +115,8 @@ pub fn run_test( block_difficulty: test.env.current_difficulty, block_randomness: Some(test.env.current_random), block_gas_limit: test.env.current_gas_limit, - block_base_fee_per_gas: U256::zero(), // TODO: fill in this field. - chain_id: U256::zero(), // TODO: fill in this field. + block_base_fee_per_gas: test.transaction.gas_price, + chain_id: U256::zero(), // TODO: fill in this field. }; let state = test diff --git a/jsontests/src/types.rs b/jsontests/src/types.rs index 82b6be9f4..33b1fb41d 100644 --- a/jsontests/src/types.rs +++ b/jsontests/src/types.rs @@ -94,7 +94,11 @@ impl TestMulti { transaction: TestTransaction { data: self.transaction.data[post_state.indexes.data].0.clone(), gas_limit: self.transaction.gas_limit[post_state.indexes.gas], - gas_price: self.transaction.gas_price.unwrap_or(U256::zero()), + gas_price: self + .transaction + .gas_price + .unwrap_or(self.env.current_base_fee), + gas_priority_fee: self.transaction.max_priority_fee_per_gas, nonce: self.transaction.nonce, secret_key: self.transaction.secret_key, sender: self.transaction.sender, @@ -236,6 +240,7 @@ pub struct TestTransaction { pub data: Vec, pub gas_limit: U256, pub gas_price: U256, + pub gas_priority_fee: Option, pub nonce: U256, pub secret_key: H256, pub sender: H160, diff --git a/src/standard/config.rs b/src/standard/config.rs index 63300bab4..50760948d 100644 --- a/src/standard/config.rs +++ b/src/standard/config.rs @@ -97,6 +97,8 @@ pub struct Config { pub has_base_fee: bool, /// Has PUSH0 opcode. See [EIP-3855](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3855.md) pub has_push0: bool, + /// Uses EIP-1559 (Base fee is burned when this flag is enabled) [EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md) + pub eip_1559: bool, } impl Config { @@ -150,6 +152,7 @@ impl Config { has_ext_code_hash: false, has_base_fee: false, has_push0: false, + eip_1559: false, } } @@ -203,6 +206,7 @@ impl Config { has_ext_code_hash: true, has_base_fee: false, has_push0: false, + eip_1559: false, } } @@ -237,6 +241,7 @@ impl Config { disallow_executable_format, warm_coinbase_address, max_initcode_size, + eip_1559, } = inputs; // See https://eips.ethereum.org/EIPS/eip-2929 @@ -299,6 +304,7 @@ impl Config { has_ext_code_hash: true, has_base_fee, has_push0, + eip_1559, } } } @@ -315,6 +321,7 @@ struct DerivedConfigInputs { disallow_executable_format: bool, warm_coinbase_address: bool, max_initcode_size: Option, + eip_1559: bool, } impl DerivedConfigInputs { @@ -329,6 +336,7 @@ impl DerivedConfigInputs { disallow_executable_format: false, warm_coinbase_address: false, max_initcode_size: None, + eip_1559: false, } } @@ -343,6 +351,7 @@ impl DerivedConfigInputs { disallow_executable_format: true, warm_coinbase_address: false, max_initcode_size: None, + eip_1559: true, } } @@ -357,6 +366,7 @@ impl DerivedConfigInputs { disallow_executable_format: true, warm_coinbase_address: false, max_initcode_size: None, + eip_1559: true, } } @@ -372,6 +382,7 @@ impl DerivedConfigInputs { warm_coinbase_address: true, // 2 * 24576 as per EIP-3860 max_initcode_size: Some(0xC000), + eip_1559: true, } } } diff --git a/src/standard/invoker/mod.rs b/src/standard/invoker/mod.rs index e7e6576e6..e1fcb1d89 100644 --- a/src/standard/invoker/mod.rs +++ b/src/standard/invoker/mod.rs @@ -65,7 +65,7 @@ pub enum TransactValue { /// The invoke used in a top-layer transaction stack. pub struct TransactInvoke { pub create_address: Option, - pub gas_fee: U256, + pub gas_limit: U256, pub gas_price: U256, pub caller: H160, } @@ -230,7 +230,7 @@ where let value = args.value(); let invoke = TransactInvoke { - gas_fee, + gas_limit: args.gas_limit(), gas_price: args.gas_price(), caller: args.caller(), create_address: match &args { @@ -387,8 +387,6 @@ where Ok(_) | Err(ExitError::Reverted) => left_gas, Err(_) => U256::zero(), }; - let refunded_fee = refunded_gas.saturating_mul(invoke.gas_price); - let coinbase_reward = invoke.gas_fee.saturating_sub(refunded_fee); match &result { Ok(_) => { @@ -399,7 +397,22 @@ where } } + let refunded_fee = refunded_gas.saturating_mul(invoke.gas_price); handler.deposit(invoke.caller, refunded_fee); + // Reward coinbase address + // EIP-1559 updated the fee system so that miners only get to keep the priority fee. + // The base fee is always burned. + let coinbase_gas_price = if substate.config().eip_1559 { + invoke + .gas_price + .saturating_sub(handler.block_base_fee_per_gas()) + } else { + invoke.gas_price + }; + let coinbase_reward = invoke + .gas_limit + .saturating_mul(coinbase_gas_price) + .saturating_sub(refunded_fee); handler.deposit(handler.block_coinbase(), coinbase_reward); result From 654fb20800753f164af96b0f2fd41e62fc8794b2 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Wed, 8 May 2024 10:23:46 +0100 Subject: [PATCH 2/7] feat: add Cancun configuration --- src/standard/config.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/standard/config.rs b/src/standard/config.rs index 50760948d..75c72428f 100644 --- a/src/standard/config.rs +++ b/src/standard/config.rs @@ -230,6 +230,11 @@ impl Config { Self::config_with_derived_values(DerivedConfigInputs::shanghai()) } + /// Cancun hard fork configuration. + pub const fn cancun() -> Config { + Self::config_with_derived_values(DerivedConfigInputs::cancun()) + } + const fn config_with_derived_values(inputs: DerivedConfigInputs) -> Config { let DerivedConfigInputs { gas_storage_read_warm, @@ -312,8 +317,11 @@ impl Config { /// Independent inputs that are used to derive other config values. /// See `Config::config_with_derived_values` implementation for details. struct DerivedConfigInputs { + /// `WARM_STORAGE_READ_COST` (see EIP-2929). gas_storage_read_warm: u64, + /// `COLD_SLOAD_COST` (see EIP-2929). gas_sload_cold: u64, + /// `ACCESS_LIST_STORAGE_KEY_COST` (see EIP-2930). gas_access_list_storage_key: u64, decrease_clears_refund: bool, has_base_fee: bool, @@ -385,4 +393,20 @@ impl DerivedConfigInputs { eip_1559: true, } } + + const fn cancun() -> Self { + Self { + gas_storage_read_warm: 100, + gas_sload_cold: 2100, + gas_access_list_storage_key: 1900, + decrease_clears_refund: true, + has_base_fee: true, + has_push0: true, + disallow_executable_format: true, + warm_coinbase_address: true, + // 2 * (MAX_CODE_SIZE = `24576`) = (0xC000 = 49152) as per EIP-3860 + max_initcode_size: Some(0xC000), + eip_1559: true, + } + } } From 80d2d3c7e66087b3a305dfd3362c07002d78b2f0 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Wed, 8 May 2024 13:01:49 +0100 Subject: [PATCH 3/7] fix(eip-2929): some addresses were considered cold when they shouldn't --- interpreter/src/eval/system.rs | 7 --- src/standard/gasometer/mod.rs | 87 ++++++++++++++++++++++++++-------- 2 files changed, 66 insertions(+), 28 deletions(-) diff --git a/interpreter/src/eval/system.rs b/interpreter/src/eval/system.rs index 88256632a..bd97880d5 100644 --- a/interpreter/src/eval/system.rs +++ b/interpreter/src/eval/system.rs @@ -47,7 +47,6 @@ pub fn balance, H: RuntimeEnvironment + RuntimeBackend, T handler: &mut H, ) -> Control { pop!(machine, address); - handler.mark_hot(address.into(), None); push_u256!(machine, handler.balance(address.into())); Control::Continue @@ -127,7 +126,6 @@ pub fn extcodesize, H: RuntimeEnvironment + RuntimeBacken handler: &mut H, ) -> Control { pop!(machine, address); - handler.mark_hot(address.into(), None); let code_size = handler.code_size(address.into()); push_u256!(machine, code_size); @@ -139,7 +137,6 @@ pub fn extcodehash, H: RuntimeEnvironment + RuntimeBacken handler: &mut H, ) -> Control { pop!(machine, address); - handler.mark_hot(address.into(), None); let code_hash = handler.code_hash(address.into()); push!(machine, code_hash); @@ -152,8 +149,6 @@ pub fn extcodecopy, H: RuntimeEnvironment + RuntimeBacken ) -> Control { pop!(machine, address); pop_u256!(machine, memory_offset, code_offset, len); - - handler.mark_hot(address.into(), None); try_or_fail!(machine.memory.resize_offset(memory_offset, len)); let code = handler.code(address.into()); @@ -263,7 +258,6 @@ pub fn sload, H: RuntimeEnvironment + RuntimeBackend, Tr> handler: &mut H, ) -> Control { pop!(machine, index); - handler.mark_hot(machine.state.as_ref().context.address, Some(index)); let value = handler.storage(machine.state.as_ref().context.address, index); push!(machine, value); @@ -275,7 +269,6 @@ pub fn sstore, H: RuntimeEnvironment + RuntimeBackend, Tr handler: &mut H, ) -> Control { pop!(machine, index, value); - handler.mark_hot(machine.state.as_ref().context.address, Some(index)); match handler.set_storage(machine.state.as_ref().context.address, index, value) { Ok(()) => Control::Continue, diff --git a/src/standard/gasometer/mod.rs b/src/standard/gasometer/mod.rs index a526de53b..4e55d7db3 100644 --- a/src/standard/gasometer/mod.rs +++ b/src/standard/gasometer/mod.rs @@ -278,7 +278,7 @@ fn dynamic_opcode_cost( stack: &Stack, is_static: bool, config: &Config, - handler: &H, + handler: &mut H, ) -> Result<(GasCost, Option), ExitError> { let gas_cost = match opcode { Opcode::RETURN => GasCost::Zero, @@ -302,40 +302,59 @@ fn dynamic_opcode_cost( Opcode::EXTCODESIZE => { let target = stack.peek(0)?.into(); - GasCost::ExtCodeSize { - target_is_cold: handler.is_cold(target, None), - } + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + + GasCost::ExtCodeSize { target_is_cold } } Opcode::BALANCE => { let target = stack.peek(0)?.into(); - GasCost::Balance { - target_is_cold: handler.is_cold(target, None), - } + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + + GasCost::Balance { target_is_cold } } Opcode::BLOCKHASH => GasCost::BlockHash, Opcode::EXTCODEHASH if config.has_ext_code_hash => { let target = stack.peek(0)?.into(); - GasCost::ExtCodeHash { - target_is_cold: handler.is_cold(target, None), - } + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + + GasCost::ExtCodeHash { target_is_cold } } Opcode::EXTCODEHASH => GasCost::Invalid(opcode), Opcode::CALLCODE => { let target = stack.peek(1)?.into(); + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + GasCost::CallCode { value: U256::from_big_endian(&stack.peek(2)?[..]), gas: U256::from_big_endian(&stack.peek(0)?[..]), - target_is_cold: handler.is_cold(target, None), + target_is_cold, target_exists: { handler.exists(target) }, } } Opcode::STATICCALL => { let target = stack.peek(1)?.into(); + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + GasCost::StaticCall { gas: U256::from_big_endian(&stack.peek(0)?[..]), - target_is_cold: handler.is_cold(target, None), + target_is_cold, target_exists: { handler.exists(target) }, } } @@ -344,8 +363,13 @@ fn dynamic_opcode_cost( }, Opcode::EXTCODECOPY => { let target = stack.peek(0)?.into(); + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + GasCost::ExtCodeCopy { - target_is_cold: handler.is_cold(target, None), + target_is_cold, len: U256::from_big_endian(&stack.peek(3)?[..]), } } @@ -357,16 +381,24 @@ fn dynamic_opcode_cost( }, Opcode::SLOAD => { let index = stack.peek(0)?; - GasCost::SLoad { - target_is_cold: handler.is_cold(address, Some(index)), - } + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(address, Some(index)); + handler.mark_hot(address, Some(index)); + + GasCost::SLoad { target_is_cold } } Opcode::DELEGATECALL if config.has_delegate_call => { let target = stack.peek(1)?.into(); + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + GasCost::DelegateCall { gas: U256::from_big_endian(&stack.peek(0)?[..]), - target_is_cold: handler.is_cold(target, None), + target_is_cold, target_exists: { handler.exists(target) }, } } @@ -382,11 +414,15 @@ fn dynamic_opcode_cost( let index = stack.peek(0)?; let value = stack.peek(1)?; + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(address, Some(index)); + handler.mark_hot(address, Some(index)); + GasCost::SStore { original: handler.original_storage(address, index), current: handler.storage(address, index), new: value, - target_is_cold: handler.is_cold(address, Some(index)), + target_is_cold, } } Opcode::LOG0 if !is_static => GasCost::Log { @@ -415,9 +451,14 @@ fn dynamic_opcode_cost( }, Opcode::SUICIDE if !is_static => { let target = stack.peek(0)?.into(); + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + GasCost::Suicide { value: handler.balance(address), - target_is_cold: handler.is_cold(target, None), + target_is_cold, target_exists: { handler.exists(target) }, already_removed: handler.deleted(address), } @@ -427,10 +468,15 @@ fn dynamic_opcode_cost( || (is_static && U256::from_big_endian(&stack.peek(2)?[..]) == U256::zero()) => { let target = stack.peek(1)?.into(); + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + GasCost::Call { value: U256::from_big_endian(&stack.peek(2)?[..]), gas: U256::from_big_endian(&stack.peek(0)?[..]), - target_is_cold: handler.is_cold(target, None), + target_is_cold, target_exists: { handler.exists(target) }, } } @@ -696,7 +742,6 @@ impl GasCost { new, target_is_cold, } => costs::sstore_cost(original, current, new, gas, target_is_cold, config)?, - GasCost::Sha3 { len } => costs::sha3_cost(len)?, GasCost::Log { n, len } => costs::log_cost(n, len)?, GasCost::VeryLowCopy { len } => costs::verylowcopy_cost(len)?, From 6e9a7bd67806d0a10a4f01c086d9c7a622edf1e4 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Tue, 4 Jun 2024 10:56:10 +0100 Subject: [PATCH 4/7] Revert "feat: add Cancun configuration" This reverts commit 654fb20800753f164af96b0f2fd41e62fc8794b2. --- src/standard/config.rs | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/standard/config.rs b/src/standard/config.rs index cbeea9ec7..41dfe621c 100644 --- a/src/standard/config.rs +++ b/src/standard/config.rs @@ -234,11 +234,6 @@ impl Config { Self::config_with_derived_values(DerivedConfigInputs::shanghai()) } - /// Cancun hard fork configuration. - pub const fn cancun() -> Config { - Self::config_with_derived_values(DerivedConfigInputs::cancun()) - } - const fn config_with_derived_values(inputs: DerivedConfigInputs) -> Config { let DerivedConfigInputs { gas_storage_read_warm, @@ -323,11 +318,8 @@ impl Config { /// Independent inputs that are used to derive other config values. /// See `Config::config_with_derived_values` implementation for details. struct DerivedConfigInputs { - /// `WARM_STORAGE_READ_COST` (see EIP-2929). gas_storage_read_warm: u64, - /// `COLD_SLOAD_COST` (see EIP-2929). gas_sload_cold: u64, - /// `ACCESS_LIST_STORAGE_KEY_COST` (see EIP-2930). gas_access_list_storage_key: u64, decrease_clears_refund: bool, has_base_fee: bool, @@ -404,21 +396,4 @@ impl DerivedConfigInputs { eip_1153_enabled: false, } } - - const fn cancun() -> Self { - Self { - gas_storage_read_warm: 100, - gas_sload_cold: 2100, - gas_access_list_storage_key: 1900, - decrease_clears_refund: true, - has_base_fee: true, - has_push0: true, - disallow_executable_format: true, - warm_coinbase_address: true, - // 2 * (MAX_CODE_SIZE = `24576`) = (0xC000 = 49152) as per EIP-3860 - max_initcode_size: Some(0xC000), - eip_1559: true, - eip_1153_enabled: true, - } - } } From 743067949e8363d3d624075214b73763543c0ba4 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Tue, 4 Jun 2024 11:07:13 +0100 Subject: [PATCH 5/7] Revert "burn base fee after eip-1559 included in london fork" This reverts commit 1e318692de81bec946662dac4ccf438220787c51. --- jsontests/src/run.rs | 4 ++-- jsontests/src/types.rs | 7 +------ src/standard/config.rs | 11 ----------- src/standard/invoker/mod.rs | 21 ++++----------------- 4 files changed, 7 insertions(+), 36 deletions(-) diff --git a/jsontests/src/run.rs b/jsontests/src/run.rs index 3f113652a..fcc649f8c 100644 --- a/jsontests/src/run.rs +++ b/jsontests/src/run.rs @@ -121,8 +121,8 @@ pub fn run_test( block_difficulty: test.env.current_difficulty, block_randomness: Some(test.env.current_random), block_gas_limit: test.env.current_gas_limit, - block_base_fee_per_gas: test.transaction.gas_price, - chain_id: U256::zero(), // TODO: fill in this field. + block_base_fee_per_gas: U256::zero(), // TODO: fill in this field. + chain_id: U256::zero(), // TODO: fill in this field. }; let state = test diff --git a/jsontests/src/types.rs b/jsontests/src/types.rs index 28179d328..9e93a29a2 100644 --- a/jsontests/src/types.rs +++ b/jsontests/src/types.rs @@ -94,11 +94,7 @@ impl TestMulti { transaction: TestTransaction { data: self.transaction.data[post_state.indexes.data].0.clone(), gas_limit: self.transaction.gas_limit[post_state.indexes.gas], - gas_price: self - .transaction - .gas_price - .unwrap_or(self.env.current_base_fee), - gas_priority_fee: self.transaction.max_priority_fee_per_gas, + gas_price: self.transaction.gas_price.unwrap_or(U256::zero()), nonce: self.transaction.nonce, secret_key: self.transaction.secret_key, sender: self.transaction.sender, @@ -240,7 +236,6 @@ pub struct TestTransaction { pub data: Vec, pub gas_limit: U256, pub gas_price: U256, - pub gas_priority_fee: Option, pub nonce: U256, pub secret_key: H256, pub sender: H160, diff --git a/src/standard/config.rs b/src/standard/config.rs index 41dfe621c..5cb65b5d8 100644 --- a/src/standard/config.rs +++ b/src/standard/config.rs @@ -97,8 +97,6 @@ pub struct Config { pub has_base_fee: bool, /// Has PUSH0 opcode. See [EIP-3855](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3855.md) pub has_push0: bool, - /// Uses EIP-1559 (Base fee is burned when this flag is enabled) [EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md) - pub eip_1559: bool, /// Enables transient storage. See [EIP-1153](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1153.md) pub eip_1153_enabled: bool, } @@ -154,7 +152,6 @@ impl Config { has_ext_code_hash: false, has_base_fee: false, has_push0: false, - eip_1559: false, eip_1153_enabled: false, } } @@ -209,7 +206,6 @@ impl Config { has_ext_code_hash: true, has_base_fee: false, has_push0: false, - eip_1559: false, eip_1153_enabled: false, } } @@ -245,7 +241,6 @@ impl Config { disallow_executable_format, warm_coinbase_address, max_initcode_size, - eip_1559, eip_1153_enabled, } = inputs; @@ -309,7 +304,6 @@ impl Config { has_ext_code_hash: true, has_base_fee, has_push0, - eip_1559, eip_1153_enabled, } } @@ -327,7 +321,6 @@ struct DerivedConfigInputs { disallow_executable_format: bool, warm_coinbase_address: bool, max_initcode_size: Option, - eip_1559: bool, eip_1153_enabled: bool, } @@ -343,7 +336,6 @@ impl DerivedConfigInputs { disallow_executable_format: false, warm_coinbase_address: false, max_initcode_size: None, - eip_1559: false, eip_1153_enabled: false, } } @@ -359,7 +351,6 @@ impl DerivedConfigInputs { disallow_executable_format: true, warm_coinbase_address: false, max_initcode_size: None, - eip_1559: true, eip_1153_enabled: false, } } @@ -375,7 +366,6 @@ impl DerivedConfigInputs { disallow_executable_format: true, warm_coinbase_address: false, max_initcode_size: None, - eip_1559: true, eip_1153_enabled: false, } } @@ -392,7 +382,6 @@ impl DerivedConfigInputs { warm_coinbase_address: true, // 2 * 24576 as per EIP-3860 max_initcode_size: Some(0xC000), - eip_1559: true, eip_1153_enabled: false, } } diff --git a/src/standard/invoker/mod.rs b/src/standard/invoker/mod.rs index 25f688d1d..70bf27454 100644 --- a/src/standard/invoker/mod.rs +++ b/src/standard/invoker/mod.rs @@ -76,7 +76,7 @@ pub enum TransactValue { /// The invoke used in a top-layer transaction stack. pub struct TransactInvoke { pub create_address: Option, - pub gas_limit: U256, + pub gas_fee: U256, pub gas_price: U256, pub caller: H160, } @@ -241,7 +241,7 @@ where let value = args.value(); let invoke = TransactInvoke { - gas_limit: args.gas_limit(), + gas_fee, gas_price: args.gas_price(), caller: args.caller(), create_address: match &args { @@ -398,6 +398,8 @@ where Ok(_) | Err(ExitError::Reverted) => left_gas, Err(_) => U256::zero(), }; + let refunded_fee = refunded_gas.saturating_mul(invoke.gas_price); + let coinbase_reward = invoke.gas_fee.saturating_sub(refunded_fee); match &result { Ok(_) => { @@ -408,22 +410,7 @@ where } } - let refunded_fee = refunded_gas.saturating_mul(invoke.gas_price); handler.deposit(invoke.caller, refunded_fee); - // Reward coinbase address - // EIP-1559 updated the fee system so that miners only get to keep the priority fee. - // The base fee is always burned. - let coinbase_gas_price = if substate.config().eip_1559 { - invoke - .gas_price - .saturating_sub(handler.block_base_fee_per_gas()) - } else { - invoke.gas_price - }; - let coinbase_reward = invoke - .gas_limit - .saturating_mul(coinbase_gas_price) - .saturating_sub(refunded_fee); handler.deposit(handler.block_coinbase(), coinbase_reward); result From caed3bcef99b947ed99e4ecc4095a3f002ac00b3 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Tue, 4 Jun 2024 12:19:28 +0100 Subject: [PATCH 6/7] add eip-2929 test --- .github/workflows/rust.yml | 5 ++++- jsontests/src/lib.rs | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8de37da97..69859fd26 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -52,4 +52,7 @@ jobs: jsontests/res/ethtests/GeneralStateTests/VMTests/vmBitwiseLogicOperation/ \ jsontests/res/ethtests/GeneralStateTests/VMTests/vmIOandFlowOperations/ \ jsontests/res/ethtests/GeneralStateTests/VMTests/vmLogTest/ \ - jsontests/res/ethtests/GeneralStateTests/VMTests/vmTests/ + jsontests/res/ethtests/GeneralStateTests/VMTests/vmTests/ \ + jsontests/res/ethtests/GeneralStateTests/VMTests/vmTests/ \ + jsontests/res/ethtests/GeneralStateTests/stEIP150singleCodeGasPrices/eip2929.json + diff --git a/jsontests/src/lib.rs b/jsontests/src/lib.rs index 3dca24ae6..28661212f 100644 --- a/jsontests/src/lib.rs +++ b/jsontests/src/lib.rs @@ -73,3 +73,11 @@ fn vm_tests() { let tests_status = run::run_single(JSON_FILENAME, false).unwrap(); tests_status.print_total(); } + +#[test] +fn sqt_eip_2930() { + const JSON_FILENAME: &str = + "res/ethtests/GeneralStateTests/stEIP150singleCodeGasPrices/eip2929.json"; + let tests_status = run::run_single(JSON_FILENAME, false).unwrap(); + tests_status.print_total(); +} From c9316761b1e8d330880cf3b171230741712e7a14 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Tue, 4 Jun 2024 12:22:26 +0100 Subject: [PATCH 7/7] remove duplicated test --- .github/workflows/rust.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 69859fd26..b4dc811bd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -53,6 +53,5 @@ jobs: jsontests/res/ethtests/GeneralStateTests/VMTests/vmIOandFlowOperations/ \ jsontests/res/ethtests/GeneralStateTests/VMTests/vmLogTest/ \ jsontests/res/ethtests/GeneralStateTests/VMTests/vmTests/ \ - jsontests/res/ethtests/GeneralStateTests/VMTests/vmTests/ \ jsontests/res/ethtests/GeneralStateTests/stEIP150singleCodeGasPrices/eip2929.json