Skip to content

Commit

Permalink
Fix MaxFeePerDataGas affects consensus on low balance
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 committed Jun 14, 2023
1 parent d093db7 commit 6105dfb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public static IEnumerable<TestCaseData> 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 does not cover {nameof(Transaction.MaxFeePerDataGas)}, all funds are returned",
ExpectedResult = UInt256.Zero,
};
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down

0 comments on commit 6105dfb

Please sign in to comment.