Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<PackageVersion Include="Nethermind.Libp2p" Version="1.0.0-preview.45" />
<PackageVersion Include="Nethermind.Libp2p.Protocols.PubsubPeerDiscovery" Version="1.0.0-preview.45" />
<PackageVersion Include="Nethermind.MclBindings" Version="1.0.4" />
<PackageVersion Include="Nethermind.Numerics.Int256" Version="1.3.6" />
<PackageVersion Include="Nethermind.Numerics.Int256" Version="1.4.0" />
Comment thread
benaadams marked this conversation as resolved.
<PackageVersion Include="Nito.Collections.Deque" Version="1.2.1" />
<PackageVersion Include="NJsonSchema" Version="11.3.2" />
<PackageVersion Include="NLog" Version="5.5.1" />
Expand Down Expand Up @@ -89,4 +89,4 @@
<PackageVersion Include="Websocket.Client" Version="5.3.0" />
<PackageVersion Include="ZstdSharp.Port" Version="0.8.6" />
</ItemGroup>
</Project>
</Project>
14 changes: 8 additions & 6 deletions src/Nethermind/Nethermind.Core/BaseFeeCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public UInt256 Calculate(BlockHeader parent, IEip1559Spec specFor1559)
if (specFor1559.IsEip1559Enabled)
{
UInt256 parentBaseFee = parent.BaseFeePerGas;
long gasDelta;
UInt256 feeDelta;
bool isForkBlockNumber = specFor1559.Eip1559TransitionBlock == parent.Number + 1;
long parentGasTarget = parent.GasLimit / specFor1559.ElasticityMultiplier;
if (isForkBlockNumber)
Expand All @@ -33,18 +31,22 @@ public UInt256 Calculate(BlockHeader parent, IEip1559Spec specFor1559)
{
expectedBaseFee = parent.BaseFeePerGas;
}
else if (parentGasTarget == 0 || specFor1559.BaseFeeMaxChangeDenominator.IsZero)
{
expectedBaseFee = parentBaseFee;
}
else if (parent.GasUsed > parentGasTarget)
{
gasDelta = parent.GasUsed - parentGasTarget;
feeDelta = UInt256.Max(
long gasDelta = parent.GasUsed - parentGasTarget;
UInt256 feeDelta = UInt256.Max(
parentBaseFee * (UInt256)gasDelta / (UInt256)parentGasTarget / specFor1559.BaseFeeMaxChangeDenominator,
UInt256.One);
expectedBaseFee = parentBaseFee + feeDelta;
}
else
{
gasDelta = parentGasTarget - parent.GasUsed;
feeDelta = parentBaseFee * (UInt256)gasDelta / (UInt256)parentGasTarget / specFor1559.BaseFeeMaxChangeDenominator;
long gasDelta = parentGasTarget - parent.GasUsed;
UInt256 feeDelta = parentBaseFee * (UInt256)gasDelta / (UInt256)parentGasTarget / specFor1559.BaseFeeMaxChangeDenominator;
expectedBaseFee = UInt256.Max(parentBaseFee - feeDelta, 0);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ static bool FakeExponentialOverflow(UInt256 factor, UInt256 num, UInt256 denomin
return true;
}

accumulator = updatedAccumulator / multipliedDenominator;
accumulator = multipliedDenominator.IsZero ? default : updatedAccumulator / multipliedDenominator;
}

feePerBlobGas = output / denominator;
feePerBlobGas = denominator.IsZero ? default : output / denominator;
return false;
}

Expand Down
18 changes: 10 additions & 8 deletions src/Nethermind/Nethermind.Optimism/OptimismCostHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ public UInt256 ComputeDaFootprint(Block block)
continue;

UInt256 flzLen = L1CostFastlzCoef * ComputeFlzCompressLen(tx);
UInt256 daUsageEstimate = UInt256.Max(
MinTransactionSizeScaled,
flzLen > L1CostInterceptNeg ? flzLen - L1CostInterceptNeg : 0 // avoid uint underflow
) / DaFootprintScale;
UInt256 daUsageEstimate = DaFootprintScale.IsZero ?
default :
UInt256.Max(
MinTransactionSizeScaled,
flzLen > L1CostInterceptNeg ? flzLen - L1CostInterceptNeg : 0 // avoid uint underflow
) / DaFootprintScale;

footprint += daUsageEstimate * daFootprintScalar;
}
Expand Down Expand Up @@ -205,19 +207,19 @@ public static UInt256 ComputeL1CostFjord(UInt256 fastLzSize, UInt256 l1BaseFee,
}

estimatedSize = UInt256.Max(MinTransactionSizeScaled, fastLzCost);
return estimatedSize * l1FeeScaled / FjordDivisor;
return FjordDivisor.IsZero ? default : estimatedSize * l1FeeScaled / FjordDivisor;
}

// Ecotone formula: (dataGas) * (16 * l1BaseFee * l1BaseFeeScalar + l1BlobBaseFee*l1BlobBaseFeeScalar) / 16e6
public static UInt256 ComputeL1CostEcotone(UInt256 dataGas, UInt256 l1BaseFee, UInt256 blobBaseFee, UInt256 l1BaseFeeScalar, UInt256 l1BlobBaseFeeScalar)
{
return dataGas * (PrecisionMultiplier * l1BaseFee * l1BaseFeeScalar + blobBaseFee * l1BlobBaseFeeScalar) / PrecisionDivisor;
return PrecisionDivisor.IsZero ? default : dataGas * (PrecisionMultiplier * l1BaseFee * l1BaseFeeScalar + blobBaseFee * l1BlobBaseFeeScalar) / PrecisionDivisor;
}

