From 82fc1a919408410c76ac243aed111ab8a215abb6 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Mon, 30 Dec 2024 09:49:19 +0000 Subject: [PATCH 01/24] start implementing eip7843 --- .../Nethermind.Core/Specs/IReleaseSpec.cs | 5 ++ .../Nethermind.Core/Specs/ISpecProvider.cs | 23 ++++++++ .../Precompiles/Blake2FPrecompile.cs | 2 +- .../Precompiles/Bls/G1AddPrecompile.cs | 2 +- .../Precompiles/Bls/G1MSMPrecompile.cs | 4 +- .../Precompiles/Bls/G1MulPrecompile.cs | 59 ------------------- .../Precompiles/Bls/G2AddPrecompile.cs | 4 +- .../Precompiles/Bls/G2MSMPrecompile.cs | 4 +- .../Precompiles/Bls/MapFp2ToG2Precompile.cs | 4 +- .../Precompiles/Bls/MapFpToG1Precompile.cs | 4 +- .../Precompiles/Bls/PairingCheckPrecompile.cs | 4 +- .../Precompiles/EcRecoverPrecompile.cs | 2 +- .../Nethermind.Evm/Precompiles/IPrecompile.cs | 2 +- .../Precompiles/IdentityPrecompile.cs | 2 +- .../Precompiles/ModExpPrecompile.cs | 2 +- .../Precompiles/ModExpPrecompilePreEip2565.cs | 2 +- .../Precompiles/PointEvaluationPrecompile.cs | 2 +- .../Precompiles/Ripemd160Precompile.cs | 2 +- .../Precompiles/Secp256r1Precompile.cs | 2 +- .../Precompiles/Sha256Precompile.cs | 2 +- .../Precompiles/Snarks/Bn254AddPrecompile.cs | 2 +- .../Precompiles/Snarks/Bn254MulPrecompile.cs | 2 +- .../Snarks/Bn254PairingPrecompile.cs | 4 +- .../Nethermind.Evm/VirtualMachine.cs | 3 +- .../Nethermind.Shutter/ShutterTime.cs | 26 ++++---- .../ChainSpecBasedSpecProvider.cs | 2 + .../Nethermind.Specs/ReleaseSpec.cs | 2 + 27 files changed, 72 insertions(+), 102 deletions(-) delete mode 100644 src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs diff --git a/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs b/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs index 0241fa1912a..8e7c60df854 100644 --- a/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs +++ b/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs @@ -418,6 +418,11 @@ public interface IReleaseSpec : IEip1559Spec, IReceiptSpec bool IsAuthorizationListEnabled => IsEip7702Enabled; + /// + /// EIP-7843: Slot precompile + /// + bool IsEip7843Enabled { get; } + public bool RequestsEnabled => ConsolidationRequestsEnabled || WithdrawalRequestsEnabled || DepositsEnabled; } } diff --git a/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs b/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs index 67bb4619bd8..c9c3875cb5b 100644 --- a/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs +++ b/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only +using System; using Nethermind.Int256; namespace Nethermind.Core.Specs @@ -64,6 +65,12 @@ public interface ISpecProvider /// ulong ChainId { get; } + + /// + /// Duration of each slot + /// + TimeSpan SlotLength { get; } + /// /// Original engine of the chain /// @@ -100,5 +107,21 @@ public static IReleaseSpec GetSpec(this ISpecProvider specProvider, ForkActivati /// for every new not yet scheduled EIP. Because of that we can't use long.MaxValue and /// ulong.MaxValue for GetFinalSpec that is why we have long.MaxValue-1, ulong.MaxValue-1 public static IReleaseSpec GetFinalSpec(this ISpecProvider specProvider) => specProvider.GetSpec(long.MaxValue - 1, ulong.MaxValue - 1); + + public static ulong CalculateSlot(this ISpecProvider specProvider, ulong timestamp) + { + if (specProvider.BeaconChainGenesisTimestamp is null) + { + throw new InvalidOperationException("BeaconChainGenesisTimestamp is not set."); + } + + long timeSinceGenesis = (long)timestamp - (long)specProvider.BeaconChainGenesisTimestamp.Value; + if (timeSinceGenesis < 0) + { + throw new InvalidOperationException($"Timestamp {timestamp} is before genesis timestamp {specProvider.BeaconChainGenesisTimestamp.Value}."); + } + + return (ulong)timeSinceGenesis / (ulong)specProvider.SlotLength.TotalSeconds; + } } } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs index f8b096da06d..e4d7343f04b 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs @@ -39,7 +39,7 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec return rounds; } - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { if (inputData.Length != RequiredInputLength) { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs index 53df7f426df..fee3a770813 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs @@ -28,7 +28,7 @@ private G1AddPrecompile() public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; [SkipLocalsInit] - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.BlsG1AddPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs index 3627c6bfae7..fc85e94793b 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs @@ -23,7 +23,7 @@ private G1MSMPrecompile() { } - public static Address Address { get; } = Address.FromNumber(0x0d); + public static Address Address { get; } = Address.FromNumber(0x0c); public long BaseGasCost(IReleaseSpec releaseSpec) => 0L; @@ -36,7 +36,7 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec public const int ItemSize = 160; [SkipLocalsInit] - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.BlsG1MSMPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs deleted file mode 100644 index 18eb5889913..00000000000 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs +++ /dev/null @@ -1,59 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited -// SPDX-License-Identifier: LGPL-3.0-only - -using System; -using System.Runtime.CompilerServices; -using Nethermind.Core; -using Nethermind.Core.Specs; -using G1 = Nethermind.Crypto.Bls.P1; - -namespace Nethermind.Evm.Precompiles.Bls; - -/// -/// https://eips.ethereum.org/EIPS/eip-2537 -/// -public class G1MulPrecompile : IPrecompile -{ - public static readonly G1MulPrecompile Instance = new(); - - private G1MulPrecompile() - { - } - - public static Address Address { get; } = Address.FromNumber(0x0c); - - public long BaseGasCost(IReleaseSpec releaseSpec) => 12000L; - - public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; - - [SkipLocalsInit] - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) - { - Metrics.BlsG1MulPrecompile++; - - const int expectedInputLength = BlsConst.LenG1 + BlsConst.LenFr; - if (inputData.Length != expectedInputLength) - { - return IPrecompile.Failure; - } - - G1 x = new(stackalloc long[G1.Sz]); - if (!x.TryDecodeRaw(inputData[..BlsConst.LenG1].Span) || !(BlsConst.DisableSubgroupChecks || x.InGroup())) - { - return IPrecompile.Failure; - } - - bool scalarIsInfinity = !inputData.Span[BlsConst.LenG1..].ContainsAnyExcept((byte)0); - if (scalarIsInfinity || x.IsInf()) - { - return (BlsConst.G1Inf, true); - } - - Span scalar = stackalloc byte[32]; - inputData.Span[BlsConst.LenG1..].CopyTo(scalar); - scalar.Reverse(); - - G1 res = x.Mult(scalar); - return (res.EncodeRaw(), true); - } -} diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs index 710954f3a3b..5f15350df88 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs @@ -21,14 +21,14 @@ private G2AddPrecompile() { } - public static Address Address { get; } = Address.FromNumber(0x0e); + public static Address Address { get; } = Address.FromNumber(0x0d); public long BaseGasCost(IReleaseSpec releaseSpec) => 800L; public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; [SkipLocalsInit] - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.BlsG2AddPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs index ca261920ed7..e25e07af5e2 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs @@ -23,7 +23,7 @@ private G2MSMPrecompile() { } - public static Address Address { get; } = Address.FromNumber(0x10); + public static Address Address { get; } = Address.FromNumber(0xe); public long BaseGasCost(IReleaseSpec releaseSpec) => 0L; @@ -36,7 +36,7 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec public const int ItemSize = 288; [SkipLocalsInit] - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.BlsG2MSMPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs index 5190c58be57..3832c8ac084 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs @@ -21,14 +21,14 @@ private MapFp2ToG2Precompile() { } - public static Address Address { get; } = Address.FromNumber(0x13); + public static Address Address { get; } = Address.FromNumber(0x11); public long BaseGasCost(IReleaseSpec releaseSpec) => 75000; public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; [SkipLocalsInit] - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.BlsMapFp2ToG2Precompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs index eb1032ea1f5..1c7647af3e6 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs @@ -20,14 +20,14 @@ private MapFpToG1Precompile() { } - public static Address Address { get; } = Address.FromNumber(0x12); + public static Address Address { get; } = Address.FromNumber(0x10); public long BaseGasCost(IReleaseSpec releaseSpec) => 5500L; public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; [SkipLocalsInit] - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.BlsMapFpToG1Precompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs index 75cd9167364..416b835507a 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs @@ -23,14 +23,14 @@ public class PairingCheckPrecompile : IPrecompile private PairingCheckPrecompile() { } - public static Address Address { get; } = Address.FromNumber(0x11); + public static Address Address { get; } = Address.FromNumber(0xf); public long BaseGasCost(IReleaseSpec releaseSpec) => 65000L; public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 43000L * (inputData.Length / PairSize); [SkipLocalsInit] - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.BlsPairingCheckPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs index f022dfbc490..d6233170bca 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs @@ -28,7 +28,7 @@ private EcRecoverPrecompile() private readonly byte[] _zero31 = new byte[31]; - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.EcRecoverPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs index 3cf1a564d62..c158a938b56 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs @@ -15,7 +15,7 @@ public interface IPrecompile long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec); - (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec); + (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext context); protected static (ReadOnlyMemory, bool) Failure { get; } = (Array.Empty(), false); } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs index 71b584012d2..5c2aee54726 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs @@ -21,7 +21,7 @@ private IdentityPrecompile() public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 3L * EvmPooledMemory.Div32Ceiling((ulong)inputData.Length); - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { return (inputData.ToArray(), true); } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs index df72af9fb97..827ae73a40f 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs @@ -102,7 +102,7 @@ private static (int, int, int) GetInputLengths(ReadOnlyMemory inputData) return (baseLength, expLength, modulusLength); } - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.ModExpPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs index cae14f37871..b9837caef5d 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs @@ -56,7 +56,7 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec } } - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.ModExpPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs index bda625a1470..454338a8e76 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs @@ -26,7 +26,7 @@ public class PointEvaluationPrecompile : IPrecompile public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0; - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { [SkipLocalsInit] [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs index 72916147539..311b2dbe20c 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs @@ -29,7 +29,7 @@ private Ripemd160Precompile() public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 120L * EvmPooledMemory.Div32Ceiling((ulong)inputData.Length); - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.Ripemd160Precompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Secp256r1Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Secp256r1Precompile.cs index f269b6ce985..bc1e6c0dec5 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Secp256r1Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Secp256r1Precompile.cs @@ -22,7 +22,7 @@ public class Secp256r1Precompile : IPrecompile // TODO can be optimized - Go implementation is 2-6 times faster depending on the platform. Options: // - Try to replicate Go version in C# // - Compile Go code into a library and call it via P/Invoke - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { if (inputData.Length != 160) return (null, true); diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs index b45852f6bb2..0698f612d9f 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs @@ -21,7 +21,7 @@ private Sha256Precompile() { } public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 12L * EvmPooledMemory.Div32Ceiling((ulong)inputData.Length); - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.Sha256Precompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs index 45c0f6380d9..790fd5796a2 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs @@ -21,7 +21,7 @@ public class Bn254AddPrecompile : IPrecompile public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; - public unsafe (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public unsafe (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.Bn254AddPrecompile++; Span inputDataSpan = stackalloc byte[128]; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254MulPrecompile.cs index a69d85d1b2e..63607c579e7 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254MulPrecompile.cs @@ -21,7 +21,7 @@ public class Bn254MulPrecompile : IPrecompile public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.Bn254MulPrecompile++; Span inputDataSpan = stackalloc byte[96]; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254PairingPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254PairingPrecompile.cs index 1941f8f85db..3c7e7a9fb20 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254PairingPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254PairingPrecompile.cs @@ -24,10 +24,10 @@ public class Bn254PairingPrecompile : IPrecompile public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => (releaseSpec.IsEip1108Enabled ? 34000L : 80000L) * (inputData.Length / PairSize); - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext context) { Metrics.Bn254PairingPrecompile++; - if (releaseSpec.IsOpGraniteEnabled && inputData.Length > Bn256PairingMaxInputSizeGranite) + if (context.Spec.IsOpGraniteEnabled && inputData.Length > Bn256PairingMaxInputSizeGranite) { return IPrecompile.Failure; } diff --git a/src/Nethermind/Nethermind.Evm/VirtualMachine.cs b/src/Nethermind/Nethermind.Evm/VirtualMachine.cs index c7c32b01ded..448abce3047 100644 --- a/src/Nethermind/Nethermind.Evm/VirtualMachine.cs +++ b/src/Nethermind/Nethermind.Evm/VirtualMachine.cs @@ -601,7 +601,8 @@ private CallResult ExecutePrecompile(EvmState state, IReleaseSpec spec) try { - (ReadOnlyMemory output, bool success) = precompile.Run(callData, spec); + PrecompileContext context = new(spec, _specProvider, state.Env.TxExecutionContext.BlockExecutionContext); + (ReadOnlyMemory output, bool success) = precompile.Run(callData, context); CallResult callResult = new(output, success, !success); return callResult; } diff --git a/src/Nethermind/Nethermind.Shutter/ShutterTime.cs b/src/Nethermind/Nethermind.Shutter/ShutterTime.cs index d7872fbdc25..bfae23e401a 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterTime.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterTime.cs @@ -3,10 +3,11 @@ using System; using Nethermind.Core; +using Nethermind.Specs; namespace Nethermind.Shutter; -public class ShutterTime(ulong genesisTimestampMs, ITimestamper timestamper, TimeSpan slotLength, TimeSpan blockUpToDateCutoff) +public class ShutterTime(ulong genesisTimestampMs, ITimestamper timestamper, TimeSpan slotLength, TimeSpan blockUpToDateCutoff, ISpecProvider specProvider) { public class ShutterSlotCalulationException(string message, Exception? innerException = null) : Exception(message, innerException); @@ -21,22 +22,17 @@ public long GetCurrentOffsetMs(ulong slot, ulong? slotTimestampMs = null) public bool IsBlockUpToDate(Block head) => timestamper.UtcNowOffset.ToUnixTimeSeconds() - (long)head.Header.Timestamp < blockUpToDateCutoff.TotalSeconds; - public ulong GetSlot(ulong slotTimestampMs) + public (ulong slot, long slotOffset) GetBuildingSlotAndOffset(ulong slotTimestampMs) { - long slotTimeSinceGenesis = (long)slotTimestampMs - (long)GenesisTimestampMs; - if (slotTimeSinceGenesis < 0) + try { - throw new ShutterSlotCalulationException($"Slot timestamp {slotTimestampMs}ms was before than genesis timestamp {GenesisTimestampMs}ms."); + ulong buildingSlot = specProvider.CalculateSlot(slotTimestampMs / 1000); + long offset = GetCurrentOffsetMs(buildingSlot, slotTimestampMs); + return (buildingSlot, offset); + } + catch (InvalidOperationException ex) + { + throw new ShutterSlotCalulationException($"Unable to calculate slot for timestamp {slotTimestampMs / 1000}s.", ex); } - - return (ulong)slotTimeSinceGenesis / (ulong)slotLength.TotalMilliseconds; - } - - public (ulong slot, long slotOffset) GetBuildingSlotAndOffset(ulong slotTimestampMs) - { - ulong buildingSlot = GetSlot(slotTimestampMs); - long offset = GetCurrentOffsetMs(buildingSlot, slotTimestampMs); - - return (buildingSlot, offset); } } diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs index ca46a2ce93f..f0cfb723b38 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs @@ -269,5 +269,7 @@ public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalD public ulong NetworkId => _chainSpec.NetworkId; public ulong ChainId => _chainSpec.ChainId; public string SealEngine => _chainSpec.SealEngineType; + + public ulong SlotLength => _chainSpec.Parameters.SlotLength ?? 12; } } diff --git a/src/Nethermind/Nethermind.Specs/ReleaseSpec.cs b/src/Nethermind/Nethermind.Specs/ReleaseSpec.cs index f01c3fa9f91..fee87ba0274 100644 --- a/src/Nethermind/Nethermind.Specs/ReleaseSpec.cs +++ b/src/Nethermind/Nethermind.Specs/ReleaseSpec.cs @@ -133,5 +133,7 @@ public Address Eip2935ContractAddress get => IsEip2935Enabled ? _eip2935ContractAddress : null; set => _eip2935ContractAddress = value; } + + public bool IsEip7843Enabled { get; set; } } } From 2efd109c036c006a6690fcef736338efaa72a927 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Mon, 30 Dec 2024 10:18:37 +0000 Subject: [PATCH 02/24] restore accidental changes --- .../Precompiles/Bls/G1MSMPrecompile.cs | 2 +- .../Precompiles/Bls/G1MulPrecompile.cs | 59 +++++++++++++++++++ .../Precompiles/Bls/G2AddPrecompile.cs | 2 +- .../Precompiles/Bls/G2MSMPrecompile.cs | 2 +- .../Precompiles/Bls/MapFpToG1Precompile.cs | 2 +- .../Precompiles/Bls/PairingCheckPrecompile.cs | 2 +- 6 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs index fc85e94793b..75bfd99a5ab 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs @@ -23,7 +23,7 @@ private G1MSMPrecompile() { } - public static Address Address { get; } = Address.FromNumber(0x0c); + public static Address Address { get; } = Address.FromNumber(0x0d); public long BaseGasCost(IReleaseSpec releaseSpec) => 0L; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs new file mode 100644 index 00000000000..18eb5889913 --- /dev/null +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs @@ -0,0 +1,59 @@ +// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System; +using System.Runtime.CompilerServices; +using Nethermind.Core; +using Nethermind.Core.Specs; +using G1 = Nethermind.Crypto.Bls.P1; + +namespace Nethermind.Evm.Precompiles.Bls; + +/// +/// https://eips.ethereum.org/EIPS/eip-2537 +/// +public class G1MulPrecompile : IPrecompile +{ + public static readonly G1MulPrecompile Instance = new(); + + private G1MulPrecompile() + { + } + + public static Address Address { get; } = Address.FromNumber(0x0c); + + public long BaseGasCost(IReleaseSpec releaseSpec) => 12000L; + + public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; + + [SkipLocalsInit] + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + { + Metrics.BlsG1MulPrecompile++; + + const int expectedInputLength = BlsConst.LenG1 + BlsConst.LenFr; + if (inputData.Length != expectedInputLength) + { + return IPrecompile.Failure; + } + + G1 x = new(stackalloc long[G1.Sz]); + if (!x.TryDecodeRaw(inputData[..BlsConst.LenG1].Span) || !(BlsConst.DisableSubgroupChecks || x.InGroup())) + { + return IPrecompile.Failure; + } + + bool scalarIsInfinity = !inputData.Span[BlsConst.LenG1..].ContainsAnyExcept((byte)0); + if (scalarIsInfinity || x.IsInf()) + { + return (BlsConst.G1Inf, true); + } + + Span scalar = stackalloc byte[32]; + inputData.Span[BlsConst.LenG1..].CopyTo(scalar); + scalar.Reverse(); + + G1 res = x.Mult(scalar); + return (res.EncodeRaw(), true); + } +} diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs index 5f15350df88..942724cfda6 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs @@ -21,7 +21,7 @@ private G2AddPrecompile() { } - public static Address Address { get; } = Address.FromNumber(0x0d); + public static Address Address { get; } = Address.FromNumber(0x0e); public long BaseGasCost(IReleaseSpec releaseSpec) => 800L; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs index e25e07af5e2..e0d9a36f606 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs @@ -23,7 +23,7 @@ private G2MSMPrecompile() { } - public static Address Address { get; } = Address.FromNumber(0xe); + public static Address Address { get; } = Address.FromNumber(0x10); public long BaseGasCost(IReleaseSpec releaseSpec) => 0L; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs index 1c7647af3e6..12d1c6899db 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs @@ -20,7 +20,7 @@ private MapFpToG1Precompile() { } - public static Address Address { get; } = Address.FromNumber(0x10); + public static Address Address { get; } = Address.FromNumber(0x13); public long BaseGasCost(IReleaseSpec releaseSpec) => 5500L; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs index 416b835507a..31a3d0c4e15 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs @@ -23,7 +23,7 @@ public class PairingCheckPrecompile : IPrecompile private PairingCheckPrecompile() { } - public static Address Address { get; } = Address.FromNumber(0xf); + public static Address Address { get; } = Address.FromNumber(0x11); public long BaseGasCost(IReleaseSpec releaseSpec) => 65000L; From ddd03fe07390b43d62165df37e69af74c72c61ed Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Mon, 30 Dec 2024 10:20:49 +0000 Subject: [PATCH 03/24] add precompile context and slot precompile files --- .../Precompiles/PrecompileContext.cs | 19 +++++++++ .../Precompiles/SlotPrecompile.cs | 39 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/Nethermind/Nethermind.Evm/Precompiles/PrecompileContext.cs create mode 100644 src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/PrecompileContext.cs b/src/Nethermind/Nethermind.Evm/Precompiles/PrecompileContext.cs new file mode 100644 index 00000000000..0e788cb7a71 --- /dev/null +++ b/src/Nethermind/Nethermind.Evm/Precompiles/PrecompileContext.cs @@ -0,0 +1,19 @@ +using Nethermind.Core; +using Nethermind.Core.Specs; + +namespace Nethermind.Evm.Precompiles +{ + public class PrecompileContext + { + public IReleaseSpec Spec { get; } + public ISpecProvider SpecProvider { get; } + public BlockExecutionContext BlockExecutionContext { get; } + + public PrecompileContext(IReleaseSpec spec, ISpecProvider specProvider, BlockExecutionContext blockExecutionContext) + { + Spec = spec; + SpecProvider = specProvider; + BlockExecutionContext = blockExecutionContext; + } + } +} \ No newline at end of file diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs new file mode 100644 index 00000000000..296cfc98320 --- /dev/null +++ b/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs @@ -0,0 +1,39 @@ +using System; +using Nethermind.Core; +using Nethermind.Core.Specs; + +namespace Nethermind.Evm.Precompiles +{ + public class SlotPrecompile : IPrecompile + { + public static SlotPrecompile Instance { get; } = new(); + + public static Address Address => new("0x0000000000000000000000000000000000000014"); + + private SlotPrecompile() { } + + public long BaseGasCost(IReleaseSpec releaseSpec) + { + return 2; + } + + public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + { + return 0; + } + + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext context) + { + ulong slotNumber = context.SpecProvider.CalculateSlot(context.BlockExecutionContext.Header.Timestamp); + + byte[] result = new byte[32]; + for (int i = 0; i < 8; i++) + { + result[31 - i] = (byte)(slotNumber & 0xFF); + slotNumber >>= 8; + } + + return (result, true); + } + } +} \ No newline at end of file From 24bfed68e4299d825e88ab3d6210b936b8bfb96c Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Mon, 30 Dec 2024 10:25:03 +0000 Subject: [PATCH 04/24] remove slot length stuff --- .../Nethermind.Core/Specs/ISpecProvider.cs | 21 --------------- .../Precompiles/SlotPrecompile.cs | 2 +- .../Nethermind.Shutter/ShutterTime.cs | 26 +++++++++++-------- .../ChainSpecBasedSpecProvider.cs | 2 -- 4 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs b/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs index c9c3875cb5b..eb3f216445b 100644 --- a/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs +++ b/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs @@ -66,11 +66,6 @@ public interface ISpecProvider ulong ChainId { get; } - /// - /// Duration of each slot - /// - TimeSpan SlotLength { get; } - /// /// Original engine of the chain /// @@ -107,21 +102,5 @@ public static IReleaseSpec GetSpec(this ISpecProvider specProvider, ForkActivati /// for every new not yet scheduled EIP. Because of that we can't use long.MaxValue and /// ulong.MaxValue for GetFinalSpec that is why we have long.MaxValue-1, ulong.MaxValue-1 public static IReleaseSpec GetFinalSpec(this ISpecProvider specProvider) => specProvider.GetSpec(long.MaxValue - 1, ulong.MaxValue - 1); - - public static ulong CalculateSlot(this ISpecProvider specProvider, ulong timestamp) - { - if (specProvider.BeaconChainGenesisTimestamp is null) - { - throw new InvalidOperationException("BeaconChainGenesisTimestamp is not set."); - } - - long timeSinceGenesis = (long)timestamp - (long)specProvider.BeaconChainGenesisTimestamp.Value; - if (timeSinceGenesis < 0) - { - throw new InvalidOperationException($"Timestamp {timestamp} is before genesis timestamp {specProvider.BeaconChainGenesisTimestamp.Value}."); - } - - return (ulong)timeSinceGenesis / (ulong)specProvider.SlotLength.TotalSeconds; - } } } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs index 296cfc98320..7919f61d9fa 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs @@ -24,7 +24,7 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext context) { - ulong slotNumber = context.SpecProvider.CalculateSlot(context.BlockExecutionContext.Header.Timestamp); + ulong slotNumber = 420; byte[] result = new byte[32]; for (int i = 0; i < 8; i++) diff --git a/src/Nethermind/Nethermind.Shutter/ShutterTime.cs b/src/Nethermind/Nethermind.Shutter/ShutterTime.cs index bfae23e401a..d7872fbdc25 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterTime.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterTime.cs @@ -3,11 +3,10 @@ using System; using Nethermind.Core; -using Nethermind.Specs; namespace Nethermind.Shutter; -public class ShutterTime(ulong genesisTimestampMs, ITimestamper timestamper, TimeSpan slotLength, TimeSpan blockUpToDateCutoff, ISpecProvider specProvider) +public class ShutterTime(ulong genesisTimestampMs, ITimestamper timestamper, TimeSpan slotLength, TimeSpan blockUpToDateCutoff) { public class ShutterSlotCalulationException(string message, Exception? innerException = null) : Exception(message, innerException); @@ -22,17 +21,22 @@ public long GetCurrentOffsetMs(ulong slot, ulong? slotTimestampMs = null) public bool IsBlockUpToDate(Block head) => timestamper.UtcNowOffset.ToUnixTimeSeconds() - (long)head.Header.Timestamp < blockUpToDateCutoff.TotalSeconds; - public (ulong slot, long slotOffset) GetBuildingSlotAndOffset(ulong slotTimestampMs) + public ulong GetSlot(ulong slotTimestampMs) { - try - { - ulong buildingSlot = specProvider.CalculateSlot(slotTimestampMs / 1000); - long offset = GetCurrentOffsetMs(buildingSlot, slotTimestampMs); - return (buildingSlot, offset); - } - catch (InvalidOperationException ex) + long slotTimeSinceGenesis = (long)slotTimestampMs - (long)GenesisTimestampMs; + if (slotTimeSinceGenesis < 0) { - throw new ShutterSlotCalulationException($"Unable to calculate slot for timestamp {slotTimestampMs / 1000}s.", ex); + throw new ShutterSlotCalulationException($"Slot timestamp {slotTimestampMs}ms was before than genesis timestamp {GenesisTimestampMs}ms."); } + + return (ulong)slotTimeSinceGenesis / (ulong)slotLength.TotalMilliseconds; + } + + public (ulong slot, long slotOffset) GetBuildingSlotAndOffset(ulong slotTimestampMs) + { + ulong buildingSlot = GetSlot(slotTimestampMs); + long offset = GetCurrentOffsetMs(buildingSlot, slotTimestampMs); + + return (buildingSlot, offset); } } diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs index f0cfb723b38..ca46a2ce93f 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs @@ -269,7 +269,5 @@ public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalD public ulong NetworkId => _chainSpec.NetworkId; public ulong ChainId => _chainSpec.ChainId; public string SealEngine => _chainSpec.SealEngineType; - - public ulong SlotLength => _chainSpec.Parameters.SlotLength ?? 12; } } From 2b749aeb4abbffdee2e259ffbfad6f24552093d6 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Mon, 30 Dec 2024 10:30:36 +0000 Subject: [PATCH 05/24] reset more accidental changes --- src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs | 2 -- .../Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs | 2 +- .../Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs b/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs index eb3f216445b..67bb4619bd8 100644 --- a/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs +++ b/src/Nethermind/Nethermind.Core/Specs/ISpecProvider.cs @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only -using System; using Nethermind.Int256; namespace Nethermind.Core.Specs @@ -65,7 +64,6 @@ public interface ISpecProvider /// ulong ChainId { get; } - /// /// Original engine of the chain /// diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs index 3832c8ac084..b103205768c 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs @@ -21,7 +21,7 @@ private MapFp2ToG2Precompile() { } - public static Address Address { get; } = Address.FromNumber(0x11); + public static Address Address { get; } = Address.FromNumber(0x13); public long BaseGasCost(IReleaseSpec releaseSpec) => 75000; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs index 12d1c6899db..8f5644d3a97 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs @@ -20,7 +20,7 @@ private MapFpToG1Precompile() { } - public static Address Address { get; } = Address.FromNumber(0x13); + public static Address Address { get; } = Address.FromNumber(0x12); public long BaseGasCost(IReleaseSpec releaseSpec) => 5500L; From 6f50553d4cfddff3d270ae8cb55949349987bd33 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Tue, 31 Dec 2024 10:09:18 +0000 Subject: [PATCH 06/24] fix tests & release spec --- .../Nethermind.Core/Specs/ReleaseSpecDecorator.cs | 1 + .../Nethermind.Evm.Test/BlsG1AddPrecompileTests.cs | 4 ++-- .../Nethermind.Evm.Test/BlsG1MSMPrecompileTests.cs | 3 ++- .../Nethermind.Evm.Test/BlsG2AddPrecompileTests.cs | 2 +- .../Nethermind.Evm.Test/BlsG2MSMPrecompileTests.cs | 2 +- src/Nethermind/Nethermind.Evm.Test/BlsMapFp2ToG2Tests.cs | 2 +- src/Nethermind/Nethermind.Evm.Test/BlsMapFpToG1Tests.cs | 2 +- .../Nethermind.Evm.Test/BlsMulG1PrecompileTests.cs | 4 ++-- .../Nethermind.Evm.Test/BlsMulG2PrecompileTests.cs | 2 +- .../Nethermind.Evm.Test/BlsPairingCheckPrecompileTests.cs | 2 +- src/Nethermind/Nethermind.Evm.Test/BnAddPrecompileTests.cs | 2 +- src/Nethermind/Nethermind.Evm.Test/BnMulPrecompileTests.cs | 2 +- src/Nethermind/Nethermind.Evm.Test/BnPairPrecompileTests.cs | 2 +- src/Nethermind/Nethermind.Evm.Test/Eip2565Tests.cs | 4 ++-- .../Nethermind.Evm.Test/PointEvaluationPrecompileTests.cs | 2 +- .../Secp256r1PrecompilePrecompileTests.cs | 4 ++-- src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs | 6 ++++-- .../Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs | 2 +- .../Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs | 2 +- .../Nethermind.Specs.Test/OverridableReleaseSpec.cs | 1 + 20 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs b/src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs index 5688b8bdbf3..9851069f306 100644 --- a/src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs +++ b/src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs @@ -80,6 +80,7 @@ public class ReleaseSpecDecorator(IReleaseSpec spec) : IReleaseSpec public virtual bool IsEip6780Enabled => spec.IsEip6780Enabled; public bool IsEip7702Enabled => spec.IsEip7702Enabled; public virtual bool IsRip7212Enabled => spec.IsRip7212Enabled; + public virtual bool IsEip7843Enabled => spec.IsEip7843Enabled; public virtual bool IsOpGraniteEnabled => spec.IsOpGraniteEnabled; public virtual bool IsOpHoloceneEnabled => spec.IsOpHoloceneEnabled; public virtual bool IsOntakeEnabled => spec.IsOntakeEnabled; diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsG1AddPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsG1AddPrecompileTests.cs index 0eec6c75280..2011a9caaa4 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsG1AddPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsG1AddPrecompileTests.cs @@ -21,14 +21,14 @@ public void Test() foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { - (ReadOnlyMemory output, bool success) = precompile.Run(input, MuirGlacier.Instance); + (ReadOnlyMemory output, bool success) = precompile.Run(input, TestPrecompileContext.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); success.Should().BeTrue(); } foreach ((byte[] input, ReadOnlyMemory expectedResult) in BadInputs) { - (ReadOnlyMemory output, bool success) = precompile.Run(input, MuirGlacier.Instance); + (ReadOnlyMemory output, bool success) = precompile.Run(input, TestPrecompileContext.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); success.Should().BeFalse(); } diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsG1MSMPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsG1MSMPrecompileTests.cs index 9626fa7238e..9a5bde3195c 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsG1MSMPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsG1MSMPrecompileTests.cs @@ -7,6 +7,7 @@ using Nethermind.Core.Extensions; using Nethermind.Evm.Precompiles; using Nethermind.Evm.Precompiles.Bls; +using Nethermind.Specs; using Nethermind.Specs.Forks; using NUnit.Framework; @@ -20,7 +21,7 @@ public void Test() foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { IPrecompile precompile = G1MSMPrecompile.Instance; - (ReadOnlyMemory output, bool success) = precompile.Run(input, Prague.Instance); + (ReadOnlyMemory output, bool success) = precompile.Run(input, TestPrecompileContext.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); success.Should().BeTrue(); } diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsG2AddPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsG2AddPrecompileTests.cs index be2609d84ef..f4d2f0130d7 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsG2AddPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsG2AddPrecompileTests.cs @@ -20,7 +20,7 @@ public void Test() foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { IPrecompile precompile = G2AddPrecompile.Instance; - (ReadOnlyMemory output, bool success) = precompile.Run(input, MuirGlacier.Instance); + (ReadOnlyMemory output, bool success) = precompile.Run(input, TestPrecompileContext.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); success.Should().BeTrue(); } diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsG2MSMPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsG2MSMPrecompileTests.cs index c9310444b3b..6632753d075 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsG2MSMPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsG2MSMPrecompileTests.cs @@ -20,7 +20,7 @@ public void Test() foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { IPrecompile precompile = G2MSMPrecompile.Instance; - (ReadOnlyMemory output, bool success) = precompile.Run(input, Prague.Instance); + (ReadOnlyMemory output, bool success) = precompile.Run(input, TestPrecompileContext.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); success.Should().BeTrue(); } diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsMapFp2ToG2Tests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsMapFp2ToG2Tests.cs index 61982b51754..75a11736d05 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsMapFp2ToG2Tests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsMapFp2ToG2Tests.cs @@ -20,7 +20,7 @@ public void Test() foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { IPrecompile precompile = MapFp2ToG2Precompile.Instance; - (ReadOnlyMemory output, bool success) = precompile.Run(input, MuirGlacier.Instance); + (ReadOnlyMemory output, bool success) = precompile.Run(input, TestPrecompileContext.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); success.Should().BeTrue(); diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsMapFpToG1Tests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsMapFpToG1Tests.cs index 801f1fdc387..521cff425a3 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsMapFpToG1Tests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsMapFpToG1Tests.cs @@ -20,7 +20,7 @@ public void Test() foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { IPrecompile precompile = MapFpToG1Precompile.Instance; - (ReadOnlyMemory output, bool success) = precompile.Run(input, MuirGlacier.Instance); + (ReadOnlyMemory output, bool success) = precompile.Run(input, TestPrecompileContext.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); success.Should().BeTrue(); diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsMulG1PrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsMulG1PrecompileTests.cs index 26efd4d3724..068e0ef21ef 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsMulG1PrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsMulG1PrecompileTests.cs @@ -21,14 +21,14 @@ public void Test() foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { - (ReadOnlyMemory output, bool success) = precompile.Run(input, MuirGlacier.Instance); + (ReadOnlyMemory output, bool success) = precompile.Run(input, TestPrecompileContext.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); success.Should().BeTrue(); } foreach ((byte[] input, ReadOnlyMemory expectedResult) in BadInputs) { - (ReadOnlyMemory output, bool success) = precompile.Run(input, MuirGlacier.Instance); + (ReadOnlyMemory output, bool success) = precompile.Run(input, TestPrecompileContext.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); success.Should().BeFalse(); } diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsMulG2PrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsMulG2PrecompileTests.cs index 625dd89e7df..e6a2ffc97e4 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsMulG2PrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsMulG2PrecompileTests.cs @@ -20,7 +20,7 @@ public void Test() foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { IPrecompile precompile = G2MulPrecompile.Instance; - (ReadOnlyMemory output, bool success) = precompile.Run(input, MuirGlacier.Instance); + (ReadOnlyMemory output, bool success) = precompile.Run(input, TestPrecompileContext.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); success.Should().BeTrue(); } diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsPairingCheckPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsPairingCheckPrecompileTests.cs index ee490e4513e..f628170cfe2 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsPairingCheckPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsPairingCheckPrecompileTests.cs @@ -20,7 +20,7 @@ public void Test() foreach ((byte[] input, ReadOnlyMemory expectedResult) in Inputs) { IPrecompile precompile = PairingCheckPrecompile.Instance; - (ReadOnlyMemory output, bool success) = precompile.Run(input, MuirGlacier.Instance); + (ReadOnlyMemory output, bool success) = precompile.Run(input, TestPrecompileContext.Instance); output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray()); success.Should().BeTrue(); diff --git a/src/Nethermind/Nethermind.Evm.Test/BnAddPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BnAddPrecompileTests.cs index a22cd643b4f..c9abe884ee5 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BnAddPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BnAddPrecompileTests.cs @@ -31,7 +31,7 @@ public void Test() for (int i = 0; i < inputs.Length; i++) { IPrecompile precompile = Bn254AddPrecompile.Instance; - _ = precompile.Run(inputs[i], MuirGlacier.Instance); + _ = precompile.Run(inputs[i], TestPrecompileContext.Instance); } } } diff --git a/src/Nethermind/Nethermind.Evm.Test/BnMulPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BnMulPrecompileTests.cs index be40da630d1..5b1038b9508 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BnMulPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BnMulPrecompileTests.cs @@ -31,7 +31,7 @@ public void Test() for (int i = 0; i < inputs.Length; i++) { IPrecompile precompile = Bn254MulPrecompile.Instance; - _ = precompile.Run(inputs[i], MuirGlacier.Instance); + _ = precompile.Run(inputs[i], TestPrecompileContext.Instance); } } } diff --git a/src/Nethermind/Nethermind.Evm.Test/BnPairPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BnPairPrecompileTests.cs index 6f5d09ddd58..dfcffd1be22 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BnPairPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BnPairPrecompileTests.cs @@ -62,7 +62,7 @@ public void Test() { byte[] cloned = inputs[i].Clone() as byte[]; IPrecompile precompile = Bn254PairingPrecompile.Instance; - _ = precompile.Run(cloned, MuirGlacier.Instance); + _ = precompile.Run(cloned, TestPrecompileContext.Instance); } } } diff --git a/src/Nethermind/Nethermind.Evm.Test/Eip2565Tests.cs b/src/Nethermind/Nethermind.Evm.Test/Eip2565Tests.cs index afc87008b9a..fc859347b78 100644 --- a/src/Nethermind/Nethermind.Evm.Test/Eip2565Tests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/Eip2565Tests.cs @@ -26,7 +26,7 @@ public void Simple_routine([Random(int.MinValue, int.MaxValue, 100)] int seed) Prepare input = Prepare.EvmCode.FromCode(randomInput); - (ReadOnlyMemory, bool) gmpPair = ModExpPrecompile.Instance.Run(input.Done.ToArray(), Berlin.Instance); + (ReadOnlyMemory, bool) gmpPair = ModExpPrecompile.Instance.Run(input.Done.ToArray(), TestPrecompileContext.Instance); #pragma warning disable 618 (ReadOnlyMemory, bool) bigIntPair = ModExpPrecompile.OldRun(input.Done.ToArray()); #pragma warning restore 618 @@ -47,7 +47,7 @@ public void Overflow_gas_cost() public void ModExp_run_should_not_throw_exception(string inputStr) { Prepare input = Prepare.EvmCode.FromCode(inputStr); - Assert.DoesNotThrow(() => ModExpPrecompile.Instance.Run(input.Done.ToArray(), London.Instance)); + Assert.DoesNotThrow(() => ModExpPrecompile.Instance.Run(input.Done.ToArray(), TestPrecompileContext.Instance)); long gas = ModExpPrecompile.Instance.DataGasCost(input.Done, London.Instance); gas.Should().Be(200); } diff --git a/src/Nethermind/Nethermind.Evm.Test/PointEvaluationPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/PointEvaluationPrecompileTests.cs index 9e2706cd66e..468eb637bc4 100644 --- a/src/Nethermind/Nethermind.Evm.Test/PointEvaluationPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/PointEvaluationPrecompileTests.cs @@ -29,7 +29,7 @@ public class PointEvaluationPrecompileTests [TestCaseSource(nameof(OutputTests))] public bool Test_PointEvaluationPrecompile_Produces_Correct_Outputs(byte[] input) { - (ReadOnlyMemory output, bool success) = PointEvaluationPrecompile.Instance.Run(input, Cancun.Instance); + (ReadOnlyMemory output, bool success) = PointEvaluationPrecompile.Instance.Run(input, TestPrecompileContext.Instance); output.ToArray().Should().BeEquivalentTo(success ? _predefinedSuccessAnswer : _predefinedFailureAnswer); return success; } diff --git a/src/Nethermind/Nethermind.Evm.Test/Secp256r1PrecompilePrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/Secp256r1PrecompilePrecompileTests.cs index b123d2074b9..6a1ad561814 100644 --- a/src/Nethermind/Nethermind.Evm.Test/Secp256r1PrecompilePrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/Secp256r1PrecompilePrecompileTests.cs @@ -61,7 +61,7 @@ public class Secp256r1PrecompilePrecompileTests : VirtualMachineTestsBase public void Produces_Correct_Outputs(string input, bool isValid) { var bytes = Bytes.FromHexString(input); - (ReadOnlyMemory output, bool success) = Secp256r1Precompile.Instance.Run(bytes, Prague.Instance); + (ReadOnlyMemory output, bool success) = Secp256r1Precompile.Instance.Run(bytes, TestPrecompileContext.Instance); success.Should().BeTrue(); output.ToArray().Should().BeEquivalentTo(isValid ? ValidAnswer : []); } @@ -79,7 +79,7 @@ public void Produces_Correct_Outputs(string input, bool isValid) public void Produces_Empty_Output_On_Invalid_Input(string input) { var bytes = Bytes.FromHexString(input); - (ReadOnlyMemory output, bool success) = Secp256r1Precompile.Instance.Run(bytes, Prague.Instance); + (ReadOnlyMemory output, bool success) = Secp256r1Precompile.Instance.Run(bytes, TestPrecompileContext.Instance); success.Should().BeTrue(); output.Should().Be(ReadOnlyMemory.Empty); } diff --git a/src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs b/src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs index 6103e2df810..7882d643ee3 100644 --- a/src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs +++ b/src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs @@ -54,6 +54,8 @@ private static FrozenDictionary InitializePrecompiledCon [PointEvaluationPrecompile.Address] = new(PointEvaluationPrecompile.Instance), [Secp256r1Precompile.Address] = new(Secp256r1Precompile.Instance), + + [SlotPrecompile.Address] = new(SlotPrecompile.Instance), }.ToFrozenDictionary(); } @@ -201,12 +203,12 @@ private class CachedPrecompile( public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => precompile.DataGasCost(inputData, releaseSpec); - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext context) { PreBlockCaches.PrecompileCacheKey key = new(address, inputData); if (!cache.TryGetValue(key, out (ReadOnlyMemory, bool) result)) { - result = precompile.Run(inputData, releaseSpec); + result = precompile.Run(inputData, context); // we need to rebuild the key with data copy as the data can be changed by VM processing key = new PreBlockCaches.PrecompileCacheKey(address, inputData.ToArray()); cache.TryAdd(key, result); diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs index 18eb5889913..c5a16967e3f 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs @@ -27,7 +27,7 @@ private G1MulPrecompile() public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; [SkipLocalsInit] - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.BlsG1MulPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs index fbe99e32867..d03176e48dc 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs @@ -28,7 +28,7 @@ private G2MulPrecompile() public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; [SkipLocalsInit] - public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext _) { Metrics.BlsG2MulPrecompile++; diff --git a/src/Nethermind/Nethermind.Specs.Test/OverridableReleaseSpec.cs b/src/Nethermind/Nethermind.Specs.Test/OverridableReleaseSpec.cs index 1187f58d568..fb10de20d18 100644 --- a/src/Nethermind/Nethermind.Specs.Test/OverridableReleaseSpec.cs +++ b/src/Nethermind/Nethermind.Specs.Test/OverridableReleaseSpec.cs @@ -113,6 +113,7 @@ public OverridableReleaseSpec(IReleaseSpec spec) public bool IsEip3541Enabled => _spec.IsEip3541Enabled; public bool IsEip4844Enabled => _spec.IsEip4844Enabled; public bool IsRip7212Enabled => _spec.IsRip7212Enabled; + public bool IsEip7843Enabled => _spec.IsEip7843Enabled; public bool IsOpGraniteEnabled => _spec.IsOpGraniteEnabled; public bool IsOpHoloceneEnabled => _spec.IsOpHoloceneEnabled; From 27bf630010805b3f6bbfdf82b2d7f808eb8c6040 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Tue, 31 Dec 2024 10:37:41 +0000 Subject: [PATCH 07/24] add slot number to block header and payloadattributes --- .../Nethermind.Consensus/EngineApiVersions.cs | 1 + .../Producers/BlockProducerBase.cs | 3 ++- .../Producers/PayloadAttributes.cs | 15 +++++++++++++-- .../Builders/BlockHeaderBuilder.cs | 6 ++++++ src/Nethermind/Nethermind.Core/Block.cs | 2 ++ src/Nethermind/Nethermind.Core/BlockHeader.cs | 9 ++++++++- .../Nethermind.Evm/Precompiles/SlotPrecompile.cs | 7 ++++++- .../Nethermind.Facade/BlockchainBridge.cs | 6 ++++++ .../Simulate/SimulateBridgeHelper.cs | 1 + .../Data/ExecutionPayload.cs | 8 ++++++++ .../Nethermind.Serialization.Rlp/HeaderDecoder.cs | 10 ++++++++++ .../ChainSpecStyle/ChainSpecLoader.cs | 6 ++++++ .../ChainSpecStyle/Json/ChainSpecParamsJson.cs | 1 + 13 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/EngineApiVersions.cs b/src/Nethermind/Nethermind.Consensus/EngineApiVersions.cs index 145810a7364..fad7ce67df2 100644 --- a/src/Nethermind/Nethermind.Consensus/EngineApiVersions.cs +++ b/src/Nethermind/Nethermind.Consensus/EngineApiVersions.cs @@ -9,4 +9,5 @@ public static class EngineApiVersions public const int Shanghai = 2; public const int Cancun = 3; public const int Prague = 4; + public const int Osaka = 5; } diff --git a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs index f9603373e30..5fd64fbbc9a 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs @@ -232,7 +232,8 @@ protected virtual BlockHeader PrepareBlockHeader(BlockHeader parent, { Author = blockAuthor, MixHash = payloadAttributes?.PrevRandao, - ParentBeaconBlockRoot = payloadAttributes?.ParentBeaconBlockRoot + ParentBeaconBlockRoot = payloadAttributes?.ParentBeaconBlockRoot, + SlotNumber = payloadAttributes?.SlotNumber, }; UInt256 difficulty = _difficultyCalculator.Calculate(header, parent); diff --git a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs index e04cb6b46b9..d1ea5bc3fc7 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs @@ -26,6 +26,8 @@ public class PayloadAttributes public Hash256? ParentBeaconBlockRoot { get; set; } + public ulong? SlotNumber { get; set; } + public virtual long? GetGasLimit() => null; public override string ToString() => ToString(string.Empty); @@ -35,7 +37,8 @@ public string ToString(string indentation) var sb = new StringBuilder($"{indentation}{nameof(PayloadAttributes)} {{") .Append($"{nameof(Timestamp)}: {Timestamp}, ") .Append($"{nameof(PrevRandao)}: {PrevRandao}, ") - .Append($"{nameof(SuggestedFeeRecipient)}: {SuggestedFeeRecipient}"); + .Append($"{nameof(SuggestedFeeRecipient)}: {SuggestedFeeRecipient}") + .Append($"{nameof(SlotNumber)}: {SlotNumber}"); if (Withdrawals is not null) { @@ -71,7 +74,8 @@ protected virtual int ComputePayloadIdMembersSize() => + Keccak.Size // prev randao + Address.Size // suggested fee recipient + (Withdrawals is null ? 0 : Keccak.Size) // withdrawals root hash - + (ParentBeaconBlockRoot is null ? 0 : Keccak.Size); // parent beacon block root + + (ParentBeaconBlockRoot is null ? 0 : Keccak.Size) // parent beacon block root + + (SlotNumber is null ? 0 : sizeof(ulong)); // slot number protected static string ComputePayloadId(Span inputSpan) { @@ -110,6 +114,12 @@ protected virtual int WritePayloadIdMembers(BlockHeader parentHeader, Span position += Keccak.Size; } + if (SlotNumber is not null) + { + BinaryPrimitives.WriteUInt64BigEndian(inputSpan.Slice(position, sizeof(ulong)), SlotNumber.Value); + position += sizeof(ulong); + } + return position; } @@ -166,6 +176,7 @@ public static class PayloadAttributesExtensions public static int GetVersion(this PayloadAttributes executionPayload) => executionPayload switch { + { SlotNumber: not null } => EngineApiVersions.Osaka, // todo: set based on fork { ParentBeaconBlockRoot: not null, Withdrawals: not null } => EngineApiVersions.Cancun, { Withdrawals: not null } => EngineApiVersions.Shanghai, _ => EngineApiVersions.Paris diff --git a/src/Nethermind/Nethermind.Core.Test/Builders/BlockHeaderBuilder.cs b/src/Nethermind/Nethermind.Core.Test/Builders/BlockHeaderBuilder.cs index f36678b4087..ac6b138314c 100644 --- a/src/Nethermind/Nethermind.Core.Test/Builders/BlockHeaderBuilder.cs +++ b/src/Nethermind/Nethermind.Core.Test/Builders/BlockHeaderBuilder.cs @@ -201,4 +201,10 @@ public BlockHeaderBuilder WithRequestsHash(Hash256? requestsHash) TestObjectInternal.RequestsHash = requestsHash; return this; } + + public BlockHeaderBuilder WithSlotNumber(ulong slotNumber) + { + TestObjectInternal.SlotNumber = slotNumber; + return this; + } } diff --git a/src/Nethermind/Nethermind.Core/Block.cs b/src/Nethermind/Nethermind.Core/Block.cs index 81cc39e53af..bfb7a56b2dc 100644 --- a/src/Nethermind/Nethermind.Core/Block.cs +++ b/src/Nethermind/Nethermind.Core/Block.cs @@ -117,6 +117,8 @@ public Transaction[] Transactions public Hash256? RequestsHash => Header.RequestsHash; // do not add setter here + public ulong? SlotNumber => Header.SlotNumber; // do not add setter here + [JsonIgnore] public byte[][]? ExecutionRequests { get; set; } diff --git a/src/Nethermind/Nethermind.Core/BlockHeader.cs b/src/Nethermind/Nethermind.Core/BlockHeader.cs index 426478dbe00..82666140ead 100644 --- a/src/Nethermind/Nethermind.Core/BlockHeader.cs +++ b/src/Nethermind/Nethermind.Core/BlockHeader.cs @@ -28,7 +28,8 @@ public BlockHeader( ulong? blobGasUsed = null, ulong? excessBlobGas = null, Hash256? parentBeaconBlockRoot = null, - Hash256? requestsHash = null) + Hash256? requestsHash = null, + ulong? slotNumber = null) { ParentHash = parentHash; UnclesHash = unclesHash; @@ -42,6 +43,7 @@ public BlockHeader( RequestsHash = requestsHash; BlobGasUsed = blobGasUsed; ExcessBlobGas = excessBlobGas; + SlotNumber = slotNumber; } public WeakReference? MaybeParent { get; set; } @@ -75,6 +77,7 @@ public BlockHeader( public Hash256? RequestsHash { get; set; } public ulong? BlobGasUsed { get; set; } public ulong? ExcessBlobGas { get; set; } + public ulong? SlotNumber { get; set; } public bool HasBody => (TxRoot is not null && TxRoot != Keccak.EmptyTreeHash) || (UnclesHash is not null && UnclesHash != Keccak.OfAnEmptySequenceRlp) || (WithdrawalsRoot is not null && WithdrawalsRoot != Keccak.EmptyTreeHash); @@ -122,6 +125,10 @@ public string ToString(string indent) { builder.AppendLine($"{indent}RequestsHash: {RequestsHash}"); } + if (SlotNumber is not null) + { + builder.AppendLine($"{indent}SlotNumber: {SlotNumber}"); + } return builder.ToString(); } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs index 7919f61d9fa..e569f12c84c 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs @@ -24,7 +24,12 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext context) { - ulong slotNumber = 420; + ulong? slotNumber = context.BlockExecutionContext.Header.SlotNumber; + + if (slotNumber is null) + { + return IPrecompile.Failure; + } byte[] result = new byte[32]; for (int i = 0; i < 8; i++) diff --git a/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs b/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs index 42e3c884e2f..571d47abfe5 100644 --- a/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs +++ b/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs @@ -295,6 +295,12 @@ private TransactionResult CallAndRestore( ? BlobGasCalculator.CalculateExcessBlobGas(blockHeader, releaseSpec) : blockHeader.ExcessBlobGas; } + + if (releaseSpec.IsEip7843Enabled) + { + callHeader.SlotNumber = blockHeader.SlotNumber; + } + callHeader.MixHash = blockHeader.MixHash; callHeader.IsPostMerge = blockHeader.Difficulty == 0; transaction.Hash = transaction.CalculateHash(); diff --git a/src/Nethermind/Nethermind.Facade/Simulate/SimulateBridgeHelper.cs b/src/Nethermind/Nethermind.Facade/Simulate/SimulateBridgeHelper.cs index 33f55e74aed..e61d6f13051 100644 --- a/src/Nethermind/Nethermind.Facade/Simulate/SimulateBridgeHelper.cs +++ b/src/Nethermind/Nethermind.Facade/Simulate/SimulateBridgeHelper.cs @@ -296,6 +296,7 @@ private BlockHeader GetCallHeader(BlockStateCall b : BaseFeeCalculator.Calculate(parent, spec); result.ExcessBlobGas = spec.IsEip4844Enabled ? BlobGasCalculator.CalculateExcessBlobGas(parent, spec) : (ulong?)0; + result.SlotNumber = spec.IsEip7843Enabled && parent.SlotNumber is not null ? parent.SlotNumber.Value + 1 : null; return result; } diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs index 81aa243fe78..c1af56e75cd 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs @@ -105,6 +105,13 @@ public byte[][] Transactions [JsonIgnore] public Hash256? ParentBeaconBlockRoot { get; set; } + /// + /// Gets or sets as defined in + /// EIP-7843. + /// + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public ulong? SlotNumber { get; set; } + public static ExecutionPayload Create(Block block) => Create(block); protected static TExecutionPayload Create(Block block) where TExecutionPayload : ExecutionPayload, new() @@ -125,6 +132,7 @@ public byte[][] Transactions Timestamp = block.Timestamp, BaseFeePerGas = block.BaseFeePerGas, Withdrawals = block.Withdrawals, + SlotNumber = block.SlotNumber, }; executionPayload.SetTransactions(block.Transactions); return executionPayload; diff --git a/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs b/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs index e70f2c9c9b6..9a0e6b944a0 100644 --- a/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs +++ b/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs @@ -94,6 +94,11 @@ public class HeaderDecoder : IRlpValueDecoder, IRlpStreamDecoder= 6 && decoderContext.Position != headerCheck) + { + blockHeader.SlotNumber = decoderContext.DecodeULong(); + } } @@ -186,6 +191,11 @@ public class HeaderDecoder : IRlpValueDecoder, IRlpStreamDecoder= 6 && rlpStream.Position != headerCheck) + { + blockHeader.SlotNumber = rlpStream.DecodeULong(); + } } if ((rlpBehaviors & RlpBehaviors.AllowExtraBytes) != RlpBehaviors.AllowExtraBytes) diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs index dc7b75faa8b..c149a3990c1 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs @@ -335,6 +335,12 @@ private static void LoadGenesis(ChainSpecJson chainSpecJson, ChainSpec chainSpec genesisHeader.ReceiptsRoot = Keccak.EmptyTreeHash; } + bool isEip7843Enabled = chainSpecJson.Params.Eip7843TransitionTimestamp is not null && genesisHeader.Timestamp >= chainSpecJson.Params.Eip7843TransitionTimestamp; + if (isEip7843Enabled) + { + genesisHeader.SlotNumber = 0; + } + genesisHeader.AuRaStep = step; genesisHeader.AuRaSignature = auRaSignature; diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/Json/ChainSpecParamsJson.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/Json/ChainSpecParamsJson.cs index ff9e33274c6..94afc1af632 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/Json/ChainSpecParamsJson.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/Json/ChainSpecParamsJson.cs @@ -161,4 +161,5 @@ internal class ChainSpecParamsJson public ulong? Eip7702TransitionTimestamp { get; set; } public ulong? OpGraniteTransitionTimestamp { get; set; } public ulong? OpHoloceneTransitionTimestamp { get; set; } + public ulong? Eip7843TransitionTimestamp { get; set; } } From 886317b6d4d6e06b9d645cce8521c92b45b64df5 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Tue, 31 Dec 2024 11:26:36 +0000 Subject: [PATCH 08/24] use payloadattributes slot number in shutter block building --- .../Nethermind.Shutter/ShutterApi.cs | 6 +-- .../Nethermind.Shutter/ShutterBlockHandler.cs | 9 ++-- .../ShutterBlockImprovementContext.cs | 48 ++++++------------- .../Nethermind.Shutter/ShutterTime.cs | 20 +------- .../Nethermind.Shutter/ShutterTxSource.cs | 11 ++--- 5 files changed, 24 insertions(+), 70 deletions(-) diff --git a/src/Nethermind/Nethermind.Shutter/ShutterApi.cs b/src/Nethermind/Nethermind.Shutter/ShutterApi.cs index 9832503b8ed..d2f7ff5e6fb 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterApi.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterApi.cs @@ -96,10 +96,9 @@ IPAddress ip TxLoader, Time, logManager, - _slotLength, BlockWaitCutoff); - TxSource = new ShutterTxSource(TxLoader, _cfg, Time, logManager); + TxSource = new ShutterTxSource(TxLoader, _cfg, logManager); KeyValidator = new ShutterKeyValidator(_cfg, Eon, logManager); @@ -116,8 +115,7 @@ public ShutterBlockImprovementContextFactory GetBlockImprovementContextFactory(I TxSource, _cfg, Time, - _logManager, - _slotLength + _logManager ); return BlockImprovementContextFactory; } diff --git a/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs b/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs index f3cad2b8fcf..0710413a683 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs @@ -34,7 +34,7 @@ public class ShutterBlockHandler : IShutterBlockHandler private readonly ReadOnlyBlockTree _readOnlyBlockTree; private readonly ulong _chainId; private readonly IShutterConfig _cfg; - private readonly TimeSpan _slotLength; + private readonly TimeSpan _maxWaitTime = TimeSpan.FromSeconds(10); private readonly TimeSpan _blockWaitCutoff; private readonly ReadOnlyTxProcessingEnvFactory _envFactory; private bool _haveCheckedRegistered = false; @@ -55,7 +55,6 @@ public ShutterBlockHandler( ShutterTxLoader txLoader, ShutterTime time, ILogManager logManager, - TimeSpan slotLength, TimeSpan blockWaitCutoff) { _chainId = chainId; @@ -71,7 +70,6 @@ public ShutterBlockHandler( _abiEncoder = abiEncoder; _logManager = logManager; _envFactory = envFactory; - _slotLength = slotLength; _blockWaitCutoff = blockWaitCutoff; _blockTree.NewHeadBlock += OnNewHeadBlock; @@ -91,6 +89,7 @@ public ShutterBlockHandler( tcs = new(); + // n.b. this does not currently support changes to slot length long offset = _time.GetCurrentOffsetMs(slot); long waitTime = (long)_blockWaitCutoff.TotalMilliseconds - offset; if (waitTime <= 0) @@ -98,7 +97,7 @@ public ShutterBlockHandler( if (_logger.IsDebug) _logger.Debug($"Shutter no longer waiting for block in slot {slot}, offset of {offset}ms is after cutoff of {(int)_blockWaitCutoff.TotalMilliseconds}ms."); return null; } - waitTime = Math.Min(waitTime, 2 * (long)_slotLength.TotalMilliseconds); + waitTime = Math.Min(waitTime, (long)_maxWaitTime.TotalMilliseconds); ulong taskId = _blockWaitTaskId++; CancellationTokenSource timeoutSource = initTimeoutSource is null ? new CancellationTokenSource((int)waitTime) : initTimeoutSource((int)waitTime); @@ -170,7 +169,7 @@ private void OnNewHeadBlock(object? _, BlockEventArgs e) lock (_syncObject) { - ulong slot = _time.GetSlot(head.Timestamp * 1000); + ulong slot = head.SlotNumber ?? 0; _slotToBlockHash.Set(slot, head.Hash); if (_blockWaitTasks.Remove(slot, out Dictionary? waitTasks)) diff --git a/src/Nethermind/Nethermind.Shutter/ShutterBlockImprovementContext.cs b/src/Nethermind/Nethermind.Shutter/ShutterBlockImprovementContext.cs index 3868bea2497..e59bf504b4d 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterBlockImprovementContext.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterBlockImprovementContext.cs @@ -19,8 +19,7 @@ public class ShutterBlockImprovementContextFactory( ShutterTxSource shutterTxSource, IShutterConfig shutterConfig, ShutterTime time, - ILogManager logManager, - TimeSpan slotLength) : IBlockImprovementContextFactory + ILogManager logManager) : IBlockImprovementContextFactory { public IBlockImprovementContext StartBlockImprovementContext( Block currentBestBlock, @@ -35,7 +34,6 @@ public IBlockImprovementContext StartBlockImprovementContext( parentHeader, payloadAttributes, startDateTime, - slotLength, logManager); } @@ -58,8 +56,9 @@ public class ShutterBlockImprovementContext : IBlockImprovementContext private readonly ShutterTime _time; private readonly BlockHeader _parentHeader; private readonly PayloadAttributes _payloadAttributes; + private readonly TimeSpan _keyWaitTimeout = TimeSpan.FromSeconds(10); + private readonly ulong _slotNumber; private readonly ulong _slotTimestampMs; - private readonly TimeSpan _slotLength; internal ShutterBlockImprovementContext( IBlockProducer blockProducer, @@ -70,16 +69,8 @@ internal ShutterBlockImprovementContext( BlockHeader parentHeader, PayloadAttributes payloadAttributes, DateTimeOffset startDateTime, - TimeSpan slotLength, ILogManager logManager) { - if (slotLength == TimeSpan.Zero) - { - throw new ArgumentException("Cannot be zero.", nameof(slotLength)); - } - - _slotTimestampMs = payloadAttributes.Timestamp * 1000; - _cancellationTokenSource = new CancellationTokenSource(); CurrentBestBlock = currentBestBlock; StartDateTime = startDateTime; @@ -87,10 +78,11 @@ internal ShutterBlockImprovementContext( _blockProducer = blockProducer; _txSignal = shutterTxSignal; _shutterConfig = shutterConfig; - _time = time; _parentHeader = parentHeader; _payloadAttributes = payloadAttributes; - _slotLength = slotLength; + _time = time; + _slotNumber = payloadAttributes.SlotNumber ?? 0; + _slotTimestampMs = payloadAttributes.Timestamp * 1000; ImprovementTask = Task.Run(ImproveBlock); } @@ -105,34 +97,22 @@ public void Dispose() { if (_logger.IsDebug) _logger.Debug("Running Shutter block improvement."); - ulong slot; - long offset; - try - { - (slot, offset) = _time.GetBuildingSlotAndOffset(_slotTimestampMs); - } - catch (ShutterTime.ShutterSlotCalulationException e) - { - if (_logger.IsWarn) _logger.Warn($"Could not calculate Shutter building slot: {e}"); - await BuildBlock(); - return CurrentBestBlock; - } - - bool includedShutterTxs = await TryBuildShutterBlock(slot); + bool includedShutterTxs = await TryBuildShutterBlock(_slotNumber); if (includedShutterTxs) { return CurrentBestBlock; } + long offset = _time.GetCurrentOffsetMs(_slotNumber, _slotTimestampMs); long waitTime = _shutterConfig.MaxKeyDelay - offset; if (waitTime <= 0) { - if (_logger.IsWarn) _logger.Warn($"Cannot await Shutter decryption keys for slot {slot}, offset of {offset}ms is too late."); + if (_logger.IsWarn) _logger.Warn($"Cannot await Shutter decryption keys for slot {_slotNumber}, offset of {offset}ms is too late."); return CurrentBestBlock; } - waitTime = Math.Min(waitTime, 2 * (long)_slotLength.TotalMilliseconds); + waitTime = Math.Min(waitTime, (long)_keyWaitTimeout.TotalMilliseconds); - if (_logger.IsDebug) _logger.Debug($"Awaiting Shutter decryption keys for {slot} at offset {offset}ms. Timeout in {waitTime}ms..."); + if (_logger.IsDebug) _logger.Debug($"Awaiting Shutter decryption keys for {_slotNumber} at offset {offset}ms. Timeout in {waitTime}ms..."); ObjectDisposedException.ThrowIf(_cancellationTokenSource is null, this); @@ -141,18 +121,18 @@ public void Dispose() try { - await _txSignal.WaitForTransactions(slot, source.Token); + await _txSignal.WaitForTransactions(_slotNumber, source.Token); } catch (OperationCanceledException) { Metrics.ShutterKeysMissed++; - if (_logger.IsWarn) _logger.Warn($"Shutter decryption keys not received in time for slot {slot}."); + if (_logger.IsWarn) _logger.Warn($"Shutter decryption keys not received in time for slot {_slotNumber}."); return CurrentBestBlock; } // should succeed after waiting for transactions - await TryBuildShutterBlock(slot); + await TryBuildShutterBlock(_slotNumber); return CurrentBestBlock; } diff --git a/src/Nethermind/Nethermind.Shutter/ShutterTime.cs b/src/Nethermind/Nethermind.Shutter/ShutterTime.cs index d7872fbdc25..b43a8d6a30e 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterTime.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterTime.cs @@ -12,6 +12,7 @@ public class ShutterSlotCalulationException(string message, Exception? innerExce public readonly ulong GenesisTimestampMs = genesisTimestampMs; + // n.b. cannot handle changes to slot length public ulong GetSlotTimestampMs(ulong slot) => GenesisTimestampMs + slot * (ulong)slotLength.TotalMilliseconds; @@ -20,23 +21,4 @@ public long GetCurrentOffsetMs(ulong slot, ulong? slotTimestampMs = null) public bool IsBlockUpToDate(Block head) => timestamper.UtcNowOffset.ToUnixTimeSeconds() - (long)head.Header.Timestamp < blockUpToDateCutoff.TotalSeconds; - - public ulong GetSlot(ulong slotTimestampMs) - { - long slotTimeSinceGenesis = (long)slotTimestampMs - (long)GenesisTimestampMs; - if (slotTimeSinceGenesis < 0) - { - throw new ShutterSlotCalulationException($"Slot timestamp {slotTimestampMs}ms was before than genesis timestamp {GenesisTimestampMs}ms."); - } - - return (ulong)slotTimeSinceGenesis / (ulong)slotLength.TotalMilliseconds; - } - - public (ulong slot, long slotOffset) GetBuildingSlotAndOffset(ulong slotTimestampMs) - { - ulong buildingSlot = GetSlot(slotTimestampMs); - long offset = GetCurrentOffsetMs(buildingSlot, slotTimestampMs); - - return (buildingSlot, offset); - } } diff --git a/src/Nethermind/Nethermind.Shutter/ShutterTxSource.cs b/src/Nethermind/Nethermind.Shutter/ShutterTxSource.cs index 281a39622ce..72b9de08232 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterTxSource.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterTxSource.cs @@ -18,7 +18,6 @@ namespace Nethermind.Shutter; public class ShutterTxSource( ShutterTxLoader txLoader, IShutterConfig shutterConfig, - ShutterTime shutterTime, ILogManager logManager) : ITxSource, IShutterTxSignal { @@ -36,16 +35,12 @@ public IEnumerable GetTransactions(BlockHeader parent, long gasLimi return []; } - ulong buildingSlot; - try + if (payloadAttributes?.SlotNumber is null) { - (buildingSlot, _) = shutterTime.GetBuildingSlotAndOffset(payloadAttributes!.Timestamp * 1000); - } - catch (ShutterTime.ShutterSlotCalulationException e) - { - if (_logger.IsDebug) _logger.Warn($"DEBUG/ERROR Could not calculate Shutter building slot: {e}"); + if (_logger.IsDebug) _logger.Warn($"DEBUG/ERROR PayloadAttributes.SlotNumber is null"); return []; } + ulong buildingSlot = payloadAttributes.SlotNumber.Value; ShutterTransactions? shutterTransactions = _txCache.Get(buildingSlot); if (shutterTransactions is null) From ee4988e534ff7186b9d8b8fab4d8c556ecec8784 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Tue, 31 Dec 2024 11:35:01 +0000 Subject: [PATCH 09/24] update usings and add TestPrecompileContext --- .../BlsG1MSMPrecompileTests.cs | 2 -- .../BlsG2AddPrecompileTests.cs | 1 - .../BlsG2MSMPrecompileTests.cs | 1 - .../Nethermind.Evm.Test/BlsMapFp2ToG2Tests.cs | 1 - .../Nethermind.Evm.Test/BlsMapFpToG1Tests.cs | 1 - .../BlsMulG2PrecompileTests.cs | 1 - .../Nethermind.Evm.Test/BnAddPrecompileTests.cs | 1 - .../Nethermind.Evm.Test/BnMulPrecompileTests.cs | 1 - .../Nethermind.Evm.Test/BnPairPrecompileTests.cs | 1 - .../Secp256r1PrecompilePrecompileTests.cs | 1 - .../Nethermind.Evm.Test/TestPrecompileContext.cs | 16 ++++++++++++++++ 11 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 src/Nethermind/Nethermind.Evm.Test/TestPrecompileContext.cs diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsG1MSMPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsG1MSMPrecompileTests.cs index 9a5bde3195c..cff19a5b685 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsG1MSMPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsG1MSMPrecompileTests.cs @@ -7,8 +7,6 @@ using Nethermind.Core.Extensions; using Nethermind.Evm.Precompiles; using Nethermind.Evm.Precompiles.Bls; -using Nethermind.Specs; -using Nethermind.Specs.Forks; using NUnit.Framework; namespace Nethermind.Evm.Test; diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsG2AddPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsG2AddPrecompileTests.cs index f4d2f0130d7..4ca0f025243 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsG2AddPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsG2AddPrecompileTests.cs @@ -7,7 +7,6 @@ using Nethermind.Core.Extensions; using Nethermind.Evm.Precompiles; using Nethermind.Evm.Precompiles.Bls; -using Nethermind.Specs.Forks; using NUnit.Framework; namespace Nethermind.Evm.Test; diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsG2MSMPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsG2MSMPrecompileTests.cs index 6632753d075..25802ae5c80 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsG2MSMPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsG2MSMPrecompileTests.cs @@ -8,7 +8,6 @@ using Nethermind.Evm.Precompiles; using Nethermind.Evm.Precompiles.Bls; using NUnit.Framework; -using Nethermind.Specs.Forks; namespace Nethermind.Evm.Test; diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsMapFp2ToG2Tests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsMapFp2ToG2Tests.cs index 75a11736d05..90fb4b2f846 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsMapFp2ToG2Tests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsMapFp2ToG2Tests.cs @@ -7,7 +7,6 @@ using Nethermind.Core.Extensions; using Nethermind.Evm.Precompiles; using Nethermind.Evm.Precompiles.Bls; -using Nethermind.Specs.Forks; using NUnit.Framework; namespace Nethermind.Evm.Test; diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsMapFpToG1Tests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsMapFpToG1Tests.cs index 521cff425a3..d69f081810e 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsMapFpToG1Tests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsMapFpToG1Tests.cs @@ -7,7 +7,6 @@ using Nethermind.Core.Extensions; using Nethermind.Evm.Precompiles; using Nethermind.Evm.Precompiles.Bls; -using Nethermind.Specs.Forks; using NUnit.Framework; namespace Nethermind.Evm.Test; diff --git a/src/Nethermind/Nethermind.Evm.Test/BlsMulG2PrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BlsMulG2PrecompileTests.cs index e6a2ffc97e4..f56f5e9b0e1 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BlsMulG2PrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BlsMulG2PrecompileTests.cs @@ -7,7 +7,6 @@ using Nethermind.Core.Extensions; using Nethermind.Evm.Precompiles; using Nethermind.Evm.Precompiles.Bls; -using Nethermind.Specs.Forks; using NUnit.Framework; namespace Nethermind.Evm.Test; diff --git a/src/Nethermind/Nethermind.Evm.Test/BnAddPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BnAddPrecompileTests.cs index c9abe884ee5..15150515294 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BnAddPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BnAddPrecompileTests.cs @@ -4,7 +4,6 @@ using Nethermind.Core.Extensions; using Nethermind.Evm.Precompiles; using Nethermind.Evm.Precompiles.Snarks; -using Nethermind.Specs.Forks; using NUnit.Framework; namespace Nethermind.Evm.Test; diff --git a/src/Nethermind/Nethermind.Evm.Test/BnMulPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BnMulPrecompileTests.cs index 5b1038b9508..4111e41b870 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BnMulPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BnMulPrecompileTests.cs @@ -4,7 +4,6 @@ using Nethermind.Core.Extensions; using Nethermind.Evm.Precompiles; using Nethermind.Evm.Precompiles.Snarks; -using Nethermind.Specs.Forks; using NUnit.Framework; namespace Nethermind.Evm.Test; diff --git a/src/Nethermind/Nethermind.Evm.Test/BnPairPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BnPairPrecompileTests.cs index dfcffd1be22..1510f1027e3 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BnPairPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BnPairPrecompileTests.cs @@ -4,7 +4,6 @@ using Nethermind.Core.Extensions; using Nethermind.Evm.Precompiles; using Nethermind.Evm.Precompiles.Snarks; -using Nethermind.Specs.Forks; using NUnit.Framework; namespace Nethermind.Evm.Test; diff --git a/src/Nethermind/Nethermind.Evm.Test/Secp256r1PrecompilePrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/Secp256r1PrecompilePrecompileTests.cs index 6a1ad561814..5e9d152c87e 100644 --- a/src/Nethermind/Nethermind.Evm.Test/Secp256r1PrecompilePrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/Secp256r1PrecompilePrecompileTests.cs @@ -5,7 +5,6 @@ using FluentAssertions; using Nethermind.Core.Extensions; using Nethermind.Evm.Precompiles; -using Nethermind.Specs.Forks; using NUnit.Framework; namespace Nethermind.Evm.Test diff --git a/src/Nethermind/Nethermind.Evm.Test/TestPrecompileContext.cs b/src/Nethermind/Nethermind.Evm.Test/TestPrecompileContext.cs new file mode 100644 index 00000000000..10fc83b24c7 --- /dev/null +++ b/src/Nethermind/Nethermind.Evm.Test/TestPrecompileContext.cs @@ -0,0 +1,16 @@ +using Nethermind.Core.Specs; +using Nethermind.Evm.Precompiles; +using Nethermind.Specs; +using Nethermind.Specs.Forks; + +namespace Nethermind.Evm.Test; + +public class TestPrecompileContext : PrecompileContext +{ + public static TestPrecompileContext Instance { get; } = new(Prague.Instance, TestSpecProvider.Instance, new()); + + private TestPrecompileContext(IReleaseSpec spec, ISpecProvider specProvider, BlockExecutionContext blockExecutionContext) + : base(spec, specProvider, blockExecutionContext) + { + } +} \ No newline at end of file From a7f9098728218dfcaaa82f75e781916a67b720f6 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Tue, 31 Dec 2024 11:41:57 +0000 Subject: [PATCH 10/24] fix block handler tests --- .../Builders/BlockBuilder.cs | 6 ++++++ .../ShutterBlockHandlerTests.cs | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs b/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs index c806756c7a7..fd6b3a648ed 100644 --- a/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs +++ b/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs @@ -288,5 +288,11 @@ public BlockBuilder WithParentBeaconBlockRoot(Hash256? parentBeaconBlockRoot) TestObjectInternal.Header.ParentBeaconBlockRoot = parentBeaconBlockRoot; return this; } + + public BlockBuilder WithSlotNumber(ulong slotNumber) + { + TestObjectInternal.Header.SlotNumber = slotNumber; + return this; + } } } diff --git a/src/Nethermind/Nethermind.Shutter.Test/ShutterBlockHandlerTests.cs b/src/Nethermind/Nethermind.Shutter.Test/ShutterBlockHandlerTests.cs index 33c44829e95..bc0f4e35315 100644 --- a/src/Nethermind/Nethermind.Shutter.Test/ShutterBlockHandlerTests.cs +++ b/src/Nethermind/Nethermind.Shutter.Test/ShutterBlockHandlerTests.cs @@ -24,7 +24,10 @@ public void Can_wait_for_valid_block() CancellationTokenSource source = new(); Task waitTask = blockHandler.WaitForBlockInSlot(ShutterTestsCommon.InitialSlot, source.Token); - Block result = Build.A.Block.WithTimestamp(ShutterTestsCommon.InitialSlotTimestamp).TestObject; + Block result = Build.A.Block + .WithTimestamp(ShutterTestsCommon.InitialSlotTimestamp) + .WithSlotNumber(ShutterTestsCommon.InitialSlot) + .TestObject; api.TriggerNewHeadBlock(new(result)); Assert.That(result, Is.EqualTo(waitTask.Result)); @@ -72,12 +75,20 @@ public void Ignores_outdated_block() ShutterApiSimulator api = ShutterTestsCommon.InitApi(rnd, timestamper); // not triggered on outdated block - api.TriggerNewHeadBlock(new(Build.A.Block.WithTimestamp(ShutterTestsCommon.InitialSlotTimestamp).TestObject)); + Block block1 = Build.A.Block + .WithTimestamp(ShutterTestsCommon.InitialSlotTimestamp) + .WithSlotNumber(ShutterTestsCommon.InitialSlot) + .TestObject; + api.TriggerNewHeadBlock(new(block1)); Assert.That(api.EonUpdateCalled, Is.EqualTo(0)); // triggered on up to date block ulong upToDateTimestamp = ShutterTestsCommon.InitialSlotTimestamp + 2 * (ulong)ShutterTestsCommon.BlockUpToDateCutoff.TotalSeconds; - api.TriggerNewHeadBlock(new(Build.A.Block.WithTimestamp(upToDateTimestamp).TestObject)); + Block block2 = Build.A.Block + .WithTimestamp(upToDateTimestamp) + .WithSlotNumber(ShutterTestsCommon.InitialSlot) + .TestObject; + api.TriggerNewHeadBlock(new(block2)); Assert.That(api.EonUpdateCalled, Is.EqualTo(1)); } } From 74c7d7a50e84b3b168da6e38f03e621b24353e02 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Tue, 31 Dec 2024 11:43:57 +0000 Subject: [PATCH 11/24] fix whitespace --- src/Nethermind/Nethermind.Evm.Test/TestPrecompileContext.cs | 6 +++--- .../Nethermind.Evm/Precompiles/PrecompileContext.cs | 2 +- src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Nethermind/Nethermind.Evm.Test/TestPrecompileContext.cs b/src/Nethermind/Nethermind.Evm.Test/TestPrecompileContext.cs index 10fc83b24c7..b52618ea74c 100644 --- a/src/Nethermind/Nethermind.Evm.Test/TestPrecompileContext.cs +++ b/src/Nethermind/Nethermind.Evm.Test/TestPrecompileContext.cs @@ -8,9 +8,9 @@ namespace Nethermind.Evm.Test; public class TestPrecompileContext : PrecompileContext { public static TestPrecompileContext Instance { get; } = new(Prague.Instance, TestSpecProvider.Instance, new()); - - private TestPrecompileContext(IReleaseSpec spec, ISpecProvider specProvider, BlockExecutionContext blockExecutionContext) + + private TestPrecompileContext(IReleaseSpec spec, ISpecProvider specProvider, BlockExecutionContext blockExecutionContext) : base(spec, specProvider, blockExecutionContext) { } -} \ No newline at end of file +} diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/PrecompileContext.cs b/src/Nethermind/Nethermind.Evm/Precompiles/PrecompileContext.cs index 0e788cb7a71..f29536b15a4 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/PrecompileContext.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/PrecompileContext.cs @@ -16,4 +16,4 @@ public PrecompileContext(IReleaseSpec spec, ISpecProvider specProvider, BlockExe BlockExecutionContext = blockExecutionContext; } } -} \ No newline at end of file +} diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs index e569f12c84c..2eb87ab6177 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs @@ -7,7 +7,7 @@ namespace Nethermind.Evm.Precompiles public class SlotPrecompile : IPrecompile { public static SlotPrecompile Instance { get; } = new(); - + public static Address Address => new("0x0000000000000000000000000000000000000014"); private SlotPrecompile() { } @@ -30,7 +30,7 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec { return IPrecompile.Failure; } - + byte[] result = new byte[32]; for (int i = 0; i < 8; i++) { @@ -41,4 +41,4 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec return (result, true); } } -} \ No newline at end of file +} From 45268fb1387839f8d7581d003b67b7c4458b49b1 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Tue, 31 Dec 2024 11:48:15 +0000 Subject: [PATCH 12/24] fix precompile benchmarks --- .../Nethermind.Precompiles.Benchmark.csproj | 1 + .../PrecompileBenchmarkBase.cs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Precompiles.Benchmark/Nethermind.Precompiles.Benchmark.csproj b/src/Nethermind/Nethermind.Precompiles.Benchmark/Nethermind.Precompiles.Benchmark.csproj index 1fa7275f368..eef5bb7c491 100644 --- a/src/Nethermind/Nethermind.Precompiles.Benchmark/Nethermind.Precompiles.Benchmark.csproj +++ b/src/Nethermind/Nethermind.Precompiles.Benchmark/Nethermind.Precompiles.Benchmark.csproj @@ -11,6 +11,7 @@ + diff --git a/src/Nethermind/Nethermind.Precompiles.Benchmark/PrecompileBenchmarkBase.cs b/src/Nethermind/Nethermind.Precompiles.Benchmark/PrecompileBenchmarkBase.cs index 5dbaf5406d2..a8632b066ec 100644 --- a/src/Nethermind/Nethermind.Precompiles.Benchmark/PrecompileBenchmarkBase.cs +++ b/src/Nethermind/Nethermind.Precompiles.Benchmark/PrecompileBenchmarkBase.cs @@ -8,9 +8,9 @@ using System.Linq; using BenchmarkDotNet.Attributes; using Nethermind.Core.Extensions; +using Nethermind.Evm.Test; using Nethermind.Evm.Precompiles; using Nethermind.Serialization.Json; -using Nethermind.Specs.Forks; namespace Nethermind.Precompiles.Benchmark { @@ -89,7 +89,7 @@ private static byte[] LineToTestInput(string line) [Benchmark(Baseline = true)] public (ReadOnlyMemory, bool) Baseline() { - return Input.Precompile.Run(Input.Bytes, Berlin.Instance); + return Input.Precompile.Run(Input.Bytes, TestPrecompileContext.Instance); } } } From 20f5165de643015426fe494c81d605d4ca016df8 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Wed, 1 Jan 2025 14:45:44 +0000 Subject: [PATCH 13/24] remove slot number from execution payload --- .../Producers/BlockProducerBase.cs | 1 - .../Builders/BlockBuilder.cs | 6 ------ .../Builders/BlockHeaderBuilder.cs | 6 ------ src/Nethermind/Nethermind.Core/Block.cs | 1 - src/Nethermind/Nethermind.Core/BlockHeader.cs | 9 +-------- .../Precompiles/SlotPrecompile.cs | 2 +- .../Nethermind.Facade/BlockchainBridge.cs | 5 ----- .../Simulate/SimulateBridgeHelper.cs | 1 - .../Data/ExecutionPayload.cs | 8 -------- .../HeaderDecoder.cs | 10 ---------- .../ShutterBlockHandlerTests.cs | 17 +++-------------- .../Nethermind.Shutter/ShutterBlockHandler.cs | 3 ++- .../ChainSpecStyle/ChainSpecLoader.cs | 6 ------ 13 files changed, 7 insertions(+), 68 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs index 5fd64fbbc9a..7f9247d2f43 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs @@ -233,7 +233,6 @@ protected virtual BlockHeader PrepareBlockHeader(BlockHeader parent, Author = blockAuthor, MixHash = payloadAttributes?.PrevRandao, ParentBeaconBlockRoot = payloadAttributes?.ParentBeaconBlockRoot, - SlotNumber = payloadAttributes?.SlotNumber, }; UInt256 difficulty = _difficultyCalculator.Calculate(header, parent); diff --git a/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs b/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs index fd6b3a648ed..c806756c7a7 100644 --- a/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs +++ b/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs @@ -288,11 +288,5 @@ public BlockBuilder WithParentBeaconBlockRoot(Hash256? parentBeaconBlockRoot) TestObjectInternal.Header.ParentBeaconBlockRoot = parentBeaconBlockRoot; return this; } - - public BlockBuilder WithSlotNumber(ulong slotNumber) - { - TestObjectInternal.Header.SlotNumber = slotNumber; - return this; - } } } diff --git a/src/Nethermind/Nethermind.Core.Test/Builders/BlockHeaderBuilder.cs b/src/Nethermind/Nethermind.Core.Test/Builders/BlockHeaderBuilder.cs index ac6b138314c..f36678b4087 100644 --- a/src/Nethermind/Nethermind.Core.Test/Builders/BlockHeaderBuilder.cs +++ b/src/Nethermind/Nethermind.Core.Test/Builders/BlockHeaderBuilder.cs @@ -201,10 +201,4 @@ public BlockHeaderBuilder WithRequestsHash(Hash256? requestsHash) TestObjectInternal.RequestsHash = requestsHash; return this; } - - public BlockHeaderBuilder WithSlotNumber(ulong slotNumber) - { - TestObjectInternal.SlotNumber = slotNumber; - return this; - } } diff --git a/src/Nethermind/Nethermind.Core/Block.cs b/src/Nethermind/Nethermind.Core/Block.cs index bfb7a56b2dc..8bedefb13d4 100644 --- a/src/Nethermind/Nethermind.Core/Block.cs +++ b/src/Nethermind/Nethermind.Core/Block.cs @@ -117,7 +117,6 @@ public Transaction[] Transactions public Hash256? RequestsHash => Header.RequestsHash; // do not add setter here - public ulong? SlotNumber => Header.SlotNumber; // do not add setter here [JsonIgnore] public byte[][]? ExecutionRequests { get; set; } diff --git a/src/Nethermind/Nethermind.Core/BlockHeader.cs b/src/Nethermind/Nethermind.Core/BlockHeader.cs index 82666140ead..426478dbe00 100644 --- a/src/Nethermind/Nethermind.Core/BlockHeader.cs +++ b/src/Nethermind/Nethermind.Core/BlockHeader.cs @@ -28,8 +28,7 @@ public BlockHeader( ulong? blobGasUsed = null, ulong? excessBlobGas = null, Hash256? parentBeaconBlockRoot = null, - Hash256? requestsHash = null, - ulong? slotNumber = null) + Hash256? requestsHash = null) { ParentHash = parentHash; UnclesHash = unclesHash; @@ -43,7 +42,6 @@ public BlockHeader( RequestsHash = requestsHash; BlobGasUsed = blobGasUsed; ExcessBlobGas = excessBlobGas; - SlotNumber = slotNumber; } public WeakReference? MaybeParent { get; set; } @@ -77,7 +75,6 @@ public BlockHeader( public Hash256? RequestsHash { get; set; } public ulong? BlobGasUsed { get; set; } public ulong? ExcessBlobGas { get; set; } - public ulong? SlotNumber { get; set; } public bool HasBody => (TxRoot is not null && TxRoot != Keccak.EmptyTreeHash) || (UnclesHash is not null && UnclesHash != Keccak.OfAnEmptySequenceRlp) || (WithdrawalsRoot is not null && WithdrawalsRoot != Keccak.EmptyTreeHash); @@ -125,10 +122,6 @@ public string ToString(string indent) { builder.AppendLine($"{indent}RequestsHash: {RequestsHash}"); } - if (SlotNumber is not null) - { - builder.AppendLine($"{indent}SlotNumber: {SlotNumber}"); - } return builder.ToString(); } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs index 2eb87ab6177..7d26e4fb42f 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs @@ -24,7 +24,7 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext context) { - ulong? slotNumber = context.BlockExecutionContext.Header.SlotNumber; + ulong? slotNumber = 0; if (slotNumber is null) { diff --git a/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs b/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs index 571d47abfe5..cd546b21602 100644 --- a/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs +++ b/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs @@ -296,11 +296,6 @@ private TransactionResult CallAndRestore( : blockHeader.ExcessBlobGas; } - if (releaseSpec.IsEip7843Enabled) - { - callHeader.SlotNumber = blockHeader.SlotNumber; - } - callHeader.MixHash = blockHeader.MixHash; callHeader.IsPostMerge = blockHeader.Difficulty == 0; transaction.Hash = transaction.CalculateHash(); diff --git a/src/Nethermind/Nethermind.Facade/Simulate/SimulateBridgeHelper.cs b/src/Nethermind/Nethermind.Facade/Simulate/SimulateBridgeHelper.cs index e61d6f13051..33f55e74aed 100644 --- a/src/Nethermind/Nethermind.Facade/Simulate/SimulateBridgeHelper.cs +++ b/src/Nethermind/Nethermind.Facade/Simulate/SimulateBridgeHelper.cs @@ -296,7 +296,6 @@ private BlockHeader GetCallHeader(BlockStateCall b : BaseFeeCalculator.Calculate(parent, spec); result.ExcessBlobGas = spec.IsEip4844Enabled ? BlobGasCalculator.CalculateExcessBlobGas(parent, spec) : (ulong?)0; - result.SlotNumber = spec.IsEip7843Enabled && parent.SlotNumber is not null ? parent.SlotNumber.Value + 1 : null; return result; } diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs index c1af56e75cd..81aa243fe78 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs @@ -105,13 +105,6 @@ public byte[][] Transactions [JsonIgnore] public Hash256? ParentBeaconBlockRoot { get; set; } - /// - /// Gets or sets as defined in - /// EIP-7843. - /// - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public ulong? SlotNumber { get; set; } - public static ExecutionPayload Create(Block block) => Create(block); protected static TExecutionPayload Create(Block block) where TExecutionPayload : ExecutionPayload, new() @@ -132,7 +125,6 @@ public byte[][] Transactions Timestamp = block.Timestamp, BaseFeePerGas = block.BaseFeePerGas, Withdrawals = block.Withdrawals, - SlotNumber = block.SlotNumber, }; executionPayload.SetTransactions(block.Transactions); return executionPayload; diff --git a/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs b/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs index 9a0e6b944a0..e70f2c9c9b6 100644 --- a/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs +++ b/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs @@ -94,11 +94,6 @@ public class HeaderDecoder : IRlpValueDecoder, IRlpStreamDecoder= 6 && decoderContext.Position != headerCheck) - { - blockHeader.SlotNumber = decoderContext.DecodeULong(); - } } @@ -191,11 +186,6 @@ public class HeaderDecoder : IRlpValueDecoder, IRlpStreamDecoder= 6 && rlpStream.Position != headerCheck) - { - blockHeader.SlotNumber = rlpStream.DecodeULong(); - } } if ((rlpBehaviors & RlpBehaviors.AllowExtraBytes) != RlpBehaviors.AllowExtraBytes) diff --git a/src/Nethermind/Nethermind.Shutter.Test/ShutterBlockHandlerTests.cs b/src/Nethermind/Nethermind.Shutter.Test/ShutterBlockHandlerTests.cs index bc0f4e35315..33c44829e95 100644 --- a/src/Nethermind/Nethermind.Shutter.Test/ShutterBlockHandlerTests.cs +++ b/src/Nethermind/Nethermind.Shutter.Test/ShutterBlockHandlerTests.cs @@ -24,10 +24,7 @@ public void Can_wait_for_valid_block() CancellationTokenSource source = new(); Task waitTask = blockHandler.WaitForBlockInSlot(ShutterTestsCommon.InitialSlot, source.Token); - Block result = Build.A.Block - .WithTimestamp(ShutterTestsCommon.InitialSlotTimestamp) - .WithSlotNumber(ShutterTestsCommon.InitialSlot) - .TestObject; + Block result = Build.A.Block.WithTimestamp(ShutterTestsCommon.InitialSlotTimestamp).TestObject; api.TriggerNewHeadBlock(new(result)); Assert.That(result, Is.EqualTo(waitTask.Result)); @@ -75,20 +72,12 @@ public void Ignores_outdated_block() ShutterApiSimulator api = ShutterTestsCommon.InitApi(rnd, timestamper); // not triggered on outdated block - Block block1 = Build.A.Block - .WithTimestamp(ShutterTestsCommon.InitialSlotTimestamp) - .WithSlotNumber(ShutterTestsCommon.InitialSlot) - .TestObject; - api.TriggerNewHeadBlock(new(block1)); + api.TriggerNewHeadBlock(new(Build.A.Block.WithTimestamp(ShutterTestsCommon.InitialSlotTimestamp).TestObject)); Assert.That(api.EonUpdateCalled, Is.EqualTo(0)); // triggered on up to date block ulong upToDateTimestamp = ShutterTestsCommon.InitialSlotTimestamp + 2 * (ulong)ShutterTestsCommon.BlockUpToDateCutoff.TotalSeconds; - Block block2 = Build.A.Block - .WithTimestamp(upToDateTimestamp) - .WithSlotNumber(ShutterTestsCommon.InitialSlot) - .TestObject; - api.TriggerNewHeadBlock(new(block2)); + api.TriggerNewHeadBlock(new(Build.A.Block.WithTimestamp(upToDateTimestamp).TestObject)); Assert.That(api.EonUpdateCalled, Is.EqualTo(1)); } } diff --git a/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs b/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs index 0710413a683..3b47dbc711f 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs @@ -169,7 +169,8 @@ private void OnNewHeadBlock(object? _, BlockEventArgs e) lock (_syncObject) { - ulong slot = head.SlotNumber ?? 0; + // todo: fix, move to BlockEventArgs + ulong slot = 0; _slotToBlockHash.Set(slot, head.Hash); if (_blockWaitTasks.Remove(slot, out Dictionary? waitTasks)) diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs index c149a3990c1..dc7b75faa8b 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs @@ -335,12 +335,6 @@ private static void LoadGenesis(ChainSpecJson chainSpecJson, ChainSpec chainSpec genesisHeader.ReceiptsRoot = Keccak.EmptyTreeHash; } - bool isEip7843Enabled = chainSpecJson.Params.Eip7843TransitionTimestamp is not null && genesisHeader.Timestamp >= chainSpecJson.Params.Eip7843TransitionTimestamp; - if (isEip7843Enabled) - { - genesisHeader.SlotNumber = 0; - } - genesisHeader.AuRaStep = step; genesisHeader.AuRaSignature = auRaSignature; From 5c7a51358031b99e1c882d319fa817c9a745b646 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Wed, 1 Jan 2025 15:39:34 +0000 Subject: [PATCH 14/24] try to implement in newPayload parameter --- src/Nethermind/Nethermind.Core/Block.cs | 2 ++ .../Nethermind.Merge.Plugin/Data/ExecutionPayload.cs | 7 +++++++ .../Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs | 1 + .../Data/IExecutionPayloadParams.cs | 9 ++++++++- .../Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs | 1 + 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Core/Block.cs b/src/Nethermind/Nethermind.Core/Block.cs index 8bedefb13d4..2a311e995dd 100644 --- a/src/Nethermind/Nethermind.Core/Block.cs +++ b/src/Nethermind/Nethermind.Core/Block.cs @@ -117,6 +117,8 @@ public Transaction[] Transactions public Hash256? RequestsHash => Header.RequestsHash; // do not add setter here + [JsonIgnore] + public ulong? SlotNumber { get; set; } [JsonIgnore] public byte[][]? ExecutionRequests { get; set; } diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs index 81aa243fe78..87613d4f48a 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs @@ -105,6 +105,13 @@ public byte[][] Transactions [JsonIgnore] public Hash256? ParentBeaconBlockRoot { get; set; } + /// + /// Gets or sets as defined in + /// EIP-7843. + /// + [JsonIgnore] + public ulong? SlotNumber { get; set; } + public static ExecutionPayload Create(Block block) => Create(block); protected static TExecutionPayload Create(Block block) where TExecutionPayload : ExecutionPayload, new() diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs index 3b42b48eb9a..d05c5bfac76 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs @@ -37,6 +37,7 @@ public override bool TryGetBlock([NotNullWhen(true)] out Block? block, UInt256? block.Header.BlobGasUsed = BlobGasUsed; block.Header.ExcessBlobGas = ExcessBlobGas; block.Header.RequestsHash = ExecutionRequests is not null ? ExecutionRequestExtensions.CalculateHashFromFlatEncodedRequests(ExecutionRequests) : null; + block.SlotNumber = SlotNumber; return true; } diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs index 87860936d86..c11e02821ec 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs @@ -25,7 +25,8 @@ public class ExecutionPayloadParams( TVersionedExecutionPayload executionPayload, byte[]?[] blobVersionedHashes, Hash256? parentBeaconBlockRoot, - byte[][]? executionRequests = null) + byte[][]? executionRequests = null, + ulong? slotNumber = null) : IExecutionPayloadParams where TVersionedExecutionPayload : ExecutionPayload { public TVersionedExecutionPayload ExecutionPayload => executionPayload; @@ -36,6 +37,12 @@ public class ExecutionPayloadParams( /// public byte[][]? ExecutionRequests { get; set; } = executionRequests; + /// + /// Gets or sets as defined in + /// EIP-7843. + /// + public ulong? SlotNumber { get; set; } = slotNumber; + ExecutionPayload IExecutionPayloadParams.ExecutionPayload => ExecutionPayload; public ValidationResult ValidateParams(IReleaseSpec spec, int version, out string? error) diff --git a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs index 8ac6060a548..64676d17db9 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs @@ -63,6 +63,7 @@ protected async Task> NewPayload(IExecutionPayloa { ExecutionPayload executionPayload = executionPayloadParams.ExecutionPayload; executionPayload.ExecutionRequests = executionPayloadParams.ExecutionRequests; + executionPayload.SlotNumber = executionPayloadParams.SlotNumber; if (!executionPayload.ValidateFork(_specProvider)) { From 0a1717365d83440941aeab27f71a1b752f9e710f Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Wed, 1 Jan 2025 15:39:58 +0000 Subject: [PATCH 15/24] add files --- .../EngineRpcModule.Osaka.cs | 23 +++++++++++++++++++ .../IEngineRpcModule.Osaka.cs | 19 +++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Osaka.cs create mode 100644 src/Nethermind/Nethermind.Merge.Plugin/IEngineRpcModule.Osaka.cs diff --git a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Osaka.cs b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Osaka.cs new file mode 100644 index 00000000000..b16f5ca5632 --- /dev/null +++ b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Osaka.cs @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System.Threading.Tasks; +using Nethermind.Consensus; +using Nethermind.Core.Crypto; +using Nethermind.JsonRpc; +using Nethermind.Merge.Plugin.Data; +using Nethermind.Merge.Plugin.Handlers; + +namespace Nethermind.Merge.Plugin; + +public partial class EngineRpcModule : IEngineRpcModule +{ + readonly IAsyncHandler _getPayloadHandlerV4; + + /// + /// Method parameter list is extended with parameter. + /// EIP-7843. + /// + public Task> engine_newPayloadV5(ExecutionPayloadV3 executionPayload, byte[]?[] blobVersionedHashes, Hash256? parentBeaconBlockRoot, byte[][]? executionRequests, ulong? slotNumber) + => NewPayload(new ExecutionPayloadParams(executionPayload, blobVersionedHashes, parentBeaconBlockRoot, executionRequests, slotNumber), EngineApiVersions.Osaka); +} diff --git a/src/Nethermind/Nethermind.Merge.Plugin/IEngineRpcModule.Osaka.cs b/src/Nethermind/Nethermind.Merge.Plugin/IEngineRpcModule.Osaka.cs new file mode 100644 index 00000000000..ed2f487cb62 --- /dev/null +++ b/src/Nethermind/Nethermind.Merge.Plugin/IEngineRpcModule.Osaka.cs @@ -0,0 +1,19 @@ +// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System.Threading.Tasks; +using Nethermind.Core.Crypto; +using Nethermind.JsonRpc; +using Nethermind.JsonRpc.Modules; +using Nethermind.Merge.Plugin.Data; + +namespace Nethermind.Merge.Plugin; + +public partial interface IEngineRpcModule : IRpcModule +{ + [JsonRpcMethod( + Description = "Verifies the payload according to the execution environment rules and returns the verification status and hash of the last valid block.", + IsSharable = true, + IsImplemented = true)] + Task> engine_newPayloadV5(ExecutionPayloadV3 executionPayload, byte[]?[] blobVersionedHashes, Hash256? parentBeaconBlockRoot, byte[][]? executionRequests, ulong? slotNumber); +} From cbe4bce05acca1d343968ff9346bc4bfba08c5f0 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Wed, 1 Jan 2025 16:38:22 +0000 Subject: [PATCH 16/24] use whole executionenvironment in precompilecontext --- .../TestPrecompileContext.cs | 4 ++-- .../Precompiles/PrecompileContext.cs | 19 +++++++------------ .../Precompiles/SlotPrecompile.cs | 5 ++++- .../Nethermind.Evm/VirtualMachine.cs | 2 +- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Nethermind/Nethermind.Evm.Test/TestPrecompileContext.cs b/src/Nethermind/Nethermind.Evm.Test/TestPrecompileContext.cs index b52618ea74c..09fa8346720 100644 --- a/src/Nethermind/Nethermind.Evm.Test/TestPrecompileContext.cs +++ b/src/Nethermind/Nethermind.Evm.Test/TestPrecompileContext.cs @@ -9,8 +9,8 @@ public class TestPrecompileContext : PrecompileContext { public static TestPrecompileContext Instance { get; } = new(Prague.Instance, TestSpecProvider.Instance, new()); - private TestPrecompileContext(IReleaseSpec spec, ISpecProvider specProvider, BlockExecutionContext blockExecutionContext) - : base(spec, specProvider, blockExecutionContext) + private TestPrecompileContext(IReleaseSpec spec, ISpecProvider specProvider, ExecutionEnvironment executionEnvironment) + : base(spec, specProvider, executionEnvironment) { } } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/PrecompileContext.cs b/src/Nethermind/Nethermind.Evm/Precompiles/PrecompileContext.cs index f29536b15a4..fd9ae2825c7 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/PrecompileContext.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/PrecompileContext.cs @@ -1,19 +1,14 @@ -using Nethermind.Core; +// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + using Nethermind.Core.Specs; namespace Nethermind.Evm.Precompiles { - public class PrecompileContext + public class PrecompileContext(IReleaseSpec spec, ISpecProvider specProvider, ExecutionEnvironment executionEnvironment) { - public IReleaseSpec Spec { get; } - public ISpecProvider SpecProvider { get; } - public BlockExecutionContext BlockExecutionContext { get; } - - public PrecompileContext(IReleaseSpec spec, ISpecProvider specProvider, BlockExecutionContext blockExecutionContext) - { - Spec = spec; - SpecProvider = specProvider; - BlockExecutionContext = blockExecutionContext; - } + public IReleaseSpec Spec { get; } = spec; + public ISpecProvider SpecProvider { get; } = specProvider; + public ExecutionEnvironment ExecutionEnvironment { get; } = executionEnvironment; } } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs index 2eb87ab6177..563526c1227 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/SlotPrecompile.cs @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + using System; using Nethermind.Core; using Nethermind.Core.Specs; @@ -24,7 +27,7 @@ public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, PrecompileContext context) { - ulong? slotNumber = context.BlockExecutionContext.Header.SlotNumber; + ulong? slotNumber = context.ExecutionEnvironment.TxExecutionContext.BlockExecutionContext.Header.SlotNumber; if (slotNumber is null) { diff --git a/src/Nethermind/Nethermind.Evm/VirtualMachine.cs b/src/Nethermind/Nethermind.Evm/VirtualMachine.cs index 448abce3047..5609b3cc51f 100644 --- a/src/Nethermind/Nethermind.Evm/VirtualMachine.cs +++ b/src/Nethermind/Nethermind.Evm/VirtualMachine.cs @@ -601,7 +601,7 @@ private CallResult ExecutePrecompile(EvmState state, IReleaseSpec spec) try { - PrecompileContext context = new(spec, _specProvider, state.Env.TxExecutionContext.BlockExecutionContext); + PrecompileContext context = new(spec, _specProvider, state.Env); (ReadOnlyMemory output, bool success) = precompile.Run(callData, context); CallResult callResult = new(output, success, !success); return callResult; From 7962c069e23e8e68dd5ee07930f3f8b9b9d0f431 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Wed, 1 Jan 2025 17:42:12 +0000 Subject: [PATCH 17/24] add to block execution context --- .../BlockProcessor.BlockValidationTransactionsExecutor.cs | 2 +- src/Nethermind/Nethermind.Evm/BlockExecutionContext.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.BlockValidationTransactionsExecutor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.BlockValidationTransactionsExecutor.cs index 6d2299ef920..0eedaa923d6 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.BlockValidationTransactionsExecutor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.BlockValidationTransactionsExecutor.cs @@ -43,7 +43,7 @@ public TxReceipt[] ProcessTransactions(Block block, ProcessingOptions processing return receiptsTracer.TxReceipts.ToArray(); } - protected virtual BlockExecutionContext CreateBlockExecutionContext(Block block) => new(block.Header); + protected virtual BlockExecutionContext CreateBlockExecutionContext(Block block) => new(block.Header, block.SlotNumber); protected virtual void ProcessTransaction(in BlockExecutionContext blkCtx, Transaction currentTx, int index, BlockReceiptsTracer receiptsTracer, ProcessingOptions processingOptions) { diff --git a/src/Nethermind/Nethermind.Evm/BlockExecutionContext.cs b/src/Nethermind/Nethermind.Evm/BlockExecutionContext.cs index 2bd0b7456b9..81025b34a2b 100644 --- a/src/Nethermind/Nethermind.Evm/BlockExecutionContext.cs +++ b/src/Nethermind/Nethermind.Evm/BlockExecutionContext.cs @@ -11,8 +11,9 @@ public readonly struct BlockExecutionContext { public BlockHeader Header { get; } public UInt256? BlobBaseFee { get; } + public ulong? SlotNumber { get; } - public BlockExecutionContext(BlockHeader blockHeader) + public BlockExecutionContext(BlockHeader blockHeader, ulong? slotNumber = null) { Header = blockHeader; if (blockHeader?.ExcessBlobGas is not null) @@ -23,6 +24,8 @@ public BlockExecutionContext(BlockHeader blockHeader) } BlobBaseFee = feePerBlobGas; } + + SlotNumber = slotNumber; } public BlockExecutionContext(BlockHeader blockHeader, UInt256 forceBlobBaseFee) From 4f9d221c1f68f86f32efb94dfb9e0fbf92a1bd26 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Thu, 2 Jan 2025 10:05:15 +0000 Subject: [PATCH 18/24] undo small changes --- .../Nethermind.Consensus/Producers/BlockProducerBase.cs | 2 +- src/Nethermind/Nethermind.Facade/BlockchainBridge.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs index 7f9247d2f43..f9603373e30 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs @@ -232,7 +232,7 @@ protected virtual BlockHeader PrepareBlockHeader(BlockHeader parent, { Author = blockAuthor, MixHash = payloadAttributes?.PrevRandao, - ParentBeaconBlockRoot = payloadAttributes?.ParentBeaconBlockRoot, + ParentBeaconBlockRoot = payloadAttributes?.ParentBeaconBlockRoot }; UInt256 difficulty = _difficultyCalculator.Calculate(header, parent); diff --git a/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs b/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs index cd546b21602..42e3c884e2f 100644 --- a/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs +++ b/src/Nethermind/Nethermind.Facade/BlockchainBridge.cs @@ -295,7 +295,6 @@ private TransactionResult CallAndRestore( ? BlobGasCalculator.CalculateExcessBlobGas(blockHeader, releaseSpec) : blockHeader.ExcessBlobGas; } - callHeader.MixHash = blockHeader.MixHash; callHeader.IsPostMerge = blockHeader.Difficulty == 0; transaction.Hash = transaction.CalculateHash(); From 5bf98d066376205a2338a4d8f941f66b53439c77 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Thu, 2 Jan 2025 13:32:18 +0000 Subject: [PATCH 19/24] use slot number in shutter block handler --- src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs b/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs index 3b47dbc711f..800d83f0299 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs @@ -169,8 +169,7 @@ private void OnNewHeadBlock(object? _, BlockEventArgs e) lock (_syncObject) { - // todo: fix, move to BlockEventArgs - ulong slot = 0; + ulong slot = e.Block.SlotNumber!; _slotToBlockHash.Set(slot, head.Hash); if (_blockWaitTasks.Remove(slot, out Dictionary? waitTasks)) From 7a92e0592ceda3143123699823eb5456c8620329 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Thu, 2 Jan 2025 13:58:58 +0000 Subject: [PATCH 20/24] fix, add to chainspec --- src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs | 2 ++ src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs | 1 + src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs | 1 + .../Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs | 1 + src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Osaka.cs | 2 -- src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs | 2 +- .../Nethermind.Specs/ChainSpecStyle/ChainParameters.cs | 1 + .../ChainSpecStyle/ChainSpecBasedSpecProvider.cs | 2 ++ .../Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs | 1 + 9 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs b/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs index 8e7c60df854..fe8abe1822d 100644 --- a/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs +++ b/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs @@ -362,6 +362,8 @@ public interface IReleaseSpec : IEip1559Spec, IReceiptSpec public bool Bls381Enabled => IsEip2537Enabled; + public bool SlotEnabled => IsEip7843Enabled; + public bool ChargeForTopLevelCreate => IsEip2Enabled; public bool FailOnOutOfGasCodeDeposit => IsEip2Enabled; diff --git a/src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs b/src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs index 9851069f306..0b60a863904 100644 --- a/src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs +++ b/src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs @@ -101,6 +101,7 @@ public class ReleaseSpecDecorator(IReleaseSpec spec) : IReleaseSpec public virtual bool Bn128Enabled => spec.Bn128Enabled; public virtual bool BlakeEnabled => spec.BlakeEnabled; public virtual bool Bls381Enabled => spec.Bls381Enabled; + public virtual bool SlotEnabled => spec.SlotEnabled; public virtual bool ChargeForTopLevelCreate => spec.ChargeForTopLevelCreate; public virtual bool FailOnOutOfGasCodeDeposit => spec.FailOnOutOfGasCodeDeposit; public virtual bool UseShanghaiDDosProtection => spec.UseShanghaiDDosProtection; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs b/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs index 11ba1f00ae5..8243c4a5989 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs @@ -38,6 +38,7 @@ public static bool IsPrecompile(this Address address, IReleaseSpec releaseSpec) 0x11 => releaseSpec.Bls381Enabled, 0x12 => releaseSpec.Bls381Enabled, 0x13 => releaseSpec.Bls381Enabled, + 0x14 => releaseSpec.SlotEnabled, _ => false }, 0x01 => (data[4] >>> 24) switch diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs index c11e02821ec..58ff6ed6ee7 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs @@ -16,6 +16,7 @@ public interface IExecutionPayloadParams { ExecutionPayload ExecutionPayload { get; } byte[][]? ExecutionRequests { get; set; } + public ulong? SlotNumber { get; set; } ValidationResult ValidateParams(IReleaseSpec spec, int version, out string? error); } diff --git a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Osaka.cs b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Osaka.cs index b16f5ca5632..963c7c926d5 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Osaka.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Osaka.cs @@ -12,8 +12,6 @@ namespace Nethermind.Merge.Plugin; public partial class EngineRpcModule : IEngineRpcModule { - readonly IAsyncHandler _getPayloadHandlerV4; - /// /// Method parameter list is extended with parameter. /// EIP-7843. diff --git a/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs b/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs index 800d83f0299..6521339648b 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterBlockHandler.cs @@ -169,7 +169,7 @@ private void OnNewHeadBlock(object? _, BlockEventArgs e) lock (_syncObject) { - ulong slot = e.Block.SlotNumber!; + ulong slot = e.Block.SlotNumber!.Value; _slotToBlockHash.Set(slot, head.Hash); if (_blockWaitTasks.Remove(slot, out Dictionary? waitTasks)) diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainParameters.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainParameters.cs index 72badcbc77a..06044219fcf 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainParameters.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainParameters.cs @@ -129,6 +129,7 @@ public class ChainParameters public Address Eip2935ContractAddress { get; set; } public ulong? Rip7212TransitionTimestamp { get; set; } public ulong? Eip7702TransitionTimestamp { get; set; } + public ulong? Eip7843TransitionTimestamp { get; set; } public ulong? OpGraniteTransitionTimestamp { get; set; } public ulong? OpHoloceneTransitionTimestamp { get; set; } diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs index ca46a2ce93f..a71e5df28b0 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs @@ -234,6 +234,8 @@ private ReleaseSpec CreateReleaseSpec(ChainSpec chainSpec, long releaseStartBloc releaseSpec.IsEip7251Enabled = (chainSpec.Parameters.Eip7251TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp; releaseSpec.Eip7251ContractAddress = chainSpec.Parameters.Eip7251ContractAddress; + releaseSpec.IsEip7843Enabled = (chainSpec.Parameters.Eip7843TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp; + releaseSpec.IsOntakeEnabled = (chainSpec.Parameters.OntakeTransition ?? long.MaxValue) <= releaseStartBlock; foreach (IChainSpecEngineParameters item in _chainSpec.EngineChainSpecParametersProvider diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs index dc7b75faa8b..f1e833e37f4 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs @@ -163,6 +163,7 @@ bool GetForInnerPathExistence(KeyValuePair o) => Eip7002ContractAddress = chainSpecJson.Params.Eip7002ContractAddress ?? Eip7002Constants.WithdrawalRequestPredeployAddress, Eip7251TransitionTimestamp = chainSpecJson.Params.Eip7251TransitionTimestamp, Eip7251ContractAddress = chainSpecJson.Params.Eip7251ContractAddress ?? Eip7251Constants.ConsolidationRequestPredeployAddress, + Eip7843TransitionTimestamp = chainSpecJson.Params.Eip7843TransitionTimestamp, FeeCollector = chainSpecJson.Params.FeeCollector, Eip1559FeeCollectorTransition = chainSpecJson.Params.Eip1559FeeCollectorTransition, Eip1559BaseFeeMinValueTransition = chainSpecJson.Params.Eip1559BaseFeeMinValueTransition, From cdc86b03c4c40fba189292b273073601cd1ad291 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Thu, 2 Jan 2025 14:58:30 +0000 Subject: [PATCH 21/24] shutter fallback to timestamp if slotnumber not in payloadattributes --- src/Nethermind/Nethermind.Shutter/ShutterApi.cs | 2 +- .../ShutterBlockImprovementContext.cs | 2 +- src/Nethermind/Nethermind.Shutter/ShutterTime.cs | 12 ++++++++++++ src/Nethermind/Nethermind.Shutter/ShutterTxSource.cs | 8 ++++---- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Nethermind/Nethermind.Shutter/ShutterApi.cs b/src/Nethermind/Nethermind.Shutter/ShutterApi.cs index d2f7ff5e6fb..42ca73702c4 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterApi.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterApi.cs @@ -98,7 +98,7 @@ IPAddress ip logManager, BlockWaitCutoff); - TxSource = new ShutterTxSource(TxLoader, _cfg, logManager); + TxSource = new ShutterTxSource(TxLoader, _cfg, Time, logManager); KeyValidator = new ShutterKeyValidator(_cfg, Eon, logManager); diff --git a/src/Nethermind/Nethermind.Shutter/ShutterBlockImprovementContext.cs b/src/Nethermind/Nethermind.Shutter/ShutterBlockImprovementContext.cs index e59bf504b4d..174066b828c 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterBlockImprovementContext.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterBlockImprovementContext.cs @@ -81,8 +81,8 @@ internal ShutterBlockImprovementContext( _parentHeader = parentHeader; _payloadAttributes = payloadAttributes; _time = time; - _slotNumber = payloadAttributes.SlotNumber ?? 0; _slotTimestampMs = payloadAttributes.Timestamp * 1000; + _slotNumber = payloadAttributes.SlotNumber ?? _time.GetSlot(_slotTimestampMs); ImprovementTask = Task.Run(ImproveBlock); } diff --git a/src/Nethermind/Nethermind.Shutter/ShutterTime.cs b/src/Nethermind/Nethermind.Shutter/ShutterTime.cs index b43a8d6a30e..55875021808 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterTime.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterTime.cs @@ -21,4 +21,16 @@ public long GetCurrentOffsetMs(ulong slot, ulong? slotTimestampMs = null) public bool IsBlockUpToDate(Block head) => timestamper.UtcNowOffset.ToUnixTimeSeconds() - (long)head.Header.Timestamp < blockUpToDateCutoff.TotalSeconds; + + + public ulong GetSlot(ulong slotTimestampMs) + { + long slotTimeSinceGenesis = (long)slotTimestampMs - (long)GenesisTimestampMs; + if (slotTimeSinceGenesis < 0) + { + throw new ShutterSlotCalulationException($"Slot timestamp {slotTimestampMs}ms was before than genesis timestamp {GenesisTimestampMs}ms."); + } + + return (ulong)slotTimeSinceGenesis / (ulong)slotLength.TotalMilliseconds; + } } diff --git a/src/Nethermind/Nethermind.Shutter/ShutterTxSource.cs b/src/Nethermind/Nethermind.Shutter/ShutterTxSource.cs index 72b9de08232..fc556836480 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterTxSource.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterTxSource.cs @@ -18,6 +18,7 @@ namespace Nethermind.Shutter; public class ShutterTxSource( ShutterTxLoader txLoader, IShutterConfig shutterConfig, + ShutterTime time, ILogManager logManager) : ITxSource, IShutterTxSignal { @@ -35,12 +36,11 @@ public IEnumerable GetTransactions(BlockHeader parent, long gasLimi return []; } - if (payloadAttributes?.SlotNumber is null) + if (payloadAttributes!.SlotNumber is null) { - if (_logger.IsDebug) _logger.Warn($"DEBUG/ERROR PayloadAttributes.SlotNumber is null"); - return []; + if (_logger.IsDebug) _logger.Warn($"PayloadAttributes.SlotNumber is null"); } - ulong buildingSlot = payloadAttributes.SlotNumber.Value; + ulong buildingSlot = payloadAttributes.SlotNumber ?? time.GetSlot(payloadAttributes.Timestamp * 1000); ShutterTransactions? shutterTransactions = _txCache.Get(buildingSlot); if (shutterTransactions is null) From e3a0817ce24ca5e42376431244d4f7efe0d2da6f Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Thu, 2 Jan 2025 22:08:13 +0000 Subject: [PATCH 22/24] pass slot number in when producing block --- .../Nethermind.Consensus/Producers/BlockProducerBase.cs | 7 ++++++- .../Nethermind.Consensus/Producers/BlockToProduce.cs | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs index f9603373e30..b69716eb9ea 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs @@ -252,7 +252,12 @@ protected virtual Block PrepareBlock(BlockHeader parent, PayloadAttributes? payl IEnumerable transactions = _txSource.GetTransactions(parent, header.GasLimit, payloadAttributes); - return new BlockToProduce(header, transactions, Array.Empty(), payloadAttributes?.Withdrawals); + return new BlockToProduce( + header, + transactions, + Array.Empty(), + payloadAttributes?.Withdrawals, + payloadAttributes?.SlotNumber); } } } diff --git a/src/Nethermind/Nethermind.Consensus/Producers/BlockToProduce.cs b/src/Nethermind/Nethermind.Consensus/Producers/BlockToProduce.cs index f7796208ecb..49b1654db59 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/BlockToProduce.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/BlockToProduce.cs @@ -32,10 +32,12 @@ public class BlockToProduce : Block public BlockToProduce(BlockHeader blockHeader, IEnumerable transactions, IEnumerable uncles, - IEnumerable? withdrawals = null) + IEnumerable? withdrawals = null, + ulong? slotNumber = null) : base(blockHeader, Array.Empty(), uncles, withdrawals) { Transactions = transactions; + SlotNumber = slotNumber; } public override Block WithReplacedHeader(BlockHeader newHeader) => new BlockToProduce(newHeader, Transactions, Uncles, Withdrawals); From 5cb46b231466a39fc4270dcf4e4e1de13ad667db Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Sat, 4 Jan 2025 18:42:47 +0000 Subject: [PATCH 23/24] fix payloadattributes order --- .../Nethermind.Consensus/Producers/PayloadAttributes.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs index d1ea5bc3fc7..5f48eacec43 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs @@ -37,8 +37,7 @@ public string ToString(string indentation) var sb = new StringBuilder($"{indentation}{nameof(PayloadAttributes)} {{") .Append($"{nameof(Timestamp)}: {Timestamp}, ") .Append($"{nameof(PrevRandao)}: {PrevRandao}, ") - .Append($"{nameof(SuggestedFeeRecipient)}: {SuggestedFeeRecipient}") - .Append($"{nameof(SlotNumber)}: {SlotNumber}"); + .Append($"{nameof(SuggestedFeeRecipient)}: {SuggestedFeeRecipient}"); if (Withdrawals is not null) { @@ -50,6 +49,11 @@ public string ToString(string indentation) sb.Append($", {nameof(ParentBeaconBlockRoot)} : {ParentBeaconBlockRoot}"); } + if (SlotNumber is not null) + { + sb.Append($", {nameof(SlotNumber)}: {SlotNumber}"); + } + sb.Append('}'); return sb.ToString(); From 94b5b939c660e7ff8c475e51c503c9392b2a7323 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Sat, 4 Jan 2025 18:45:16 +0000 Subject: [PATCH 24/24] fix whitespace --- src/Nethermind/Nethermind.Shutter/ShutterTime.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Shutter/ShutterTime.cs b/src/Nethermind/Nethermind.Shutter/ShutterTime.cs index 55875021808..28f3a8b74c5 100644 --- a/src/Nethermind/Nethermind.Shutter/ShutterTime.cs +++ b/src/Nethermind/Nethermind.Shutter/ShutterTime.cs @@ -21,7 +21,7 @@ public long GetCurrentOffsetMs(ulong slot, ulong? slotTimestampMs = null) public bool IsBlockUpToDate(Block head) => timestamper.UtcNowOffset.ToUnixTimeSeconds() - (long)head.Header.Timestamp < blockUpToDateCutoff.TotalSeconds; - + public ulong GetSlot(ulong slotTimestampMs) {