Skip to content

Commit

Permalink
Add OP Granite fork (#7503)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Sep 28, 2024
1 parent b8a5f1e commit ec35a25
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/Nethermind/Chains/base-mainnet.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Base Goerli",
"dataDir": "base-goerli",
"name": "Base Mainnet",
"dataDir": "base-mainnet",
"engine": {
"Optimism": {
"params": {
Expand All @@ -9,6 +9,7 @@
"canyonTimestamp": "0x65a01e91",
"ecotoneTimestamp": "0x65f23e01",
"fjordTimestamp": "0x668eb001",
"graniteTimestamp": "0x66e1be81",
"l1FeeRecipient": "0x420000000000000000000000000000000000001A",
"l1BlockAddress": "0x4200000000000000000000000000000000000015",
"canyonBaseFeeChangeDenominator": "250",
Expand Down Expand Up @@ -65,6 +66,7 @@
"eip6780TransitionTimestamp": "0x65f23e01",

"rip7212TransitionTimestamp": "0x668eb001",
"opGraniteTransitionTimestamp": "0x66e1be81",

"terminalTotalDifficulty": "0"
},
Expand Down
2 changes: 2 additions & 0 deletions src/Nethermind/Chains/base-sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"canyonTimestamp": "0x6553a790",
"ecotoneTimestamp": "0x65d62c10",
"fjordTimestamp": "0x66575100",
"graniteTimestamp": "0x66ba3180",
"l1FeeRecipient": "0x420000000000000000000000000000000000001A",
"l1BlockAddress": "0x4200000000000000000000000000000000000015",
"canyonBaseFeeChangeDenominator": "250",
Expand Down Expand Up @@ -65,6 +66,7 @@
"eip6780TransitionTimestamp": "0x65D62C10",

"rip7212TransitionTimestamp": "0x66575100",
"opGraniteTransitionTimestamp": "0x66ba3180",

"terminalTotalDifficulty": "0"
},
Expand Down
2 changes: 2 additions & 0 deletions src/Nethermind/Chains/op-mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"canyonTimestamp": "0x65a01e91",
"ecotoneTimestamp": "0x65f23e01",
"fjordTimestamp": "0x668eb001",
"graniteTimestamp": "0x66e1be81",
"l1FeeRecipient": "0x420000000000000000000000000000000000001A",
"l1BlockAddress": "0x4200000000000000000000000000000000000015",
"canyonBaseFeeChangeDenominator": "250",
Expand Down Expand Up @@ -70,6 +71,7 @@
"eip6780TransitionTimestamp": "0x65f23e01",

"rip7212TransitionTimestamp": "0x668eb001",
"opGraniteTransitionTimestamp": "0x66e1be81",

"terminalTotalDifficulty": "0"
},
Expand Down
4 changes: 3 additions & 1 deletion src/Nethermind/Chains/op-sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"canyonTimestamp": "0x6553a790",
"ecotoneTimestamp": "0x65D62C10",
"fjordTimestamp": "0x66575100",
"graniteTimestamp": "0x66ba3180",
"l1FeeRecipient": "0x420000000000000000000000000000000000001A",
"l1BlockAddress": "0x4200000000000000000000000000000000000015",
"canyonBaseFeeChangeDenominator": "250",
Expand Down Expand Up @@ -62,6 +63,7 @@
"eip5656TransitionTimestamp": "0x65D62C10",
"eip6780TransitionTimestamp": "0x65D62C10",
"rip7212TransitionTimestamp": "0x66575100",
"opGraniteTransitionTimestamp": "0x66ba3180",
"terminalTotalDifficulty": "0"
},
"genesis": {
Expand Down Expand Up @@ -12574,4 +12576,4 @@
"balance": "0x0"
}
}
}
}
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ public interface IReleaseSpec : IEip1559Spec, IReceiptSpec
/// </summary>
bool IsRip7212Enabled { get; }

/// OP Granite
bool IsOpGraniteEnabled { get; }

