Skip to content

Commit

Permalink
Temporary fix gas rules, probably not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 committed Apr 20, 2023
1 parent e5441a3 commit 66c66e9
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ private void Execute(Transaction transaction, BlockHeader block, ITxTracer txTra
bool notSystemTransaction = !transaction.IsSystem();
bool deleteCallerAccount = false;

if (UInt256.MaxValue == block.ParentExcessDataGas && spec.IsEip4844Enabled)
{
throw new InvalidOperationException();
}

if (!notSystemTransaction)
{
spec = new SystemTransactionReleaseSpec(spec);
Expand Down Expand Up @@ -178,10 +183,6 @@ private void Execute(Transaction transaction, BlockHeader block, ITxTracer txTra
QuickFail(transaction, block, txTracer, eip658NotEnabled, "sender has deployed code");
return;
}
if (UInt256.MaxValue == block.ParentExcessDataGas && spec.IsEip4844Enabled)
{
throw new InvalidOperationException();
}

if (!noValidation && transaction.Nonce >= ulong.MaxValue - 1)
{
Expand Down Expand Up @@ -256,13 +257,13 @@ private void Execute(Transaction transaction, BlockHeader block, ITxTracer txTra
}

UInt256 blobsGasCost = IntrinsicGasCalculator.CalculateBlobsGasCost(transaction, block.ParentExcessDataGas, spec);
UInt256 senderReservedGasPayment = noValidation ? UInt256.Zero : ((ulong)gasLimit * effectiveGasPrice + blobsGasCost);
UInt256 senderReservedGasPayment = noValidation ? UInt256.Zero : ((ulong)gasLimit * effectiveGasPrice);

if (notSystemTransaction)
{
UInt256 senderBalance = _stateProvider.GetBalance(caller);
if (!noValidation && ((ulong)intrinsicGas * effectiveGasPrice + value + blobsGasCost > senderBalance ||
senderReservedGasPayment + value > senderBalance))
senderReservedGasPayment + value + blobsGasCost > senderBalance))
{
TraceLogInvalidTx(transaction,
$"INSUFFICIENT_SENDER_BALANCE: ({caller})_BALANCE = {senderBalance}");
Expand All @@ -271,7 +272,7 @@ private void Execute(Transaction transaction, BlockHeader block, ITxTracer txTra
}

if (!noValidation && spec.IsEip1559Enabled && !transaction.IsFree() &&
senderBalance < (UInt256)transaction.GasLimit * transaction.MaxFeePerGas + value)
senderBalance < (UInt256)transaction.GasLimit * transaction.MaxFeePerGas + value + blobsGasCost)
{
TraceLogInvalidTx(transaction,
$"INSUFFICIENT_MAX_FEE_PER_GAS_FOR_SENDER_BALANCE: ({caller})_BALANCE = {senderBalance}, MAX_FEE_PER_GAS: {transaction.MaxFeePerGas}");
Expand Down Expand Up @@ -511,6 +512,7 @@ private void Execute(Transaction transaction, BlockHeader block, ITxTracer txTra
substate.Logs.Any() ? substate.Logs.ToArray() : Array.Empty<LogEntry>(), stateRoot);
}
}
_stateProvider.SubtractFromBalance(caller, blobsGasCost, spec);
}

private void PrepareAccountForContractDeployment(Address contractAddress, IReleaseSpec spec)
Expand Down

0 comments on commit 66c66e9

Please sign in to comment.