From 57a6811e8c64c70468749647ce17b9bbcce84dd0 Mon Sep 17 00:00:00 2001 From: Alexey Osipov Date: Wed, 14 Jun 2023 22:02:05 +0300 Subject: [PATCH] Fix MaxFeePerDataGas affects consensus on low balance --- .../Nethermind.Evm.Test/TransactionProcessorEip4844Tests.cs | 5 +++++ .../TransactionProcessing/TransactionProcessor.cs | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Evm.Test/TransactionProcessorEip4844Tests.cs b/src/Nethermind/Nethermind.Evm.Test/TransactionProcessorEip4844Tests.cs index 6408fa4afe27..3a18273cbb55 100644 --- a/src/Nethermind/Nethermind.Evm.Test/TransactionProcessorEip4844Tests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/TransactionProcessorEip4844Tests.cs @@ -120,6 +120,11 @@ public static IEnumerable BalanceIsNotAffectedWhenNotEnoughFunds() TestName = $"Rejected if balance is not enough due to data gas price hiking, all funds are returned", ExpectedResult = UInt256.Zero, }; + yield return new TestCaseData((UInt256)(GasCostOf.Transaction + Eip4844Constants.DataGasPerBlob), 1, 2ul, 0ul) + { + TestName = $"Rejected if balance is does not cover {nameof(Transaction.MaxFeePerDataGas)}, all funds are returned", + ExpectedResult = UInt256.Zero, + }; } [Test] diff --git a/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs b/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs index 232765073549..926404c8d082 100644 --- a/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs +++ b/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs @@ -258,8 +258,12 @@ private void Execute(Transaction transaction, BlockHeader block, ITxTracer txTra return; } + UInt256 maxDataGasPrice = spec.IsEip4844Enabled + ? DataGasCalculator.CalculateDataGas(transaction) * transaction.MaxFeePerDataGas.Value + : UInt256.Zero; + if (!noValidation && spec.IsEip1559Enabled && !transaction.IsFree() && - (UInt256)transaction.GasLimit * transaction.MaxFeePerGas + value + dataGasPrice > senderBalance) + (UInt256)transaction.GasLimit * transaction.MaxFeePerGas + value + maxDataGasPrice > senderBalance) { TraceLogInvalidTx(transaction, $"INSUFFICIENT_MAX_FEE_PER_GAS_FOR_SENDER_BALANCE: ({caller})_BALANCE = {senderBalance}, MAX_FEE_PER_GAS: {transaction.MaxFeePerGas}");