// Pre-Ecotone formula: (dataGas + overhead) * l1BaseFee * scalar / 1e6
public static UInt256 ComputeL1CostPreEcotone(UInt256 dataGasWithOverhead, UInt256 l1BaseFee, UInt256 feeScalar)
{
return dataGasWithOverhead * l1BaseFee * feeScalar / BasicDivisor;
return BasicDivisor.IsZero ? default : dataGasWithOverhead * l1BaseFee * feeScalar / BasicDivisor;
}

// Based on:
Expand Down Expand Up @@ -321,7 +323,7 @@ uint setNextHash(uint ip, ref Span<uint> ht)
return FlzCompressLen(encoded);
}

internal static UInt256 ComputeGasUsedFjord(UInt256 estimatedSize) => estimatedSize * GasCostOf.TxDataNonZeroEip2028 / BasicDivisor;
internal static UInt256 ComputeGasUsedFjord(UInt256 estimatedSize) => BasicDivisor.IsZero ? default : estimatedSize * GasCostOf.TxDataNonZeroEip2028 / BasicDivisor;

// https://specs.optimism.io/protocol/jovian/exec-engine.html#scalar-loading
// https://specs.optimism.io/protocol/jovian/l1-attributes.html
Expand Down
8 changes: 4 additions & 4 deletions src/Nethermind/Nethermind.Runner/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@
"Microsoft.IdentityModel.JsonWebTokens": "[8.15.0, )",
"Nethermind.Crypto.SecP256k1": "[1.5.0, )",
"Nethermind.Logging": "[1.37.0-unstable, )",
"Nethermind.Numerics.Int256": "[1.3.6, )",
"Nethermind.Numerics.Int256": "[1.4.0, )",
"NonBlocking": "[2.1.2, )",
"TestableIO.System.IO.Abstractions.Wrappers": "[22.1.0, )"
}
Expand Down Expand Up @@ -1489,9 +1489,9 @@
},
"Nethermind.Numerics.Int256": {
"type": "CentralTransitive",
"requested": "[1.3.6, )",
"resolved": "1.3.6",
"contentHash": "Sk/CakMkQZuCUflJxYlj9gVTfxbTPJKsgDS5fsRWdzYA6hHVQipNJfyD6xnrF3u1X6XJadeyTTa3Rs80hJCMvQ=="
"requested": "[1.4.0, )",
"resolved": "1.4.0",
"contentHash": "w8HRMsdpX9fG9kcELJeJPEKIZgOUTCe47ebtejCvfBYQVlabA9blqba6QWIt5oG8cRSgnVlQ24DsdGsLzqFM+Q=="
},
"Nito.Collections.Deque": {
"type": "CentralTransitive",
Expand Down
13 changes: 10 additions & 3 deletions src/Nethermind/Nethermind.Taiko/Rpc/SurgeGasPriceOracle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,16 @@ public override async ValueTask<UInt256> GetGasPriceEstimate()
Math.Max(averageGasUsage, _surgeConfig.L2GasPerL2Batch);

// Adjust the gas price estimate with the config values.
UInt256 adjustedGasPriceEstimate = gasPriceEstimate + gasPriceEstimate * (UInt256)_surgeConfig.BoostBaseFeePercentage / 100;
adjustedGasPriceEstimate = adjustedGasPriceEstimate * 100 / (UInt256)_surgeConfig.SharingPercentage;

UInt256 adjustedGasPriceEstimate;
if (_surgeConfig.SharingPercentage == 0)
{
adjustedGasPriceEstimate = default;
}
else
{
adjustedGasPriceEstimate = gasPriceEstimate + gasPriceEstimate * (UInt256)_surgeConfig.BoostBaseFeePercentage / 100;
adjustedGasPriceEstimate = adjustedGasPriceEstimate * 100 / (UInt256)_surgeConfig.SharingPercentage;
}
// Update the cache and timestamp
_gasPriceEstimation.Set(headBlockHash, adjustedGasPriceEstimate);
_lastGasPriceCalculation = DateTime.UtcNow;
Expand Down
27 changes: 21 additions & 6 deletions src/Nethermind/Nethermind.Taiko/TaikoHeaderValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,37 @@ private static UInt256 CalculateEip4396BaseFee(BlockHeader parent, ulong parentB
{
// If the parent block used more gas than its target, the baseFee should increase
// max(1, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
UInt256 gasUsedDelta = (ulong)parent.GasUsed - parentAdjustedGasTarget;
UInt256 feeDelta = parent.BaseFeePerGas * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator;

if (feeDelta < 1)
UInt256 feeDelta;
if (parentGasTarget == 0 || baseFeeChangeDenominator.IsZero)
{
feeDelta = 1;
}
else
{
UInt256 gasUsedDelta = (ulong)parent.GasUsed - parentAdjustedGasTarget;
feeDelta = parent.BaseFeePerGas * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator;
if (feeDelta < 1)
{
feeDelta = 1;
}
}

baseFee = parent.BaseFeePerGas + feeDelta;
}
else
{
// Otherwise if the parent block used less gas than its target, the baseFee should decrease
// max(0, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator)
UInt256 gasUsedDelta = parentAdjustedGasTarget - (ulong)parent.GasUsed;
UInt256 feeDelta = parent.BaseFeePerGas * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator;
UInt256 feeDelta;
if (parentGasTarget == 0 || baseFeeChangeDenominator.IsZero)
{
feeDelta = 0;
}
else
{
UInt256 gasUsedDelta = parentAdjustedGasTarget - (ulong)parent.GasUsed;
feeDelta = parent.BaseFeePerGas * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator;
}

baseFee = parent.BaseFeePerGas > feeDelta ? parent.BaseFeePerGas - feeDelta : UInt256.Zero;
}
Expand Down