/// <summary>
/// Should transactions be validated against chainId.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class ReleaseSpecDecorator(IReleaseSpec spec) : IReleaseSpec
public virtual Address Eip2935ContractAddress => spec.Eip2935ContractAddress;
public virtual bool IsEip6780Enabled => spec.IsEip6780Enabled;
public virtual bool IsRip7212Enabled => spec.IsRip7212Enabled;
public virtual bool IsOpGraniteEnabled => spec.IsOpGraniteEnabled;
public virtual ulong WithdrawalTimestamp => spec.WithdrawalTimestamp;
public virtual ulong Eip4844TransitionTimestamp => spec.Eip4844TransitionTimestamp;
public virtual bool IsEip158IgnoredAccount(Address address) => spec.IsEip158IgnoredAccount(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Nethermind.Evm.Precompiles.Snarks;
/// </summary>
public class Bn254PairingPrecompile : IPrecompile<Bn254PairingPrecompile>
{
private const int Bn256PairingMaxInputSizeGranite = 112687;
private const int PairSize = 192;

public static Bn254PairingPrecompile Instance = new Bn254PairingPrecompile();
Expand All @@ -27,7 +28,10 @@ public class Bn254PairingPrecompile : IPrecompile<Bn254PairingPrecompile>
public (ReadOnlyMemory<byte>, bool) Run(in ReadOnlyMemory<byte> inputData, IReleaseSpec releaseSpec)
{
Metrics.Bn254PairingPrecompile++;

if (releaseSpec.IsOpGraniteEnabled && inputData.Length > Bn256PairingMaxInputSizeGranite)
{
return IPrecompile.Failure;
}
if (inputData.Length % PairSize > 0)
{
// note that it will not happen in case of null / 0 length
Expand Down
5 changes: 3 additions & 2 deletions src/Nethermind/Nethermind.Network/ProtocolValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ private bool ValidateEthProtocol(ISession session, ProtocolInitializedEventArgs
return Disconnect(session, DisconnectReason.MissingForkId, CompatibilityValidationType.MissingForkId, "missing fork id");
}

if (_forkInfo.ValidateForkId(syncPeerArgs.ForkId.Value, _blockTree.Head?.Header) != ValidationResult.Valid)
ValidationResult validationResult = _forkInfo.ValidateForkId(syncPeerArgs.ForkId.Value, _blockTree.Head?.Header);
if (validationResult != ValidationResult.Valid)
{
return Disconnect(session, DisconnectReason.InvalidForkId, CompatibilityValidationType.InvalidForkId, "invalid fork id");
return Disconnect(session, DisconnectReason.InvalidForkId, CompatibilityValidationType.InvalidForkId, $"{validationResult}, network id {syncPeerArgs.NetworkId} fork id {syncPeerArgs.ForkId.Value}");
}

return true;
Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Optimism/IOptimismSpecHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IOptimismSpecHelper
bool IsCanyon(BlockHeader header);
bool IsEcotone(BlockHeader header);
bool IsFjord(BlockHeader header);
bool IsGranite(BlockHeader header);
Address? Create2DeployerAddress { get; }
byte[]? Create2DeployerCode { get; }
}
6 changes: 6 additions & 0 deletions src/Nethermind/Nethermind.Optimism/OPConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class OptimismSpecHelper(OptimismParameters parameters) : IOptimismSpecHe
private readonly ulong? _canyonTimestamp = parameters.CanyonTimestamp;
private readonly ulong? _ecotoneTimestamp = parameters.EcotoneTimestamp;
private readonly ulong? _fjordTimestamp = parameters.FjordTimestamp;
private readonly ulong? _graniteTimestamp = parameters.GraniteTimestamp;

public Address L1FeeReceiver { get; init; } = parameters.L1FeeRecipient;

Expand Down Expand Up @@ -41,6 +42,11 @@ public bool IsFjord(BlockHeader header)
return header.Timestamp >= _fjordTimestamp;
}

public bool IsGranite(BlockHeader header)
{
return header.Timestamp >= _graniteTimestamp;
}

public Address? Create2DeployerAddress { get; } = parameters.Create2DeployerAddress;
public byte[]? Create2DeployerCode { get; } = parameters.Create2DeployerCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public OverridableReleaseSpec(IReleaseSpec spec)
public bool IsEip3541Enabled => _spec.IsEip3541Enabled;
public bool IsEip4844Enabled => _spec.IsEip4844Enabled;
public bool IsRip7212Enabled => _spec.IsRip7212Enabled;
public bool IsOpGraniteEnabled => _spec.IsOpGraniteEnabled;
public bool IsEip3607Enabled { get; set; }

public bool IsEip158IgnoredAccount(Address address) => _spec.IsEip158IgnoredAccount(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public class ChainParameters
public ulong? Eip2935TransitionTimestamp { get; set; }
public Address Eip2935ContractAddress { get; set; }
public ulong? Rip7212TransitionTimestamp { get; set; }
public ulong? OpGraniteTransitionTimestamp { get; set; }

#region EIP-4844 parameters
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ private static ReleaseSpec CreateReleaseSpec(ChainSpec chainSpec, long releaseSt

releaseSpec.IsEip4844Enabled = (chainSpec.Parameters.Eip4844TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp;
releaseSpec.IsRip7212Enabled = (chainSpec.Parameters.Rip7212TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp;
releaseSpec.IsOpGraniteEnabled = (chainSpec.Parameters.OpGraniteTransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp;
releaseSpec.Eip4844TransitionTimestamp = chainSpec.Parameters.Eip4844TransitionTimestamp ?? ulong.MaxValue;
releaseSpec.IsEip5656Enabled = (chainSpec.Parameters.Eip5656TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp;
releaseSpec.IsEip6780Enabled = (chainSpec.Parameters.Eip6780TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ bool GetForInnerPathExistence(KeyValuePair<string, JsonElement> o) =>
Eip5656TransitionTimestamp = chainSpecJson.Params.Eip5656TransitionTimestamp,
Eip6780TransitionTimestamp = chainSpecJson.Params.Eip6780TransitionTimestamp,
Rip7212TransitionTimestamp = chainSpecJson.Params.Rip7212TransitionTimestamp,
OpGraniteTransitionTimestamp = chainSpecJson.Params.OpGraniteTransitionTimestamp,
Eip4788TransitionTimestamp = chainSpecJson.Params.Eip4788TransitionTimestamp,
Eip4788ContractAddress = chainSpecJson.Params.Eip4788ContractAddress ?? Eip4788Constants.BeaconRootsAddress,
Eip2935TransitionTimestamp = chainSpecJson.Params.Eip2935TransitionTimestamp,
Expand Down Expand Up @@ -339,6 +340,7 @@ static AuRaParameters.Validator LoadValidator(ChainSpecJson.AuRaValidatorJson va
CanyonTimestamp = chainSpecJson.Engine.Optimism.CanyonTimestamp,
EcotoneTimestamp = chainSpecJson.Engine.Optimism.EcotoneTimestamp,
FjordTimestamp = chainSpecJson.Engine.Optimism.FjordTimestamp,
GraniteTimestamp = chainSpecJson.Engine.Optimism.GraniteTimestamp,

L1FeeRecipient = chainSpecJson.Engine.Optimism.L1FeeRecipient,
L1BlockAddress = chainSpecJson.Engine.Optimism.L1BlockAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ internal class OptimismEngineJson
public ulong? CanyonTimestamp => Params.CanyonTimestamp;
public ulong? EcotoneTimestamp => Params.EcotoneTimestamp;
public ulong? FjordTimestamp => Params.FjordTimestamp;
public ulong? GraniteTimestamp => Params.GraniteTimestamp;
public Address L1FeeRecipient => Params.L1FeeRecipient;
public Address L1BlockAddress => Params.L1BlockAddress;
public UInt256 CanyonBaseFeeChangeDenominator => Params.CanyonBaseFeeChangeDenominator;
Expand All @@ -190,6 +191,7 @@ internal class OptimismEngineParamsJson
public ulong? CanyonTimestamp { get; set; }
public ulong? EcotoneTimestamp { get; set; }
public ulong? FjordTimestamp { get; set; }
public ulong? GraniteTimestamp { get; set; }
public Address L1FeeRecipient { get; set; }
public Address L1BlockAddress { get; set; }
public UInt256 CanyonBaseFeeChangeDenominator { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,5 @@ internal class ChainSpecParamsJson
public UInt256? Eip4844MinBlobGasPrice { get; set; }
public ulong? Eip4844TargetBlobGasPerBlock { get; set; }
public ulong? Rip7212TransitionTimestamp { get; set; }
public ulong? OpGraniteTransitionTimestamp { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class OptimismParameters
public ulong? EcotoneTimestamp { get; set; }

public ulong? FjordTimestamp { get; set; }
public ulong? GraniteTimestamp { get; set; }

public Address L1FeeRecipient { get; set; }

Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Specs/ReleaseSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public bool IsEip1559Enabled
public bool IsEip4895Enabled { get; set; }
public bool IsEip4844Enabled { get; set; }
public bool IsRip7212Enabled { get; set; }
public bool IsOpGraniteEnabled { get; set; }
public bool IsEip5656Enabled { get; set; }
public bool IsEip6780Enabled { get; set; }
public bool IsEip4788Enabled { get; set; }
Expand Down

0 comments on commit ec35a25

Please sign in to comment.