Skip to content

Commit

Permalink
add eip7742 logic to TryCalculateFeePerBlobGas
Browse files Browse the repository at this point in the history
  • Loading branch information
yerke26 committed Nov 4, 2024
1 parent ba1a3de commit 87e721a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,22 @@ public static ulong CalculateBlobGas(Transaction[] transactions)
return CalculateBlobGas(blobCount);
}

public static bool TryCalculateBlobBaseFee(BlockHeader header, Transaction transaction, out UInt256 blobBaseFee)
public static bool TryCalculateBlobBaseFee(BlockHeader header, Transaction transaction, out UInt256 blobBaseFee, IReleaseSpec spec)
{
if (!TryCalculateFeePerBlobGas(header.ExcessBlobGas.Value, out UInt256 feePerBlobGas))
if (!TryCalculateFeePerBlobGas(out UInt256 feePerBlobGas, header, spec))
{
blobBaseFee = UInt256.MaxValue;
return false;
}
return !UInt256.MultiplyOverflow(CalculateBlobGas(transaction), feePerBlobGas, out blobBaseFee);
}

public static bool TryCalculateFeePerBlobGas(BlockHeader header, out UInt256 feePerBlobGas)
public static bool TryCalculateFeePerBlobGas(BlockHeader header, out UInt256 feePerBlobGas, IReleaseSpec spec)
{
feePerBlobGas = UInt256.MaxValue;
return header.ExcessBlobGas is not null
&& TryCalculateFeePerBlobGas(header.ExcessBlobGas.Value, out feePerBlobGas);
return TryCalculateFeePerBlobGas(out feePerBlobGas, header, spec);
}

public static bool TryCalculateFeePerBlobGas(ulong excessBlobGas, out UInt256 feePerBlobGas)
public static bool TryCalculateFeePerBlobGas(out UInt256 feePerBlobGas, BlockHeader header, IReleaseSpec spec)
{
static bool FakeExponentialOverflow(UInt256 factor, UInt256 num, UInt256 denominator, out UInt256 feePerBlobGas)
{
Expand Down Expand Up @@ -86,7 +84,13 @@ static bool FakeExponentialOverflow(UInt256 factor, UInt256 num, UInt256 denomin
return false;
}

return !FakeExponentialOverflow(Eip4844Constants.MinBlobGasPrice, excessBlobGas, Eip4844Constants.BlobGasPriceUpdateFraction, out feePerBlobGas);
var denominator = spec.IsEip7742Enabled
? Eip7742Constants.BlobGasPriceUpdateFraction * header.TargetBlobCount

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.sln)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (release, SendBlobs/SendBlobs.sln)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.sln)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (release, Evm/Evm.sln)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (release, TxParser/TxParser.csproj)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (release, TxParser/TxParser.csproj)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.sln)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (release, DocGen/DocGen.sln)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Benchmarks)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Benchmarks)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (release, Benchmarks)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (release, Benchmarks)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Nethermind)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Nethermind)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (release, Nethermind)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (release, Nethermind)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

The name 'Eip7742Constants' does not exist in the current context

Check failure on line 88 in src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs

View workflow job for this annotation

GitHub Actions / Build (release, EthereumTests)

The name 'Eip7742Constants' does not exist in the current context
?? throw new InvalidDataException("header is missing target blob count")
: Eip4844Constants.BlobGasPriceUpdateFraction;

feePerBlobGas = UInt256.MaxValue;
return header.ExcessBlobGas is not null && !FakeExponentialOverflow(Eip4844Constants.MinBlobGasPrice, header.ExcessBlobGas.Value, denominator, out feePerBlobGas);
}

public static ulong? CalculateExcessBlobGas(BlockHeader? parentBlockHeader, IReleaseSpec releaseSpec, BlockHeader header)
Expand Down

0 comments on commit 87e721a

Please sign in to comment.