From 962de192115c004b22466b4fa66cf7416a4d7702 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Wed, 19 Jul 2023 15:36:57 +0100 Subject: [PATCH 01/43] - Added Eip4788 to ReleaseSpecs - Added Eip4788 wiring to ChainSpecs --- src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs | 8 +++++++- .../Nethermind.Specs/ChainSpecStyle/ChainParameters.cs | 1 + .../ChainSpecStyle/ChainSpecBasedSpecProvider.cs | 1 + .../Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs | 1 + .../ChainSpecStyle/Json/ChainSpecParamsJson.cs | 1 + src/Nethermind/Nethermind.Specs/Forks/16_Cancun.cs | 1 + src/Nethermind/Nethermind.Specs/ReleaseSpec.cs | 1 + .../Nethermind.Specs/SystemTransactionReleaseSpec.cs | 1 + 8 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs b/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs index 4dfc2b7b533..f35ac63a0ef 100644 --- a/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs +++ b/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs @@ -267,6 +267,11 @@ public interface IReleaseSpec : IEip1559Spec, IReceiptSpec /// bool IsEip4844Enabled { get; } + /// + /// Parent Beacon Block precompile + /// + bool IsEip4788Enabled { get; } + /// /// SELFDESTRUCT only in same transaction /// @@ -352,6 +357,7 @@ public interface IReleaseSpec : IEip1559Spec, IReceiptSpec public bool WithdrawalsEnabled => IsEip4895Enabled; public bool SelfdestructOnlyOnSameTransaction => IsEip6780Enabled; - bool MCopyIncluded => IsEip5656Enabled; + public bool IsBeaconParentBlockRootAvailable => IsEip4788Enabled; + public bool MCopyIncluded => IsEip5656Enabled; } } diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainParameters.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainParameters.cs index 7f12e7acf4f..5c3a6f79fc7 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainParameters.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainParameters.cs @@ -115,5 +115,6 @@ public class ChainParameters public ulong? Eip1153TransitionTimestamp { get; set; } public ulong? Eip5656TransitionTimestamp { get; set; } public ulong? Eip6780TransitionTimestamp { get; set; } + public ulong? Eip4788TransitionTimestamp { get; set; } } } diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs index 655fa41af9f..ecef8dc1df2 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecBasedSpecProvider.cs @@ -238,6 +238,7 @@ private static ReleaseSpec CreateReleaseSpec(ChainSpec chainSpec, long releaseSt releaseSpec.Eip4844TransitionTimestamp = chainSpec.Parameters.Eip4844TransitionTimestamp ?? ulong.MaxValue; releaseSpec.IsEip5656Enabled = (chainSpec.Parameters.Eip5656TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp; releaseSpec.IsEip6780Enabled = (chainSpec.Parameters.Eip6780TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp; + releaseSpec.IsEip4788Enabled = (chainSpec.Parameters.Eip4788TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp; return releaseSpec; } diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs index f1827795e42..d0c109c26b1 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs @@ -142,6 +142,7 @@ private void LoadParameters(ChainSpecJson chainSpecJson, ChainSpec chainSpec) Eip2537TransitionTimestamp = chainSpecJson.Params.Eip2537TransitionTimestamp, Eip5656TransitionTimestamp = chainSpecJson.Params.Eip5656TransitionTimestamp, Eip6780TransitionTimestamp = chainSpecJson.Params.Eip6780TransitionTimestamp, + Eip4788TransitionTimestamp = chainSpecJson.Params.Eip4788TransitionTimestamp, TransactionPermissionContract = chainSpecJson.Params.TransactionPermissionContract, TransactionPermissionContractTransition = chainSpecJson.Params.TransactionPermissionContractTransition, ValidateChainIdTransition = chainSpecJson.Params.ValidateChainIdTransition, diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/Json/ChainSpecParamsJson.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/Json/ChainSpecParamsJson.cs index d1fabed369a..677c0c45a13 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/Json/ChainSpecParamsJson.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/Json/ChainSpecParamsJson.cs @@ -143,5 +143,6 @@ internal class ChainSpecParamsJson public ulong? Eip2537TransitionTimestamp { get; set; } public ulong? Eip5656TransitionTimestamp { get; set; } public ulong? Eip6780TransitionTimestamp { get; set; } + public ulong? Eip4788TransitionTimestamp { get; set; } } } diff --git a/src/Nethermind/Nethermind.Specs/Forks/16_Cancun.cs b/src/Nethermind/Nethermind.Specs/Forks/16_Cancun.cs index f50e02308f1..bc4c01ab58e 100644 --- a/src/Nethermind/Nethermind.Specs/Forks/16_Cancun.cs +++ b/src/Nethermind/Nethermind.Specs/Forks/16_Cancun.cs @@ -17,6 +17,7 @@ protected Cancun() IsEip5656Enabled = true; IsEip4844Enabled = true; IsEip6780Enabled = true; + IsEip4788Enabled = true; } public new static IReleaseSpec Instance => LazyInitializer.EnsureInitialized(ref _instance, () => new Cancun()); diff --git a/src/Nethermind/Nethermind.Specs/ReleaseSpec.cs b/src/Nethermind/Nethermind.Specs/ReleaseSpec.cs index 029dbf37b08..7f40302ee2d 100644 --- a/src/Nethermind/Nethermind.Specs/ReleaseSpec.cs +++ b/src/Nethermind/Nethermind.Specs/ReleaseSpec.cs @@ -81,5 +81,6 @@ public ReleaseSpec Clone() public bool IsEip4844Enabled { get; set; } public bool IsEip5656Enabled { get; set; } public bool IsEip6780Enabled { get; set; } + public bool IsEip4788Enabled { get; set; } } } diff --git a/src/Nethermind/Nethermind.Specs/SystemTransactionReleaseSpec.cs b/src/Nethermind/Nethermind.Specs/SystemTransactionReleaseSpec.cs index 3dc669059c3..3b63d5a731a 100644 --- a/src/Nethermind/Nethermind.Specs/SystemTransactionReleaseSpec.cs +++ b/src/Nethermind/Nethermind.Specs/SystemTransactionReleaseSpec.cs @@ -128,5 +128,6 @@ public bool IsEip158IgnoredAccount(Address address) public bool IsEip4895Enabled => _spec.IsEip4895Enabled; public bool IsEip5656Enabled => _spec.IsEip5656Enabled; public bool IsEip6780Enabled => _spec.IsEip6780Enabled; + public bool IsEip4788Enabled => _spec.IsEip4788Enabled; } } From ec00aece66c4b018d5af422644dfa5ae06d66e2e Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Wed, 19 Jul 2023 15:37:51 +0100 Subject: [PATCH 02/43] - Added passing state to Precompiles - Added Eip4788 stateful precompile --- src/Nethermind/Nethermind.Evm/GasCostOf.cs | 2 + src/Nethermind/Nethermind.Evm/Metrics.cs | 6 +- .../Precompiles/AddressExtensions.cs | 1 + .../Precompiles/Blake2FPrecompile.cs | 3 +- .../Precompiles/Bls/G1AddPrecompile.cs | 3 +- .../Precompiles/Bls/G1MulPrecompile.cs | 3 +- .../Precompiles/Bls/G1MultiExpPrecompile.cs | 3 +- .../Precompiles/Bls/G2AddPrecompile.cs | 3 +- .../Precompiles/Bls/G2MulPrecompile.cs | 3 +- .../Precompiles/Bls/G2MultiExpPrecompile.cs | 3 +- .../Precompiles/Bls/MapToG1Precompile.cs | 3 +- .../Precompiles/Bls/MapToG2Precompile.cs | 3 +- .../Precompiles/Bls/PairingPrecompile.cs | 3 +- .../Precompiles/EcRecoverPrecompile.cs | 3 +- .../Nethermind.Evm/Precompiles/IPrecompile.cs | 3 +- .../Precompiles/IdentityPrecompile.cs | 3 +- .../Precompiles/ModExpPrecompile.cs | 3 +- .../Precompiles/ModExpPrecompilePreEip2565.cs | 3 +- .../Precompiles/PointEvaluationPrecompile.cs | 3 +- .../Precompiles/Ripemd160Precompile.cs | 3 +- .../Precompiles/Sha256Precompile.cs | 3 +- .../Precompiles/Snarks/Bn254AddPrecompile.cs | 3 +- .../Precompiles/Snarks/Bn254MulPrecompile.cs | 3 +- .../Snarks/Bn254PairingPrecompile.cs | 3 +- .../Stateful/BeaconBlockRootPrecompile.cs | 70 +++++++++++++++++++ .../Nethermind.Evm/VirtualMachine.cs | 4 +- 26 files changed, 123 insertions(+), 23 deletions(-) create mode 100644 src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs diff --git a/src/Nethermind/Nethermind.Evm/GasCostOf.cs b/src/Nethermind/Nethermind.Evm/GasCostOf.cs index 5e8b2291dc1..8c51d8bd144 100644 --- a/src/Nethermind/Nethermind.Evm/GasCostOf.cs +++ b/src/Nethermind/Nethermind.Evm/GasCostOf.cs @@ -54,6 +54,8 @@ public static class GasCostOf public const long InitCodeWord = 2; //eip-3860 gas per word cost for init code size public const long ColdSLoad = 2100; // eip-2929 + public const long ParentBeaconBlockPrecompile = ColdSLoad * 2; // Eip hardcded 4200 // eip-2929 + public const long ColdAccountAccess = 2600; // eip-2929 public const long WarmStateRead = 100; // eip-2929 diff --git a/src/Nethermind/Nethermind.Evm/Metrics.cs b/src/Nethermind/Nethermind.Evm/Metrics.cs index cf38e9a2922..28983fe03a1 100644 --- a/src/Nethermind/Nethermind.Evm/Metrics.cs +++ b/src/Nethermind/Nethermind.Evm/Metrics.cs @@ -84,12 +84,16 @@ public class Metrics [Description("Number of Point Evaluation precompile calls.")] public static long PointEvaluationPrecompile { get; set; } + [CounterMetric] + [Description("Number of Parent Beacon Block Root precompile calls.")] + public static int BeaconBlockRootPrecompile { get; set; } + + [Description("Number of calls made to addresses without code.")] public static long EmptyCalls { get; set; } [Description("Number of contract create calls.")] public static long Creates { get; set; } - internal static long Transactions { get; set; } internal static decimal AveGasPrice { get; set; } internal static decimal MinGasPrice { get; set; } = decimal.MaxValue; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs b/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs index 560ef8ca8e7..e10e45cb40b 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs @@ -27,6 +27,7 @@ public static bool IsPrecompile(this Address address, IReleaseSpec releaseSpec) 0x08 => releaseSpec.Bn128Enabled, 0x09 => releaseSpec.BlakeEnabled, 0x0a => releaseSpec.IsEip4844Enabled, + 0x0b => releaseSpec.IsBeaconParentBlockRootAvailable, 0x0c => releaseSpec.Bls381Enabled, 0x0d => releaseSpec.Bls381Enabled, 0x0e => releaseSpec.Bls381Enabled, diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs index f0d37413475..2de732ab581 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs @@ -6,6 +6,7 @@ using Nethermind.Core.Extensions; using Nethermind.Core.Specs; using Nethermind.Crypto.Blake2; +using Nethermind.State; namespace Nethermind.Evm.Precompiles { @@ -39,7 +40,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return rounds; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { 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 e3bc46d020d..36382217d17 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs @@ -5,6 +5,7 @@ using Nethermind.Core; using Nethermind.Core.Specs; using Nethermind.Crypto; +using Nethermind.State; namespace Nethermind.Evm.Precompiles.Bls; @@ -31,7 +32,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { const int expectedInputLength = 4 * BlsParams.LenFp; if (inputData.Length != expectedInputLength) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs index bcf58d628ed..1110b26c70b 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs @@ -5,6 +5,7 @@ using Nethermind.Core; using Nethermind.Core.Specs; using Nethermind.Crypto; +using Nethermind.State; namespace Nethermind.Evm.Precompiles.Bls; @@ -31,7 +32,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { const int expectedInputLength = 2 * BlsParams.LenFp + BlsParams.LenFr; if (inputData.Length != expectedInputLength) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs index 337a27876fc..1b598feab4e 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs @@ -5,6 +5,7 @@ using Nethermind.Core; using Nethermind.Core.Specs; using Nethermind.Crypto; +using Nethermind.State; namespace Nethermind.Evm.Precompiles.Bls; @@ -34,7 +35,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS private const int ItemSize = 160; - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { if (inputData.Length % ItemSize > 0 || inputData.Length == 0) { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs index 387b15b7cb2..8e73dce031e 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs @@ -5,6 +5,7 @@ using Nethermind.Core; using Nethermind.Core.Specs; using Nethermind.Crypto; +using Nethermind.State; namespace Nethermind.Evm.Precompiles.Bls; @@ -31,7 +32,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { const int expectedInputLength = 8 * BlsParams.LenFp; if (inputData.Length != expectedInputLength) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs index e8bcb212b90..f7f9d1d6720 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs @@ -5,6 +5,7 @@ using Nethermind.Core; using Nethermind.Core.Specs; using Nethermind.Crypto; +using Nethermind.State; namespace Nethermind.Evm.Precompiles.Bls; @@ -31,7 +32,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { const int expectedInputLength = 4 * BlsParams.LenFp + BlsParams.LenFr; if (inputData.Length != expectedInputLength) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs index 8092a7923fe..9167cbf8206 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs @@ -5,6 +5,7 @@ using Nethermind.Core; using Nethermind.Core.Specs; using Nethermind.Crypto; +using Nethermind.State; namespace Nethermind.Evm.Precompiles.Bls; @@ -34,7 +35,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS private const int ItemSize = 288; - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { if (inputData.Length % ItemSize > 0 || inputData.Length == 0) { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs index e15d5fb320a..c5107a3deaa 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs @@ -5,6 +5,7 @@ using Nethermind.Core; using Nethermind.Core.Specs; using Nethermind.Crypto; +using Nethermind.State; namespace Nethermind.Evm.Precompiles.Bls; @@ -31,7 +32,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { const int expectedInputLength = 64; if (inputData.Length != expectedInputLength) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs index b0fa9e16ad9..ccfd181ef91 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs @@ -5,6 +5,7 @@ using Nethermind.Core; using Nethermind.Core.Specs; using Nethermind.Crypto; +using Nethermind.State; namespace Nethermind.Evm.Precompiles.Bls; @@ -31,7 +32,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { const int expectedInputLength = 2 * BlsParams.LenFp; if (inputData.Length != expectedInputLength) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs index 0d7e5144efa..e4e547e6bba 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs @@ -5,6 +5,7 @@ using Nethermind.Core; using Nethermind.Core.Specs; using Nethermind.Crypto; +using Nethermind.State; namespace Nethermind.Evm.Precompiles.Bls; @@ -28,7 +29,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 23000L * (inputData.Length / PairSize); } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { if (inputData.Length % PairSize > 0 || inputData.Length == 0) { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs index 831bdef83b3..7843d2695bd 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs @@ -8,6 +8,7 @@ using Nethermind.Core.Specs; using Nethermind.Crypto; using Nethermind.Logging; +using Nethermind.State; namespace Nethermind.Evm.Precompiles { @@ -35,7 +36,7 @@ public long BaseGasCost(IReleaseSpec releaseSpec) private readonly byte[] _zero31 = new byte[31]; - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { Metrics.EcRecoverPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs index 1d80239ebdf..320ae003957 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs @@ -4,6 +4,7 @@ using System; using Nethermind.Core; using Nethermind.Core.Specs; +using Nethermind.State; namespace Nethermind.Evm.Precompiles { @@ -15,6 +16,6 @@ public interface IPrecompile long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec); - (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec); + (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState state = null); } } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs index a760f842d71..ed64181487b 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs @@ -4,6 +4,7 @@ using System; using Nethermind.Core; using Nethermind.Core.Specs; +using Nethermind.State; namespace Nethermind.Evm.Precompiles { @@ -27,7 +28,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 3L * EvmPooledMemory.Div32Ceiling((ulong)inputData.Length); } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { return (inputData, true); } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs index f45048107d2..94c1f8e024a 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs @@ -9,6 +9,7 @@ using Nethermind.Core.Specs; using Nethermind.Int256; using MathGmp.Native; +using Nethermind.State; namespace Nethermind.Evm.Precompiles { @@ -102,7 +103,7 @@ private static (int, int, int) GetInputLengths(in ReadOnlyMemory inputData return (baseLength, expLength, modulusLength); } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { Metrics.ModExpPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs index a2bee188147..ac8634a5ab5 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs @@ -7,6 +7,7 @@ using Nethermind.Core.Extensions; using Nethermind.Core.Specs; using Nethermind.Int256; +using Nethermind.State; namespace Nethermind.Evm.Precompiles { @@ -56,7 +57,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS } } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { Metrics.ModExpPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs index 60734490d18..02cd6a8979f 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs @@ -8,6 +8,7 @@ using Nethermind.Core.Specs; using Nethermind.Crypto; using Nethermind.Int256; +using Nethermind.State; namespace Nethermind.Evm.Precompiles; @@ -26,7 +27,7 @@ public class PointEvaluationPrecompile : IPrecompile public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0; - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { [SkipLocalsInit] [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs index 8c357d917d1..c1164220b7b 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs @@ -6,6 +6,7 @@ using Nethermind.Core.Extensions; using Nethermind.Core.Specs; using Nethermind.Crypto; +using Nethermind.State; namespace Nethermind.Evm.Precompiles { @@ -35,7 +36,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 120L * EvmPooledMemory.Div32Ceiling((ulong)inputData.Length); } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { Metrics.Ripemd160Precompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs index fdb5dacf80b..de15b339718 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs @@ -6,6 +6,7 @@ using System.Threading; using Nethermind.Core; using Nethermind.Core.Specs; +using Nethermind.State; namespace Nethermind.Evm.Precompiles { @@ -42,7 +43,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 12L * EvmPooledMemory.Div32Ceiling((ulong)inputData.Length); } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { Metrics.Sha256Precompile++; InitIfNeeded(); diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs index 4ce9259c3d8..9f1306bf9e0 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs @@ -5,6 +5,7 @@ using Nethermind.Core; using Nethermind.Core.Specs; using Nethermind.Crypto; +using Nethermind.State; namespace Nethermind.Evm.Precompiles.Snarks; @@ -27,7 +28,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public unsafe (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public unsafe (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { 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 64659eb0bbb..ead321acad4 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254MulPrecompile.cs @@ -5,6 +5,7 @@ using Nethermind.Core; using Nethermind.Core.Specs; using Nethermind.Crypto; +using Nethermind.State; namespace Nethermind.Evm.Precompiles.Snarks; @@ -27,7 +28,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { 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 8cff25969d4..e59985e8181 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254PairingPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254PairingPrecompile.cs @@ -5,6 +5,7 @@ using Nethermind.Core; using Nethermind.Core.Specs; using Nethermind.Crypto; +using Nethermind.State; namespace Nethermind.Evm.Precompiles.Snarks; @@ -29,7 +30,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return (releaseSpec.IsEip1108Enabled ? 34000L : 80000L) * (inputData.Length / PairSize); } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) { Metrics.Bn254PairingPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs new file mode 100644 index 00000000000..75caa7eb7c5 --- /dev/null +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs @@ -0,0 +1,70 @@ +using System; +using Nethermind.Core; +using Nethermind.Core.Crypto; +using Nethermind.Core.Specs; +using Nethermind.Int256; +using Nethermind.State; + +namespace Nethermind.Evm.Precompiles.Stateful; +public class BeaconBlockRootPrecompile : IPrecompile +{ + public static Address Address { get; } = Address.FromNumber(0x0B); + public static UInt256 HISTORICAL_ROOTS_LENGTH = 98304; + + public static IPrecompile Instance => new BeaconBlockRootPrecompile(); + + private byte[] SloadFromStorage(IWorldState state, in UInt256 index) + { + StorageCell storageCell = new(Address, index); + return state.Get(storageCell); + } + public static void SetupBeaconBlockRootPrecompileState(IWorldState stateProvider, Block block, Keccak parentBeaconBlockRoot) + { + if (parentBeaconBlockRoot is null) return; + UInt256 timestamp = block.Header.Timestamp; + + UInt256.Mod(timestamp, HISTORICAL_ROOTS_LENGTH, out UInt256 timestampReduced); + UInt256 rootIndex = timestampReduced + HISTORICAL_ROOTS_LENGTH; + + StorageCell tsStorageCell = new(Address, timestampReduced); + StorageCell brStorageCell = new(Address, rootIndex); + + stateProvider.Set(tsStorageCell, timestamp.ToBigEndian()); + stateProvider.Set(brStorageCell, parentBeaconBlockRoot.Bytes.ToArray()); + } + + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState state) + { + Metrics.BeaconBlockRootPrecompile++; + + if (inputData.Length != 32) + { + return (Array.Empty(), false); + } + + UInt256 timestamp = new UInt256(inputData.Span, true); + UInt256.Mod(timestamp, HISTORICAL_ROOTS_LENGTH, out UInt256 timestampReduced); + UInt256 recordedTimestamp = new UInt256(SloadFromStorage(state, timestampReduced), true); + + if (recordedTimestamp != timestamp) + { + return (default, true); + } + else + { + UInt256 timestampExtended = timestampReduced + HISTORICAL_ROOTS_LENGTH; + byte[] recordedRoot = SloadFromStorage(state, timestampExtended); + return (recordedRoot, true); + } + } + + public long BaseGasCost(IReleaseSpec releaseSpec) + { + return GasCostOf.ParentBeaconBlockPrecompile; + } + + public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) + { + return 0L; + } +} diff --git a/src/Nethermind/Nethermind.Evm/VirtualMachine.cs b/src/Nethermind/Nethermind.Evm/VirtualMachine.cs index 256694bb2f8..b4bce261470 100644 --- a/src/Nethermind/Nethermind.Evm/VirtualMachine.cs +++ b/src/Nethermind/Nethermind.Evm/VirtualMachine.cs @@ -33,6 +33,7 @@ namespace Nethermind.Evm; +using Nethermind.Evm.Precompiles.Stateful; using Nethermind.Int256; public class VirtualMachine : IVirtualMachine @@ -542,6 +543,7 @@ private void InitializePrecompiledContracts() [MapToG2Precompile.Address] = new(MapToG2Precompile.Instance), [PointEvaluationPrecompile.Address] = new(PointEvaluationPrecompile.Instance), + [BeaconBlockRootPrecompile.Address] = new(BeaconBlockRootPrecompile.Instance), }; } @@ -672,7 +674,7 @@ private CallResult ExecutePrecompile(EvmState state, IReleaseSpec spec) try { - (ReadOnlyMemory output, bool success) = precompile.Run(callData, spec); + (ReadOnlyMemory output, bool success) = precompile.Run(callData, spec, _state); CallResult callResult = new(output.ToArray(), success, !success); return callResult; } From 30f15e07f2e9c0444f4bc7dc75a11d7605d7e368 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Wed, 19 Jul 2023 15:46:35 +0100 Subject: [PATCH 03/43] - Adds consensus logic of Eip4788 --- .../Processing/BlockProcessor.cs | 11 ++++++++ .../Producers/PayloadAttributes.cs | 18 +++++++++++-- .../Validators/BlockValidator.cs | 5 ++++ src/Nethermind/Nethermind.Core/Block.cs | 1 + src/Nethermind/Nethermind.Core/BlockHeader.cs | 9 ++++++- .../Data/ExecutionPayloadV3.cs | 11 ++++++++ .../Data/IExecutionPayloadParams.cs | 25 ++++++++++++----- .../EngineRpcModule.Cancun.cs | 4 +-- .../IEngineRpcModule.Cancun.cs | 2 +- .../HeaderDecoder.cs | 27 +++++++++++++++---- .../Nethermind.State/IWorldState.cs | 2 ++ .../Nethermind.State/StateProvider.cs | 11 ++++++++ src/Nethermind/Nethermind.State/WorldState.cs | 10 +++++++ 13 files changed, 118 insertions(+), 18 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs index 7ff421dc73c..35003b91d0e 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs @@ -15,6 +15,7 @@ using Nethermind.Core.Specs; using Nethermind.Crypto; using Nethermind.Evm; +using Nethermind.Evm.Precompiles.Stateful; using Nethermind.Evm.Tracing; using Nethermind.Int256; using Nethermind.Logging; @@ -222,9 +223,19 @@ protected virtual TxReceipt[] ProcessBlock( { IReleaseSpec spec = _specProvider.GetSpec(block.Header); + if (spec.IsBeaconParentBlockRootAvailable) + { + _stateProvider.CreateAccountIfNotExists(BeaconBlockRootPrecompile.Address, 1); + } + _receiptsTracer.SetOtherTracer(blockTracer); _receiptsTracer.StartNewBlockTrace(block); + if (spec.IsBeaconParentBlockRootAvailable) + { + BeaconBlockRootPrecompile.SetupBeaconBlockRootPrecompileState(_stateProvider, block, block.ParentBeaconBlockRoot); + } + TxReceipt[] receipts = _blockTransactionsExecutor.ProcessTransactions(block, options, _receiptsTracer, spec); if (spec.IsEip4844Enabled) diff --git a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs index a2e78b2a2fd..211e33e58e6 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs @@ -25,6 +25,7 @@ public class PayloadAttributes public IList? Withdrawals { get; set; } + public Keccak? BeaconParentBlockRoot { get; set; } /// Gets or sets the gas limit. /// Used for MEV-Boost only. public long? GasLimit { get; set; } @@ -43,6 +44,11 @@ public string ToString(string indentation) sb.Append($", {nameof(Withdrawals)} count: {Withdrawals.Count}"); } + if(BeaconParentBlockRoot is not null) + { + sb.Append($", {nameof(BeaconParentBlockRoot)} : {BeaconParentBlockRoot}"); + } + sb.Append('}'); return sb.ToString(); @@ -54,7 +60,10 @@ public static class PayloadAttributesExtensions public static string ComputePayloadId(this PayloadAttributes payloadAttributes, BlockHeader parentHeader) { bool hasWithdrawals = payloadAttributes.Withdrawals is not null; - Span inputSpan = stackalloc byte[32 + 32 + 32 + 20 + (hasWithdrawals ? 32 : 0)]; + bool hasBeaconParentBlockRoot = payloadAttributes.BeaconParentBlockRoot is not null; + + const int preambleLength = 32 + 32 + 32 + 20; + Span inputSpan = stackalloc byte[preambleLength + (hasWithdrawals ? 32 : 0) + (hasBeaconParentBlockRoot ? 32 : 0)]; parentHeader.Hash!.Bytes.CopyTo(inputSpan[..32]); BinaryPrimitives.WriteUInt64BigEndian(inputSpan.Slice(56, 8), payloadAttributes.Timestamp); @@ -67,7 +76,12 @@ public static string ComputePayloadId(this PayloadAttributes payloadAttributes, ? PatriciaTree.EmptyTreeHash : new WithdrawalTrie(payloadAttributes.Withdrawals).RootHash; - withdrawalsRootHash.Bytes.CopyTo(inputSpan[116..]); + withdrawalsRootHash.Bytes.CopyTo(inputSpan[preambleLength..]); + } + + if (hasBeaconParentBlockRoot) + { + payloadAttributes.BeaconParentBlockRoot.Bytes.CopyTo(inputSpan[(preambleLength + (hasWithdrawals ? 32 : 0))..]); } ValueKeccak inputHash = ValueKeccak.Compute(inputSpan); diff --git a/src/Nethermind/Nethermind.Consensus/Validators/BlockValidator.cs b/src/Nethermind/Nethermind.Consensus/Validators/BlockValidator.cs index d79c42a4dd0..965bb2b4ed7 100644 --- a/src/Nethermind/Nethermind.Consensus/Validators/BlockValidator.cs +++ b/src/Nethermind/Nethermind.Consensus/Validators/BlockValidator.cs @@ -146,6 +146,11 @@ public bool ValidateProcessedBlock(Block processedBlock, TxReceipt[] receipts, B if (_logger.IsError) _logger.Error($"- excess data gas: expected {suggestedBlock.Header.ExcessDataGas}, got {processedBlock.Header.ExcessDataGas}"); } + if (processedBlock.Header.ParentBeaconBlockRoot != suggestedBlock.Header.ParentBeaconBlockRoot) + { + if (_logger.IsError) _logger.Error($"- parent beacon block root : expected {suggestedBlock.Header.ParentBeaconBlockRoot}, got {processedBlock.Header.ParentBeaconBlockRoot}"); + } + for (int i = 0; i < processedBlock.Transactions.Length; i++) { if (receipts[i].Error is not null && receipts[i].GasUsed == 0 && receipts[i].Error == "invalid") diff --git a/src/Nethermind/Nethermind.Core/Block.cs b/src/Nethermind/Nethermind.Core/Block.cs index 59e9ed916bb..6b88d6680d8 100644 --- a/src/Nethermind/Nethermind.Core/Block.cs +++ b/src/Nethermind/Nethermind.Core/Block.cs @@ -107,6 +107,7 @@ public Transaction[] Transactions public bool IsBodyMissing => Header.HasBody && Body.IsEmpty; public Keccak? WithdrawalsRoot => Header.WithdrawalsRoot; // do not add setter here + public Keccak? ParentBeaconBlockRoot => Header.ParentBeaconBlockRoot; // do not add setter here public override string ToString() => ToString(Format.Short); diff --git a/src/Nethermind/Nethermind.Core/BlockHeader.cs b/src/Nethermind/Nethermind.Core/BlockHeader.cs index d9fd16d2183..979ef436ad0 100644 --- a/src/Nethermind/Nethermind.Core/BlockHeader.cs +++ b/src/Nethermind/Nethermind.Core/BlockHeader.cs @@ -26,7 +26,8 @@ public BlockHeader( ulong timestamp, byte[] extraData, ulong? dataGasUsed = null, - ulong? excessDataGas = null) + ulong? excessDataGas = null, + Keccak? parentBeaconBlockRoot = null) { ParentHash = parentHash; UnclesHash = unclesHash; @@ -38,6 +39,7 @@ public BlockHeader( ExtraData = extraData; DataGasUsed = dataGasUsed; ExcessDataGas = excessDataGas; + ParentBeaconBlockRoot = parentBeaconBlockRoot; } public WeakReference? MaybeParent { get; set; } @@ -69,6 +71,7 @@ public BlockHeader( public Keccak? WithdrawalsRoot { get; set; } public ulong? DataGasUsed { get; set; } public ulong? ExcessDataGas { get; set; } + public Keccak? ParentBeaconBlockRoot { 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); @@ -101,6 +104,10 @@ public string ToString(string indent) { builder.AppendLine($"{indent}WithdrawalsRoot: {WithdrawalsRoot}"); } + if (ParentBeaconBlockRoot is not null) + { + builder.AppendLine($"{indent}ParentBeaconBlockRoot: {ParentBeaconBlockRoot}"); + } if (DataGasUsed is not null || ExcessDataGas is not null) { builder.AppendLine($"{indent}DataGasUsed: {DataGasUsed}"); diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs index 94f7170cd02..3bb2ff4bee7 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using Nethermind.Core; +using Nethermind.Core.Crypto; using Nethermind.Core.Specs; using Nethermind.Int256; using Newtonsoft.Json; @@ -21,6 +22,7 @@ public ExecutionPayloadV3(Block block) : base(block) { DataGasUsed = block.DataGasUsed; ExcessDataGas = block.ExcessDataGas; + ParentBeaconBlockRoot = block.ParentBeaconBlockRoot; } /// @@ -35,6 +37,14 @@ public ExecutionPayloadV3(Block block) : base(block) /// public ulong? ExcessDataGas { get; set; } + + /// + /// Gets or sets as defined in + /// EIP-4788. + /// + [JsonIgnore] + public Keccak? ParentBeaconBlockRoot { get; set; } = null; + public override bool TryGetBlock(out Block? block, UInt256? totalDifficulty = null) { if (!base.TryGetBlock(out block, totalDifficulty)) @@ -44,6 +54,7 @@ public override bool TryGetBlock(out Block? block, UInt256? totalDifficulty = nu block!.Header.DataGasUsed = DataGasUsed; block.Header.ExcessDataGas = ExcessDataGas; + block.Header.ParentBeaconBlockRoot = ParentBeaconBlockRoot; return true; } diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs index 51723767251..4da759bfbdb 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; +using Nethermind.Core.Crypto; using Nethermind.Core.Extensions; using Nethermind.Core.Specs; @@ -21,11 +22,13 @@ public class ExecutionPayloadV3Params : IExecutionPayloadParams { private readonly ExecutionPayloadV3 _executionPayload; private readonly byte[]?[] _blobVersionedHashes; - - public ExecutionPayloadV3Params(ExecutionPayloadV3 executionPayload, byte[]?[] blobVersionedHashes) + private readonly byte[]? _parentBeaconBlockRoot; + + public ExecutionPayloadV3Params(ExecutionPayloadV3 executionPayload, byte[]?[] blobVersionedHashes, byte[]? parentBeaconBlockRoot) { _executionPayload = executionPayload; _blobVersionedHashes = blobVersionedHashes; + _parentBeaconBlockRoot = parentBeaconBlockRoot; } public ExecutionPayload ExecutionPayload => _executionPayload; @@ -37,13 +40,21 @@ public ValidationResult ValidateParams(IReleaseSpec spec, int version, out strin .Where(t => t.BlobVersionedHashes is not null) .SelectMany(t => t.BlobVersionedHashes!); - if (FlattenHashesFromTransactions(_executionPayload).SequenceEqual(_blobVersionedHashes, Bytes.NullableEqualityComparer)) + if (!FlattenHashesFromTransactions(_executionPayload).SequenceEqual(_blobVersionedHashes, Bytes.NullableEqualityComparer)) { - error = null; - return ValidationResult.Success; + error = "Blob versioned hashes do not match"; + return ValidationResult.Invalid; } - error = "Blob versioned hashes do not match"; - return ValidationResult.Invalid; + if (_parentBeaconBlockRoot is null) + { + error = "Parent beacon block root must be set"; + return ValidationResult.Invalid; + } + + _executionPayload.ParentBeaconBlockRoot = new Keccak(_parentBeaconBlockRoot); + + error = null; + return ValidationResult.Success; } } diff --git a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs index 41aa57d7b61..02307d25209 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs @@ -16,8 +16,8 @@ public partial class EngineRpcModule : IEngineRpcModule { private readonly IAsyncHandler _getPayloadHandlerV3; - public Task> engine_newPayloadV3(ExecutionPayloadV3 executionPayload, byte[]?[] blobVersionedHashes) => - NewPayload(new ExecutionPayloadV3Params(executionPayload, blobVersionedHashes), 3); + public Task> engine_newPayloadV3(ExecutionPayloadV3 executionPayload, byte[]?[] blobVersionedHashes, byte[]? parentBeaconBlockRoot) => + NewPayload(new ExecutionPayloadV3Params(executionPayload, blobVersionedHashes, parentBeaconBlockRoot), 3); public async Task> engine_getPayloadV3(byte[] payloadId) => await _getPayloadHandlerV3.HandleAsync(payloadId); diff --git a/src/Nethermind/Nethermind.Merge.Plugin/IEngineRpcModule.Cancun.cs b/src/Nethermind/Nethermind.Merge.Plugin/IEngineRpcModule.Cancun.cs index f22b0bcb5f7..5b3520337cc 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/IEngineRpcModule.Cancun.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/IEngineRpcModule.Cancun.cs @@ -14,7 +14,7 @@ public partial interface IEngineRpcModule : IRpcModule 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_newPayloadV3(ExecutionPayloadV3 executionPayload, byte[]?[] blobVersionedHashes); + Task> engine_newPayloadV3(ExecutionPayloadV3 executionPayload, byte[]?[] blobVersionedHashes, byte[]? beaconParentBlockRoot); [JsonRpcMethod( Description = "Returns the most recent version of an execution payload and fees with respect to the transaction set contained by the mempool.", diff --git a/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs b/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs index 057e70c4c9b..c3978dc475c 100644 --- a/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs +++ b/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited +// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only using System; @@ -77,13 +77,19 @@ public class HeaderDecoder : IRlpValueDecoder, IRlpStreamDecoder= 3 && decoderContext.Position != headerCheck) { blockHeader.DataGasUsed = decoderContext.DecodeULong(allowLeadingZeroBytes: false); blockHeader.ExcessDataGas = decoderContext.DecodeULong(allowLeadingZeroBytes: false); } + + if (itemsRemaining >= 4 && decoderContext.Position != headerCheck) + { + blockHeader.ParentBeaconBlockRoot = decoderContext.DecodeKeccak(); + } } + if ((rlpBehaviors & RlpBehaviors.AllowExtraBytes) != RlpBehaviors.AllowExtraBytes) { decoderContext.Check(headerCheck); @@ -158,11 +164,16 @@ public class HeaderDecoder : IRlpValueDecoder, IRlpStreamDecoder= 3 && rlpStream.Position != headerCheck) { blockHeader.DataGasUsed = rlpStream.DecodeUlong(allowLeadingZeroBytes: false); blockHeader.ExcessDataGas = rlpStream.DecodeUlong(allowLeadingZeroBytes: false); } + + if (itemsRemaining >= 4 && rlpStream.Position != headerCheck) + { + blockHeader.ParentBeaconBlockRoot = rlpStream.DecodeKeccak(); + } } if ((rlpBehaviors & RlpBehaviors.AllowExtraBytes) != RlpBehaviors.AllowExtraBytes) @@ -227,6 +238,11 @@ public void Encode(RlpStream rlpStream, BlockHeader? header, RlpBehaviors rlpBeh rlpStream.Encode(header.DataGasUsed.GetValueOrDefault()); rlpStream.Encode(header.ExcessDataGas.GetValueOrDefault()); } + + if (header.ParentBeaconBlockRoot is not null) + { + rlpStream.Encode(header.ParentBeaconBlockRoot ?? Keccak.Zero); + } } public Rlp Encode(BlockHeader? item, RlpBehaviors rlpBehaviors = RlpBehaviors.None) @@ -265,9 +281,10 @@ private static int GetContentLength(BlockHeader? item, RlpBehaviors rlpBehaviors + Rlp.LengthOf(item.Timestamp) + Rlp.LengthOf(item.ExtraData) + (item.BaseFeePerGas.IsZero ? 0 : Rlp.LengthOf(item.BaseFeePerGas)) - + (item.WithdrawalsRoot is null && item.DataGasUsed is null && item.ExcessDataGas is null ? 0 : Rlp.LengthOfKeccakRlp) + + (item.WithdrawalsRoot is null && item.ExcessDataGas is null ? 0 : Rlp.LengthOfKeccakRlp) + (item.DataGasUsed is null ? 0 : Rlp.LengthOf(item.DataGasUsed.Value)) - + (item.ExcessDataGas is null ? 0 : Rlp.LengthOf(item.ExcessDataGas.Value)); + + (item.ExcessDataGas is null ? 0 : Rlp.LengthOf(item.ExcessDataGas.Value)) + + (item.ParentBeaconBlockRoot is null ? 0 : Rlp.LengthOfKeccakRlp); if (notForSealing) { diff --git a/src/Nethermind/Nethermind.State/IWorldState.cs b/src/Nethermind/Nethermind.State/IWorldState.cs index 50822e73e10..06081f3a398 100644 --- a/src/Nethermind/Nethermind.State/IWorldState.cs +++ b/src/Nethermind/Nethermind.State/IWorldState.cs @@ -81,8 +81,10 @@ public interface IWorldState : IJournal, IReadOnlyStateProvider void DeleteAccount(Address address); void CreateAccount(Address address, in UInt256 balance); + void CreateAccountIfNotExists(Address address, in UInt256 balance); void CreateAccount(Address address, in UInt256 balance, in UInt256 nonce); + void CreateAccountIfNotExists(Address address, in UInt256 balance, in UInt256 nonce); void InsertCode(Address address, ReadOnlyMemory code, IReleaseSpec spec, bool isGenesis = false); diff --git a/src/Nethermind/Nethermind.State/StateProvider.cs b/src/Nethermind/Nethermind.State/StateProvider.cs index b4e20f219ea..a49ef968f6d 100644 --- a/src/Nethermind/Nethermind.State/StateProvider.cs +++ b/src/Nethermind/Nethermind.State/StateProvider.cs @@ -415,6 +415,11 @@ public void CreateAccount(Address address, in UInt256 balance) PushNew(address, account); } + public void CreateAccountIfNotExists(Address address, in UInt256 balance) + { + if (AccountExists(address)) return; + CreateAccount(address, balance); + } public void CreateAccount(Address address, in UInt256 balance, in UInt256 nonce) { @@ -424,6 +429,12 @@ public void CreateAccount(Address address, in UInt256 balance, in UInt256 nonce) PushNew(address, account); } + public void CreateAccountIfNotExists(Address address, in UInt256 balance, in UInt256 nonce) + { + if (AccountExists(address)) return; + CreateAccount(address, balance, nonce); + } + public void AddToBalanceAndCreateIfNotExists(Address address, in UInt256 balance, IReleaseSpec spec) { if (AccountExists(address)) diff --git a/src/Nethermind/Nethermind.State/WorldState.cs b/src/Nethermind/Nethermind.State/WorldState.cs index da0db388b5d..53146c3bced 100644 --- a/src/Nethermind/Nethermind.State/WorldState.cs +++ b/src/Nethermind/Nethermind.State/WorldState.cs @@ -216,5 +216,15 @@ internal void SetNonce(Address address, in UInt256 nonce) { _stateProvider.SetNonce(address, nonce); } + + public void CreateAccountIfNotExists(Address address, in UInt256 balance) + { + _stateProvider.CreateAccountIfNotExists(address, balance); + } + + public void CreateAccountIfNotExists(Address address, in UInt256 balance, in UInt256 nonce) + { + _stateProvider.CreateAccountIfNotExists(address, balance, nonce); + } } } From 17a58e2f1b573d57aa4d42335b2c99916b7f155f Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Wed, 19 Jul 2023 16:14:55 +0100 Subject: [PATCH 04/43] - Tests update --- .../Builders/BlockBuilder.cs | 6 + .../BeaconParentBlockRootPrecompileTests.cs | 150 ++++++++++++++++++ .../EngineModuleTests.V3.cs | 6 +- .../OverridableReleaseSpec.cs | 1 + 4 files changed, 160 insertions(+), 3 deletions(-) create mode 100644 src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs diff --git a/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs b/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs index c26ac138b54..a0155609824 100644 --- a/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs +++ b/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs @@ -277,5 +277,11 @@ public BlockBuilder WithWithdrawals(params Withdrawal[]? withdrawals) return this; } + + public BlockBuilder WithParentBeaconBlockRoot(Keccak keccakG) + { + TestObjectInternal.Header.ParentBeaconBlockRoot = keccakG; + return this; + } } } diff --git a/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs new file mode 100644 index 00000000000..cec5044b635 --- /dev/null +++ b/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs @@ -0,0 +1,150 @@ +// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System.Collections.Generic; +using System.Linq; +using Nethermind.Blockchain.Receipts; +using Nethermind.Blockchain; +using Nethermind.Consensus.Processing; +using Nethermind.Consensus.Rewards; +using Nethermind.Consensus.Validators; +using Nethermind.Core; +using Nethermind.Core.Extensions; +using Nethermind.Core.Specs; +using Nethermind.Core.Test.Builders; +using Nethermind.Db.Blooms; +using Nethermind.Db; +using Nethermind.Evm.TransactionProcessing; +using Nethermind.Int256; +using Nethermind.Logging; +using Nethermind.Specs; +using Nethermind.Specs.Forks; +using Nethermind.State.Repositories; +using Nethermind.State; +using Nethermind.Trie.Pruning; +using NUnit.Framework; +using Nethermind.Core.Crypto; +using Nethermind.Evm.Tracing.GethStyle; + +namespace Nethermind.Evm.Test; + +public class Eip4788Tests +{ + private WorldState _testState; + private ISpecProvider specProvider; + private SenderRecipientAndMiner senderRecipientAndMiner = SenderRecipientAndMiner.Default; + protected static IEnumerable<(IReleaseSpec Spec, bool ShouldFail)> BeacondStateRootGetPayloadV3ForDifferentSpecTestSource() + { + yield return (Shanghai.Instance, true); + yield return (Cancun.Instance, false); + } + + [TestCaseSource(nameof(BeacondStateRootGetPayloadV3ForDifferentSpecTestSource))] + public void ParentBeaconBlockRoot_Is_Stored_Correctly_and_Only_Valid_PostCancun((IReleaseSpec Spec, bool ShouldFail) testCase) + { + specProvider = new TestSpecProvider(testCase.Spec); + DbProvider dbProvider = new(DbModeHint.Mem); + dbProvider.RegisterDb(DbNames.BlockInfos, new MemDb()); + dbProvider.RegisterDb(DbNames.Blocks, new MemDb()); + dbProvider.RegisterDb(DbNames.Headers, new MemDb()); + dbProvider.RegisterDb(DbNames.State, new MemDb()); + dbProvider.RegisterDb(DbNames.Code, new MemDb()); + dbProvider.RegisterDb(DbNames.Metadata, new MemDb()); + BlockTree blockTree = new( + dbProvider, + new ChainLevelInfoRepository(dbProvider), + specProvider, + NullBloomStorage.Instance, + LimboLogs.Instance); + TrieStore trieStore = new( + dbProvider.RegisteredDbs[DbNames.State], + NoPruning.Instance, + Archive.Instance, + LimboLogs.Instance); + _testState = new( + trieStore, + dbProvider.RegisteredDbs[DbNames.Code], + LimboLogs.Instance); + StateReader stateReader = new(trieStore, dbProvider.GetDb(DbNames.State), LimboLogs.Instance); + BlockhashProvider blockhashProvider = new(blockTree, LimboLogs.Instance); + + VirtualMachine virtualMachine = new( + blockhashProvider, + specProvider, + LimboLogs.Instance); + TransactionProcessor txProcessor = new( + specProvider, + _testState, + virtualMachine, + LimboLogs.Instance); + BlockProcessor blockProcessor = new( + specProvider, + Always.Valid, + NoBlockRewards.Instance, + new BlockProcessor.BlockValidationTransactionsExecutor(txProcessor, _testState), + _testState, + NullReceiptStorage.Instance, + NullWitnessCollector.Instance, + LimboLogs.Instance); + + + + GethLikeBlockTracer? tracer = new(GethTraceOptions.Default); + Block block = CreateBlock(); + Block[] blocks = blockProcessor.Process( + Keccak.EmptyTreeHash, + new List { block }, + ProcessingOptions.None, + tracer); + List? traces = tracer.BuildResult().ToList(); + Assert.Equals(traces[0].Failed, testCase.ShouldFail); + } + + Block CreateBlock() + { + if (!_testState.AccountExists(senderRecipientAndMiner.Sender)) + _testState.CreateAccount(senderRecipientAndMiner.Sender, 100.Ether()); + else + _testState.AddToBalance(senderRecipientAndMiner.Sender, 100.Ether(), specProvider.GenesisSpec); + + if (!_testState.AccountExists(senderRecipientAndMiner.Recipient)) + _testState.CreateAccount(senderRecipientAndMiner.Recipient, 100.Ether()); + else + _testState.AddToBalance(senderRecipientAndMiner.Recipient, 100.Ether(), specProvider.GenesisSpec); + + byte[] bytecode = Prepare + .EvmCode + .TIMESTAMP() + .MSTORE(0) + .CALL(100.GWei(), Address.FromNumber(0x0B), 0, 0, 32, 32, 32) + .MLOAD(32) + .EQ(new UInt256(TestItem.KeccakG.Bytes, true)) + .JUMPI(0x53) + .INVALID() + .JUMPDEST() + .STOP() + .Done; + + _testState.InsertCode(senderRecipientAndMiner.Recipient, bytecode, specProvider.GenesisSpec); + Transaction tx = Build.A.Transaction + .WithGasLimit(1_000_000) + .WithGasPrice(1) + .WithValue(1) + .WithData(bytecode) + .WithSenderAddress(senderRecipientAndMiner.Sender) + .WithNonce(_testState.GetNonce(senderRecipientAndMiner.Sender)) + .To(senderRecipientAndMiner.Recipient) + .TestObject; + + _testState.RecalculateStateRoot(); + Block block0 = + Build.A.Block.Genesis + .WithDifficulty(1) + .WithTotalDifficulty(1L) + .WithTransactions(tx) + .WithPostMergeFlag(true) + .WithParentBeaconBlockRoot(TestItem.KeccakG) + .TestObject; + return block0; + } +} diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs index 28e355fa24a..3b31be3a94c 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs @@ -67,7 +67,7 @@ public async Task NewPayloadV3_should_decline_pre_cancun_payloads() ExecutionPayloadV3 executionPayload = CreateBlockRequestV3( CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty()); - ResultWrapper errorCode = (await rpcModule.engine_newPayloadV3(executionPayload, new byte[0][])); + ResultWrapper errorCode = (await rpcModule.engine_newPayloadV3(executionPayload, new byte[0][], Keccak.Zero.BytesToArray())); Assert.That(errorCode.ErrorCode, Is.EqualTo(ErrorCodes.UnsupportedFork)); } @@ -281,7 +281,7 @@ public async Task NewPayloadV3_should_verify_blob_versioned_hashes_again ExecutionPayloadV3 executionPayload = CreateBlockRequestV3( CreateParentBlockRequestOnHead(blockchain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty(), 0, 0, transactions: transactions); - ResultWrapper result = await engineRpcModule.engine_newPayloadV3(executionPayload, blobVersionedHashes); + ResultWrapper result = await engineRpcModule.engine_newPayloadV3(executionPayload, blobVersionedHashes, Keccak.Zero.BytesToArray()); return result.Data.Status; } @@ -344,7 +344,7 @@ private async Task SendNewBlockV3(IEngineRpcModule rpc, MergeT { ExecutionPayloadV3 executionPayload = CreateBlockRequestV3( CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals, 0, 0); - ResultWrapper executePayloadResult = await rpc.engine_newPayloadV3(executionPayload, Array.Empty()); + ResultWrapper executePayloadResult = await rpc.engine_newPayloadV3(executionPayload, Array.Empty(), Keccak.Zero.BytesToArray()); executePayloadResult.Data.Status.Should().Be(PayloadStatus.Valid); diff --git a/src/Nethermind/Nethermind.Specs.Test/OverridableReleaseSpec.cs b/src/Nethermind/Nethermind.Specs.Test/OverridableReleaseSpec.cs index dbebe3749db..48d301178e6 100644 --- a/src/Nethermind/Nethermind.Specs.Test/OverridableReleaseSpec.cs +++ b/src/Nethermind/Nethermind.Specs.Test/OverridableReleaseSpec.cs @@ -155,5 +155,6 @@ public ulong Eip4844TransitionTimestamp public ulong WithdrawalTimestamp => _spec.WithdrawalTimestamp; public bool IsEip5656Enabled => _spec.IsEip5656Enabled; public bool IsEip6780Enabled => _spec.IsEip6780Enabled; + public bool IsEip4788Enabled => _spec.IsEip4788Enabled; } } From 927c006628fb77fe48cb05378010171ecc4019d3 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Wed, 19 Jul 2023 16:27:05 +0100 Subject: [PATCH 05/43] - Minor fixes, Missing migration code --- .../Nethermind.Consensus/Processing/BlockProcessor.cs | 1 + .../Nethermind.Consensus/Producers/BlockProducerBase.cs | 1 + src/Nethermind/Nethermind.Evm.Test/VirtualMachineTestsBase.cs | 1 + src/Nethermind/Nethermind.JsonRpc/Modules/Eth/BlockForRpc.cs | 4 ++++ 4 files changed, 7 insertions(+) diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs index 35003b91d0e..cf92a4a1c67 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs @@ -294,6 +294,7 @@ private Block PrepareBlockForProcessing(Block suggestedBlock) BaseFeePerGas = bh.BaseFeePerGas, WithdrawalsRoot = bh.WithdrawalsRoot, IsPostMerge = bh.IsPostMerge, + ParentBeaconBlockRoot = bh.ParentBeaconBlockRoot, }; return suggestedBlock.CreateCopy(headerForProcessing); diff --git a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs index d4e5accf15e..3472a76a298 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs @@ -292,6 +292,7 @@ protected virtual BlockHeader PrepareBlockHeader(BlockHeader parent, { Author = blockAuthor, MixHash = payloadAttributes?.PrevRandao, + ParentBeaconBlockRoot = payloadAttributes?.BeaconParentBlockRoot }; UInt256 difficulty = _difficultyCalculator.Calculate(header, parent); diff --git a/src/Nethermind/Nethermind.Evm.Test/VirtualMachineTestsBase.cs b/src/Nethermind/Nethermind.Evm.Test/VirtualMachineTestsBase.cs index 95c5cca1c54..28b7286c325 100644 --- a/src/Nethermind/Nethermind.Evm.Test/VirtualMachineTestsBase.cs +++ b/src/Nethermind/Nethermind.Evm.Test/VirtualMachineTestsBase.cs @@ -243,6 +243,7 @@ protected virtual Block BuildBlock(long blockNumber, SenderRecipientAndMiner sen .WithDataGasUsed(0) .WithExcessDataGas(0) .WithTimestamp(timestamp) + .WithParentBeaconBlockRoot(TestItem.KeccakG) .TestObject; } diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/BlockForRpc.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/BlockForRpc.cs index 6e9a82cf353..d4c8c0fee82 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/BlockForRpc.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/BlockForRpc.cs @@ -76,6 +76,7 @@ public BlockForRpc(Block block, bool includeFullTransactionData, ISpecProvider s Uncles = block.Uncles.Select(o => o.Hash); Withdrawals = block.Withdrawals; WithdrawalsRoot = block.Header.WithdrawalsRoot; + ParentBeackBlockRoot = block.ParentBeaconBlockRoot; } public Address Author { get; set; } @@ -130,4 +131,7 @@ public BlockForRpc(Block block, bool includeFullTransactionData, ISpecProvider s [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] public ulong? ExcessDataGas { get; set; } + + [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + public Keccak? ParentBeackBlockRoot { get; set; } } From 28edbd4721b379aa0f38187483b5100109b1c93b Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Wed, 19 Jul 2023 17:52:38 +0100 Subject: [PATCH 06/43] - Test improvements --- .../Processing/BlockProcessor.cs | 2 +- .../Blockchain/TestBlockchain.cs | 23 ++++++++++++++++++- .../Stateful/BeaconBlockRootPrecompile.cs | 3 +-- .../EngineModuleTests.HelperFunctions.cs | 11 +++++---- .../EngineModuleTests.V3.cs | 6 ++--- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs index cf92a4a1c67..66aed2b19a2 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs @@ -233,7 +233,7 @@ protected virtual TxReceipt[] ProcessBlock( if (spec.IsBeaconParentBlockRootAvailable) { - BeaconBlockRootPrecompile.SetupBeaconBlockRootPrecompileState(_stateProvider, block, block.ParentBeaconBlockRoot); + BeaconBlockRootPrecompile.SetupBeaconBlockRootPrecompileState(_stateProvider, block.ParentBeaconBlockRoot, block.Timestamp); } TxReceipt[] receipts = _blockTransactionsExecutor.ProcessTransactions(block, options, _receiptsTracer, spec); diff --git a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs index 59ab6390e1e..9ad6ade9800 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -24,6 +24,7 @@ using Nethermind.Db; using Nethermind.Db.Blooms; using Nethermind.Evm; +using Nethermind.Evm.Precompiles.Stateful; using Nethermind.Evm.TransactionProcessing; using Nethermind.Int256; using Nethermind.Logging; @@ -116,6 +117,12 @@ protected virtual async Task Build(ISpecProvider? specProvider = DbProvider = await CreateDbProvider(); TrieStore = new TrieStore(StateDb, LogManager); State = new WorldState(TrieStore, DbProvider.CodeDb, LogManager); + + if(specProvider.GenesisSpec.IsEip4788Enabled) + { + State.CreateAccount(BeaconBlockRootPrecompile.Address, 1); + } + State.CreateAccount(TestItem.AddressA, (initialValues ?? InitialValue)); State.CreateAccount(TestItem.AddressB, (initialValues ?? InitialValue)); State.CreateAccount(TestItem.AddressC, (initialValues ?? InitialValue)); @@ -292,18 +299,32 @@ protected virtual Block GetGenesisBlock() genesisBlockBuilder = GenesisBlockBuilder; } - genesisBlockBuilder.WithStateRoot(State.StateRoot); if (SealEngineType == Core.SealEngineType.AuRa) { genesisBlockBuilder.WithAura(0, new byte[65]); } + if(SpecProvider.GenesisSpec.IsEip4788Enabled) + { + genesisBlockBuilder.WithParentBeaconBlockRoot(TestItem.KeccakG); + } + if (SpecProvider.GenesisSpec.IsEip4844Enabled) { genesisBlockBuilder.WithDataGasUsed(0); genesisBlockBuilder.WithExcessDataGas(0); } + + if (SpecProvider.GenesisSpec.IsEip4788Enabled) + { + BeaconBlockRootPrecompile.SetupBeaconBlockRootPrecompileState(State, genesisBlockBuilder.TestObject.ParentBeaconBlockRoot, genesisBlockBuilder.TestObject.Timestamp); + State.Commit(SpecProvider.GenesisSpec); + State.CommitTree(0); + + State.RecalculateStateRoot(); + } + genesisBlockBuilder.WithStateRoot(State.StateRoot); return genesisBlockBuilder.TestObject; } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs index 75caa7eb7c5..c73a5055852 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs @@ -18,10 +18,9 @@ private byte[] SloadFromStorage(IWorldState state, in UInt256 index) StorageCell storageCell = new(Address, index); return state.Get(storageCell); } - public static void SetupBeaconBlockRootPrecompileState(IWorldState stateProvider, Block block, Keccak parentBeaconBlockRoot) + public static void SetupBeaconBlockRootPrecompileState(IWorldState stateProvider, Keccak parentBeaconBlockRoot, UInt256 timestamp) { if (parentBeaconBlockRoot is null) return; - UInt256 timestamp = block.Header.Timestamp; UInt256.Mod(timestamp, HISTORICAL_ROOTS_LENGTH, out UInt256 timestampReduced); UInt256 rootIndex = timestampReduced + HISTORICAL_ROOTS_LENGTH; diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs index 8f48a6e3d70..5532d5e2c2b 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs @@ -84,13 +84,13 @@ private ExecutionPayload CreateParentBlockRequestOnHead(IBlockTree blockTree) }; } - private static ExecutionPayload CreateBlockRequest(ExecutionPayload parent, Address miner, IList? withdrawals = null, Transaction[]? transactions = null) - => CreateBlockRequestInternal(parent, miner, withdrawals, transactions: transactions); + private static ExecutionPayload CreateBlockRequest(ExecutionPayload parent, Address miner, IList? withdrawals = null, Transaction[]? transactions = null, Keccak? beaconParentBlockRoot = null) + => CreateBlockRequestInternal(parent, miner, withdrawals, transactions: transactions, beaconParentBlockRoot: beaconParentBlockRoot); - private static ExecutionPayloadV3 CreateBlockRequestV3(ExecutionPayload parent, Address miner, IList? withdrawals = null, ulong? dataGasUsed = null, ulong? excessDataGas = null, Transaction[]? transactions = null) - => CreateBlockRequestInternal(parent, miner, withdrawals, dataGasUsed, excessDataGas, transactions: transactions); + private static ExecutionPayloadV3 CreateBlockRequestV3(ExecutionPayload parent, Address miner, IList? withdrawals = null, ulong? dataGasUsed = null, ulong? excessDataGas = null, Transaction[]? transactions = null, Keccak? beaconParentBlockRoot = null) + => CreateBlockRequestInternal(parent, miner, withdrawals, dataGasUsed, excessDataGas, transactions: transactions, beaconParentBlockRoot: beaconParentBlockRoot); - private static T CreateBlockRequestInternal(ExecutionPayload parent, Address miner, IList? withdrawals = null, ulong? dataGasUsed = null, ulong? excessDataGas = null, Transaction[]? transactions = null) where T : ExecutionPayload, new() + private static T CreateBlockRequestInternal(ExecutionPayload parent, Address miner, IList? withdrawals = null, ulong? dataGasUsed = null, ulong? excessDataGas = null, Transaction[]? transactions = null, Keccak? beaconParentBlockRoot = null) where T : ExecutionPayload, new() { T blockRequest = new() { @@ -110,6 +110,7 @@ private static ExecutionPayloadV3 CreateBlockRequestV3(ExecutionPayload parent, { blockRequestV3.DataGasUsed = dataGasUsed; blockRequestV3.ExcessDataGas = excessDataGas; + blockRequestV3.ParentBeaconBlockRoot = beaconParentBlockRoot; } blockRequest.SetTransactions(transactions ?? Array.Empty()); diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs index 3b31be3a94c..9f659f5a980 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs @@ -67,7 +67,7 @@ public async Task NewPayloadV3_should_decline_pre_cancun_payloads() ExecutionPayloadV3 executionPayload = CreateBlockRequestV3( CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty()); - ResultWrapper errorCode = (await rpcModule.engine_newPayloadV3(executionPayload, new byte[0][], Keccak.Zero.BytesToArray())); + ResultWrapper errorCode = (await rpcModule.engine_newPayloadV3(executionPayload, new byte[0][], executionPayload.ParentBeaconBlockRoot.BytesToArray())); Assert.That(errorCode.ErrorCode, Is.EqualTo(ErrorCodes.UnsupportedFork)); } @@ -343,8 +343,8 @@ public static IEnumerable BlobVersionedHashesDoNotMatchTestSource private async Task SendNewBlockV3(IEngineRpcModule rpc, MergeTestBlockchain chain, IList? withdrawals) { ExecutionPayloadV3 executionPayload = CreateBlockRequestV3( - CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals, 0, 0); - ResultWrapper executePayloadResult = await rpc.engine_newPayloadV3(executionPayload, Array.Empty(), Keccak.Zero.BytesToArray()); + CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals, 0, 0, beaconParentBlockRoot: TestItem.KeccakE); + ResultWrapper executePayloadResult = await rpc.engine_newPayloadV3(executionPayload, Array.Empty(), executionPayload.ParentBeaconBlockRoot.BytesToArray()); executePayloadResult.Data.Status.Should().Be(PayloadStatus.Valid); From b900af35b4f50bf015f618cf2af93117ffa9f3b8 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Wed, 19 Jul 2023 21:30:40 +0100 Subject: [PATCH 07/43] - Test progress, Cleanup --- .../Nethermind.JsonRpc/JsonRpcService.cs | 6 ++- .../EngineModuleTests.HelperFunctions.cs | 25 +++++++---- .../EngineModuleTests.Synchronization.cs | 42 +++++++++---------- .../EngineModuleTests.V1.cs | 41 +++++++++++------- .../EngineModuleTests.V2.cs | 6 +-- .../EngineModuleTests.V3.cs | 11 ++++- 6 files changed, 81 insertions(+), 50 deletions(-) diff --git a/src/Nethermind/Nethermind.JsonRpc/JsonRpcService.cs b/src/Nethermind/Nethermind.JsonRpc/JsonRpcService.cs index 3bed9ae8e00..00ce0332a7d 100644 --- a/src/Nethermind/Nethermind.JsonRpc/JsonRpcService.cs +++ b/src/Nethermind/Nethermind.JsonRpc/JsonRpcService.cs @@ -320,7 +320,11 @@ private void LogRequest(string methodName, string?[] providedParameters, Paramet } else { - executionParam = _serializer.Deserialize(new JsonTextReader(new StringReader($"\"{providedParameter}\"")), paramType); + var stringReader = providedParameter.StartsWith('\"') && providedParameter.EndsWith('\"') + ? new StringReader(providedParameter) + : new StringReader($"\"{providedParameter}\""); + var jsonTextReader = new JsonTextReader(stringReader); + executionParam = _serializer.Deserialize(jsonTextReader, paramType); } } diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs index 5532d5e2c2b..002f745fc9d 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs @@ -20,6 +20,8 @@ using Nethermind.Specs; using Nethermind.Specs.Forks; using Nethermind.State; +using Nethermind.Core.Specs; +using Nethermind.Evm.Precompiles.Stateful; namespace Nethermind.Merge.Plugin.Test { @@ -84,13 +86,13 @@ private ExecutionPayload CreateParentBlockRequestOnHead(IBlockTree blockTree) }; } - private static ExecutionPayload CreateBlockRequest(ExecutionPayload parent, Address miner, IList? withdrawals = null, Transaction[]? transactions = null, Keccak? beaconParentBlockRoot = null) - => CreateBlockRequestInternal(parent, miner, withdrawals, transactions: transactions, beaconParentBlockRoot: beaconParentBlockRoot); + private static ExecutionPayload CreateBlockRequest(IReleaseSpec spec, IWorldState state, ExecutionPayload parent, Address miner, IList? withdrawals = null, Transaction[]? transactions = null, Keccak? beaconParentBlockRoot = null) + => CreateBlockRequestInternal(spec, state, parent, miner, withdrawals, transactions: transactions, beaconParentBlockRoot: beaconParentBlockRoot); - private static ExecutionPayloadV3 CreateBlockRequestV3(ExecutionPayload parent, Address miner, IList? withdrawals = null, ulong? dataGasUsed = null, ulong? excessDataGas = null, Transaction[]? transactions = null, Keccak? beaconParentBlockRoot = null) - => CreateBlockRequestInternal(parent, miner, withdrawals, dataGasUsed, excessDataGas, transactions: transactions, beaconParentBlockRoot: beaconParentBlockRoot); + private static ExecutionPayloadV3 CreateBlockRequestV3(IReleaseSpec spec, IWorldState state, ExecutionPayload parent, Address miner, IList? withdrawals = null, ulong? dataGasUsed = null, ulong? excessDataGas = null, Transaction[]? transactions = null, Keccak? beaconParentBlockRoot = null) + => CreateBlockRequestInternal(spec, state, parent, miner, withdrawals, dataGasUsed, excessDataGas, transactions: transactions, beaconParentBlockRoot: beaconParentBlockRoot); - private static T CreateBlockRequestInternal(ExecutionPayload parent, Address miner, IList? withdrawals = null, ulong? dataGasUsed = null, ulong? excessDataGas = null, Transaction[]? transactions = null, Keccak? beaconParentBlockRoot = null) where T : ExecutionPayload, new() + private static T CreateBlockRequestInternal(IReleaseSpec spec, IWorldState state, ExecutionPayload parent, Address miner, IList? withdrawals = null, ulong? dataGasUsed = null, ulong? excessDataGas = null, Transaction[]? transactions = null, Keccak? beaconParentBlockRoot = null) where T : ExecutionPayload, new() { T blockRequest = new() { @@ -111,21 +113,30 @@ private static ExecutionPayloadV3 CreateBlockRequestV3(ExecutionPayload parent, blockRequestV3.DataGasUsed = dataGasUsed; blockRequestV3.ExcessDataGas = excessDataGas; blockRequestV3.ParentBeaconBlockRoot = beaconParentBlockRoot; + + BeaconBlockRootPrecompile.SetupBeaconBlockRootPrecompileState(state, blockRequestV3.ParentBeaconBlockRoot, blockRequestV3.Timestamp); + state.Commit(spec); + state.CommitTree(blockRequestV3.BlockNumber); + + state.RecalculateStateRoot(); + blockRequestV3.StateRoot = state.StateRoot; } + + blockRequest.SetTransactions(transactions ?? Array.Empty()); TryCalculateHash(blockRequest, out Keccak? hash); blockRequest.BlockHash = hash; return blockRequest; } - private static ExecutionPayload[] CreateBlockRequestBranch(ExecutionPayload parent, Address miner, int count) + private static ExecutionPayload[] CreateBlockRequestBranch(IReleaseSpec spec, IWorldState state, ExecutionPayload parent, Address miner, int count) { ExecutionPayload currentBlock = parent; ExecutionPayload[] blockRequests = new ExecutionPayload[count]; for (int i = 0; i < count; i++) { - currentBlock = CreateBlockRequest(currentBlock, miner); + currentBlock = CreateBlockRequest(spec, state, currentBlock, miner); blockRequests[i] = currentBlock; } diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Synchronization.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Synchronization.cs index 256557f1d8b..a97fbc04bbf 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Synchronization.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Synchronization.cs @@ -204,14 +204,14 @@ public async Task should_return_invalid_lvh_null_on_invalid_blocks_during_the_sy forkchoiceUpdatedResult.Data.PayloadStatus.Status.Should() .Be(nameof(PayloadStatusV1.Syncing).ToUpper()); - ExecutionPayload[] requests = CreateBlockRequestBranch(startingNewPayload, TestItem.AddressD, 1); + ExecutionPayload[] requests = CreateBlockRequestBranch(chain.SpecProvider.GenesisSpec, chain.State, startingNewPayload, TestItem.AddressD, 1); foreach (ExecutionPayload r in requests) { ResultWrapper payloadStatus = await rpc.engine_newPayloadV1(r); payloadStatus.Data.Status.Should().Be(nameof(PayloadStatusV1.Syncing).ToUpper()); } - ExecutionPayload[] invalidRequests = CreateBlockRequestBranch(requests[0], TestItem.AddressD, 1); + ExecutionPayload[] invalidRequests = CreateBlockRequestBranch(chain.SpecProvider.GenesisSpec, chain.State, requests[0], TestItem.AddressD, 1); foreach (ExecutionPayload r in invalidRequests) { r.TryGetBlock(out Block? newBlock); @@ -231,7 +231,7 @@ public async Task newPayloadV1_can_insert_blocks_from_cache_when_syncing() Keccak startingHead = chain.BlockTree.HeadHash; ExecutionPayload parentBlockRequest = new(Build.A.Block.WithNumber(2).TestObject); - ExecutionPayload[] requests = CreateBlockRequestBranch(parentBlockRequest, Address.Zero, 7); + ExecutionPayload[] requests = CreateBlockRequestBranch(chain.SpecProvider.GenesisSpec, chain.State, parentBlockRequest, Address.Zero, 7); ResultWrapper payloadStatus; foreach (ExecutionPayload r in requests) { @@ -295,7 +295,7 @@ public async Task first_new_payload_set_beacon_main_chain() await rpc.engine_forkchoiceUpdatedV1(forkchoiceStateV1); forkchoiceUpdatedResult.Data.PayloadStatus.Status.Should() .Be(nameof(PayloadStatusV1.Syncing).ToUpper()); - ExecutionPayload[] requests = CreateBlockRequestBranch(startingNewPayload, Address.Zero, 4); + ExecutionPayload[] requests = CreateBlockRequestBranch(chain.SpecProvider.GenesisSpec, chain.State, startingNewPayload, Address.Zero, 4); foreach (ExecutionPayload r in requests) { ResultWrapper payloadStatus = await rpc.engine_newPayloadV1(r); @@ -336,7 +336,7 @@ public async Task repeated_new_payloads_do_not_change_metadata() await rpc.engine_forkchoiceUpdatedV1(forkchoiceStateV1); forkchoiceUpdatedResult.Data.PayloadStatus.Status.Should() .Be(nameof(PayloadStatusV1.Syncing).ToUpper()); - ExecutionPayload[] requests = CreateBlockRequestBranch(startingNewPayload, Address.Zero, 4); + ExecutionPayload[] requests = CreateBlockRequestBranch(chain.SpecProvider.GenesisSpec, chain.State, startingNewPayload, Address.Zero, 4); foreach (ExecutionPayload r in requests) { ResultWrapper payloadStatus = await rpc.engine_newPayloadV1(r); @@ -494,7 +494,7 @@ public async Task second_new_payload_should_not_set_beacon_main_chain() await rpc.engine_forkchoiceUpdatedV1(forkchoiceStateV1); forkchoiceUpdatedResult.Data.PayloadStatus.Status.Should() .Be(nameof(PayloadStatusV1.Syncing).ToUpper()); - ExecutionPayload[] requests = CreateBlockRequestBranch(startingNewPayload, Address.Zero, 4); + ExecutionPayload[] requests = CreateBlockRequestBranch(chain.SpecProvider.GenesisSpec, chain.State, startingNewPayload, Address.Zero, 4); foreach (ExecutionPayload r in requests) { ResultWrapper payloadStatus = await rpc.engine_newPayloadV1(r); @@ -505,7 +505,7 @@ public async Task second_new_payload_should_not_set_beacon_main_chain() lvl!.BlockInfos[0].Metadata.Should().Be(BlockMetadata.BeaconBody | BlockMetadata.BeaconHeader | BlockMetadata.BeaconMainChain); } - ExecutionPayload[] secondNewPayloads = CreateBlockRequestBranch(startingNewPayload, TestItem.AddressD, 4); + ExecutionPayload[] secondNewPayloads = CreateBlockRequestBranch(chain.SpecProvider.GenesisSpec, chain.State, startingNewPayload, TestItem.AddressD, 4); foreach (ExecutionPayload r in secondNewPayloads) { ResultWrapper payloadStatus = await rpc.engine_newPayloadV1(r); @@ -551,13 +551,13 @@ public async Task should_reorg_during_the_sync(int initialChainPayloadsCount, in await rpc.engine_newPayloadV1(startingNewPayload); ForkchoiceStateV1 forkchoiceStateV1 = new(block.Hash!, startingHead, startingHead); await rpc.engine_forkchoiceUpdatedV1(forkchoiceStateV1); - ExecutionPayload[] initialBranchPayloads = CreateBlockRequestBranch(startingNewPayload, Address.Zero, initialChainPayloadsCount); + ExecutionPayload[] initialBranchPayloads = CreateBlockRequestBranch(chain.SpecProvider.GenesisSpec, chain.State, startingNewPayload, Address.Zero, initialChainPayloadsCount); foreach (ExecutionPayload r in initialBranchPayloads) { await rpc.engine_newPayloadV1(r); } - ExecutionPayload[] newBranchPayloads = CreateBlockRequestBranch(startingNewPayload, TestItem.AddressD, reorgedChainPayloadCount); + ExecutionPayload[] newBranchPayloads = CreateBlockRequestBranch(chain.SpecProvider.GenesisSpec, chain.State, startingNewPayload, TestItem.AddressD, reorgedChainPayloadCount); foreach (ExecutionPayload r in newBranchPayloads) { await rpc.engine_newPayloadV1(r); @@ -588,7 +588,7 @@ public async Task Blocks_from_cache_inserted_when_fast_headers_sync_finish_befor using MergeTestBlockchain chain = await CreateBlockchain(); Keccak startingHead = chain.BlockTree.HeadHash; IEngineRpcModule rpc = CreateEngineModule(chain); - ExecutionPayload[] requests = CreateBlockRequestBranch(new ExecutionPayload(chain.BlockTree.Head!), Address.Zero, 7); + ExecutionPayload[] requests = CreateBlockRequestBranch(chain.SpecProvider.GenesisSpec, chain.State, new ExecutionPayload(chain.BlockTree.Head!), Address.Zero, 7); ResultWrapper payloadStatus; for (int i = 4; i < requests.Length - 1; i++) @@ -640,13 +640,13 @@ public async Task Maintain_correct_pointers_for_beacon_sync_in_archive_sync() Block[] missingBlocks = new Block[gap]; for (int i = 0; i < gap; i++) { - headBlockRequest = CreateBlockRequest(headBlockRequest, Address.Zero); + headBlockRequest = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, headBlockRequest, Address.Zero); headBlockRequest.TryGetBlock(out Block? block); missingBlocks[i] = block!; } // setting up beacon pivot - ExecutionPayload pivotRequest = CreateBlockRequest(headBlockRequest, Address.Zero); + ExecutionPayload pivotRequest = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, headBlockRequest, Address.Zero); ResultWrapper payloadStatus = await rpc.engine_newPayloadV1(pivotRequest); payloadStatus.Data.Status.Should().Be(nameof(PayloadStatusV1.Syncing).ToUpper()); pivotRequest.TryGetBlock(out Block? pivotBlock); @@ -668,7 +668,7 @@ public async Task Maintain_correct_pointers_for_beacon_sync_in_archive_sync() forkchoiceUpdatedResult.Data.PayloadStatus.Status.Should() .Be(nameof(PayloadStatusV1.Syncing).ToUpper()); // trigger insertion of blocks in cache into block tree by adding new block - ExecutionPayload bestBeaconBlockRequest = CreateBlockRequest(pivotRequest, Address.Zero); + ExecutionPayload bestBeaconBlockRequest = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, pivotRequest, Address.Zero); payloadStatus = await rpc.engine_newPayloadV1(bestBeaconBlockRequest); payloadStatus.Data.Status.Should().Be(nameof(PayloadStatusV1.Syncing).ToUpper()); // simulate headers sync by inserting 3 headers from pivot backwards @@ -722,7 +722,7 @@ public async Task Maintain_correct_pointers_for_beacon_sync_in_archive_sync() await bestBlockProcessed.WaitAsync(); // beacon sync should be finished, eventually - bestBeaconBlockRequest = CreateBlockRequest(bestBeaconBlockRequest, Address.Zero); + bestBeaconBlockRequest = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, bestBeaconBlockRequest, Address.Zero); Assert.That( () => rpc.engine_newPayloadV1(bestBeaconBlockRequest).Result.Data.Status, Is.EqualTo(PayloadStatus.Valid).After(1000, 100) @@ -798,9 +798,9 @@ public async Task Maintain_correct_pointers_for_beacon_sync_in_fast_sync() // create block gap from fast sync pivot int gap = 7; ExecutionPayload[] requests = - CreateBlockRequestBranch(new ExecutionPayload(syncedBlockTree.Head!), Address.Zero, gap); + CreateBlockRequestBranch(chain.SpecProvider.GenesisSpec, chain.State, new ExecutionPayload(syncedBlockTree.Head!), Address.Zero, gap); // setting up beacon pivot - ExecutionPayload pivotRequest = CreateBlockRequest(requests[^1], Address.Zero); + ExecutionPayload pivotRequest = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, requests[^1], Address.Zero); ResultWrapper payloadStatus = await rpc.engine_newPayloadV1(pivotRequest); payloadStatus.Data.Status.Should().Be(nameof(PayloadStatusV1.Syncing).ToUpper()); pivotRequest.TryGetBlock(out Block? pivotBlock); @@ -823,7 +823,7 @@ public async Task Maintain_correct_pointers_for_beacon_sync_in_fast_sync() forkchoiceUpdatedResult.Data.PayloadStatus.Status.Should() .Be(nameof(PayloadStatusV1.Syncing).ToUpper()); // trigger insertion of blocks in cache into block tree by adding new block - ExecutionPayload bestBeaconBlockRequest = CreateBlockRequest(pivotRequest, Address.Zero); + ExecutionPayload bestBeaconBlockRequest = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, pivotRequest, Address.Zero); payloadStatus = await rpc.engine_newPayloadV1(bestBeaconBlockRequest); payloadStatus.Data.Status.Should().Be(nameof(PayloadStatusV1.Syncing).ToUpper()); // fill in beacon headers until fast headers pivot @@ -857,12 +857,12 @@ public async Task Invalid_block_can_create_invalid_best_state_issue_but_recalcul chain.BlockTree.HeadHash.Should().Be(lastHash); // send newPayload - ExecutionPayload validBlockOnTopOfHead = CreateBlockRequest(CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); + ExecutionPayload validBlockOnTopOfHead = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); PayloadStatusV1 payloadStatusResponse = (await rpc.engine_newPayloadV1(validBlockOnTopOfHead)).Data; payloadStatusResponse.Status.Should().Be(PayloadStatus.Valid); // send block with invalid state root - ExecutionPayload blockWithInvalidStateRoot = CreateBlockRequest(validBlockOnTopOfHead, TestItem.AddressA); + ExecutionPayload blockWithInvalidStateRoot = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, validBlockOnTopOfHead, TestItem.AddressA); blockWithInvalidStateRoot.StateRoot = TestItem.KeccakB; TryCalculateHash(blockWithInvalidStateRoot, out Keccak? hash); blockWithInvalidStateRoot.BlockHash = hash; @@ -894,12 +894,12 @@ public async Task MultiSyncModeSelector_should_fix_block_tree_levels_if_needed() chain.BlockTree.HeadHash.Should().Be(lastHash); // send newPayload - ExecutionPayload validBlockOnTopOfHead = CreateBlockRequest(CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); + ExecutionPayload validBlockOnTopOfHead = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); PayloadStatusV1 payloadStatusResponse = (await rpc.engine_newPayloadV1(validBlockOnTopOfHead)).Data; payloadStatusResponse.Status.Should().Be(PayloadStatus.Valid); // send block with invalid state root - ExecutionPayload blockWithInvalidStateRoot = CreateBlockRequest(validBlockOnTopOfHead, TestItem.AddressA); + ExecutionPayload blockWithInvalidStateRoot = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, validBlockOnTopOfHead, TestItem.AddressA); blockWithInvalidStateRoot.StateRoot = TestItem.KeccakB; TryCalculateHash(blockWithInvalidStateRoot, out Keccak? hash); blockWithInvalidStateRoot.BlockHash = hash; diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs index 2138c922482..83f78dedffe 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs @@ -450,7 +450,7 @@ public async Task executePayloadV1_result_is_fail_when_blockchainprocessor_repor ((TestBlockProcessorInterceptor)chain.BlockProcessor).ExceptionToThrow = new Exception("unxpected exception"); - ExecutionPayload executionPayload = CreateBlockRequest(CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); + ExecutionPayload executionPayload = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); ResultWrapper resultWrapper = await rpc.engine_newPayloadV1(executionPayload); resultWrapper.Result.ResultType.Should().Be(ResultType.Failure); } @@ -786,7 +786,7 @@ public async Task executePayloadV1_should_not_accept_blocks_with_incorrect_ttd(l TerminalTotalDifficulty = $"{terminalTotalDifficulty}" }); IEngineRpcModule rpc = CreateEngineModule(chain); - ExecutionPayload executionPayload = CreateBlockRequest(CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); + ExecutionPayload executionPayload = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); ResultWrapper resultWrapper = await rpc.engine_newPayloadV1(executionPayload); resultWrapper.Data.Status.Should().Be(PayloadStatus.Invalid); resultWrapper.Data.LatestValidHash.Should().Be(Keccak.Zero); @@ -903,7 +903,7 @@ public async Task executePayloadV1_accepts_first_block() { using MergeTestBlockchain chain = await CreateBlockchain(); IEngineRpcModule rpc = CreateEngineModule(chain); - ExecutionPayload executionPayload = CreateBlockRequest(CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); + ExecutionPayload executionPayload = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); ResultWrapper resultWrapper = await rpc.engine_newPayloadV1(executionPayload); resultWrapper.Data.Status.Should().Be(PayloadStatus.Valid); new ExecutionPayload(chain.BlockTree.BestSuggestedBody!).Should().BeEquivalentTo(executionPayload); @@ -915,6 +915,7 @@ public async Task executePayloadV1_calculate_hash_for_cached_blocks() using MergeTestBlockchain chain = await CreateBlockchain(); IEngineRpcModule rpc = CreateEngineModule(chain); ExecutionPayload executionPayload = CreateBlockRequest( + chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); ResultWrapper resultWrapper = await rpc.engine_newPayloadV1(executionPayload); @@ -1000,7 +1001,7 @@ public async Task newPayloadV1_should_return_accepted_for_side_branch() { using MergeTestBlockchain chain = await CreateBlockchain(); IEngineRpcModule rpc = CreateEngineModule(chain); - ExecutionPayload executionPayload = CreateBlockRequest(CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); + ExecutionPayload executionPayload = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); ResultWrapper resultWrapper = await rpc.engine_newPayloadV1(executionPayload); resultWrapper.Data.Status.Should().Be(PayloadStatus.Valid); ForkchoiceStateV1 forkChoiceUpdatedRequest = new(executionPayload.BlockHash, executionPayload.BlockHash, executionPayload.BlockHash); @@ -1025,7 +1026,7 @@ public async Task executePayloadV1_processes_passed_transactions(bool moveHead) foreach (ExecutionPayload block in branch) { uint count = 10; - ExecutionPayload executePayloadRequest = CreateBlockRequest(block, TestItem.AddressA); + ExecutionPayload executePayloadRequest = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, block, TestItem.AddressA); PrivateKey from = TestItem.PrivateKeyB; Address to = TestItem.AddressD; (_, UInt256 toBalanceAfter) = AddTransactions(chain, executePayloadRequest, from, to, count, 1, out BlockHeader? parentHeader); @@ -1062,7 +1063,7 @@ public async Task executePayloadV1_transactions_produce_receipts() foreach (ExecutionPayload block in branch) { uint count = 10; - ExecutionPayload executionPayload = CreateBlockRequest(block, TestItem.AddressA); + ExecutionPayload executionPayload = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, block, TestItem.AddressA); PrivateKey from = TestItem.PrivateKeyB; Address to = TestItem.AddressD; (_, UInt256 toBalanceAfter) = AddTransactions(chain, executionPayload, from, to, count, 1, out BlockHeader parentHeader); @@ -1215,6 +1216,7 @@ public async Task exchangeTransitionConfiguration_return_with_empty_Nethermind_c private async Task SendNewBlockV1(IEngineRpcModule rpc, MergeTestBlockchain chain) { ExecutionPayload executionPayload = CreateBlockRequest( + chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); ResultWrapper executePayloadResult = @@ -1262,6 +1264,7 @@ public async Task repeat_the_same_payload_after_fcu_should_return_valid_and_be_i // Correct new payload ExecutionPayload executionPayloadV11 = CreateBlockRequest( + chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressA); ResultWrapper newPayloadResult1 = await rpc.engine_newPayloadV1(executionPayloadV11); @@ -1289,6 +1292,7 @@ public async Task payloadV1_invalid_parent_hash() // Correct new payload ExecutionPayload executionPayloadV11 = CreateBlockRequest( + chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressA); ResultWrapper newPayloadResult1 = await rpc.engine_newPayloadV1(executionPayloadV11); @@ -1301,7 +1305,7 @@ public async Task payloadV1_invalid_parent_hash() forkchoiceUpdatedResult1.Data.PayloadStatus.Status.Should().Be(PayloadStatus.Valid); // New payload unknown parent hash - ExecutionPayload executionPayloadV12A = CreateBlockRequest(executionPayloadV11, TestItem.AddressA); + ExecutionPayload executionPayloadV12A = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, executionPayloadV11, TestItem.AddressA); executionPayloadV12A.ParentHash = TestItem.KeccakB; TryCalculateHash(executionPayloadV12A, out Keccak? hash); executionPayloadV12A.BlockHash = hash; @@ -1316,7 +1320,7 @@ public async Task payloadV1_invalid_parent_hash() forkchoiceUpdatedResult2A.Data.PayloadStatus.Status.Should().Be(PayloadStatus.Syncing); // New payload with correct parent hash - ExecutionPayload executionPayloadV12B = CreateBlockRequest(executionPayloadV11, TestItem.AddressA); + ExecutionPayload executionPayloadV12B = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, executionPayloadV11, TestItem.AddressA); ResultWrapper newPayloadResult2B = await rpc.engine_newPayloadV1(executionPayloadV12B); newPayloadResult2B.Data.Status.Should().Be(PayloadStatus.Valid); @@ -1327,7 +1331,7 @@ public async Task payloadV1_invalid_parent_hash() forkchoiceUpdatedResult2B.Data.PayloadStatus.Status.Should().Be(PayloadStatus.Valid); // New payload unknown parent hash - ExecutionPayload executionPayloadV13A = CreateBlockRequest(executionPayloadV12A, TestItem.AddressA); + ExecutionPayload executionPayloadV13A = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, executionPayloadV12A, TestItem.AddressA); ResultWrapper newPayloadResult3A = await rpc.engine_newPayloadV1(executionPayloadV13A); newPayloadResult3A.Data.Status.Should().Be(PayloadStatus.Syncing); @@ -1338,7 +1342,7 @@ public async Task payloadV1_invalid_parent_hash() ResultWrapper forkchoiceUpdatedResult3A = await rpc.engine_forkchoiceUpdatedV1(forkChoiceState3A); forkchoiceUpdatedResult3A.Data.PayloadStatus.Status.Should().Be(PayloadStatus.Syncing); - ExecutionPayload executionPayloadV13B = CreateBlockRequest(executionPayloadV12B, TestItem.AddressA); + ExecutionPayload executionPayloadV13B = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, executionPayloadV12B, TestItem.AddressA); ResultWrapper newPayloadResult3B = await rpc.engine_newPayloadV1(executionPayloadV13B); newPayloadResult3B.Data.Status.Should().Be(PayloadStatus.Valid); @@ -1357,6 +1361,7 @@ public async Task inconsistent_finalized_hash() IEngineRpcModule rpc = CreateEngineModule(chain); ExecutionPayload blockRequestResult1 = CreateBlockRequest( + chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressA); ResultWrapper newPayloadResult1 = await rpc.engine_newPayloadV1(blockRequestResult1); @@ -1367,15 +1372,15 @@ public async Task inconsistent_finalized_hash() ResultWrapper forkchoiceUpdatedResult1 = await rpc.engine_forkchoiceUpdatedV1(forkChoiceState1); forkchoiceUpdatedResult1.Data.PayloadStatus.Status.Should().Be(PayloadStatus.Valid); - ExecutionPayload blockRequestResult2A = CreateBlockRequest(blockRequestResult1, TestItem.AddressB); + ExecutionPayload blockRequestResult2A = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, blockRequestResult1, TestItem.AddressB); ResultWrapper newPayloadResult2A = await rpc.engine_newPayloadV1(blockRequestResult2A); newPayloadResult2A.Data.Status.Should().Be(PayloadStatus.Valid); - ExecutionPayload blockRequestResult2B = CreateBlockRequest(blockRequestResult1, TestItem.AddressA); + ExecutionPayload blockRequestResult2B = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, blockRequestResult1, TestItem.AddressA); ResultWrapper newPayloadResult2B = await rpc.engine_newPayloadV1(blockRequestResult2B); newPayloadResult2B.Data.Status.Should().Be(PayloadStatus.Valid); - ExecutionPayload blockRequestResult3B = CreateBlockRequest(blockRequestResult2B, TestItem.AddressA); + ExecutionPayload blockRequestResult3B = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, blockRequestResult2B, TestItem.AddressA); ResultWrapper newPayloadResult3B = await rpc.engine_newPayloadV1(blockRequestResult3B); newPayloadResult3B.Data.Status.Should().Be(PayloadStatus.Valid); @@ -1393,6 +1398,7 @@ public async Task inconsistent_safe_hash() IEngineRpcModule rpc = CreateEngineModule(chain); ExecutionPayload blockRequestResult1 = CreateBlockRequest( + chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressA); ResultWrapper newPayloadResult1 = await rpc.engine_newPayloadV1(blockRequestResult1); @@ -1403,15 +1409,15 @@ public async Task inconsistent_safe_hash() ResultWrapper forkchoiceUpdatedResult1 = await rpc.engine_forkchoiceUpdatedV1(forkChoiceState1); forkchoiceUpdatedResult1.Data.PayloadStatus.Status.Should().Be(PayloadStatus.Valid); - ExecutionPayload blockRequestResult2A = CreateBlockRequest(blockRequestResult1, TestItem.AddressB); + ExecutionPayload blockRequestResult2A = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, blockRequestResult1, TestItem.AddressB); ResultWrapper newPayloadResult2A = await rpc.engine_newPayloadV1(blockRequestResult2A); newPayloadResult2A.Data.Status.Should().Be(PayloadStatus.Valid); - ExecutionPayload blockRequestResult2B = CreateBlockRequest(blockRequestResult1, TestItem.AddressA); + ExecutionPayload blockRequestResult2B = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, blockRequestResult1, TestItem.AddressA); ResultWrapper newPayloadResult2B = await rpc.engine_newPayloadV1(blockRequestResult2B); newPayloadResult2B.Data.Status.Should().Be(PayloadStatus.Valid); - ExecutionPayload blockRequestResult3B = CreateBlockRequest(blockRequestResult2B, TestItem.AddressA); + ExecutionPayload blockRequestResult3B = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, blockRequestResult2B, TestItem.AddressA); ResultWrapper newPayloadResult3B = await rpc.engine_newPayloadV1(blockRequestResult3B); newPayloadResult3B.Data.Status.Should().Be(PayloadStatus.Valid); @@ -1449,6 +1455,7 @@ await rpc.engine_forkchoiceUpdatedV1(forkChoiceStateGen, // Add one block ExecutionPayload executionPayloadV11 = CreateBlockRequest( + chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressA); executionPayloadV11.PrevRandao = prevRandao1; @@ -1474,6 +1481,7 @@ await rpc.engine_forkchoiceUpdatedV1(forkChoiceState1, { ExecutionPayload executionPayloadV12 = CreateBlockRequest( + chain.SpecProvider.GenesisSpec, chain.State, executionPayloadV11, TestItem.AddressA); @@ -1498,6 +1506,7 @@ await rpc.engine_forkchoiceUpdatedV1(forkChoiceState1, // re-org { ExecutionPayload executionPayloadV13 = CreateBlockRequest( + chain.SpecProvider.GenesisSpec, chain.State, executionPayloadV11, TestItem.AddressA); diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V2.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V2.cs index 92081e7ef40..f2b2640b13a 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V2.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V2.cs @@ -638,7 +638,7 @@ public async Task executePayloadV2_works_correctly_when_0_withdrawals_applied(( { using MergeTestBlockchain chain = await CreateBlockchain(input.ReleaseSpec); IEngineRpcModule rpc = CreateEngineModule(chain); - ExecutionPayload executionPayload = CreateBlockRequest(CreateParentBlockRequestOnHead(chain.BlockTree), + ExecutionPayload executionPayload = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, input.Withdrawals); ResultWrapper resultWrapper = await rpc.engine_newPayloadV2(executionPayload); @@ -707,7 +707,7 @@ public virtual async Task Should_handle_withdrawals_transition_when_Shanghai_for // Block without withdrawals, Timestamp = 2 ExecutionPayload executionPayload = - CreateBlockRequest(CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); + CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD); ResultWrapper resultWrapper = await rpc.engine_newPayloadV2(executionPayload); resultWrapper.Data.Status.Should().Be(PayloadStatus.Valid); @@ -873,7 +873,7 @@ private async Task BuildAndSendNewBlockV2( private async Task SendNewBlockV2(IEngineRpcModule rpc, MergeTestBlockchain chain, IList? withdrawals) { - ExecutionPayload executionPayload = CreateBlockRequest( + ExecutionPayload executionPayload = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals); ResultWrapper executePayloadResult = await rpc.engine_newPayloadV2(executionPayload); diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs index 9f659f5a980..712db89494b 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs @@ -39,6 +39,7 @@ public async Task NewPayloadV1_should_decline_post_cancun() MergeTestBlockchain chain = await CreateBlockchain(releaseSpec: Cancun.Instance); IEngineRpcModule rpcModule = CreateEngineModule(chain); ExecutionPayload executionPayload = CreateBlockRequest( + chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty()); ResultWrapper errorCode = (await rpcModule.engine_newPayloadV1(executionPayload)); @@ -52,6 +53,7 @@ public async Task NewPayloadV2_should_decline_post_cancun() MergeTestBlockchain chain = await CreateBlockchain(releaseSpec: Cancun.Instance); IEngineRpcModule rpcModule = CreateEngineModule(chain); ExecutionPayload executionPayload = CreateBlockRequest( + chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty()); ResultWrapper errorCode = (await rpcModule.engine_newPayloadV2(executionPayload)); @@ -65,6 +67,7 @@ public async Task NewPayloadV3_should_decline_pre_cancun_payloads() MergeTestBlockchain chain = await CreateBlockchain(releaseSpec: Shanghai.Instance); IEngineRpcModule rpcModule = CreateEngineModule(chain); ExecutionPayloadV3 executionPayload = CreateBlockRequestV3( + chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty()); ResultWrapper errorCode = (await rpcModule.engine_newPayloadV3(executionPayload, new byte[0][], executionPayload.ParentBeaconBlockRoot.BytesToArray())); @@ -149,7 +152,8 @@ public async Task NewPayloadV3_should_decline_null_blobversionedhashes() moduleProvider.Register(new SingletonModulePool(new SingletonFactory(rpcModule), true)); ExecutionPayloadV3 executionPayload = CreateBlockRequestV3( - CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty(), dataGasUsed: 0, excessDataGas: 0); + chain.SpecProvider.GenesisSpec, chain.State, + CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty(), dataGasUsed: 0, excessDataGas: 0); return (new(moduleProvider, LimboLogs.Instance, jsonRpcConfig), new(RpcEndpoint.Http), new(), executionPayload); } @@ -162,11 +166,12 @@ public async Task NewPayloadV3_should_decline_empty_fields() string executionPayloadString = serializer.Serialize(executionPayload); string blobsString = serializer.Serialize(Array.Empty()); + string parentBeaconBlockRootString = serializer.Serialize(TestItem.KeccakA.BytesToArray()); { JObject executionPayloadAsJObject = serializer.Deserialize(executionPayloadString); JsonRpcRequest request = RpcTest.GetJsonRequest(nameof(IEngineRpcModule.engine_newPayloadV3), - serializer.Serialize(executionPayloadAsJObject), blobsString); + serializer.Serialize(executionPayloadAsJObject), blobsString, parentBeaconBlockRootString); JsonRpcResponse response = await jsonRpcService.SendRequestAsync(request, context); Assert.That(response is JsonRpcSuccessResponse); } @@ -280,6 +285,7 @@ public async Task NewPayloadV3_should_verify_blob_versioned_hashes_again (byte[][] blobVersionedHashes, Transaction[] transactions) = BuildTransactionsAndBlobVersionedHashesList(hashesFirstBytes, transactionsAndFirstBytesOfTheirHashes, blockchain.SpecProvider.ChainId); ExecutionPayloadV3 executionPayload = CreateBlockRequestV3( + blockchain.SpecProvider.GenesisSpec, blockchain.State, CreateParentBlockRequestOnHead(blockchain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty(), 0, 0, transactions: transactions); ResultWrapper result = await engineRpcModule.engine_newPayloadV3(executionPayload, blobVersionedHashes, Keccak.Zero.BytesToArray()); @@ -343,6 +349,7 @@ public static IEnumerable BlobVersionedHashesDoNotMatchTestSource private async Task SendNewBlockV3(IEngineRpcModule rpc, MergeTestBlockchain chain, IList? withdrawals) { ExecutionPayloadV3 executionPayload = CreateBlockRequestV3( + chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals, 0, 0, beaconParentBlockRoot: TestItem.KeccakE); ResultWrapper executePayloadResult = await rpc.engine_newPayloadV3(executionPayload, Array.Empty(), executionPayload.ParentBeaconBlockRoot.BytesToArray()); From a4e316f3d0733969457d231402f8b3aebf435f4f Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Wed, 19 Jul 2023 21:54:15 +0100 Subject: [PATCH 08/43] - More tests fixes --- .../Nethermind.Core.Test/Blockchain/TestBlockchain.cs | 6 ++---- .../BeaconParentBlockRootPrecompileTests.cs | 2 +- .../Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs index 9ad6ade9800..9ac27353dde 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -118,10 +118,8 @@ protected virtual async Task Build(ISpecProvider? specProvider = TrieStore = new TrieStore(StateDb, LogManager); State = new WorldState(TrieStore, DbProvider.CodeDb, LogManager); - if(specProvider.GenesisSpec.IsEip4788Enabled) - { - State.CreateAccount(BeaconBlockRootPrecompile.Address, 1); - } + // Eip4788 precompile state account + State.CreateAccount(BeaconBlockRootPrecompile.Address, 1); State.CreateAccount(TestItem.AddressA, (initialValues ?? InitialValue)); State.CreateAccount(TestItem.AddressB, (initialValues ?? InitialValue)); diff --git a/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs index cec5044b635..a6bfa409c98 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs @@ -97,7 +97,7 @@ public void ParentBeaconBlockRoot_Is_Stored_Correctly_and_Only_Valid_PostCancun( ProcessingOptions.None, tracer); List? traces = tracer.BuildResult().ToList(); - Assert.Equals(traces[0].Failed, testCase.ShouldFail); + Assert.That(testCase.ShouldFail, Is.EqualTo(traces[0].Failed)); } Block CreateBlock() diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs index 712db89494b..18fa5da1db5 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs @@ -70,7 +70,7 @@ public async Task NewPayloadV3_should_decline_pre_cancun_payloads() chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty()); - ResultWrapper errorCode = (await rpcModule.engine_newPayloadV3(executionPayload, new byte[0][], executionPayload.ParentBeaconBlockRoot.BytesToArray())); + ResultWrapper errorCode = (await rpcModule.engine_newPayloadV3(executionPayload, new byte[0][], executionPayload.ParentBeaconBlockRoot?.BytesToArray())); Assert.That(errorCode.ErrorCode, Is.EqualTo(ErrorCodes.UnsupportedFork)); } From c911bd6c24717fbc23ac24eff3d49a487f15f850 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Wed, 19 Jul 2023 21:56:19 +0100 Subject: [PATCH 09/43] - Whitespace fixes --- .../Nethermind.Consensus/Producers/PayloadAttributes.cs | 2 +- .../Nethermind.Core.Test/Blockchain/TestBlockchain.cs | 2 +- .../Nethermind.Merge.Plugin.Test/EngineModuleTests.V2.cs | 2 +- .../Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs index 211e33e58e6..e02f6ccc4d0 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs @@ -44,7 +44,7 @@ public string ToString(string indentation) sb.Append($", {nameof(Withdrawals)} count: {Withdrawals.Count}"); } - if(BeaconParentBlockRoot is not null) + if (BeaconParentBlockRoot is not null) { sb.Append($", {nameof(BeaconParentBlockRoot)} : {BeaconParentBlockRoot}"); } diff --git a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs index 9ac27353dde..83649ac8b90 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -302,7 +302,7 @@ protected virtual Block GetGenesisBlock() genesisBlockBuilder.WithAura(0, new byte[65]); } - if(SpecProvider.GenesisSpec.IsEip4788Enabled) + if (SpecProvider.GenesisSpec.IsEip4788Enabled) { genesisBlockBuilder.WithParentBeaconBlockRoot(TestItem.KeccakG); } diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V2.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V2.cs index f2b2640b13a..a7fe7c17dd7 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V2.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V2.cs @@ -873,7 +873,7 @@ private async Task BuildAndSendNewBlockV2( private async Task SendNewBlockV2(IEngineRpcModule rpc, MergeTestBlockchain chain, IList? withdrawals) { - ExecutionPayload executionPayload = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, + ExecutionPayload executionPayload = CreateBlockRequest(chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals); ResultWrapper executePayloadResult = await rpc.engine_newPayloadV2(executionPayload); diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs index 4da759bfbdb..a6ba369f958 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs @@ -23,7 +23,7 @@ public class ExecutionPayloadV3Params : IExecutionPayloadParams private readonly ExecutionPayloadV3 _executionPayload; private readonly byte[]?[] _blobVersionedHashes; private readonly byte[]? _parentBeaconBlockRoot; - + public ExecutionPayloadV3Params(ExecutionPayloadV3 executionPayload, byte[]?[] blobVersionedHashes, byte[]? parentBeaconBlockRoot) { _executionPayload = executionPayload; From 73f9d08344f838f345faff084bd563fbdc3df0e4 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Thu, 20 Jul 2023 00:29:23 +0100 Subject: [PATCH 10/43] - Attempt fix failing JsonRpc.Tests --- .../Nethermind.Core.Test/Blockchain/TestBlockchain.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs index 83649ac8b90..a12f90b4483 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -119,7 +119,10 @@ protected virtual async Task Build(ISpecProvider? specProvider = State = new WorldState(TrieStore, DbProvider.CodeDb, LogManager); // Eip4788 precompile state account - State.CreateAccount(BeaconBlockRootPrecompile.Address, 1); + if(specProvider?.GenesisSpec?.IsEip4788Enabled ?? false) + { + State.CreateAccount(BeaconBlockRootPrecompile.Address, 1); + } State.CreateAccount(TestItem.AddressA, (initialValues ?? InitialValue)); State.CreateAccount(TestItem.AddressB, (initialValues ?? InitialValue)); From 0b6c02d7c045df80a88e9d7d5b8f89dc2c4615e8 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Thu, 20 Jul 2023 00:35:30 +0100 Subject: [PATCH 11/43] - Fix whistespace check failure --- .../Nethermind.Core.Test/Blockchain/TestBlockchain.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs index a12f90b4483..f7267ae2af3 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -119,7 +119,7 @@ protected virtual async Task Build(ISpecProvider? specProvider = State = new WorldState(TrieStore, DbProvider.CodeDb, LogManager); // Eip4788 precompile state account - if(specProvider?.GenesisSpec?.IsEip4788Enabled ?? false) + if (specProvider?.GenesisSpec?.IsEip4788Enabled ?? false) { State.CreateAccount(BeaconBlockRootPrecompile.Address, 1); } From 46108e8fe8fea096ea0a50f341425e5f25e6b72e Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Mon, 24 Jul 2023 13:36:04 +0100 Subject: [PATCH 12/43] - move setup precompile 4788 to instance method - make Instance field in Precompile static generic to match class type --- .../Nethermind.Consensus/Processing/BlockProcessor.cs | 10 +--------- .../Nethermind.Core.Test/Blockchain/TestBlockchain.cs | 2 +- .../Nethermind.Evm/Precompiles/Blake2FPrecompile.cs | 4 ++-- .../Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs | 4 ++-- .../Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs | 4 ++-- .../Precompiles/Bls/G1MultiExpPrecompile.cs | 4 ++-- .../Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs | 4 ++-- .../Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs | 4 ++-- .../Precompiles/Bls/G2MultiExpPrecompile.cs | 4 ++-- .../Precompiles/Bls/MapToG1Precompile.cs | 4 ++-- .../Precompiles/Bls/MapToG2Precompile.cs | 4 ++-- .../Precompiles/Bls/PairingPrecompile.cs | 4 ++-- .../Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs | 4 ++-- .../Nethermind.Evm/Precompiles/IPrecompile.cs | 6 ++++++ .../Nethermind.Evm/Precompiles/IdentityPrecompile.cs | 4 ++-- .../Nethermind.Evm/Precompiles/ModExpPrecompile.cs | 4 ++-- .../Precompiles/ModExpPrecompilePreEip2565.cs | 4 ++-- .../Precompiles/PointEvaluationPrecompile.cs | 4 ++-- .../Nethermind.Evm/Precompiles/Ripemd160Precompile.cs | 4 ++-- .../Nethermind.Evm/Precompiles/Sha256Precompile.cs | 4 ++-- .../Precompiles/Snarks/Bn254AddPrecompile.cs | 4 ++-- .../Precompiles/Snarks/Bn254MulPrecompile.cs | 4 ++-- .../Precompiles/Snarks/Bn254PairingPrecompile.cs | 4 ++-- .../Precompiles/Stateful/BeaconBlockRootPrecompile.cs | 9 ++++++--- .../EngineModuleTests.HelperFunctions.cs | 2 +- .../EngineModuleTests.V3.cs | 4 ++-- 26 files changed, 57 insertions(+), 56 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs index 66aed2b19a2..fb3aa951f8f 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs @@ -223,18 +223,10 @@ protected virtual TxReceipt[] ProcessBlock( { IReleaseSpec spec = _specProvider.GetSpec(block.Header); - if (spec.IsBeaconParentBlockRootAvailable) - { - _stateProvider.CreateAccountIfNotExists(BeaconBlockRootPrecompile.Address, 1); - } - _receiptsTracer.SetOtherTracer(blockTracer); _receiptsTracer.StartNewBlockTrace(block); - if (spec.IsBeaconParentBlockRootAvailable) - { - BeaconBlockRootPrecompile.SetupBeaconBlockRootPrecompileState(_stateProvider, block.ParentBeaconBlockRoot, block.Timestamp); - } + BeaconBlockRootPrecompile.Instance.SetupBeaconBlockRootPrecompileState(spec.IsBeaconParentBlockRootAvailable, _stateProvider, block.ParentBeaconBlockRoot, block.Timestamp); TxReceipt[] receipts = _blockTransactionsExecutor.ProcessTransactions(block, options, _receiptsTracer, spec); diff --git a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs index f7267ae2af3..46904fc26d8 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -319,7 +319,7 @@ protected virtual Block GetGenesisBlock() if (SpecProvider.GenesisSpec.IsEip4788Enabled) { - BeaconBlockRootPrecompile.SetupBeaconBlockRootPrecompileState(State, genesisBlockBuilder.TestObject.ParentBeaconBlockRoot, genesisBlockBuilder.TestObject.Timestamp); + BeaconBlockRootPrecompile.Instance.SetupBeaconBlockRootPrecompileState(isEip4788Enabled: true, State, genesisBlockBuilder.TestObject.ParentBeaconBlockRoot, genesisBlockBuilder.TestObject.Timestamp); State.Commit(SpecProvider.GenesisSpec); State.CommitTree(0); diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs index 2de732ab581..d426d7afdbf 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs @@ -10,13 +10,13 @@ namespace Nethermind.Evm.Precompiles { - public class Blake2FPrecompile : IPrecompile + public class Blake2FPrecompile : IPrecompile { private const int RequiredInputLength = 213; private Blake2Compression _blake = new(); - public static readonly IPrecompile Instance = new Blake2FPrecompile(); + public static readonly Blake2FPrecompile Instance = new Blake2FPrecompile(); public static Address Address { get; } = Address.FromNumber(9); diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs index 36382217d17..c795b55fad0 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs @@ -12,9 +12,9 @@ namespace Nethermind.Evm.Precompiles.Bls; /// /// https://eips.ethereum.org/EIPS/eip-2537 /// -public class G1AddPrecompile : IPrecompile +public class G1AddPrecompile : IPrecompile { - public static IPrecompile Instance = new G1AddPrecompile(); + public static G1AddPrecompile Instance = new G1AddPrecompile(); private G1AddPrecompile() { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs index 1110b26c70b..e1a4bdcd4c3 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs @@ -12,9 +12,9 @@ namespace Nethermind.Evm.Precompiles.Bls; /// /// https://eips.ethereum.org/EIPS/eip-2537 /// -public class G1MulPrecompile : IPrecompile +public class G1MulPrecompile : IPrecompile { - public static IPrecompile Instance = new G1MulPrecompile(); + public static G1MulPrecompile Instance = new G1MulPrecompile(); private G1MulPrecompile() { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs index 1b598feab4e..12a4b6f3efc 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs @@ -12,9 +12,9 @@ namespace Nethermind.Evm.Precompiles.Bls; /// /// https://eips.ethereum.org/EIPS/eip-2537 /// -public class G1MultiExpPrecompile : IPrecompile +public class G1MultiExpPrecompile : IPrecompile { - public static IPrecompile Instance = new G1MultiExpPrecompile(); + public static G1MultiExpPrecompile Instance = new G1MultiExpPrecompile(); private G1MultiExpPrecompile() { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs index 8e73dce031e..8c4538cfaa5 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs @@ -12,9 +12,9 @@ namespace Nethermind.Evm.Precompiles.Bls; /// /// https://eips.ethereum.org/EIPS/eip-2537 /// -public class G2AddPrecompile : IPrecompile +public class G2AddPrecompile : IPrecompile { - public static IPrecompile Instance = new G2AddPrecompile(); + public static G2AddPrecompile Instance = new G2AddPrecompile(); private G2AddPrecompile() { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs index f7f9d1d6720..c1c77ab8db9 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs @@ -12,9 +12,9 @@ namespace Nethermind.Evm.Precompiles.Bls; /// /// https://eips.ethereum.org/EIPS/eip-2537 /// -public class G2MulPrecompile : IPrecompile +public class G2MulPrecompile : IPrecompile { - public static IPrecompile Instance = new G2MulPrecompile(); + public static G2MulPrecompile Instance = new G2MulPrecompile(); private G2MulPrecompile() { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs index 9167cbf8206..b7b0764cf97 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs @@ -12,9 +12,9 @@ namespace Nethermind.Evm.Precompiles.Bls; /// /// https://eips.ethereum.org/EIPS/eip-2537 /// -public class G2MultiExpPrecompile : IPrecompile +public class G2MultiExpPrecompile : IPrecompile { - public static IPrecompile Instance = new G2MultiExpPrecompile(); + public static G2MultiExpPrecompile Instance = new G2MultiExpPrecompile(); private G2MultiExpPrecompile() { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs index c5107a3deaa..879cb9ab7f8 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs @@ -12,9 +12,9 @@ namespace Nethermind.Evm.Precompiles.Bls; /// /// https://eips.ethereum.org/EIPS/eip-2537 /// -public class MapToG1Precompile : IPrecompile +public class MapToG1Precompile : IPrecompile { - public static IPrecompile Instance = new MapToG1Precompile(); + public static MapToG1Precompile Instance = new MapToG1Precompile(); private MapToG1Precompile() { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs index ccfd181ef91..08126216c7e 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs @@ -12,9 +12,9 @@ namespace Nethermind.Evm.Precompiles.Bls; /// /// https://eips.ethereum.org/EIPS/eip-2537 /// -public class MapToG2Precompile : IPrecompile +public class MapToG2Precompile : IPrecompile { - public static IPrecompile Instance = new MapToG2Precompile(); + public static MapToG2Precompile Instance = new MapToG2Precompile(); private MapToG2Precompile() { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs index e4e547e6bba..15685d3a77c 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs @@ -12,7 +12,7 @@ namespace Nethermind.Evm.Precompiles.Bls; /// /// https://eips.ethereum.org/EIPS/eip-2537 /// -public class PairingPrecompile : IPrecompile +public class PairingPrecompile : IPrecompile { private const int PairSize = 384; @@ -20,7 +20,7 @@ private PairingPrecompile() { } public static Address Address { get; } = Address.FromNumber(0x12); - public static IPrecompile Instance = new PairingPrecompile(); + public static PairingPrecompile Instance = new PairingPrecompile(); public long BaseGasCost(IReleaseSpec releaseSpec) => 115000L; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs index 7843d2695bd..b32d5a19859 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs @@ -12,9 +12,9 @@ namespace Nethermind.Evm.Precompiles { - public class EcRecoverPrecompile : IPrecompile + public class EcRecoverPrecompile : IPrecompile { - public static readonly IPrecompile Instance = new EcRecoverPrecompile(); + public static readonly EcRecoverPrecompile Instance = new EcRecoverPrecompile(); private EcRecoverPrecompile() { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs index 320ae003957..4d80863624d 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs @@ -18,4 +18,10 @@ public interface IPrecompile (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState state = null); } + + + public interface IPrecompile : IPrecompile + { + static TPrecompileTypeInstance Instance { get; } + } } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs index ed64181487b..e32680848f5 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs @@ -8,9 +8,9 @@ namespace Nethermind.Evm.Precompiles { - public class IdentityPrecompile : IPrecompile + public class IdentityPrecompile : IPrecompile { - public static readonly IPrecompile Instance = new IdentityPrecompile(); + public static readonly IdentityPrecompile Instance = new IdentityPrecompile(); private IdentityPrecompile() { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs index 94c1f8e024a..17f965a4a82 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs @@ -16,9 +16,9 @@ namespace Nethermind.Evm.Precompiles /// /// https://github.com/ethereum/EIPs/blob/vbuterin-patch-2/EIPS/bigint_modexp.md /// - public class ModExpPrecompile : IPrecompile + public class ModExpPrecompile : IPrecompile { - public static readonly IPrecompile Instance = new ModExpPrecompile(); + public static readonly ModExpPrecompile Instance = new ModExpPrecompile(); private ModExpPrecompile() { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs index ac8634a5ab5..4c62296566f 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs @@ -15,9 +15,9 @@ namespace Nethermind.Evm.Precompiles /// https://github.com/ethereum/EIPs/blob/vbuterin-patch-2/EIPS/bigint_modexp.md /// [Obsolete("Pre-eip2565 implementation")] - public class ModExpPrecompilePreEip2565 : IPrecompile + public class ModExpPrecompilePreEip2565 : IPrecompile { - public static IPrecompile Instance = new ModExpPrecompilePreEip2565(); + public static ModExpPrecompilePreEip2565 Instance = new ModExpPrecompilePreEip2565(); private ModExpPrecompilePreEip2565() { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs index 02cd6a8979f..3b0e906fa49 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs @@ -12,9 +12,9 @@ namespace Nethermind.Evm.Precompiles; -public class PointEvaluationPrecompile : IPrecompile +public class PointEvaluationPrecompile : IPrecompile { - public static readonly IPrecompile Instance = new PointEvaluationPrecompile(); + public static readonly PointEvaluationPrecompile Instance = new PointEvaluationPrecompile(); private static readonly ReadOnlyMemory PointEvaluationSuccessfulResponse = ((UInt256)Ckzg.Ckzg.FieldElementsPerBlob).ToBigEndian() diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs index c1164220b7b..7c20f3c187c 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs @@ -10,9 +10,9 @@ namespace Nethermind.Evm.Precompiles { - public class Ripemd160Precompile : IPrecompile + public class Ripemd160Precompile : IPrecompile { - public static readonly IPrecompile Instance = new Ripemd160Precompile(); + public static readonly Ripemd160Precompile Instance = new Ripemd160Precompile(); // missing in .NET Core // private static RIPEMD160 _ripemd; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs index de15b339718..36bc3d121fc 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs @@ -10,11 +10,11 @@ namespace Nethermind.Evm.Precompiles { - public class Sha256Precompile : IPrecompile + public class Sha256Precompile : IPrecompile { private static ThreadLocal _sha256 = new(); - public static readonly IPrecompile Instance = new Sha256Precompile(); + public static readonly Sha256Precompile Instance = new Sha256Precompile(); private Sha256Precompile() { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs index 9f1306bf9e0..8e864bd87bc 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs @@ -12,9 +12,9 @@ namespace Nethermind.Evm.Precompiles.Snarks; /// /// https://github.com/matter-labs/eip1962/blob/master/eip196_header.h /// -public class Bn254AddPrecompile : IPrecompile +public class Bn254AddPrecompile : IPrecompile { - public static IPrecompile Instance = new Bn254AddPrecompile(); + public static Bn254AddPrecompile Instance = new Bn254AddPrecompile(); public static Address Address { get; } = Address.FromNumber(6); diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254MulPrecompile.cs index ead321acad4..09a8c2e5cc6 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254MulPrecompile.cs @@ -12,9 +12,9 @@ namespace Nethermind.Evm.Precompiles.Snarks; /// /// https://github.com/herumi/mcl/blob/master/api.md /// -public class Bn254MulPrecompile : IPrecompile +public class Bn254MulPrecompile : IPrecompile { - public static IPrecompile Instance = new Bn254MulPrecompile(); + public static Bn254MulPrecompile Instance = new Bn254MulPrecompile(); public static Address Address { get; } = Address.FromNumber(7); diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254PairingPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254PairingPrecompile.cs index e59985e8181..300ee0569e3 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254PairingPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254PairingPrecompile.cs @@ -12,11 +12,11 @@ namespace Nethermind.Evm.Precompiles.Snarks; /// /// https://github.com/herumi/mcl/blob/master/api.md /// -public class Bn254PairingPrecompile : IPrecompile +public class Bn254PairingPrecompile : IPrecompile { private const int PairSize = 192; - public static IPrecompile Instance = new Bn254PairingPrecompile(); + public static Bn254PairingPrecompile Instance = new Bn254PairingPrecompile(); public static Address Address { get; } = Address.FromNumber(8); diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs index c73a5055852..fc181abf803 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs @@ -6,20 +6,23 @@ using Nethermind.State; namespace Nethermind.Evm.Precompiles.Stateful; -public class BeaconBlockRootPrecompile : IPrecompile +public class BeaconBlockRootPrecompile : IPrecompile { public static Address Address { get; } = Address.FromNumber(0x0B); public static UInt256 HISTORICAL_ROOTS_LENGTH = 98304; - public static IPrecompile Instance => new BeaconBlockRootPrecompile(); + public static BeaconBlockRootPrecompile Instance => new BeaconBlockRootPrecompile(); private byte[] SloadFromStorage(IWorldState state, in UInt256 index) { StorageCell storageCell = new(Address, index); return state.Get(storageCell); } - public static void SetupBeaconBlockRootPrecompileState(IWorldState stateProvider, Keccak parentBeaconBlockRoot, UInt256 timestamp) + public void SetupBeaconBlockRootPrecompileState(bool isEip4788Enabled, IWorldState stateProvider, Keccak parentBeaconBlockRoot, UInt256 timestamp) { + if (!isEip4788Enabled) return; + stateProvider.CreateAccountIfNotExists(BeaconBlockRootPrecompile.Address, 1); + if (parentBeaconBlockRoot is null) return; UInt256.Mod(timestamp, HISTORICAL_ROOTS_LENGTH, out UInt256 timestampReduced); diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs index 002f745fc9d..424da333c17 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs @@ -114,7 +114,7 @@ private static ExecutionPayloadV3 CreateBlockRequestV3(IReleaseSpec spec, IWorld blockRequestV3.ExcessDataGas = excessDataGas; blockRequestV3.ParentBeaconBlockRoot = beaconParentBlockRoot; - BeaconBlockRootPrecompile.SetupBeaconBlockRootPrecompileState(state, blockRequestV3.ParentBeaconBlockRoot, blockRequestV3.Timestamp); + BeaconBlockRootPrecompile.Instance.SetupBeaconBlockRootPrecompileState(spec.IsEip4788Enabled, state, blockRequestV3.ParentBeaconBlockRoot, blockRequestV3.Timestamp); state.Commit(spec); state.CommitTree(blockRequestV3.BlockNumber); diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs index e75b33751ce..847bba6ba87 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs @@ -71,7 +71,7 @@ public async Task NewPayloadV3_should_decline_pre_cancun_payloads() chain.SpecProvider.GenesisSpec, chain.State, CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty()); - ResultWrapper result = await rpcModule.engine_newPayloadV3(executionPayload, new byte[0][], executionPayload.ParentBeaconBlockRoot?.BytesToArray())); + ResultWrapper result = await rpcModule.engine_newPayloadV3(executionPayload, new byte[0][], executionPayload.ParentBeaconBlockRoot?.BytesToArray()); Assert.That(result.ErrorCode, Is.EqualTo(ErrorCodes.UnsupportedFork)); } @@ -139,7 +139,7 @@ public virtual async Task NewPayloadV3_should_decline_mempool_encoding(bool inMe payload.Transactions = transactions.Select(tx => rlpEncoder.Encode(tx, rlpBehaviors).Bytes).ToArray(); byte[]?[] blobVersionedHashes = transactions.SelectMany(tx => tx.BlobVersionedHashes ?? Array.Empty()).ToArray(); - ResultWrapper result = await rpcModule.engine_newPayloadV3(payload, blobVersionedHashes); + ResultWrapper result = await rpcModule.engine_newPayloadV3(payload, blobVersionedHashes, TestItem.KeccakA.BytesToArray()); Assert.That(result.ErrorCode, Is.EqualTo(ErrorCodes.None)); result.Data.Status.Should().Be(expectedPayloadStatus); From ae7c4fd509922574b43d3cd26f95c7c0b8d361cd Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Mon, 24 Jul 2023 13:46:27 +0100 Subject: [PATCH 13/43] - fix some build issue --- src/Nethermind/Nethermind.Evm.Test/Eip2565Tests.cs | 4 ++-- .../Nethermind.Evm.Test/PointEvaluationPrecompileTests.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Nethermind/Nethermind.Evm.Test/Eip2565Tests.cs b/src/Nethermind/Nethermind.Evm.Test/Eip2565Tests.cs index afc87008b9a..f1160a42703 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(), Berlin.Instance, null); #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(), London.Instance, null)); 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 b03633283d9..ab368ab93bb 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, Cancun.Instance, null); output.ToArray().Should().BeEquivalentTo(success ? _predefinedSuccessAnswer : _predefinedFailureAnswer); return success; } From 629778445090095354f9475da365618df6790f39 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Mon, 24 Jul 2023 14:15:58 +0100 Subject: [PATCH 14/43] - fixed failing tests --- .../Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs index 847bba6ba87..2e78ae21b60 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs @@ -139,7 +139,7 @@ public virtual async Task NewPayloadV3_should_decline_mempool_encoding(bool inMe payload.Transactions = transactions.Select(tx => rlpEncoder.Encode(tx, rlpBehaviors).Bytes).ToArray(); byte[]?[] blobVersionedHashes = transactions.SelectMany(tx => tx.BlobVersionedHashes ?? Array.Empty()).ToArray(); - ResultWrapper result = await rpcModule.engine_newPayloadV3(payload, blobVersionedHashes, TestItem.KeccakA.BytesToArray()); + ResultWrapper result = await rpcModule.engine_newPayloadV3(payload, blobVersionedHashes, payload.ParentBeaconBlockRoot.BytesToArray()); Assert.That(result.ErrorCode, Is.EqualTo(ErrorCodes.None)); result.Data.Status.Should().Be(expectedPayloadStatus); @@ -405,7 +405,8 @@ private async Task SendNewBlockV3(IEngineRpcModule rpc, MergeT Timestamp = chain.BlockTree.Head!.Timestamp + 1, PrevRandao = TestItem.KeccakH, SuggestedFeeRecipient = TestItem.AddressF, - Withdrawals = new List { TestItem.WithdrawalA_1Eth } + Withdrawals = new List { TestItem.WithdrawalA_1Eth }, + BeaconParentBlockRoot = TestItem.KeccakE }; Keccak currentHeadHash = chain.BlockTree.HeadHash; ForkchoiceStateV1 forkchoiceState = new(currentHeadHash, currentHeadHash, currentHeadHash); From 768c1ef3f4c0bf4b6f378aab6036ca829d7f6da9 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Thu, 27 Jul 2023 19:20:31 +0100 Subject: [PATCH 15/43] - Apply changes --- .../Processing/BlockProcessor.cs | 2 +- .../Producers/PayloadAttributes.cs | 14 +-- .../Blockchain/TestBlockchain.cs | 15 ++- .../Builders/BlockBuilder.cs | 4 +- .../Nethermind.Core/Specs/IReleaseSpec.cs | 2 +- .../BeaconParentBlockRootPrecompileTests.cs | 114 +++++------------- .../Nethermind.Evm.Test/Eip2565Tests.cs | 2 +- .../PointEvaluationPrecompileTests.cs | 2 +- src/Nethermind/Nethermind.Evm/Metrics.cs | 2 +- .../Precompiles/AddressExtensions.cs | 2 +- .../Precompiles/Blake2FPrecompile.cs | 2 +- .../Precompiles/Bls/G1AddPrecompile.cs | 2 +- .../Precompiles/Bls/G1MulPrecompile.cs | 2 +- .../Precompiles/Bls/G1MultiExpPrecompile.cs | 2 +- .../Precompiles/Bls/G2AddPrecompile.cs | 2 +- .../Precompiles/Bls/G2MulPrecompile.cs | 2 +- .../Precompiles/Bls/G2MultiExpPrecompile.cs | 2 +- .../Precompiles/Bls/MapToG1Precompile.cs | 2 +- .../Precompiles/Bls/MapToG2Precompile.cs | 2 +- .../Precompiles/Bls/PairingPrecompile.cs | 2 +- .../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/Sha256Precompile.cs | 2 +- .../Precompiles/Snarks/Bn254AddPrecompile.cs | 2 +- .../Precompiles/Snarks/Bn254MulPrecompile.cs | 2 +- .../Snarks/Bn254PairingPrecompile.cs | 2 +- .../Stateful/BeaconBlockRootPrecompile.cs | 10 +- .../EngineModuleTests.HelperFunctions.cs | 18 +-- .../EngineModuleTests.V3.cs | 4 +- .../HeaderDecoder.cs | 4 +- .../Nethermind.State/IWorldState.cs | 7 +- .../Nethermind.State/StateProvider.cs | 18 +-- src/Nethermind/Nethermind.State/WorldState.cs | 13 +- 38 files changed, 102 insertions(+), 173 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs index fb3aa951f8f..75f261a4e3a 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs @@ -226,7 +226,7 @@ protected virtual TxReceipt[] ProcessBlock( _receiptsTracer.SetOtherTracer(blockTracer); _receiptsTracer.StartNewBlockTrace(block); - BeaconBlockRootPrecompile.Instance.SetupBeaconBlockRootPrecompileState(spec.IsBeaconParentBlockRootAvailable, _stateProvider, block.ParentBeaconBlockRoot, block.Timestamp); + BeaconBlockRootPrecompile.Instance.SetupBeaconBlockRootPrecompileState(spec, _stateProvider, block.ParentBeaconBlockRoot, block.Timestamp); TxReceipt[] receipts = _blockTransactionsExecutor.ProcessTransactions(block, options, _receiptsTracer, spec); diff --git a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs index e02f6ccc4d0..b1d2d9e353f 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs @@ -62,13 +62,13 @@ public static string ComputePayloadId(this PayloadAttributes payloadAttributes, bool hasWithdrawals = payloadAttributes.Withdrawals is not null; bool hasBeaconParentBlockRoot = payloadAttributes.BeaconParentBlockRoot is not null; - const int preambleLength = 32 + 32 + 32 + 20; - Span inputSpan = stackalloc byte[preambleLength + (hasWithdrawals ? 32 : 0) + (hasBeaconParentBlockRoot ? 32 : 0)]; + const int preambleLength = Keccak.Size + Keccak.Size + Keccak.Size + Address.ByteLength; + Span inputSpan = stackalloc byte[preambleLength + (hasWithdrawals ? Keccak.Size : 0) + (hasBeaconParentBlockRoot ? Keccak.Size : 0)]; - parentHeader.Hash!.Bytes.CopyTo(inputSpan[..32]); - BinaryPrimitives.WriteUInt64BigEndian(inputSpan.Slice(56, 8), payloadAttributes.Timestamp); - payloadAttributes.PrevRandao.Bytes.CopyTo(inputSpan.Slice(64, 32)); - payloadAttributes.SuggestedFeeRecipient.Bytes.CopyTo(inputSpan.Slice(96, 20)); + parentHeader.Hash!.Bytes.CopyTo(inputSpan[..Keccak.Size]); + BinaryPrimitives.WriteUInt64BigEndian(inputSpan.Slice(56, sizeof(UInt64)), payloadAttributes.Timestamp); + payloadAttributes.PrevRandao.Bytes.CopyTo(inputSpan.Slice(64, Keccak.Size)); + payloadAttributes.SuggestedFeeRecipient.Bytes.CopyTo(inputSpan.Slice(96, Address.ByteLength)); if (hasWithdrawals) { @@ -81,7 +81,7 @@ public static string ComputePayloadId(this PayloadAttributes payloadAttributes, if (hasBeaconParentBlockRoot) { - payloadAttributes.BeaconParentBlockRoot.Bytes.CopyTo(inputSpan[(preambleLength + (hasWithdrawals ? 32 : 0))..]); + payloadAttributes.BeaconParentBlockRoot.Bytes.CopyTo(inputSpan[(preambleLength + (hasWithdrawals ? Keccak.Size : 0))..]); } ValueKeccak inputHash = ValueKeccak.Compute(inputSpan); diff --git a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs index 46904fc26d8..6c7dcd4d9a9 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -108,7 +108,7 @@ protected TestBlockchain() public static TransactionBuilder BuildSimpleTransaction => Builders.Build.A.Transaction.SignedAndResolved(TestItem.PrivateKeyA).To(AccountB); - protected virtual async Task Build(ISpecProvider? specProvider = null, UInt256? initialValues = null) + protected virtual async Task Build(ISpecProvider? specProvider = null, UInt256? initialValues = null, bool addBlockOnStart = true) { Timestamper = new ManualTimestamper(new DateTime(2020, 2, 15, 12, 50, 30, DateTimeKind.Utc)); JsonSerializer = new EthereumJsonSerializer(); @@ -119,7 +119,7 @@ protected virtual async Task Build(ISpecProvider? specProvider = State = new WorldState(TrieStore, DbProvider.CodeDb, LogManager); // Eip4788 precompile state account - if (specProvider?.GenesisSpec?.IsEip4788Enabled ?? false) + if (specProvider?.GenesisSpec?.IsBeaconBlockRootAvailable ?? false) { State.CreateAccount(BeaconBlockRootPrecompile.Address, 1); } @@ -202,7 +202,10 @@ protected virtual async Task Build(ISpecProvider? specProvider = BlockTree.SuggestBlock(genesis); await WaitAsync(_resetEvent, "Failed to process genesis in time."); - await AddBlocksOnStart(); + + if(addBlockOnStart) + await AddBlocksOnStart(); + return this; } @@ -305,7 +308,7 @@ protected virtual Block GetGenesisBlock() genesisBlockBuilder.WithAura(0, new byte[65]); } - if (SpecProvider.GenesisSpec.IsEip4788Enabled) + if (SpecProvider.GenesisSpec.IsBeaconBlockRootAvailable) { genesisBlockBuilder.WithParentBeaconBlockRoot(TestItem.KeccakG); } @@ -317,9 +320,9 @@ protected virtual Block GetGenesisBlock() } - if (SpecProvider.GenesisSpec.IsEip4788Enabled) + if (SpecProvider.GenesisSpec.IsBeaconBlockRootAvailable) { - BeaconBlockRootPrecompile.Instance.SetupBeaconBlockRootPrecompileState(isEip4788Enabled: true, State, genesisBlockBuilder.TestObject.ParentBeaconBlockRoot, genesisBlockBuilder.TestObject.Timestamp); + BeaconBlockRootPrecompile.Instance.SetupBeaconBlockRootPrecompileState(SpecProvider.GenesisSpec, State, genesisBlockBuilder.TestObject.ParentBeaconBlockRoot, genesisBlockBuilder.TestObject.Timestamp); State.Commit(SpecProvider.GenesisSpec); State.CommitTree(0); diff --git a/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs b/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs index a0155609824..cf08c60e468 100644 --- a/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs +++ b/src/Nethermind/Nethermind.Core.Test/Builders/BlockBuilder.cs @@ -278,9 +278,9 @@ public BlockBuilder WithWithdrawals(params Withdrawal[]? withdrawals) return this; } - public BlockBuilder WithParentBeaconBlockRoot(Keccak keccakG) + public BlockBuilder WithParentBeaconBlockRoot(Keccak parentBeaconBlockRoot) { - TestObjectInternal.Header.ParentBeaconBlockRoot = keccakG; + TestObjectInternal.Header.ParentBeaconBlockRoot = parentBeaconBlockRoot; return this; } } diff --git a/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs b/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs index f35ac63a0ef..0108fee22e7 100644 --- a/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs +++ b/src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs @@ -357,7 +357,7 @@ public interface IReleaseSpec : IEip1559Spec, IReceiptSpec public bool WithdrawalsEnabled => IsEip4895Enabled; public bool SelfdestructOnlyOnSameTransaction => IsEip6780Enabled; - public bool IsBeaconParentBlockRootAvailable => IsEip4788Enabled; + public bool IsBeaconBlockRootAvailable => IsEip4788Enabled; public bool MCopyIncluded => IsEip5656Enabled; } } diff --git a/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs index a6bfa409c98..ff65e642044 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs @@ -25,126 +25,78 @@ using NUnit.Framework; using Nethermind.Core.Crypto; using Nethermind.Evm.Tracing.GethStyle; +using Nethermind.Core.Test.Blockchain; +using System.Threading.Tasks; namespace Nethermind.Evm.Test; -public class Eip4788Tests +public class Eip4788Tests : TestBlockchain { - private WorldState _testState; private ISpecProvider specProvider; private SenderRecipientAndMiner senderRecipientAndMiner = SenderRecipientAndMiner.Default; - protected static IEnumerable<(IReleaseSpec Spec, bool ShouldFail)> BeacondStateRootGetPayloadV3ForDifferentSpecTestSource() + protected static IEnumerable<(IReleaseSpec Spec, bool ShouldFail)> BeaconBlockRootGetPayloadV3ForDifferentSpecTestSource() { yield return (Shanghai.Instance, true); yield return (Cancun.Instance, false); } - [TestCaseSource(nameof(BeacondStateRootGetPayloadV3ForDifferentSpecTestSource))] - public void ParentBeaconBlockRoot_Is_Stored_Correctly_and_Only_Valid_PostCancun((IReleaseSpec Spec, bool ShouldFail) testCase) + [TestCaseSource(nameof(BeaconBlockRootGetPayloadV3ForDifferentSpecTestSource))] + public async Task BeaconBlockRoot_Is_Stored_Correctly_and_Only_Valid_PostCancun((IReleaseSpec Spec, bool ShouldFail) testCase) { specProvider = new TestSpecProvider(testCase.Spec); - DbProvider dbProvider = new(DbModeHint.Mem); - dbProvider.RegisterDb(DbNames.BlockInfos, new MemDb()); - dbProvider.RegisterDb(DbNames.Blocks, new MemDb()); - dbProvider.RegisterDb(DbNames.Headers, new MemDb()); - dbProvider.RegisterDb(DbNames.State, new MemDb()); - dbProvider.RegisterDb(DbNames.Code, new MemDb()); - dbProvider.RegisterDb(DbNames.Metadata, new MemDb()); - BlockTree blockTree = new( - dbProvider, - new ChainLevelInfoRepository(dbProvider), - specProvider, - NullBloomStorage.Instance, - LimboLogs.Instance); - TrieStore trieStore = new( - dbProvider.RegisteredDbs[DbNames.State], - NoPruning.Instance, - Archive.Instance, - LimboLogs.Instance); - _testState = new( - trieStore, - dbProvider.RegisteredDbs[DbNames.Code], - LimboLogs.Instance); - StateReader stateReader = new(trieStore, dbProvider.GetDb(DbNames.State), LimboLogs.Instance); - BlockhashProvider blockhashProvider = new(blockTree, LimboLogs.Instance); - - VirtualMachine virtualMachine = new( - blockhashProvider, - specProvider, - LimboLogs.Instance); - TransactionProcessor txProcessor = new( - specProvider, - _testState, - virtualMachine, - LimboLogs.Instance); - BlockProcessor blockProcessor = new( - specProvider, - Always.Valid, - NoBlockRewards.Instance, - new BlockProcessor.BlockValidationTransactionsExecutor(txProcessor, _testState), - _testState, - NullReceiptStorage.Instance, - NullWitnessCollector.Instance, - LimboLogs.Instance); - - - + TestBlockchain testBlockchain = await base.Build(specProvider, addBlockOnStart: false); GethLikeBlockTracer? tracer = new(GethTraceOptions.Default); - Block block = CreateBlock(); - Block[] blocks = blockProcessor.Process( - Keccak.EmptyTreeHash, + Block block = CreateBlock(testBlockchain.State, testCase.Spec); + _ = testBlockchain.BlockProcessor.Process( + testBlockchain.State.StateRoot, new List { block }, - ProcessingOptions.None, + ProcessingOptions.NoValidation, tracer); List? traces = tracer.BuildResult().ToList(); Assert.That(testCase.ShouldFail, Is.EqualTo(traces[0].Failed)); } - Block CreateBlock() + Block CreateBlock(IWorldState testState, IReleaseSpec spec) { - if (!_testState.AccountExists(senderRecipientAndMiner.Sender)) - _testState.CreateAccount(senderRecipientAndMiner.Sender, 100.Ether()); - else - _testState.AddToBalance(senderRecipientAndMiner.Sender, 100.Ether(), specProvider.GenesisSpec); - - if (!_testState.AccountExists(senderRecipientAndMiner.Recipient)) - _testState.CreateAccount(senderRecipientAndMiner.Recipient, 100.Ether()); - else - _testState.AddToBalance(senderRecipientAndMiner.Recipient, 100.Ether(), specProvider.GenesisSpec); + Keccak parentBeaconBlockRoot = TestItem.KeccakG; byte[] bytecode = Prepare .EvmCode .TIMESTAMP() .MSTORE(0) - .CALL(100.GWei(), Address.FromNumber(0x0B), 0, 0, 32, 32, 32) + .CALL(100.Ether(), Address.FromNumber(0x0B), 0, 0, 32, 32, 32) .MLOAD(32) - .EQ(new UInt256(TestItem.KeccakG.Bytes, true)) - .JUMPI(0x53) + .EQ(new UInt256(parentBeaconBlockRoot.Bytes, true)) + .JUMPI(0x57) .INVALID() .JUMPDEST() .STOP() .Done; - _testState.InsertCode(senderRecipientAndMiner.Recipient, bytecode, specProvider.GenesisSpec); - Transaction tx = Build.A.Transaction + testState.InsertCode(TestBlockchain.AccountA, bytecode, specProvider.GenesisSpec); + Transaction tx = Core.Test.Builders.Build.A.Transaction .WithGasLimit(1_000_000) .WithGasPrice(1) .WithValue(1) - .WithData(bytecode) - .WithSenderAddress(senderRecipientAndMiner.Sender) - .WithNonce(_testState.GetNonce(senderRecipientAndMiner.Sender)) - .To(senderRecipientAndMiner.Recipient) + .WithSenderAddress(TestBlockchain.AccountB) + .WithNonce(testState.GetNonce(TestBlockchain.AccountB)) + .To(TestBlockchain.AccountA) .TestObject; - _testState.RecalculateStateRoot(); - Block block0 = - Build.A.Block.Genesis + testState.Commit(spec); + testState.CommitTree(0); + testState.RecalculateStateRoot(); + BlockBuilder blockBuilder = Core.Test.Builders.Build.A.Block.Genesis .WithDifficulty(1) .WithTotalDifficulty(1L) .WithTransactions(tx) - .WithPostMergeFlag(true) - .WithParentBeaconBlockRoot(TestItem.KeccakG) - .TestObject; - return block0; + .WithPostMergeFlag(true); + + if(spec.IsBeaconBlockRootAvailable) + { + blockBuilder.WithParentBeaconBlockRoot(parentBeaconBlockRoot); + } + + return blockBuilder.TestObject; } } diff --git a/src/Nethermind/Nethermind.Evm.Test/Eip2565Tests.cs b/src/Nethermind/Nethermind.Evm.Test/Eip2565Tests.cs index f1160a42703..2f261a9ca3a 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, null); + (ReadOnlyMemory, bool) gmpPair = ModExpPrecompile.Instance.Run(input.Done.ToArray(), Berlin.Instance); #pragma warning disable 618 (ReadOnlyMemory, bool) bigIntPair = ModExpPrecompile.OldRun(input.Done.ToArray()); #pragma warning restore 618 diff --git a/src/Nethermind/Nethermind.Evm.Test/PointEvaluationPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/PointEvaluationPrecompileTests.cs index ab368ab93bb..b03633283d9 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, null); + (ReadOnlyMemory output, bool success) = PointEvaluationPrecompile.Instance.Run(input, Cancun.Instance); output.ToArray().Should().BeEquivalentTo(success ? _predefinedSuccessAnswer : _predefinedFailureAnswer); return success; } diff --git a/src/Nethermind/Nethermind.Evm/Metrics.cs b/src/Nethermind/Nethermind.Evm/Metrics.cs index 28983fe03a1..3ff6f21472b 100644 --- a/src/Nethermind/Nethermind.Evm/Metrics.cs +++ b/src/Nethermind/Nethermind.Evm/Metrics.cs @@ -86,7 +86,7 @@ public class Metrics [CounterMetric] [Description("Number of Parent Beacon Block Root precompile calls.")] - public static int BeaconBlockRootPrecompile { get; set; } + public static int ParentBeaconBlockRootPrecompile { get; set; } [Description("Number of calls made to addresses without code.")] diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs b/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs index e10e45cb40b..6ce10061194 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs @@ -27,7 +27,7 @@ public static bool IsPrecompile(this Address address, IReleaseSpec releaseSpec) 0x08 => releaseSpec.Bn128Enabled, 0x09 => releaseSpec.BlakeEnabled, 0x0a => releaseSpec.IsEip4844Enabled, - 0x0b => releaseSpec.IsBeaconParentBlockRootAvailable, + 0x0b => releaseSpec.IsBeaconBlockRootAvailable, 0x0c => releaseSpec.Bls381Enabled, 0x0d => releaseSpec.Bls381Enabled, 0x0e => releaseSpec.Bls381Enabled, diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs index d426d7afdbf..9b4a5cda9e8 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Blake2FPrecompile.cs @@ -40,7 +40,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return rounds; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { 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 c795b55fad0..7fe2c117716 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs @@ -32,7 +32,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { const int expectedInputLength = 4 * BlsParams.LenFp; if (inputData.Length != expectedInputLength) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs index e1a4bdcd4c3..8619e54ada6 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MulPrecompile.cs @@ -32,7 +32,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { const int expectedInputLength = 2 * BlsParams.LenFp + BlsParams.LenFr; if (inputData.Length != expectedInputLength) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs index 12a4b6f3efc..f7514bb8060 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MultiExpPrecompile.cs @@ -35,7 +35,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS private const int ItemSize = 160; - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { if (inputData.Length % ItemSize > 0 || inputData.Length == 0) { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs index 8c4538cfaa5..b247daaf7ec 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs @@ -32,7 +32,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { const int expectedInputLength = 8 * BlsParams.LenFp; if (inputData.Length != expectedInputLength) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs index c1c77ab8db9..49c4ef13388 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs @@ -32,7 +32,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { const int expectedInputLength = 4 * BlsParams.LenFp + BlsParams.LenFr; if (inputData.Length != expectedInputLength) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs index b7b0764cf97..a6e71c1afde 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MultiExpPrecompile.cs @@ -35,7 +35,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS private const int ItemSize = 288; - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { if (inputData.Length % ItemSize > 0 || inputData.Length == 0) { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs index 879cb9ab7f8..55b58a25cad 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG1Precompile.cs @@ -32,7 +32,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { const int expectedInputLength = 64; if (inputData.Length != expectedInputLength) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs index 08126216c7e..0e12870fbee 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapToG2Precompile.cs @@ -32,7 +32,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { const int expectedInputLength = 2 * BlsParams.LenFp; if (inputData.Length != expectedInputLength) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs index 15685d3a77c..c202180db1b 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingPrecompile.cs @@ -29,7 +29,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 23000L * (inputData.Length / PairSize); } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { if (inputData.Length % PairSize > 0 || inputData.Length == 0) { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs index b32d5a19859..ee9bffdf226 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/EcRecoverPrecompile.cs @@ -36,7 +36,7 @@ public long BaseGasCost(IReleaseSpec releaseSpec) private readonly byte[] _zero31 = new byte[31]; - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { Metrics.EcRecoverPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs index 4d80863624d..9b8cacb772c 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/IPrecompile.cs @@ -16,7 +16,7 @@ public interface IPrecompile long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec); - (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState state = null); + (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? state = null); } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs index e32680848f5..564061da1b6 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/IdentityPrecompile.cs @@ -28,7 +28,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 3L * EvmPooledMemory.Div32Ceiling((ulong)inputData.Length); } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { return (inputData, true); } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs index 17f965a4a82..871df924e7a 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs @@ -103,7 +103,7 @@ private static (int, int, int) GetInputLengths(in ReadOnlyMemory inputData return (baseLength, expLength, modulusLength); } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { Metrics.ModExpPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs index 4c62296566f..5635a9ae95d 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompilePreEip2565.cs @@ -57,7 +57,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS } } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { Metrics.ModExpPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs index 3b0e906fa49..4d63f51f2ea 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/PointEvaluationPrecompile.cs @@ -27,7 +27,7 @@ public class PointEvaluationPrecompile : IPrecompile public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0; - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { [SkipLocalsInit] [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs index 7c20f3c187c..ba899a59ce8 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Ripemd160Precompile.cs @@ -36,7 +36,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 120L * EvmPooledMemory.Div32Ceiling((ulong)inputData.Length); } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { Metrics.Ripemd160Precompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs index 36bc3d121fc..be0ed4d1809 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Sha256Precompile.cs @@ -43,7 +43,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 12L * EvmPooledMemory.Div32Ceiling((ulong)inputData.Length); } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { Metrics.Sha256Precompile++; InitIfNeeded(); diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs index 8e864bd87bc..07c61793d3f 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254AddPrecompile.cs @@ -28,7 +28,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public unsafe (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public unsafe (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { 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 09a8c2e5cc6..2450b8a6ec3 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254MulPrecompile.cs @@ -28,7 +28,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return 0L; } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { 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 300ee0569e3..b0e107fb401 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254PairingPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Snarks/Bn254PairingPrecompile.cs @@ -30,7 +30,7 @@ public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseS return (releaseSpec.IsEip1108Enabled ? 34000L : 80000L) * (inputData.Length / PairSize); } - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState _) + public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState? _ = null) { Metrics.Bn254PairingPrecompile++; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs index fc181abf803..6619725a83f 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs @@ -18,13 +18,11 @@ private byte[] SloadFromStorage(IWorldState state, in UInt256 index) StorageCell storageCell = new(Address, index); return state.Get(storageCell); } - public void SetupBeaconBlockRootPrecompileState(bool isEip4788Enabled, IWorldState stateProvider, Keccak parentBeaconBlockRoot, UInt256 timestamp) + public void SetupBeaconBlockRootPrecompileState(IReleaseSpec spec, IWorldState stateProvider, Keccak parentBeaconBlockRoot, UInt256 timestamp) { - if (!isEip4788Enabled) return; + if (!spec.IsBeaconBlockRootAvailable) return; stateProvider.CreateAccountIfNotExists(BeaconBlockRootPrecompile.Address, 1); - if (parentBeaconBlockRoot is null) return; - UInt256.Mod(timestamp, HISTORICAL_ROOTS_LENGTH, out UInt256 timestampReduced); UInt256 rootIndex = timestampReduced + HISTORICAL_ROOTS_LENGTH; @@ -37,9 +35,9 @@ public void SetupBeaconBlockRootPrecompileState(bool isEip4788Enabled, IWorldSta public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState state) { - Metrics.BeaconBlockRootPrecompile++; + Metrics.ParentBeaconBlockRootPrecompile++; - if (inputData.Length != 32) + if (inputData.Length != Keccak.Size) { return (Array.Empty(), false); } diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs index 424da333c17..273f3a2fc9d 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs @@ -90,7 +90,16 @@ private static ExecutionPayload CreateBlockRequest(IReleaseSpec spec, IWorldStat => CreateBlockRequestInternal(spec, state, parent, miner, withdrawals, transactions: transactions, beaconParentBlockRoot: beaconParentBlockRoot); private static ExecutionPayloadV3 CreateBlockRequestV3(IReleaseSpec spec, IWorldState state, ExecutionPayload parent, Address miner, IList? withdrawals = null, ulong? dataGasUsed = null, ulong? excessDataGas = null, Transaction[]? transactions = null, Keccak? beaconParentBlockRoot = null) - => CreateBlockRequestInternal(spec, state, parent, miner, withdrawals, dataGasUsed, excessDataGas, transactions: transactions, beaconParentBlockRoot: beaconParentBlockRoot); + { + var blockRequestV3 = CreateBlockRequestInternal(spec, state, parent, miner, withdrawals, dataGasUsed, excessDataGas, transactions: transactions, beaconParentBlockRoot: beaconParentBlockRoot); + BeaconBlockRootPrecompile.Instance.SetupBeaconBlockRootPrecompileState(spec, state, blockRequestV3.ParentBeaconBlockRoot, blockRequestV3.Timestamp); + state.Commit(spec); + state.CommitTree(blockRequestV3.BlockNumber); + + state.RecalculateStateRoot(); + blockRequestV3.StateRoot = state.StateRoot; + return blockRequestV3; + } private static T CreateBlockRequestInternal(IReleaseSpec spec, IWorldState state, ExecutionPayload parent, Address miner, IList? withdrawals = null, ulong? dataGasUsed = null, ulong? excessDataGas = null, Transaction[]? transactions = null, Keccak? beaconParentBlockRoot = null) where T : ExecutionPayload, new() { @@ -113,13 +122,6 @@ private static ExecutionPayloadV3 CreateBlockRequestV3(IReleaseSpec spec, IWorld blockRequestV3.DataGasUsed = dataGasUsed; blockRequestV3.ExcessDataGas = excessDataGas; blockRequestV3.ParentBeaconBlockRoot = beaconParentBlockRoot; - - BeaconBlockRootPrecompile.Instance.SetupBeaconBlockRootPrecompileState(spec.IsEip4788Enabled, state, blockRequestV3.ParentBeaconBlockRoot, blockRequestV3.Timestamp); - state.Commit(spec); - state.CommitTree(blockRequestV3.BlockNumber); - - state.RecalculateStateRoot(); - blockRequestV3.StateRoot = state.StateRoot; } diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs index 2e78ae21b60..1b72ad730b0 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs @@ -173,7 +173,7 @@ public async Task NewPayloadV3_should_decline_null_blobversionedhashes() ExecutionPayloadV3 executionPayload = CreateBlockRequestV3( chain.SpecProvider.GenesisSpec, chain.State, - CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty(), dataGasUsed: 0, excessDataGas: 0); + CreateParentBlockRequestOnHead(chain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty(), dataGasUsed: 0, excessDataGas: 0, beaconParentBlockRoot: TestItem.KeccakA); return (new(moduleProvider, LimboLogs.Instance, jsonRpcConfig), new(RpcEndpoint.Http), new(), executionPayload); } @@ -306,7 +306,7 @@ public async Task NewPayloadV3_should_verify_blob_versioned_hashes_again ExecutionPayloadV3 executionPayload = CreateBlockRequestV3( blockchain.SpecProvider.GenesisSpec, blockchain.State, - CreateParentBlockRequestOnHead(blockchain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty(), 0, 0, transactions: transactions); + CreateParentBlockRequestOnHead(blockchain.BlockTree), TestItem.AddressD, withdrawals: Array.Empty(), 0, 0, transactions: transactions, beaconParentBlockRoot: Keccak.Zero); ResultWrapper result = await engineRpcModule.engine_newPayloadV3(executionPayload, blobVersionedHashes, Keccak.Zero.BytesToArray()); return result.Data.Status; diff --git a/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs b/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs index c3978dc475c..5ba623d1f8f 100644 --- a/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs +++ b/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs @@ -83,7 +83,7 @@ public class HeaderDecoder : IRlpValueDecoder, IRlpStreamDecoder= 4 && decoderContext.Position != headerCheck) + if (itemsRemaining == 4 && decoderContext.Position != headerCheck) { blockHeader.ParentBeaconBlockRoot = decoderContext.DecodeKeccak(); } @@ -170,7 +170,7 @@ public class HeaderDecoder : IRlpValueDecoder, IRlpStreamDecoder= 4 && rlpStream.Position != headerCheck) + if (itemsRemaining == 4 && rlpStream.Position != headerCheck) { blockHeader.ParentBeaconBlockRoot = rlpStream.DecodeKeccak(); } diff --git a/src/Nethermind/Nethermind.State/IWorldState.cs b/src/Nethermind/Nethermind.State/IWorldState.cs index 06081f3a398..51f56ed43bc 100644 --- a/src/Nethermind/Nethermind.State/IWorldState.cs +++ b/src/Nethermind/Nethermind.State/IWorldState.cs @@ -80,11 +80,8 @@ public interface IWorldState : IJournal, IReadOnlyStateProvider void DeleteAccount(Address address); - void CreateAccount(Address address, in UInt256 balance); - void CreateAccountIfNotExists(Address address, in UInt256 balance); - - void CreateAccount(Address address, in UInt256 balance, in UInt256 nonce); - void CreateAccountIfNotExists(Address address, in UInt256 balance, in UInt256 nonce); + void CreateAccount(Address address, in UInt256 balance, in UInt256 nonce = default); + void CreateAccountIfNotExists(Address address, in UInt256 balance, in UInt256 nonce = default); void InsertCode(Address address, ReadOnlyMemory code, IReleaseSpec spec, bool isGenesis = false); diff --git a/src/Nethermind/Nethermind.State/StateProvider.cs b/src/Nethermind/Nethermind.State/StateProvider.cs index a49ef968f6d..592879ef005 100644 --- a/src/Nethermind/Nethermind.State/StateProvider.cs +++ b/src/Nethermind/Nethermind.State/StateProvider.cs @@ -407,21 +407,7 @@ public void Restore(int snapshot) _keptInCache.Clear(); } - public void CreateAccount(Address address, in UInt256 balance) - { - _needsStateRootUpdate = true; - if (_logger.IsTrace) _logger.Trace($"Creating account: {address} with balance {balance}"); - Account account = balance.IsZero ? Account.TotallyEmpty : new Account(balance); - PushNew(address, account); - } - - public void CreateAccountIfNotExists(Address address, in UInt256 balance) - { - if (AccountExists(address)) return; - CreateAccount(address, balance); - } - - public void CreateAccount(Address address, in UInt256 balance, in UInt256 nonce) + public void CreateAccount(Address address, in UInt256 balance, in UInt256 nonce = default) { _needsStateRootUpdate = true; if (_logger.IsTrace) _logger.Trace($"Creating account: {address} with balance {balance} and nonce {nonce}"); @@ -429,7 +415,7 @@ public void CreateAccount(Address address, in UInt256 balance, in UInt256 nonce) PushNew(address, account); } - public void CreateAccountIfNotExists(Address address, in UInt256 balance, in UInt256 nonce) + public void CreateAccountIfNotExists(Address address, in UInt256 balance, in UInt256 nonce = default) { if (AccountExists(address)) return; CreateAccount(address, balance, nonce); diff --git a/src/Nethermind/Nethermind.State/WorldState.cs b/src/Nethermind/Nethermind.State/WorldState.cs index 53146c3bced..cd02eec98e7 100644 --- a/src/Nethermind/Nethermind.State/WorldState.cs +++ b/src/Nethermind/Nethermind.State/WorldState.cs @@ -89,11 +89,7 @@ public void DeleteAccount(Address address) { _stateProvider.DeleteAccount(address); } - public void CreateAccount(Address address, in UInt256 balance) - { - _stateProvider.CreateAccount(address, balance); - } - public void CreateAccount(Address address, in UInt256 balance, in UInt256 nonce) + public void CreateAccount(Address address, in UInt256 balance, in UInt256 nonce = default) { _stateProvider.CreateAccount(address, balance, nonce); } @@ -217,12 +213,7 @@ internal void SetNonce(Address address, in UInt256 nonce) _stateProvider.SetNonce(address, nonce); } - public void CreateAccountIfNotExists(Address address, in UInt256 balance) - { - _stateProvider.CreateAccountIfNotExists(address, balance); - } - - public void CreateAccountIfNotExists(Address address, in UInt256 balance, in UInt256 nonce) + public void CreateAccountIfNotExists(Address address, in UInt256 balance, in UInt256 nonce = default) { _stateProvider.CreateAccountIfNotExists(address, balance, nonce); } From 27bb1ff4ce99d52aaedb8f4d5e1827c4b7284bcf Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Thu, 27 Jul 2023 21:29:24 +0100 Subject: [PATCH 16/43] - Fix failing tests --- .../EngineModuleTests.HelperFunctions.cs | 3 +++ src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs index d634e202e89..8c269bc3be0 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs @@ -22,6 +22,7 @@ using Nethermind.State; using Nethermind.Core.Specs; using Nethermind.Evm.Precompiles.Stateful; +using Nethermind.Synchronization.Blocks; namespace Nethermind.Merge.Plugin.Test { @@ -98,6 +99,8 @@ private static ExecutionPayloadV3 CreateBlockRequestV3(IReleaseSpec spec, IWorld state.RecalculateStateRoot(); blockRequestV3.StateRoot = state.StateRoot; + TryCalculateHash(blockRequestV3, out Keccak? hash); + blockRequestV3.BlockHash = hash; return blockRequestV3; } diff --git a/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs b/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs index 5bdb99c781b..e5cba70e565 100644 --- a/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs +++ b/src/Nethermind/Nethermind.Serialization.Rlp/HeaderDecoder.cs @@ -281,9 +281,8 @@ private static int GetContentLength(BlockHeader? item, RlpBehaviors rlpBehaviors + Rlp.LengthOf(item.Timestamp) + Rlp.LengthOf(item.ExtraData) + (item.BaseFeePerGas.IsZero ? 0 : Rlp.LengthOf(item.BaseFeePerGas)) - + (item.WithdrawalsRoot is null && item.BlobGasUsed is null ? 0 : Rlp.LengthOfKeccakRlp) - + (item.ParentBeaconBlockRoot is null ? 0 : Rlp.LengthOfKeccakRlp) + (item.WithdrawalsRoot is null && item.BlobGasUsed is null && item.ExcessBlobGas is null ? 0 : Rlp.LengthOfKeccakRlp) + + (item.ParentBeaconBlockRoot is null ? 0 : Rlp.LengthOfKeccakRlp) + (item.BlobGasUsed is null ? 0 : Rlp.LengthOf(item.BlobGasUsed.Value)) + (item.ExcessBlobGas is null ? 0 : Rlp.LengthOf(item.ExcessBlobGas.Value)); From fc7ed2df72c546d5566f31d70a940f4c2daa7e5d Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Thu, 27 Jul 2023 21:31:00 +0100 Subject: [PATCH 17/43] - ws fixes --- .../Nethermind.Core.Test/Blockchain/TestBlockchain.cs | 2 +- .../Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs index 31565d95ece..8b56f579a9b 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -203,7 +203,7 @@ protected virtual async Task Build(ISpecProvider? specProvider = await WaitAsync(_resetEvent, "Failed to process genesis in time."); - if(addBlockOnStart) + if (addBlockOnStart) await AddBlocksOnStart(); return this; diff --git a/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs index ff65e642044..14da91798b5 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs @@ -92,7 +92,7 @@ Block CreateBlock(IWorldState testState, IReleaseSpec spec) .WithTransactions(tx) .WithPostMergeFlag(true); - if(spec.IsBeaconBlockRootAvailable) + if (spec.IsBeaconBlockRootAvailable) { blockBuilder.WithParentBeaconBlockRoot(parentBeaconBlockRoot); } From 13d3c1df2c673a7da48561bae9477b9fb4aca16a Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Mon, 31 Jul 2023 15:02:44 +0100 Subject: [PATCH 18/43] - Introduce IBeaconBlockRootHandler --- ...sts.TestAccountAbstractionRpcBlockchain.cs | 4 +- .../AuraBlockProcessorTests.cs | 2 + .../AuRaContractGasLimitOverrideTests.cs | 2 + .../Transactions/TxCertifierFilterTests.cs | 4 +- .../Transactions/TxPermissionFilterTest.cs | 2 + .../BlockProcessorTests.cs | 10 +++-- .../Producers/DevBlockproducerTests.cs | 4 +- .../Nethermind.Blockchain.Test/ReorgTests.cs | 4 +- .../CliqueBlockProducerTests.cs | 7 +++- .../AuRaBlockProcessor.cs | 5 ++- .../NullBeaconBlockRootHandler.cs | 22 +++++++++++ .../InitializeBlockchainAuRa.cs | 2 + .../StartBlockProducerAuRa.cs | 2 + .../BeaconBlockRoot/BeaconBlockRootHandler.cs | 38 +++++++++++++++++++ .../IBeaconBlockRootHandler.cs | 17 +++++++++ .../Processing/BlockProcessor.cs | 9 +++-- .../Processing/ReadOnlyChainProcessingEnv.cs | 4 +- .../Producers/BlockProducerEnvFactory.cs | 4 +- .../Blockchain/TestBlockchain.cs | 9 ++++- .../Stateful/BeaconBlockRootPrecompile.cs | 14 ------- .../Modules/Trace/ParityStyleTracerTests.cs | 4 +- .../AuRaMergeBlockProcessor.cs | 3 ++ .../AuRaMergeBlockProducerEnvFactory.cs | 4 +- .../InitializeBlockchainAuRaMerge.cs | 2 + .../EngineModuleTests.HelperFunctions.cs | 7 +++- .../EngineModuleTests.Setup.cs | 4 +- .../MevRpcModuleTests.TestMevRpcBlockchain.cs | 4 +- .../SyncThreadTests.cs | 5 ++- 28 files changed, 159 insertions(+), 39 deletions(-) create mode 100644 src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs create mode 100644 src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/BeaconBlockRootHandler.cs create mode 100644 src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/IBeaconBlockRootHandler.cs diff --git a/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs b/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs index e7726ddbbe0..e291cba930c 100644 --- a/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs +++ b/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs @@ -38,6 +38,7 @@ using Nethermind.State; using NSubstitute; using Nethermind.Config; +using Nethermind.Consensus.BeaconBlockRoot; namespace Nethermind.AccountAbstraction.Test { @@ -192,7 +193,8 @@ protected override BlockProcessor CreateBlockProcessor() State, ReceiptStorage, NullWitnessCollector.Instance, - LogManager); + LogManager, + beaconBlockRootHandler: new BeaconBlockRootHandler()); var parser = new AbiDefinitionParser(); parser.RegisterAbiTypeFactory(new AbiTuple()); diff --git a/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs b/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs index 60033b7820c..470b1eaf80e 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs @@ -8,6 +8,7 @@ using Nethermind.Blockchain.Receipts; using Nethermind.Blockchain.Test.Validators; using Nethermind.Consensus.AuRa; +using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Rewards; using Nethermind.Consensus.Transactions; @@ -161,6 +162,7 @@ void Process(AuRaBlockProcessor auRaBlockProcessor, int blockNumber, Keccak stat LimboLogs.Instance, Substitute.For(), new WithdrawalProcessor(stateProvider, LimboLogs.Instance), + new BeaconBlockRootHandler(), txFilter, contractRewriter: contractRewriter); diff --git a/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs b/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs index c5f1a04d732..189dbe8933b 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs @@ -8,6 +8,7 @@ using Nethermind.Abi; using Nethermind.Consensus; using Nethermind.Consensus.AuRa; +using Nethermind.Consensus.AuRa.BeaconBlockRoot; using Nethermind.Consensus.AuRa.Contracts; using Nethermind.Consensus.AuRa.Withdrawals; using Nethermind.Consensus.Processing; @@ -100,6 +101,7 @@ protected override BlockProcessor CreateBlockProcessor() LimboLogs.Instance, BlockTree, NullWithdrawalProcessor.Instance, + NullBeaconBlockRootHandler.Instance, null, GasLimitCalculator as AuRaContractGasLimitOverride); } diff --git a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs index 887961a3c6d..526f7308fcb 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs @@ -7,6 +7,7 @@ using Nethermind.Abi; using Nethermind.AuRa.Test.Contract; using Nethermind.Consensus.AuRa; +using Nethermind.Consensus.AuRa.BeaconBlockRoot; using Nethermind.Consensus.AuRa.Contracts; using Nethermind.Consensus.AuRa.Transactions; using Nethermind.Consensus.AuRa.Withdrawals; @@ -156,7 +157,8 @@ protected override BlockProcessor CreateBlockProcessor() ReceiptStorage, LimboLogs.Instance, BlockTree, - NullWithdrawalProcessor.Instance); + NullWithdrawalProcessor.Instance, + NullBeaconBlockRootHandler.Instance); } protected override Task AddBlocksOnStart() => Task.CompletedTask; diff --git a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs index 099792d03c3..1e15b2d3e9a 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs @@ -30,6 +30,7 @@ using Nethermind.TxPool; using NSubstitute; using NUnit.Framework; +using Nethermind.Consensus.AuRa.BeaconBlockRoot; namespace Nethermind.AuRa.Test.Transactions; @@ -298,6 +299,7 @@ protected override BlockProcessor CreateBlockProcessor() LimboLogs.Instance, BlockTree, NullWithdrawalProcessor.Instance, + NullBeaconBlockRootHandler.Instance, PermissionBasedTxFilter); } diff --git a/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs index 58c6fb51a53..228bf57dbf7 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs @@ -29,6 +29,7 @@ using Nethermind.Consensus.Withdrawals; using Nethermind.Core.Test.Blockchain; using Nethermind.Evm.TransactionProcessing; +using Nethermind.Consensus.BeaconBlockRoot; namespace Nethermind.Blockchain.Test { @@ -51,7 +52,8 @@ public void Prepared_block_contains_author_field() stateProvider, NullReceiptStorage.Instance, NullWitnessCollector.Instance, - LimboLogs.Instance); + LimboLogs.Instance, + beaconBlockRootHandler: new BeaconBlockRootHandler()); BlockHeader header = Build.A.BlockHeader.WithAuthor(TestItem.AddressD).TestObject; Block block = Build.A.Block.WithHeader(header).TestObject; @@ -82,7 +84,8 @@ public void Can_store_a_witness() stateProvider, NullReceiptStorage.Instance, witnessCollector, - LimboLogs.Instance); + LimboLogs.Instance, + beaconBlockRootHandler: new BeaconBlockRootHandler()); BlockHeader header = Build.A.BlockHeader.WithAuthor(TestItem.AddressD).TestObject; Block block = Build.A.Block.WithHeader(header).TestObject; @@ -111,7 +114,8 @@ public void Recovers_state_on_cancel() stateProvider, NullReceiptStorage.Instance, NullWitnessCollector.Instance, - LimboLogs.Instance); + LimboLogs.Instance, + beaconBlockRootHandler: new BeaconBlockRootHandler()); BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithAuthor(TestItem.AddressD).TestObject; Block block = Build.A.Block.WithTransactions(1, MuirGlacier.Instance).WithHeader(header).TestObject; diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs index c8de8362917..07ef04cf183 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs @@ -5,6 +5,7 @@ using FluentAssertions; using Nethermind.Blockchain.Receipts; using Nethermind.Config; +using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Producers; using Nethermind.Consensus.Rewards; @@ -76,7 +77,8 @@ public void Test() stateProvider, NullReceiptStorage.Instance, NullWitnessCollector.Instance, - LimboLogs.Instance); + LimboLogs.Instance, + beaconBlockRootHandler: new BeaconBlockRootHandler()); BlockchainProcessor blockchainProcessor = new( blockTree, blockProcessor, diff --git a/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs index 8795add9d9c..d6cafc04d0a 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs @@ -7,6 +7,7 @@ using Nethermind.Blockchain.Receipts; using Nethermind.Blockchain.Spec; using Nethermind.Blockchain.Synchronization; +using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Comparers; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Rewards; @@ -85,7 +86,8 @@ public void Setup() stateProvider, NullReceiptStorage.Instance, new WitnessCollector(memDbProvider.StateDb, LimboLogs.Instance), - LimboLogs.Instance); + LimboLogs.Instance, + beaconBlockRootHandler: new BeaconBlockRootHandler()); _blockchainProcessor = new BlockchainProcessor( _blockTree, blockProcessor, diff --git a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs index b905d8e6a49..d7b17a93fa3 100644 --- a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs +++ b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs @@ -37,6 +37,7 @@ using Nethermind.TxPool; using NUnit.Framework; using Nethermind.Config; +using Nethermind.Consensus.BeaconBlockRoot; namespace Nethermind.Clique.Test { @@ -132,7 +133,8 @@ public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = f stateProvider, NullReceiptStorage.Instance, NullWitnessCollector.Instance, - nodeLogManager); + nodeLogManager, + beaconBlockRootHandler: new BeaconBlockRootHandler()); BlockchainProcessor processor = new(blockTree, blockProcessor, new AuthorRecoveryStep(snapshotManager), stateReader, nodeLogManager, BlockchainProcessor.Options.NoReceipts); processor.Start(); @@ -151,7 +153,8 @@ public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = f minerStateProvider, NullReceiptStorage.Instance, NullWitnessCollector.Instance, - nodeLogManager); + nodeLogManager, + beaconBlockRootHandler: new BeaconBlockRootHandler()); BlockchainProcessor minerProcessor = new(blockTree, minerBlockProcessor, new AuthorRecoveryStep(snapshotManager), stateReader, nodeLogManager, BlockchainProcessor.Options.NoReceipts); diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs b/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs index 52dc575fab0..9c765af5886 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs @@ -6,6 +6,7 @@ using Nethermind.Blockchain.Find; using Nethermind.Blockchain.Receipts; using Nethermind.Consensus.AuRa.Validators; +using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Rewards; using Nethermind.Consensus.Transactions; @@ -43,6 +44,7 @@ public AuRaBlockProcessor( ILogManager logManager, IBlockTree blockTree, IWithdrawalProcessor withdrawalProcessor, + IBeaconBlockRootHandler beaconBlockRootHandler, ITxFilter? txFilter = null, AuRaContractGasLimitOverride? gasLimitOverride = null, ContractRewriter? contractRewriter = null) @@ -55,7 +57,8 @@ public AuRaBlockProcessor( receiptStorage, NullWitnessCollector.Instance, logManager, - withdrawalProcessor) + withdrawalProcessor, + beaconBlockRootHandler) { _specProvider = specProvider; _blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree)); diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs new file mode 100644 index 00000000000..dcc3ff88734 --- /dev/null +++ b/src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Nethermind.Consensus.BeaconBlockRoot; +using Nethermind.Core; +using Nethermind.Core.Specs; +using Nethermind.State; + +namespace Nethermind.Consensus.AuRa.BeaconBlockRoot; +internal class NullBeaconBlockRootHandler : IBeaconBlockRootHandler +{ + public void HandleBeaconBlockRoot(Block block, IReleaseSpec spec, IWorldState state) + { + } + + public static IBeaconBlockRootHandler Instance { get; } = new NullBeaconBlockRootHandler(); +} diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs index 57cca506565..c6e91c70949 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs @@ -9,6 +9,7 @@ using Nethermind.Blockchain.Data; using Nethermind.Blockchain.Services; using Nethermind.Config; +using Nethermind.Consensus.AuRa.BeaconBlockRoot; using Nethermind.Consensus.AuRa.Config; using Nethermind.Consensus.AuRa.Contracts; using Nethermind.Consensus.AuRa.Contracts.DataStore; @@ -97,6 +98,7 @@ protected virtual BlockProcessor NewBlockProcessor(AuRaNethermindApi api, ITxFil _api.LogManager, _api.BlockTree, NullWithdrawalProcessor.Instance, + NullBeaconBlockRootHandler.Instance, txFilter, GetGasLimitCalculator(), contractRewriter diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs index c8bd56c76e6..c181b8cfbf6 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs @@ -10,6 +10,7 @@ using Nethermind.Blockchain; using Nethermind.Blockchain.Data; using Nethermind.Config; +using Nethermind.Consensus.AuRa.BeaconBlockRoot; using Nethermind.Consensus.AuRa.Config; using Nethermind.Consensus.AuRa.Contracts; using Nethermind.Consensus.AuRa.Contracts.DataStore; @@ -159,6 +160,7 @@ private BlockProcessor CreateBlockProcessor(ReadOnlyTxProcessingEnv changeableTx _api.LogManager, changeableTxProcessingEnv.BlockTree, NullWithdrawalProcessor.Instance, + NullBeaconBlockRootHandler.Instance, auRaTxFilter, CreateGasLimitCalculator(constantContractTxProcessingEnv) as AuRaContractGasLimitOverride, contractRewriter) diff --git a/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/BeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/BeaconBlockRootHandler.cs new file mode 100644 index 00000000000..92f6a588b59 --- /dev/null +++ b/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/BeaconBlockRootHandler.cs @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Nethermind.Core.Specs; +using Nethermind.Core; +using Nethermind.Evm.Precompiles.Stateful; +using Nethermind.Int256; +using Nethermind.State; +using static Nethermind.Evm.Precompiles.Stateful.BeaconBlockRootPrecompile; + + +namespace Nethermind.Consensus.BeaconBlockRoot; +public class BeaconBlockRootHandler : IBeaconBlockRootHandler +{ + public void HandleBeaconBlockRoot(Block block, IReleaseSpec spec, IWorldState stateProvider) + { + if (!spec.IsBeaconBlockRootAvailable) return; + + var timestamp = (UInt256)block.Timestamp; + var parentBeaconBlockRoot = block.ParentBeaconBlockRoot; + + stateProvider.CreateAccountIfNotExists(BeaconBlockRootPrecompile.Address, 1); + + UInt256.Mod(timestamp, HISTORICAL_ROOTS_LENGTH, out UInt256 timestampReduced); + UInt256 rootIndex = timestampReduced + HISTORICAL_ROOTS_LENGTH; + + StorageCell tsStorageCell = new(BeaconBlockRootPrecompile.Address, timestampReduced); + StorageCell brStorageCell = new(BeaconBlockRootPrecompile.Address, rootIndex); + + stateProvider.Set(tsStorageCell, timestamp.ToBigEndian()); + stateProvider.Set(brStorageCell, parentBeaconBlockRoot.Bytes.ToArray()); + } +} diff --git a/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/IBeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/IBeaconBlockRootHandler.cs new file mode 100644 index 00000000000..fd9f875827c --- /dev/null +++ b/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/IBeaconBlockRootHandler.cs @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Nethermind.Core.Specs; +using Nethermind.Core; +using Nethermind.State; + +namespace Nethermind.Consensus.BeaconBlockRoot; +public interface IBeaconBlockRootHandler +{ + void HandleBeaconBlockRoot(Block block, IReleaseSpec spec, IWorldState state); +} diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs index eecc6047ec7..ca17e95f466 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs @@ -7,6 +7,7 @@ using System.Numerics; using Nethermind.Blockchain; using Nethermind.Blockchain.Receipts; +using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Rewards; using Nethermind.Consensus.Validators; using Nethermind.Consensus.Withdrawals; @@ -33,6 +34,7 @@ public partial class BlockProcessor : IBlockProcessor private readonly IReceiptStorage _receiptStorage; private readonly IWitnessCollector _witnessCollector; private readonly IWithdrawalProcessor _withdrawalProcessor; + private readonly IBeaconBlockRootHandler _beaconBlockRootHandler; private readonly IBlockValidator _blockValidator; private readonly IRewardCalculator _rewardCalculator; private readonly IBlockProcessor.IBlockTransactionsExecutor _blockTransactionsExecutor; @@ -54,7 +56,8 @@ public BlockProcessor( IReceiptStorage? receiptStorage, IWitnessCollector? witnessCollector, ILogManager? logManager, - IWithdrawalProcessor? withdrawalProcessor = null) + IWithdrawalProcessor? withdrawalProcessor = null, + IBeaconBlockRootHandler? beaconBlockRootHandler = null) { _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider)); @@ -65,7 +68,7 @@ public BlockProcessor( _withdrawalProcessor = withdrawalProcessor ?? new WithdrawalProcessor(stateProvider, logManager); _rewardCalculator = rewardCalculator ?? throw new ArgumentNullException(nameof(rewardCalculator)); _blockTransactionsExecutor = blockTransactionsExecutor ?? throw new ArgumentNullException(nameof(blockTransactionsExecutor)); - + _beaconBlockRootHandler = beaconBlockRootHandler ?? throw new ArgumentNullException(nameof(beaconBlockRootHandler)); _receiptsTracer = new BlockReceiptsTracer(); } @@ -226,7 +229,7 @@ protected virtual TxReceipt[] ProcessBlock( _receiptsTracer.SetOtherTracer(blockTracer); _receiptsTracer.StartNewBlockTrace(block); - BeaconBlockRootPrecompile.Instance.SetupBeaconBlockRootPrecompileState(spec, _stateProvider, block.ParentBeaconBlockRoot, block.Timestamp); + _beaconBlockRootHandler.HandleBeaconBlockRoot(block, spec, _stateProvider); TxReceipt[] receipts = _blockTransactionsExecutor.ProcessTransactions(block, options, _receiptsTracer, spec); diff --git a/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs b/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs index da38938699c..77ef0e87bc2 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs @@ -3,6 +3,7 @@ using System; using Nethermind.Blockchain.Receipts; +using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Rewards; using Nethermind.Consensus.Validators; using Nethermind.Consensus.Withdrawals; @@ -50,7 +51,8 @@ public ReadOnlyChainProcessingEnv( StateProvider, receiptStorage, NullWitnessCollector.Instance, - logManager); + logManager, + beaconBlockRootHandler: new BeaconBlockRootHandler()); _blockProcessingQueue = new BlockchainProcessor(_txEnv.BlockTree, BlockProcessor, recoveryStep, _txEnv.StateReader, logManager, BlockchainProcessor.Options.NoReceipts); BlockProcessingQueue = _blockProcessingQueue; diff --git a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs index 3d88b53ba6a..9bef9948d42 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs @@ -4,6 +4,7 @@ using Nethermind.Blockchain; using Nethermind.Blockchain.Receipts; using Nethermind.Config; +using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Comparers; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Rewards; @@ -149,7 +150,8 @@ protected virtual BlockProcessor CreateBlockProcessor(ReadOnlyTxProcessingEnv re receiptStorage, NullWitnessCollector.Instance, logManager, - new BlockProductionWithdrawalProcessor(new WithdrawalProcessor(readOnlyTxProcessingEnv.StateProvider, logManager))); + new BlockProductionWithdrawalProcessor(new WithdrawalProcessor(readOnlyTxProcessingEnv.StateProvider, logManager)), + new BeaconBlockRootHandler()); } } diff --git a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs index 8b56f579a9b..c3f32abc498 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -10,6 +10,7 @@ using Nethermind.Blockchain.Receipts; using Nethermind.Config; using Nethermind.Consensus; +using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Comparers; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Producers; @@ -50,6 +51,7 @@ public class TestBlockchain : IDisposable public ITxPool TxPool { get; set; } = null!; public IDb CodeDb => DbProvider.CodeDb; public IBlockProcessor BlockProcessor { get; set; } = null!; + public IBeaconBlockRootHandler BeaconBlockRootHandler { get; set; } = null!; public IBlockchainProcessor BlockchainProcessor { get; set; } = null!; public IBlockPreprocessorStep BlockPreprocessorStep { get; set; } = null!; @@ -177,6 +179,7 @@ protected virtual async Task Build(ISpecProvider? specProvider = BloomStorage bloomStorage = new(new BloomConfig(), new MemDb(), new InMemoryDictionaryFileStoreFactory()); ReceiptsRecovery receiptsRecovery = new(new EthereumEcdsa(SpecProvider.ChainId, LimboLogs.Instance), SpecProvider); LogFinder = new LogFinder(BlockTree, ReceiptStorage, ReceiptStorage, bloomStorage, LimboLogs.Instance, receiptsRecovery); + BeaconBlockRootHandler = new BeaconBlockRootHandler(); BlockProcessor = CreateBlockProcessor(); BlockchainProcessor chainProcessor = new(BlockTree, BlockProcessor, BlockPreprocessorStep, StateReader, LogManager, Consensus.Processing.BlockchainProcessor.Options.Default); @@ -322,7 +325,8 @@ protected virtual Block GetGenesisBlock() if (SpecProvider.GenesisSpec.IsBeaconBlockRootAvailable) { - BeaconBlockRootPrecompile.Instance.SetupBeaconBlockRootPrecompileState(SpecProvider.GenesisSpec, State, genesisBlockBuilder.TestObject.ParentBeaconBlockRoot, genesisBlockBuilder.TestObject.Timestamp); + + BeaconBlockRootHandler.HandleBeaconBlockRoot(genesisBlockBuilder.TestObject, SpecProvider.GenesisSpec, State); State.Commit(SpecProvider.GenesisSpec); State.CommitTree(0); @@ -348,7 +352,8 @@ protected virtual IBlockProcessor CreateBlockProcessor() => State, ReceiptStorage, NullWitnessCollector.Instance, - LogManager); + LogManager, + beaconBlockRootHandler: BeaconBlockRootHandler); public async Task WaitForNewHead() { diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs index 6619725a83f..4664162f8bc 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs @@ -18,20 +18,6 @@ private byte[] SloadFromStorage(IWorldState state, in UInt256 index) StorageCell storageCell = new(Address, index); return state.Get(storageCell); } - public void SetupBeaconBlockRootPrecompileState(IReleaseSpec spec, IWorldState stateProvider, Keccak parentBeaconBlockRoot, UInt256 timestamp) - { - if (!spec.IsBeaconBlockRootAvailable) return; - stateProvider.CreateAccountIfNotExists(BeaconBlockRootPrecompile.Address, 1); - - UInt256.Mod(timestamp, HISTORICAL_ROOTS_LENGTH, out UInt256 timestampReduced); - UInt256 rootIndex = timestampReduced + HISTORICAL_ROOTS_LENGTH; - - StorageCell tsStorageCell = new(Address, timestampReduced); - StorageCell brStorageCell = new(Address, rootIndex); - - stateProvider.Set(tsStorageCell, timestamp.ToBigEndian()); - stateProvider.Set(brStorageCell, parentBeaconBlockRoot.Bytes.ToArray()); - } public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState state) { diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs index b956aa649f5..f0c88cd08ea 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs @@ -33,6 +33,7 @@ using Nethermind.Evm.TransactionProcessing; using Nethermind.Trie.Pruning; using NSubstitute; +using Nethermind.Consensus.BeaconBlockRoot; namespace Nethermind.JsonRpc.Test.Modules.Trace { @@ -76,7 +77,8 @@ public void Setup() stateProvider, NullReceiptStorage.Instance, NullWitnessCollector.Instance, - LimboLogs.Instance); + LimboLogs.Instance, + beaconBlockRootHandler: new BeaconBlockRootHandler()); RecoverSignatures txRecovery = new(new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance), NullTxPool.Instance, specProvider, LimboLogs.Instance); _processor = new BlockchainProcessor(_blockTree, blockProcessor, txRecovery, stateReader, LimboLogs.Instance, BlockchainProcessor.Options.NoReceipts); diff --git a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs index 9e675bab24c..8a982a4c7d4 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs @@ -5,6 +5,7 @@ using Nethermind.Blockchain.Receipts; using Nethermind.Consensus; using Nethermind.Consensus.AuRa; +using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Rewards; using Nethermind.Consensus.Transactions; @@ -30,6 +31,7 @@ public AuRaMergeBlockProcessor( ILogManager logManager, IBlockTree blockTree, IWithdrawalProcessor withdrawalProcessor, + IBeaconBlockRootHandler beaconBlockRootHandler, ITxFilter? txFilter = null, AuRaContractGasLimitOverride? gasLimitOverride = null, ContractRewriter? contractRewriter = null @@ -43,6 +45,7 @@ public AuRaMergeBlockProcessor( logManager, blockTree, withdrawalProcessor, + beaconBlockRootHandler, txFilter, gasLimitOverride, contractRewriter diff --git a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs index a16c283a4ec..82e52156bdb 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs @@ -7,6 +7,7 @@ using Nethermind.Config; using Nethermind.Consensus.AuRa.Config; using Nethermind.Consensus.AuRa.InitializationSteps; +using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Comparers; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Producers; @@ -87,7 +88,8 @@ protected override BlockProcessor CreateBlockProcessor( withdrawalContractFactory.Create(readOnlyTxProcessingEnv.TransactionProcessor), logManager ) - ) + ), + new BeaconBlockRootHandler() ); } diff --git a/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs b/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs index d599ae32a96..64c6d1770fc 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs @@ -7,6 +7,7 @@ using Nethermind.Consensus.AuRa.InitializationSteps; using Nethermind.Consensus.AuRa.Transactions; using Nethermind.Consensus.AuRa.Validators; +using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Transactions; using Nethermind.Core; @@ -39,6 +40,7 @@ protected override BlockProcessor NewBlockProcessor(AuRaNethermindApi api, ITxFi _api.BlockTree!, new AuraWithdrawalProcessor( withdrawalContractFactory.Create(_api.TransactionProcessor!), _api.LogManager), + new BeaconBlockRootHandler(), txFilter, GetGasLimitCalculator(), contractRewriter diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs index 8c269bc3be0..e47769ab920 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs @@ -23,6 +23,7 @@ using Nethermind.Core.Specs; using Nethermind.Evm.Precompiles.Stateful; using Nethermind.Synchronization.Blocks; +using Nethermind.Consensus.BeaconBlockRoot; namespace Nethermind.Merge.Plugin.Test { @@ -30,8 +31,8 @@ namespace Nethermind.Merge.Plugin.Test public partial class EngineModuleTests { private static readonly DateTime Timestamp = DateTimeOffset.FromUnixTimeSeconds(1000).UtcDateTime; + private static readonly IBeaconBlockRootHandler _beaconBlockRootHandler = new BeaconBlockRootHandler(); private ITimestamper Timestamper { get; } = new ManualTimestamper(Timestamp); - private void AssertExecutionStatusChanged(IBlockFinder blockFinder, Keccak headBlockHash, Keccak finalizedBlockHash, Keccak safeBlockHash) { @@ -93,7 +94,9 @@ private static ExecutionPayload CreateBlockRequest(IReleaseSpec spec, IWorldStat private static ExecutionPayloadV3 CreateBlockRequestV3(IReleaseSpec spec, IWorldState state, ExecutionPayload parent, Address miner, IList? withdrawals = null, ulong? blobGasUsed = null, ulong? excessBlobGas = null, Transaction[]? transactions = null, Keccak? beaconParentBlockRoot = null) { var blockRequestV3 = CreateBlockRequestInternal(spec, state, parent, miner, withdrawals, blobGasUsed, excessBlobGas, transactions: transactions, beaconParentBlockRoot: beaconParentBlockRoot); - BeaconBlockRootPrecompile.Instance.SetupBeaconBlockRootPrecompileState(spec, state, blockRequestV3.ParentBeaconBlockRoot, blockRequestV3.Timestamp); + blockRequestV3.TryGetBlock(out Block? block); + _beaconBlockRootHandler.HandleBeaconBlockRoot(block!, spec, state); + state.Commit(spec); state.CommitTree(blockRequestV3.BlockNumber); diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs index abe7a3f24e6..c767054ac7b 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs @@ -10,6 +10,7 @@ using Nethermind.Blockchain.Synchronization; using Nethermind.Config; using Nethermind.Consensus; +using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Comparers; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Producers; @@ -223,7 +224,8 @@ protected override IBlockProcessor CreateBlockProcessor() State, ReceiptStorage, NullWitnessCollector.Instance, - LogManager); + LogManager, + beaconBlockRootHandler: new BeaconBlockRootHandler()); return new TestBlockProcessorInterceptor(processor, _blockProcessingThrottle); } diff --git a/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs b/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs index 2155ea50b7f..20f270ce199 100644 --- a/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs +++ b/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs @@ -9,6 +9,7 @@ using Nethermind.Blockchain; using Nethermind.Config; using Nethermind.Consensus; +using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Comparers; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Producers; @@ -206,7 +207,8 @@ protected override BlockProcessor CreateBlockProcessor() State, ReceiptStorage, NullWitnessCollector.Instance, - LogManager); + LogManager, + beaconBlockRootHandler: new BeaconBlockRootHandler()); _tracerFactory = new TracerFactory( DbProvider, diff --git a/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs index a3ca85cfec9..e40e0396da3 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs @@ -43,6 +43,7 @@ using BlockTree = Nethermind.Blockchain.BlockTree; using Nethermind.Synchronization.SnapSync; using Nethermind.Config; +using Nethermind.Consensus.BeaconBlockRoot; namespace Nethermind.Synchronization.Test { @@ -299,7 +300,7 @@ private SyncTestContext CreateSyncManager(int index) stateProvider, receiptStorage, NullWitnessCollector.Instance, - logManager); + logManager, beaconBlockRootHandler: new BeaconBlockRootHandler()); RecoverSignatures step = new(ecdsa, txPool, specProvider, logManager); BlockchainProcessor processor = new(tree, blockProcessor, step, stateReader, logManager, @@ -321,7 +322,7 @@ private SyncTestContext CreateSyncManager(int index) devState, receiptStorage, NullWitnessCollector.Instance, - logManager); + logManager, beaconBlockRootHandler: new BeaconBlockRootHandler()); BlockchainProcessor devChainProcessor = new(tree, devBlockProcessor, step, stateReader, logManager, BlockchainProcessor.Options.NoReceipts); From b2a1456cae57b1a6dbe3d00afd23adc0c331035d Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Mon, 31 Jul 2023 15:04:36 +0100 Subject: [PATCH 19/43] - Removed unnecessary "null" default value --- .../Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs index 0b58ce8f0bc..f93d876bb04 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV3.cs @@ -43,7 +43,7 @@ public ExecutionPayloadV3(Block block) : base(block) /// EIP-4788. /// [JsonIgnore] - public Keccak? ParentBeaconBlockRoot { get; set; } = null; + public Keccak? ParentBeaconBlockRoot { get; set; } public override bool TryGetBlock(out Block? block, UInt256? totalDifficulty = null) { From 8d45da3d0fa93600e3c9a67350e82f50d0f45b36 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Mon, 31 Jul 2023 15:07:34 +0100 Subject: [PATCH 20/43] - Fixed some naming inconsistensies --- src/Nethermind/Nethermind.Evm/GasCostOf.cs | 2 +- src/Nethermind/Nethermind.Evm/Metrics.cs | 2 +- .../Precompiles/Stateful/BeaconBlockRootPrecompile.cs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Evm/GasCostOf.cs b/src/Nethermind/Nethermind.Evm/GasCostOf.cs index 8c51d8bd144..6cd434c45a1 100644 --- a/src/Nethermind/Nethermind.Evm/GasCostOf.cs +++ b/src/Nethermind/Nethermind.Evm/GasCostOf.cs @@ -54,7 +54,7 @@ public static class GasCostOf public const long InitCodeWord = 2; //eip-3860 gas per word cost for init code size public const long ColdSLoad = 2100; // eip-2929 - public const long ParentBeaconBlockPrecompile = ColdSLoad * 2; // Eip hardcded 4200 // eip-2929 + public const long BeaconBlockRootPrecompile = ColdSLoad * 2; // Eip hardcded 4200 // eip-2929 public const long ColdAccountAccess = 2600; // eip-2929 public const long WarmStateRead = 100; // eip-2929 diff --git a/src/Nethermind/Nethermind.Evm/Metrics.cs b/src/Nethermind/Nethermind.Evm/Metrics.cs index 3ff6f21472b..28983fe03a1 100644 --- a/src/Nethermind/Nethermind.Evm/Metrics.cs +++ b/src/Nethermind/Nethermind.Evm/Metrics.cs @@ -86,7 +86,7 @@ public class Metrics [CounterMetric] [Description("Number of Parent Beacon Block Root precompile calls.")] - public static int ParentBeaconBlockRootPrecompile { get; set; } + public static int BeaconBlockRootPrecompile { get; set; } [Description("Number of calls made to addresses without code.")] diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs index 4664162f8bc..a548c4c5971 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs @@ -21,7 +21,7 @@ private byte[] SloadFromStorage(IWorldState state, in UInt256 index) public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState state) { - Metrics.ParentBeaconBlockRootPrecompile++; + Metrics.BeaconBlockRootPrecompile++; if (inputData.Length != Keccak.Size) { @@ -46,7 +46,7 @@ private byte[] SloadFromStorage(IWorldState state, in UInt256 index) public long BaseGasCost(IReleaseSpec releaseSpec) { - return GasCostOf.ParentBeaconBlockPrecompile; + return GasCostOf.BeaconBlockRootPrecompile; } public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) From dcf7998e0f9846d66f221f75b8ae0fe4aedbdc8b Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Mon, 31 Jul 2023 15:09:20 +0100 Subject: [PATCH 21/43] - Fix ws problems --- .../Nethermind.Clique.Test/CliqueBlockProducerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs index d7b17a93fa3..e798c852e95 100644 --- a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs +++ b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs @@ -134,7 +134,7 @@ public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = f NullReceiptStorage.Instance, NullWitnessCollector.Instance, nodeLogManager, - beaconBlockRootHandler: new BeaconBlockRootHandler()); + beaconBlockRootHandler: new BeaconBlockRootHandler()); BlockchainProcessor processor = new(blockTree, blockProcessor, new AuthorRecoveryStep(snapshotManager), stateReader, nodeLogManager, BlockchainProcessor.Options.NoReceipts); processor.Start(); From 011687dd57e0dd7cbdbdfb191565215ddafca8cc Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Mon, 31 Jul 2023 15:53:10 +0100 Subject: [PATCH 22/43] - Fix default behavior of beaconBlockRootHandler argument in BlockProcessor.ctor --- ...RpcModuleTests.TestAccountAbstractionRpcBlockchain.cs | 3 +-- .../Nethermind.Blockchain.Test/BlockProcessorTests.cs | 9 +++------ .../Producers/DevBlockproducerTests.cs | 3 +-- src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs | 3 +-- .../Nethermind.Clique.Test/CliqueBlockProducerTests.cs | 6 ++---- .../Nethermind.Consensus/Processing/BlockProcessor.cs | 4 ++-- .../Processing/ReadOnlyChainProcessingEnv.cs | 3 +-- .../Producers/BlockProducerEnvFactory.cs | 3 +-- .../Nethermind.Core.Test/Blockchain/TestBlockchain.cs | 3 +-- .../Modules/Trace/ParityStyleTracerTests.cs | 3 +-- .../EngineModuleTests.Setup.cs | 3 +-- .../MevRpcModuleTests.TestMevRpcBlockchain.cs | 3 +-- .../Nethermind.Synchronization.Test/SyncThreadTests.cs | 4 ++-- 13 files changed, 18 insertions(+), 32 deletions(-) diff --git a/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs b/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs index e291cba930c..0e8a3bbee22 100644 --- a/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs +++ b/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs @@ -193,8 +193,7 @@ protected override BlockProcessor CreateBlockProcessor() State, ReceiptStorage, NullWitnessCollector.Instance, - LogManager, - beaconBlockRootHandler: new BeaconBlockRootHandler()); + LogManager); var parser = new AbiDefinitionParser(); parser.RegisterAbiTypeFactory(new AbiTuple()); diff --git a/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs index 228bf57dbf7..907602dc071 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs @@ -52,8 +52,7 @@ public void Prepared_block_contains_author_field() stateProvider, NullReceiptStorage.Instance, NullWitnessCollector.Instance, - LimboLogs.Instance, - beaconBlockRootHandler: new BeaconBlockRootHandler()); + LimboLogs.Instance); BlockHeader header = Build.A.BlockHeader.WithAuthor(TestItem.AddressD).TestObject; Block block = Build.A.Block.WithHeader(header).TestObject; @@ -84,8 +83,7 @@ public void Can_store_a_witness() stateProvider, NullReceiptStorage.Instance, witnessCollector, - LimboLogs.Instance, - beaconBlockRootHandler: new BeaconBlockRootHandler()); + LimboLogs.Instance); BlockHeader header = Build.A.BlockHeader.WithAuthor(TestItem.AddressD).TestObject; Block block = Build.A.Block.WithHeader(header).TestObject; @@ -114,8 +112,7 @@ public void Recovers_state_on_cancel() stateProvider, NullReceiptStorage.Instance, NullWitnessCollector.Instance, - LimboLogs.Instance, - beaconBlockRootHandler: new BeaconBlockRootHandler()); + LimboLogs.Instance); BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithAuthor(TestItem.AddressD).TestObject; Block block = Build.A.Block.WithTransactions(1, MuirGlacier.Instance).WithHeader(header).TestObject; diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs index 07ef04cf183..dc1feb3f289 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs @@ -77,8 +77,7 @@ public void Test() stateProvider, NullReceiptStorage.Instance, NullWitnessCollector.Instance, - LimboLogs.Instance, - beaconBlockRootHandler: new BeaconBlockRootHandler()); + LimboLogs.Instance); BlockchainProcessor blockchainProcessor = new( blockTree, blockProcessor, diff --git a/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs index d6cafc04d0a..92d4b1d13f4 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs @@ -86,8 +86,7 @@ public void Setup() stateProvider, NullReceiptStorage.Instance, new WitnessCollector(memDbProvider.StateDb, LimboLogs.Instance), - LimboLogs.Instance, - beaconBlockRootHandler: new BeaconBlockRootHandler()); + LimboLogs.Instance); _blockchainProcessor = new BlockchainProcessor( _blockTree, blockProcessor, diff --git a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs index e798c852e95..e37d0499fa5 100644 --- a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs +++ b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs @@ -133,8 +133,7 @@ public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = f stateProvider, NullReceiptStorage.Instance, NullWitnessCollector.Instance, - nodeLogManager, - beaconBlockRootHandler: new BeaconBlockRootHandler()); + nodeLogManager); BlockchainProcessor processor = new(blockTree, blockProcessor, new AuthorRecoveryStep(snapshotManager), stateReader, nodeLogManager, BlockchainProcessor.Options.NoReceipts); processor.Start(); @@ -153,8 +152,7 @@ public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = f minerStateProvider, NullReceiptStorage.Instance, NullWitnessCollector.Instance, - nodeLogManager, - beaconBlockRootHandler: new BeaconBlockRootHandler()); + nodeLogManager); BlockchainProcessor minerProcessor = new(blockTree, minerBlockProcessor, new AuthorRecoveryStep(snapshotManager), stateReader, nodeLogManager, BlockchainProcessor.Options.NoReceipts); diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs index ca17e95f466..fc14690cf9c 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs @@ -57,7 +57,7 @@ public BlockProcessor( IWitnessCollector? witnessCollector, ILogManager? logManager, IWithdrawalProcessor? withdrawalProcessor = null, - IBeaconBlockRootHandler? beaconBlockRootHandler = null) + IBeaconBlockRootHandler beaconBlockRootHandler = null) { _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider)); @@ -68,7 +68,7 @@ public BlockProcessor( _withdrawalProcessor = withdrawalProcessor ?? new WithdrawalProcessor(stateProvider, logManager); _rewardCalculator = rewardCalculator ?? throw new ArgumentNullException(nameof(rewardCalculator)); _blockTransactionsExecutor = blockTransactionsExecutor ?? throw new ArgumentNullException(nameof(blockTransactionsExecutor)); - _beaconBlockRootHandler = beaconBlockRootHandler ?? throw new ArgumentNullException(nameof(beaconBlockRootHandler)); + _beaconBlockRootHandler = beaconBlockRootHandler ?? new BeaconBlockRootHandler(); _receiptsTracer = new BlockReceiptsTracer(); } diff --git a/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs b/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs index 77ef0e87bc2..17b1d1c0264 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs @@ -51,8 +51,7 @@ public ReadOnlyChainProcessingEnv( StateProvider, receiptStorage, NullWitnessCollector.Instance, - logManager, - beaconBlockRootHandler: new BeaconBlockRootHandler()); + logManager); _blockProcessingQueue = new BlockchainProcessor(_txEnv.BlockTree, BlockProcessor, recoveryStep, _txEnv.StateReader, logManager, BlockchainProcessor.Options.NoReceipts); BlockProcessingQueue = _blockProcessingQueue; diff --git a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs index 9bef9948d42..a2c6fb85a83 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs @@ -150,8 +150,7 @@ protected virtual BlockProcessor CreateBlockProcessor(ReadOnlyTxProcessingEnv re receiptStorage, NullWitnessCollector.Instance, logManager, - new BlockProductionWithdrawalProcessor(new WithdrawalProcessor(readOnlyTxProcessingEnv.StateProvider, logManager)), - new BeaconBlockRootHandler()); + new BlockProductionWithdrawalProcessor(new WithdrawalProcessor(readOnlyTxProcessingEnv.StateProvider, logManager))); } } diff --git a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs index c3f32abc498..44d5a4020e2 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -352,8 +352,7 @@ protected virtual IBlockProcessor CreateBlockProcessor() => State, ReceiptStorage, NullWitnessCollector.Instance, - LogManager, - beaconBlockRootHandler: BeaconBlockRootHandler); + LogManager); public async Task WaitForNewHead() { diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs index f0c88cd08ea..fc63ad785c9 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs @@ -77,8 +77,7 @@ public void Setup() stateProvider, NullReceiptStorage.Instance, NullWitnessCollector.Instance, - LimboLogs.Instance, - beaconBlockRootHandler: new BeaconBlockRootHandler()); + LimboLogs.Instance); RecoverSignatures txRecovery = new(new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance), NullTxPool.Instance, specProvider, LimboLogs.Instance); _processor = new BlockchainProcessor(_blockTree, blockProcessor, txRecovery, stateReader, LimboLogs.Instance, BlockchainProcessor.Options.NoReceipts); diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs index c767054ac7b..d9593b1a2aa 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs @@ -224,8 +224,7 @@ protected override IBlockProcessor CreateBlockProcessor() State, ReceiptStorage, NullWitnessCollector.Instance, - LogManager, - beaconBlockRootHandler: new BeaconBlockRootHandler()); + LogManager); return new TestBlockProcessorInterceptor(processor, _blockProcessingThrottle); } diff --git a/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs b/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs index 20f270ce199..94ec284d6a4 100644 --- a/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs +++ b/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs @@ -207,8 +207,7 @@ protected override BlockProcessor CreateBlockProcessor() State, ReceiptStorage, NullWitnessCollector.Instance, - LogManager, - beaconBlockRootHandler: new BeaconBlockRootHandler()); + LogManager); _tracerFactory = new TracerFactory( DbProvider, diff --git a/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs index e40e0396da3..627f66976d2 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs @@ -300,7 +300,7 @@ private SyncTestContext CreateSyncManager(int index) stateProvider, receiptStorage, NullWitnessCollector.Instance, - logManager, beaconBlockRootHandler: new BeaconBlockRootHandler()); + logManager); RecoverSignatures step = new(ecdsa, txPool, specProvider, logManager); BlockchainProcessor processor = new(tree, blockProcessor, step, stateReader, logManager, @@ -322,7 +322,7 @@ private SyncTestContext CreateSyncManager(int index) devState, receiptStorage, NullWitnessCollector.Instance, - logManager, beaconBlockRootHandler: new BeaconBlockRootHandler()); + logManager); BlockchainProcessor devChainProcessor = new(tree, devBlockProcessor, step, stateReader, logManager, BlockchainProcessor.Options.NoReceipts); From 5c2da2f8518ae558bfcaf241ed0fc7a468f131af Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Thu, 3 Aug 2023 17:34:07 +0100 Subject: [PATCH 23/43] - fix --- .../Producers/PayloadAttributes.cs | 11 +++++++---- .../EngineModuleTests.V3.cs | 7 ++++--- .../Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs | 4 ++++ .../Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs | 2 +- .../Handlers/EngineRpcCapabilitiesProvider.cs | 1 + .../IEngineRpcModule.Cancun.cs | 8 ++++++++ 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs index b1d2d9e353f..c565ba7f813 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs @@ -15,7 +15,7 @@ namespace Nethermind.Consensus.Producers; -public class PayloadAttributes +public class PayloadAttributes { public ulong Timestamp { get; set; } @@ -90,7 +90,7 @@ public static string ComputePayloadId(this PayloadAttributes payloadAttributes, } public static int GetVersion(this PayloadAttributes executionPayload) => - executionPayload.Withdrawals is null ? 1 : 2; + executionPayload.Withdrawals is null ? 1 : executionPayload.BeaconParentBlockRoot is null ? 2 : 3; public static bool Validate( this PayloadAttributes payloadAttributes, @@ -102,9 +102,12 @@ public static bool Validate( error = actualVersion switch { - 1 when spec.WithdrawalsEnabled => "PayloadAttributesV2 expected", + <= 1 when spec.WithdrawalsEnabled => "PayloadAttributesV2 expected", > 1 when !spec.WithdrawalsEnabled => "PayloadAttributesV1 expected", - _ => actualVersion > version ? $"PayloadAttributesV{version} expected" : null + <= 2 when spec.IsBeaconBlockRootAvailable => "PayloadAttributesV3 expected", + > 2 when !spec.IsBeaconBlockRootAvailable => "PayloadAttributesV2 or PayloadAttributesV1 expected", + _ when actualVersion > version => $"PayloadAttributesV{version} expected", + _ => null }; return error is null; diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs index 60e4964f186..56ca14691a8 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs @@ -406,12 +406,13 @@ private async Task SendNewBlockV3(IEngineRpcModule rpc, MergeT PrevRandao = TestItem.KeccakH, SuggestedFeeRecipient = TestItem.AddressF, Withdrawals = new List { TestItem.WithdrawalA_1Eth }, - BeaconParentBlockRoot = TestItem.KeccakE + BeaconParentBlockRoot = spec.IsBeaconBlockRootAvailable ? TestItem.KeccakE : null }; Keccak currentHeadHash = chain.BlockTree.HeadHash; ForkchoiceStateV1 forkchoiceState = new(currentHeadHash, currentHeadHash, currentHeadHash); - string payloadId = rpcModule.engine_forkchoiceUpdatedV2(forkchoiceState, payloadAttributes).Result.Data - .PayloadId!; + string payloadId = spec.IsBeaconBlockRootAvailable + ? rpcModule.engine_forkchoiceUpdatedV3(forkchoiceState, payloadAttributes).Result.Data.PayloadId! + : rpcModule.engine_forkchoiceUpdatedV2(forkchoiceState, payloadAttributes).Result.Data.PayloadId!; return (rpcModule, payloadId, txs); } } diff --git a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs index 02307d25209..340350e7b32 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Nethermind.Consensus.Producers; using Nethermind.Core.Extensions; using Nethermind.JsonRpc; using Nethermind.Merge.Plugin.Data; @@ -16,6 +17,9 @@ public partial class EngineRpcModule : IEngineRpcModule { private readonly IAsyncHandler _getPayloadHandlerV3; + public Task> engine_forkchoiceUpdatedV3(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes = null) + => ForkchoiceUpdated(forkchoiceState, payloadAttributes, 3); + public Task> engine_newPayloadV3(ExecutionPayloadV3 executionPayload, byte[]?[] blobVersionedHashes, byte[]? parentBeaconBlockRoot) => NewPayload(new ExecutionPayloadV3Params(executionPayload, blobVersionedHashes, parentBeaconBlockRoot), 3); diff --git a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs index 585af416360..38ae6d49c41 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs @@ -41,7 +41,7 @@ private async Task> ForkchoiceUpdated(F if (payloadAttributes?.Validate(_specProvider, version, out string? error) == false) { if (_logger.IsWarn) _logger.Warn(error); - return ResultWrapper.Fail(error, ErrorCodes.InvalidParams); + return ResultWrapper.Fail(error, version == 3 ? ErrorCodes.UnsupportedFork : ErrorCodes.InvalidParams); } if (await _locker.WaitAsync(_timeout)) diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Handlers/EngineRpcCapabilitiesProvider.cs b/src/Nethermind/Nethermind.Merge.Plugin/Handlers/EngineRpcCapabilitiesProvider.cs index 2248b429359..1d69034f935 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Handlers/EngineRpcCapabilitiesProvider.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Handlers/EngineRpcCapabilitiesProvider.cs @@ -42,6 +42,7 @@ public EngineRpcCapabilitiesProvider(ISpecProvider specProvider) #region Cancun _capabilities[nameof(IEngineRpcModule.engine_getPayloadV3)] = (spec.IsEip4844Enabled, spec.IsEip4844Enabled); + _capabilities[nameof(IEngineRpcModule.engine_forkchoiceUpdatedV3)] = (spec.IsEip4844Enabled, spec.IsEip4844Enabled); _capabilities[nameof(IEngineRpcModule.engine_newPayloadV3)] = (spec.IsEip4844Enabled, spec.IsEip4844Enabled); #endregion } diff --git a/src/Nethermind/Nethermind.Merge.Plugin/IEngineRpcModule.Cancun.cs b/src/Nethermind/Nethermind.Merge.Plugin/IEngineRpcModule.Cancun.cs index 5b3520337cc..fa3c978842f 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/IEngineRpcModule.Cancun.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/IEngineRpcModule.Cancun.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using System.Threading.Tasks; +using Nethermind.Consensus.Producers; using Nethermind.JsonRpc; using Nethermind.JsonRpc.Modules; using Nethermind.Merge.Plugin.Data; @@ -10,6 +11,13 @@ 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_forkchoiceUpdatedV3(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes = null); + [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, From cac566fe4bc2a3c5b410a7fec14635cf6df79bfa Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Thu, 3 Aug 2023 21:41:25 +0100 Subject: [PATCH 24/43] - Fix ws --- .../Nethermind.Consensus/Producers/PayloadAttributes.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs index c565ba7f813..c6b3fda1eb7 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs @@ -15,7 +15,7 @@ namespace Nethermind.Consensus.Producers; -public class PayloadAttributes +public class PayloadAttributes { public ulong Timestamp { get; set; } @@ -106,7 +106,7 @@ public static bool Validate( > 1 when !spec.WithdrawalsEnabled => "PayloadAttributesV1 expected", <= 2 when spec.IsBeaconBlockRootAvailable => "PayloadAttributesV3 expected", > 2 when !spec.IsBeaconBlockRootAvailable => "PayloadAttributesV2 or PayloadAttributesV1 expected", - _ when actualVersion > version => $"PayloadAttributesV{version} expected", + _ when actualVersion > version => $"PayloadAttributesV{version} expected", _ => null }; From ce1cb7cf6b1466025145755e65c021bb353d2807 Mon Sep 17 00:00:00 2001 From: "lukasz.rozmej" Date: Fri, 4 Aug 2023 12:05:52 +0200 Subject: [PATCH 25/43] small improvements --- .../Nethermind.Consensus/Producers/PayloadAttributes.cs | 7 ++++++- .../Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs | 5 +++-- .../Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs | 7 ++++--- .../Nethermind.Merge.Plugin/EngineRpcModule.Shanghai.cs | 5 +++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs index c6b3fda1eb7..3bf1828dbca 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs @@ -90,7 +90,12 @@ public static string ComputePayloadId(this PayloadAttributes payloadAttributes, } public static int GetVersion(this PayloadAttributes executionPayload) => - executionPayload.Withdrawals is null ? 1 : executionPayload.BeaconParentBlockRoot is null ? 2 : 3; + executionPayload switch + { + { BeaconParentBlockRoot: not null, Withdrawals: not null } => 3, + { Withdrawals: not null } => 2, + _ => 1 + }; public static bool Validate( this PayloadAttributes payloadAttributes, diff --git a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs index 340350e7b32..af06cc8939e 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs @@ -16,12 +16,13 @@ namespace Nethermind.Merge.Plugin; public partial class EngineRpcModule : IEngineRpcModule { private readonly IAsyncHandler _getPayloadHandlerV3; + public const int CancunVersion = 3; public Task> engine_forkchoiceUpdatedV3(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes = null) - => ForkchoiceUpdated(forkchoiceState, payloadAttributes, 3); + => ForkchoiceUpdated(forkchoiceState, payloadAttributes, CancunVersion); public Task> engine_newPayloadV3(ExecutionPayloadV3 executionPayload, byte[]?[] blobVersionedHashes, byte[]? parentBeaconBlockRoot) => - NewPayload(new ExecutionPayloadV3Params(executionPayload, blobVersionedHashes, parentBeaconBlockRoot), 3); + NewPayload(new ExecutionPayloadV3Params(executionPayload, blobVersionedHashes, parentBeaconBlockRoot), CancunVersion); public async Task> engine_getPayloadV3(byte[] payloadId) => await _getPayloadHandlerV3.HandleAsync(payloadId); diff --git a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs index 38ae6d49c41..daca3b99a23 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs @@ -23,25 +23,26 @@ public partial class EngineRpcModule : IEngineRpcModule private readonly SemaphoreSlim _locker = new(1, 1); private readonly TimeSpan _timeout = TimeSpan.FromSeconds(8); private readonly GCKeeper _gcKeeper; + public const int ParisVersion = 1; public ResultWrapper engine_exchangeTransitionConfigurationV1( TransitionConfigurationV1 beaconTransitionConfiguration) => _transitionConfigurationHandler.Handle(beaconTransitionConfiguration); public async Task> engine_forkchoiceUpdatedV1(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes = null) - => await ForkchoiceUpdated(forkchoiceState, payloadAttributes, 1); + => await ForkchoiceUpdated(forkchoiceState, payloadAttributes, ParisVersion); public Task> engine_getPayloadV1(byte[] payloadId) => _getPayloadHandlerV1.HandleAsync(payloadId); public async Task> engine_newPayloadV1(ExecutionPayload executionPayload) - => await NewPayload(executionPayload, 1); + => await NewPayload(executionPayload, ParisVersion); private async Task> ForkchoiceUpdated(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes, int version) { if (payloadAttributes?.Validate(_specProvider, version, out string? error) == false) { if (_logger.IsWarn) _logger.Warn(error); - return ResultWrapper.Fail(error, version == 3 ? ErrorCodes.UnsupportedFork : ErrorCodes.InvalidParams); + return ResultWrapper.Fail(error, version >= CancunVersion ? ErrorCodes.UnsupportedFork : ErrorCodes.InvalidParams); } if (await _locker.WaitAsync(_timeout)) diff --git a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Shanghai.cs b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Shanghai.cs index 99792015ae3..544c57c9266 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Shanghai.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Shanghai.cs @@ -16,9 +16,10 @@ public partial class EngineRpcModule : IEngineRpcModule private readonly IAsyncHandler, IEnumerable> _executionGetPayloadBodiesByHashV1Handler; private readonly IGetPayloadBodiesByRangeV1Handler _executionGetPayloadBodiesByRangeV1Handler; private readonly IAsyncHandler _getPayloadHandlerV2; + public const int ShanghaiVersion = 2; public Task> engine_forkchoiceUpdatedV2(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes = null) - => ForkchoiceUpdated(forkchoiceState, payloadAttributes, 2); + => ForkchoiceUpdated(forkchoiceState, payloadAttributes, ShanghaiVersion); public Task> engine_getPayloadV2(byte[] payloadId) => _getPayloadHandlerV2.HandleAsync(payloadId); @@ -30,5 +31,5 @@ public Task> engine_forkchoiceUpdatedV2 => _executionGetPayloadBodiesByRangeV1Handler.Handle(start, count); public Task> engine_newPayloadV2(ExecutionPayload executionPayload) - => NewPayload(executionPayload, 2); + => NewPayload(executionPayload, ShanghaiVersion); } From 8b411d590fd6651eabc583e96dac64109962c068 Mon Sep 17 00:00:00 2001 From: "lukasz.rozmej" Date: Fri, 4 Aug 2023 12:10:55 +0200 Subject: [PATCH 26/43] Add EngineApiVersions --- .../Nethermind.Consensus/EgineApiVersions.cs | 11 +++++++++++ .../Producers/PayloadAttributes.cs | 6 +++--- .../Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs | 6 +++--- .../Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs | 8 ++++---- .../EngineRpcModule.Shanghai.cs | 8 ++++---- 5 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 src/Nethermind/Nethermind.Consensus/EgineApiVersions.cs diff --git a/src/Nethermind/Nethermind.Consensus/EgineApiVersions.cs b/src/Nethermind/Nethermind.Consensus/EgineApiVersions.cs new file mode 100644 index 00000000000..2a00c892d58 --- /dev/null +++ b/src/Nethermind/Nethermind.Consensus/EgineApiVersions.cs @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +namespace Nethermind.Consensus; + +public static class EngineApiVersions +{ + public const int Paris = 1; + public const int Shanghai = 2; + public const int Cancun = 3; +} diff --git a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs index 3bf1828dbca..6451826b923 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs @@ -92,9 +92,9 @@ public static string ComputePayloadId(this PayloadAttributes payloadAttributes, public static int GetVersion(this PayloadAttributes executionPayload) => executionPayload switch { - { BeaconParentBlockRoot: not null, Withdrawals: not null } => 3, - { Withdrawals: not null } => 2, - _ => 1 + { BeaconParentBlockRoot: not null, Withdrawals: not null } => EngineApiVersions.Cancun, + { Withdrawals: not null } => EngineApiVersions.Shanghai, + _ => EngineApiVersions.Paris }; public static bool Validate( diff --git a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs index af06cc8939e..688f4ff0db3 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Cancun.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Nethermind.Consensus; using Nethermind.Consensus.Producers; using Nethermind.Core.Extensions; using Nethermind.JsonRpc; @@ -16,13 +17,12 @@ namespace Nethermind.Merge.Plugin; public partial class EngineRpcModule : IEngineRpcModule { private readonly IAsyncHandler _getPayloadHandlerV3; - public const int CancunVersion = 3; public Task> engine_forkchoiceUpdatedV3(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes = null) - => ForkchoiceUpdated(forkchoiceState, payloadAttributes, CancunVersion); + => ForkchoiceUpdated(forkchoiceState, payloadAttributes, EngineApiVersions.Cancun); public Task> engine_newPayloadV3(ExecutionPayloadV3 executionPayload, byte[]?[] blobVersionedHashes, byte[]? parentBeaconBlockRoot) => - NewPayload(new ExecutionPayloadV3Params(executionPayload, blobVersionedHashes, parentBeaconBlockRoot), CancunVersion); + NewPayload(new ExecutionPayloadV3Params(executionPayload, blobVersionedHashes, parentBeaconBlockRoot), EngineApiVersions.Cancun); public async Task> engine_getPayloadV3(byte[] payloadId) => await _getPayloadHandlerV3.HandleAsync(payloadId); diff --git a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs index daca3b99a23..23a4c9740c9 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Paris.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Threading; using System.Threading.Tasks; +using Nethermind.Consensus; using Nethermind.Consensus.Producers; using Nethermind.Core.Specs; using Nethermind.JsonRpc; @@ -23,26 +24,25 @@ public partial class EngineRpcModule : IEngineRpcModule private readonly SemaphoreSlim _locker = new(1, 1); private readonly TimeSpan _timeout = TimeSpan.FromSeconds(8); private readonly GCKeeper _gcKeeper; - public const int ParisVersion = 1; public ResultWrapper engine_exchangeTransitionConfigurationV1( TransitionConfigurationV1 beaconTransitionConfiguration) => _transitionConfigurationHandler.Handle(beaconTransitionConfiguration); public async Task> engine_forkchoiceUpdatedV1(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes = null) - => await ForkchoiceUpdated(forkchoiceState, payloadAttributes, ParisVersion); + => await ForkchoiceUpdated(forkchoiceState, payloadAttributes, EngineApiVersions.Paris); public Task> engine_getPayloadV1(byte[] payloadId) => _getPayloadHandlerV1.HandleAsync(payloadId); public async Task> engine_newPayloadV1(ExecutionPayload executionPayload) - => await NewPayload(executionPayload, ParisVersion); + => await NewPayload(executionPayload, EngineApiVersions.Paris); private async Task> ForkchoiceUpdated(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes, int version) { if (payloadAttributes?.Validate(_specProvider, version, out string? error) == false) { if (_logger.IsWarn) _logger.Warn(error); - return ResultWrapper.Fail(error, version >= CancunVersion ? ErrorCodes.UnsupportedFork : ErrorCodes.InvalidParams); + return ResultWrapper.Fail(error, version >= EngineApiVersions.Cancun ? ErrorCodes.UnsupportedFork : ErrorCodes.InvalidParams); } if (await _locker.WaitAsync(_timeout)) diff --git a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Shanghai.cs b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Shanghai.cs index 544c57c9266..9a763427453 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Shanghai.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Shanghai.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Threading.Tasks; +using Nethermind.Consensus; using Nethermind.Consensus.Producers; using Nethermind.Core.Crypto; using Nethermind.JsonRpc; @@ -16,10 +17,9 @@ public partial class EngineRpcModule : IEngineRpcModule private readonly IAsyncHandler, IEnumerable> _executionGetPayloadBodiesByHashV1Handler; private readonly IGetPayloadBodiesByRangeV1Handler _executionGetPayloadBodiesByRangeV1Handler; private readonly IAsyncHandler _getPayloadHandlerV2; - public const int ShanghaiVersion = 2; - + public Task> engine_forkchoiceUpdatedV2(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes = null) - => ForkchoiceUpdated(forkchoiceState, payloadAttributes, ShanghaiVersion); + => ForkchoiceUpdated(forkchoiceState, payloadAttributes, EngineApiVersions.Shanghai); public Task> engine_getPayloadV2(byte[] payloadId) => _getPayloadHandlerV2.HandleAsync(payloadId); @@ -31,5 +31,5 @@ public Task> engine_forkchoiceUpdatedV2 => _executionGetPayloadBodiesByRangeV1Handler.Handle(start, count); public Task> engine_newPayloadV2(ExecutionPayload executionPayload) - => NewPayload(executionPayload, ShanghaiVersion); + => NewPayload(executionPayload, EngineApiVersions.Shanghai); } From c2d18767ec95292d500713b9fbbfb11027b3416a Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Fri, 4 Aug 2023 11:56:17 +0100 Subject: [PATCH 27/43] - refactor PayloadAttributes.Validate --- .../Producers/PayloadAttributes.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs index 6451826b923..71aa6f71a2a 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs @@ -97,6 +97,14 @@ public static int GetVersion(this PayloadAttributes executionPayload) => _ => EngineApiVersions.Paris }; + public static int ExpectedVersion(this IReleaseSpec spec) => + spec switch + { + { WithdrawalsEnabled: true, IsBeaconBlockRootAvailable: true } => EngineApiVersions.Cancun, + { WithdrawalsEnabled: true } => EngineApiVersions.Shanghai, + _ => EngineApiVersions.Paris + }; + public static bool Validate( this PayloadAttributes payloadAttributes, IReleaseSpec spec, @@ -104,13 +112,11 @@ public static bool Validate( [NotNullWhen(false)] out string? error) { int actualVersion = payloadAttributes.GetVersion(); + int expectedVersion = spec.ExpectedVersion(); error = actualVersion switch { - <= 1 when spec.WithdrawalsEnabled => "PayloadAttributesV2 expected", - > 1 when !spec.WithdrawalsEnabled => "PayloadAttributesV1 expected", - <= 2 when spec.IsBeaconBlockRootAvailable => "PayloadAttributesV3 expected", - > 2 when !spec.IsBeaconBlockRootAvailable => "PayloadAttributesV2 or PayloadAttributesV1 expected", + _ when actualVersion != expectedVersion => $"PayloadAttributesV{expectedVersion} expected", _ when actualVersion > version => $"PayloadAttributesV{version} expected", _ => null }; From 2a822bb3bf2fa98807286f80b54a9e7725f099dc Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Fri, 4 Aug 2023 12:35:18 +0100 Subject: [PATCH 28/43] - ws fix --- src/Nethermind/Nethermind.Consensus/EgineApiVersions.cs | 2 +- .../Nethermind.Merge.Plugin/EngineRpcModule.Shanghai.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/EgineApiVersions.cs b/src/Nethermind/Nethermind.Consensus/EgineApiVersions.cs index 2a00c892d58..598c8784907 100644 --- a/src/Nethermind/Nethermind.Consensus/EgineApiVersions.cs +++ b/src/Nethermind/Nethermind.Consensus/EgineApiVersions.cs @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited +// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only namespace Nethermind.Consensus; diff --git a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Shanghai.cs b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Shanghai.cs index 9a763427453..8c29a9ba971 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Shanghai.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.Shanghai.cs @@ -17,7 +17,7 @@ public partial class EngineRpcModule : IEngineRpcModule private readonly IAsyncHandler, IEnumerable> _executionGetPayloadBodiesByHashV1Handler; private readonly IGetPayloadBodiesByRangeV1Handler _executionGetPayloadBodiesByRangeV1Handler; private readonly IAsyncHandler _getPayloadHandlerV2; - + public Task> engine_forkchoiceUpdatedV2(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes = null) => ForkchoiceUpdated(forkchoiceState, payloadAttributes, EngineApiVersions.Shanghai); From 3d975ef3759987fadbe4ac9876134e5a2cd10c4d Mon Sep 17 00:00:00 2001 From: Alexey Date: Fri, 4 Aug 2023 17:48:20 +0300 Subject: [PATCH 29/43] Init beacon root precompile state for genesis (#5982) --- .../BeaconBlockRoot/BeaconBlockRootHandler.cs | 0 .../BeaconBlockRoot/IBeaconBlockRootHandler.cs | 0 src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs | 5 +++++ .../Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs | 6 ++++++ .../ChainSpecStyle/Json/ChainSpecGenesisJson.cs | 1 + 5 files changed, 12 insertions(+) rename src/Nethermind/{Nethermind.Consensus => Nethermind.Blockchain}/BeaconBlockRoot/BeaconBlockRootHandler.cs (100%) rename src/Nethermind/{Nethermind.Consensus => Nethermind.Blockchain}/BeaconBlockRoot/IBeaconBlockRootHandler.cs (100%) diff --git a/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/BeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs similarity index 100% rename from src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/BeaconBlockRootHandler.cs rename to src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs diff --git a/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/IBeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs similarity index 100% rename from src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/IBeaconBlockRootHandler.cs rename to src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs diff --git a/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs b/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs index 8cac17f0ed3..77aad4871d2 100644 --- a/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs +++ b/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs @@ -15,6 +15,7 @@ using Nethermind.Evm.TransactionProcessing; using Nethermind.Specs.ChainSpecStyle; using Nethermind.State; +using Nethermind.Consensus.BeaconBlockRoot; namespace Nethermind.Blockchain { @@ -24,6 +25,7 @@ public class GenesisLoader private readonly ISpecProvider _specProvider; private readonly IWorldState _stateProvider; private readonly ITransactionProcessor _transactionProcessor; + private readonly BeaconBlockRootHandler _beaconBlockRootHandler; public GenesisLoader( ChainSpec chainSpec, @@ -35,6 +37,7 @@ public GenesisLoader( _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider)); _stateProvider = stateProvider ?? throw new ArgumentNullException(nameof(stateProvider)); _transactionProcessor = transactionProcessor ?? throw new ArgumentNullException(nameof(transactionProcessor)); + _beaconBlockRootHandler = new BeaconBlockRootHandler(); } public Block Load() @@ -45,6 +48,8 @@ public Block Load() // we no longer need the allocations - 0.5MB RAM, 9000 objects for mainnet _chainSpec.Allocations = null; + _beaconBlockRootHandler?.HandleBeaconBlockRoot(genesis, _specProvider.GenesisSpec, _stateProvider); + _stateProvider.Commit(_specProvider.GenesisSpec, true); _stateProvider.CommitTree(0); diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs index d0e10630fbc..5362e45e86b 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs @@ -389,6 +389,12 @@ private static void LoadGenesis(ChainSpecJson chainSpecJson, ChainSpec chainSpec genesisHeader.ExcessBlobGas = chainSpecJson.Genesis.ExcessBlobGas; } + bool isEip4788Enabled = chainSpecJson.Params.Eip4788TransitionTimestamp != null && genesisHeader.Timestamp >= chainSpecJson.Params.Eip4788TransitionTimestamp; + if (isEip4788Enabled) + { + genesisHeader.ParentBeaconBlockRoot = chainSpecJson.Genesis.ParentBeaconBlockRoot; + } + genesisHeader.AuRaStep = step; genesisHeader.AuRaSignature = auRaSignature; diff --git a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/Json/ChainSpecGenesisJson.cs b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/Json/ChainSpecGenesisJson.cs index c6ef813acb5..52190d8a622 100644 --- a/src/Nethermind/Nethermind.Specs/ChainSpecStyle/Json/ChainSpecGenesisJson.cs +++ b/src/Nethermind/Nethermind.Specs/ChainSpecStyle/Json/ChainSpecGenesisJson.cs @@ -25,5 +25,6 @@ internal class ChainSpecGenesisJson public ulong? BlobGasUsed { get; set; } public ulong? ExcessBlobGas { get; set; } + public Keccak ParentBeaconBlockRoot { get; set; } } } From 467d74c6d990d350c6112b12024614dd44d6bab6 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Mon, 7 Aug 2023 12:20:00 +0100 Subject: [PATCH 30/43] - Applied suggested changes --- .../AuraBlockProcessorTests.cs | 1 - .../AuRaContractGasLimitOverrideTests.cs | 1 - .../Transactions/TxCertifierFilterTests.cs | 3 +-- .../Transactions/TxPermissionFilterTest.cs | 1 - .../AuRaBlockProcessor.cs | 4 +--- .../NullBeaconBlockRootHandler.cs | 2 +- .../InitializeBlockchainAuRa.cs | 1 - .../StartBlockProducerAuRa.cs | 1 - .../BeaconBlockRoot/BeaconBlockRootHandler.cs | 2 +- .../BeaconBlockRoot/IBeaconBlockRootHandler.cs | 2 +- .../Processing/BlockProcessor.cs | 7 +++---- .../Producers/PayloadAttributes.cs | 17 +++++++++-------- .../Blockchain/TestBlockchain.cs | 2 +- .../AuRaMergeBlockProcessor.cs | 2 -- .../AuRaMergeBlockProducerEnvFactory.cs | 4 +--- .../InitializeBlockchainAuRaMerge.cs | 1 - .../EngineModuleTests.HelperFunctions.cs | 2 +- 17 files changed, 20 insertions(+), 33 deletions(-) diff --git a/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs b/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs index 470b1eaf80e..86a4359df7b 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs @@ -162,7 +162,6 @@ void Process(AuRaBlockProcessor auRaBlockProcessor, int blockNumber, Keccak stat LimboLogs.Instance, Substitute.For(), new WithdrawalProcessor(stateProvider, LimboLogs.Instance), - new BeaconBlockRootHandler(), txFilter, contractRewriter: contractRewriter); diff --git a/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs b/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs index 189dbe8933b..b8cd92cd95d 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs @@ -101,7 +101,6 @@ protected override BlockProcessor CreateBlockProcessor() LimboLogs.Instance, BlockTree, NullWithdrawalProcessor.Instance, - NullBeaconBlockRootHandler.Instance, null, GasLimitCalculator as AuRaContractGasLimitOverride); } diff --git a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs index 526f7308fcb..9817d8f1359 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs @@ -157,8 +157,7 @@ protected override BlockProcessor CreateBlockProcessor() ReceiptStorage, LimboLogs.Instance, BlockTree, - NullWithdrawalProcessor.Instance, - NullBeaconBlockRootHandler.Instance); + NullWithdrawalProcessor.Instance); } protected override Task AddBlocksOnStart() => Task.CompletedTask; diff --git a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs index 1e15b2d3e9a..d75d7130308 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs @@ -299,7 +299,6 @@ protected override BlockProcessor CreateBlockProcessor() LimboLogs.Instance, BlockTree, NullWithdrawalProcessor.Instance, - NullBeaconBlockRootHandler.Instance, PermissionBasedTxFilter); } diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs b/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs index 9c765af5886..34956b42472 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs @@ -44,7 +44,6 @@ public AuRaBlockProcessor( ILogManager logManager, IBlockTree blockTree, IWithdrawalProcessor withdrawalProcessor, - IBeaconBlockRootHandler beaconBlockRootHandler, ITxFilter? txFilter = null, AuRaContractGasLimitOverride? gasLimitOverride = null, ContractRewriter? contractRewriter = null) @@ -57,8 +56,7 @@ public AuRaBlockProcessor( receiptStorage, NullWitnessCollector.Instance, logManager, - withdrawalProcessor, - beaconBlockRootHandler) + withdrawalProcessor) { _specProvider = specProvider; _blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree)); diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs index dcc3ff88734..692e729113c 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs @@ -14,7 +14,7 @@ namespace Nethermind.Consensus.AuRa.BeaconBlockRoot; internal class NullBeaconBlockRootHandler : IBeaconBlockRootHandler { - public void HandleBeaconBlockRoot(Block block, IReleaseSpec spec, IWorldState state) + public void InitStatefulPrecompiles(Block block, IReleaseSpec spec, IWorldState state) { } diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs index c6e91c70949..31471d7d057 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs @@ -98,7 +98,6 @@ protected virtual BlockProcessor NewBlockProcessor(AuRaNethermindApi api, ITxFil _api.LogManager, _api.BlockTree, NullWithdrawalProcessor.Instance, - NullBeaconBlockRootHandler.Instance, txFilter, GetGasLimitCalculator(), contractRewriter diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs index c181b8cfbf6..2307baacbe5 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs @@ -160,7 +160,6 @@ private BlockProcessor CreateBlockProcessor(ReadOnlyTxProcessingEnv changeableTx _api.LogManager, changeableTxProcessingEnv.BlockTree, NullWithdrawalProcessor.Instance, - NullBeaconBlockRootHandler.Instance, auRaTxFilter, CreateGasLimitCalculator(constantContractTxProcessingEnv) as AuRaContractGasLimitOverride, contractRewriter) diff --git a/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/BeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/BeaconBlockRootHandler.cs index 92f6a588b59..aa7ccb0998c 100644 --- a/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/BeaconBlockRootHandler.cs +++ b/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/BeaconBlockRootHandler.cs @@ -17,7 +17,7 @@ namespace Nethermind.Consensus.BeaconBlockRoot; public class BeaconBlockRootHandler : IBeaconBlockRootHandler { - public void HandleBeaconBlockRoot(Block block, IReleaseSpec spec, IWorldState stateProvider) + public void InitStatefulPrecompiles(Block block, IReleaseSpec spec, IWorldState stateProvider) { if (!spec.IsBeaconBlockRootAvailable) return; diff --git a/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/IBeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/IBeaconBlockRootHandler.cs index fd9f875827c..c5df8917040 100644 --- a/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/IBeaconBlockRootHandler.cs +++ b/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/IBeaconBlockRootHandler.cs @@ -13,5 +13,5 @@ namespace Nethermind.Consensus.BeaconBlockRoot; public interface IBeaconBlockRootHandler { - void HandleBeaconBlockRoot(Block block, IReleaseSpec spec, IWorldState state); + void InitStatefulPrecompiles(Block block, IReleaseSpec spec, IWorldState state); } diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs index fc14690cf9c..2f749df9848 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs @@ -56,8 +56,7 @@ public BlockProcessor( IReceiptStorage? receiptStorage, IWitnessCollector? witnessCollector, ILogManager? logManager, - IWithdrawalProcessor? withdrawalProcessor = null, - IBeaconBlockRootHandler beaconBlockRootHandler = null) + IWithdrawalProcessor? withdrawalProcessor = null) { _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider)); @@ -68,7 +67,7 @@ public BlockProcessor( _withdrawalProcessor = withdrawalProcessor ?? new WithdrawalProcessor(stateProvider, logManager); _rewardCalculator = rewardCalculator ?? throw new ArgumentNullException(nameof(rewardCalculator)); _blockTransactionsExecutor = blockTransactionsExecutor ?? throw new ArgumentNullException(nameof(blockTransactionsExecutor)); - _beaconBlockRootHandler = beaconBlockRootHandler ?? new BeaconBlockRootHandler(); + _beaconBlockRootHandler = new BeaconBlockRootHandler(); _receiptsTracer = new BlockReceiptsTracer(); } @@ -229,7 +228,7 @@ protected virtual TxReceipt[] ProcessBlock( _receiptsTracer.SetOtherTracer(blockTracer); _receiptsTracer.StartNewBlockTrace(block); - _beaconBlockRootHandler.HandleBeaconBlockRoot(block, spec, _stateProvider); + _beaconBlockRootHandler.InitStatefulPrecompiles(block, spec, _stateProvider); TxReceipt[] receipts = _blockTransactionsExecutor.ProcessTransactions(block, options, _receiptsTracer, spec); diff --git a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs index 71aa6f71a2a..449fdc1e40d 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs @@ -97,7 +97,7 @@ public static int GetVersion(this PayloadAttributes executionPayload) => _ => EngineApiVersions.Paris }; - public static int ExpectedVersion(this IReleaseSpec spec) => + public static int ExpectedEngineSpecVersion(this IReleaseSpec spec) => spec switch { { WithdrawalsEnabled: true, IsBeaconBlockRootAvailable: true } => EngineApiVersions.Cancun, @@ -112,15 +112,16 @@ public static bool Validate( [NotNullWhen(false)] out string? error) { int actualVersion = payloadAttributes.GetVersion(); - int expectedVersion = spec.ExpectedVersion(); + int expectedVersion = spec.ExpectedEngineSpecVersion(); - error = actualVersion switch + error = null; + if(actualVersion != expectedVersion) { - _ when actualVersion != expectedVersion => $"PayloadAttributesV{expectedVersion} expected", - _ when actualVersion > version => $"PayloadAttributesV{version} expected", - _ => null - }; - + error = $"PayloadAttributesV{expectedVersion} expected"; + } else if(actualVersion > version) + { + error = $"PayloadAttributesV{version} expected"; + } return error is null; } diff --git a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs index 44d5a4020e2..85ac4557efc 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -326,7 +326,7 @@ protected virtual Block GetGenesisBlock() if (SpecProvider.GenesisSpec.IsBeaconBlockRootAvailable) { - BeaconBlockRootHandler.HandleBeaconBlockRoot(genesisBlockBuilder.TestObject, SpecProvider.GenesisSpec, State); + BeaconBlockRootHandler.InitStatefulPrecompiles(genesisBlockBuilder.TestObject, SpecProvider.GenesisSpec, State); State.Commit(SpecProvider.GenesisSpec); State.CommitTree(0); diff --git a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs index 8a982a4c7d4..a43ae3613dc 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs @@ -31,7 +31,6 @@ public AuRaMergeBlockProcessor( ILogManager logManager, IBlockTree blockTree, IWithdrawalProcessor withdrawalProcessor, - IBeaconBlockRootHandler beaconBlockRootHandler, ITxFilter? txFilter = null, AuRaContractGasLimitOverride? gasLimitOverride = null, ContractRewriter? contractRewriter = null @@ -45,7 +44,6 @@ public AuRaMergeBlockProcessor( logManager, blockTree, withdrawalProcessor, - beaconBlockRootHandler, txFilter, gasLimitOverride, contractRewriter diff --git a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs index 82e52156bdb..a7124794e22 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs @@ -88,9 +88,7 @@ protected override BlockProcessor CreateBlockProcessor( withdrawalContractFactory.Create(readOnlyTxProcessingEnv.TransactionProcessor), logManager ) - ), - new BeaconBlockRootHandler() - ); + )); } protected override TxPoolTxSource CreateTxPoolTxSource( diff --git a/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs b/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs index 64c6d1770fc..73bed01f05e 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs @@ -40,7 +40,6 @@ protected override BlockProcessor NewBlockProcessor(AuRaNethermindApi api, ITxFi _api.BlockTree!, new AuraWithdrawalProcessor( withdrawalContractFactory.Create(_api.TransactionProcessor!), _api.LogManager), - new BeaconBlockRootHandler(), txFilter, GetGasLimitCalculator(), contractRewriter diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs index e47769ab920..36f116dcba3 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs @@ -95,7 +95,7 @@ private static ExecutionPayloadV3 CreateBlockRequestV3(IReleaseSpec spec, IWorld { var blockRequestV3 = CreateBlockRequestInternal(spec, state, parent, miner, withdrawals, blobGasUsed, excessBlobGas, transactions: transactions, beaconParentBlockRoot: beaconParentBlockRoot); blockRequestV3.TryGetBlock(out Block? block); - _beaconBlockRootHandler.HandleBeaconBlockRoot(block!, spec, state); + _beaconBlockRootHandler.InitStatefulPrecompiles(block!, spec, state); state.Commit(spec); state.CommitTree(blockRequestV3.BlockNumber); From 2e3c632d4920a8ff8e2e4a5ec422d2e5709e7289 Mon Sep 17 00:00:00 2001 From: Alexey Osipov Date: Tue, 8 Aug 2023 10:53:08 +0300 Subject: [PATCH 31/43] Fix merge --- src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs b/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs index 77aad4871d2..7e25b52eca9 100644 --- a/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs +++ b/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs @@ -48,7 +48,7 @@ public Block Load() // we no longer need the allocations - 0.5MB RAM, 9000 objects for mainnet _chainSpec.Allocations = null; - _beaconBlockRootHandler?.HandleBeaconBlockRoot(genesis, _specProvider.GenesisSpec, _stateProvider); + _beaconBlockRootHandler?.InitStatefulPrecompiles(genesis, _specProvider.GenesisSpec, _stateProvider); _stateProvider.Commit(_specProvider.GenesisSpec, true); From 763d03271e5db7d9af8f6d6e9a56616e27adb45e Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Tue, 8 Aug 2023 13:28:08 +0100 Subject: [PATCH 32/43] - Added a engine_fcuV3 test --- .../EngineModuleTests.V3.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs index 56ca14691a8..81b2b5ad3f6 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs @@ -8,6 +8,8 @@ using System.Threading; using System.Threading.Tasks; using FluentAssertions; +using k8s; +using Nethermind.Consensus; using Nethermind.Consensus.Producers; using Nethermind.Core; using Nethermind.Core.Crypto; @@ -110,6 +112,31 @@ public async Task GetPayloadV3_should_fail_on_unknown_payload() responseFirst.ErrorCode.Should().Be(MergeErrorCodes.UnknownPayload); } + [TestCase(1, true)] + [TestCase(2, true)] + [TestCase(3, false)] + public async Task ForkchoiceUpdatedV3_should_fail_on_wrong_payloadVersion(int version, bool shoudlFail) + { + using SemaphoreSlim blockImprovementLock = new(0); + using MergeTestBlockchain chain = await CreateBlockchain(Cancun.Instance); + IEngineRpcModule rpc = CreateEngineModule(chain); + + Keccak currentHeadHash = chain.BlockTree.HeadHash; + ForkchoiceStateV1 forkchoiceState = new(currentHeadHash, currentHeadHash, currentHeadHash); + PayloadAttributes payloadAttributes = new() + { + Timestamp = chain.BlockTree.Head!.Timestamp + 1, + PrevRandao = TestItem.KeccakH, + SuggestedFeeRecipient = TestItem.AddressF, + Withdrawals = version >= EngineApiVersions.Shanghai ? new List { TestItem.WithdrawalA_1Eth } : null, + BeaconParentBlockRoot = version >= EngineApiVersions.Cancun ? TestItem.KeccakE : null + }; + + ResultWrapper responseFirst = await rpc.engine_forkchoiceUpdatedV3(forkchoiceState, payloadAttributes); + responseFirst.Should().NotBeNull(); + responseFirst.Result.ResultType.Should().Be(shoudlFail ? ResultType.Failure : ResultType.Success); + } + [TestCase(0)] [TestCase(1)] [TestCase(2)] From c4c4b120fc9b29eeaccb920fd05d821584eac391 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Tue, 8 Aug 2023 13:50:50 +0100 Subject: [PATCH 33/43] - Add simple BeaconParentBlockRoot test for NewPayloadV3 --- .../EngineModuleTests.V3.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs index 81b2b5ad3f6..9f5588ce0b0 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs @@ -153,6 +153,21 @@ public async Task GetPayloadV3_should_return_all_the_blobs(int blobTxCount) Assert.That(getPayloadResultBlobsBundle.Proofs!.Length, Is.EqualTo(blobTxCount)); } + [TestCase(true, PayloadStatus.Valid)] + [TestCase(false, PayloadStatus.Invalid)] + public virtual async Task NewPayloadV3_should_fail_on_null_parentBeaconBlockHash(bool includeParentBeaconBlockRoot, string expectedPayloadStatus) + { + (IEngineRpcModule rpcModule, string payloadId, Transaction[] transactions) = await BuildAndGetPayloadV3Result(Cancun.Instance, 1); + + ExecutionPayloadV3 payload = (await rpcModule.engine_getPayloadV3(Bytes.FromHexString(payloadId))).Data!.ExecutionPayload; + + byte[]?[] blobVersionedHashes = transactions.SelectMany(tx => tx.BlobVersionedHashes ?? Array.Empty()).ToArray(); + ResultWrapper result = await rpcModule.engine_newPayloadV3(payload, blobVersionedHashes, includeParentBeaconBlockRoot ? payload.ParentBeaconBlockRoot.BytesToArray() : null); + + Assert.That(result.ErrorCode, Is.EqualTo(ErrorCodes.None)); + result.Data.Status.Should().Be(expectedPayloadStatus); + } + [TestCase(false, PayloadStatus.Valid)] [TestCase(true, PayloadStatus.Invalid)] public virtual async Task NewPayloadV3_should_decline_mempool_encoding(bool inMempoolForm, string expectedPayloadStatus) From 14476489032187ab5a73f4dfca6105e01223a328 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Tue, 8 Aug 2023 14:18:23 +0100 Subject: [PATCH 34/43] - Assert precompile creation at cancun block execution --- .../BlockProcessorTests.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs index 907602dc071..53455af5f39 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs @@ -96,6 +96,42 @@ public void Can_store_a_witness() witnessCollector.Received(1).Persist(block.Hash); } + [Test, Timeout(Timeout.MaxTestTime)] + public void Creates_BeaconRootPrecompile_on_cancun_genesis() + { + IDb stateDb = new MemDb(); + IDb codeDb = new MemDb(); + var trieStore = new TrieStore(stateDb, LimboLogs.Instance); + + IWorldState stateProvider = new WorldState(trieStore, codeDb, LimboLogs.Instance); + ITransactionProcessor transactionProcessor = Substitute.For(); + IWitnessCollector witnessCollector = Substitute.For(); + BlockProcessor processor = new( + new TestSpecProvider(Cancun.Instance), + TestBlockValidator.AlwaysValid, + NoBlockRewards.Instance, + new BlockProcessor.BlockValidationTransactionsExecutor(transactionProcessor, stateProvider), + stateProvider, + NullReceiptStorage.Instance, + witnessCollector, + LimboLogs.Instance); + + BlockHeader header = Build.A.BlockHeader.WithAuthor(TestItem.AddressD).TestObject; + Block block = Build.A.Block.WithHeader(header) + .WithParentBeaconBlockRoot(Keccak.Zero) + .TestObject; + + Assert.IsFalse(stateProvider.AccountExists(Evm.Precompiles.Stateful.BeaconBlockRootPrecompile.Address)); + + _ = processor.Process( + Keccak.EmptyTreeHash, + new List { block }, + ProcessingOptions.None, + NullBlockTracer.Instance); + + Assert.IsTrue(stateProvider.AccountExists(Evm.Precompiles.Stateful.BeaconBlockRootPrecompile.Address)); + } + [Test, Timeout(Timeout.MaxTestTime)] public void Recovers_state_on_cancel() { From 3a5379aa181dfb470d8131a4edcf4c537083d9cb Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Tue, 8 Aug 2023 17:13:51 +0100 Subject: [PATCH 35/43] - Applied flcl's fixes --- .../BeaconBlockRoot/BeaconBlockRootHandler.cs | 4 ++-- .../Producers/BlockProducerBase.cs | 2 +- .../Producers/PayloadAttributes.cs | 12 ++++++------ .../EngineModuleTests.V3.cs | 4 ++-- .../Data/IExecutionPayloadParams.cs | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/BeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/BeaconBlockRootHandler.cs index aa7ccb0998c..814e5cdebb1 100644 --- a/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/BeaconBlockRootHandler.cs +++ b/src/Nethermind/Nethermind.Consensus/BeaconBlockRoot/BeaconBlockRootHandler.cs @@ -12,7 +12,7 @@ using Nethermind.Int256; using Nethermind.State; using static Nethermind.Evm.Precompiles.Stateful.BeaconBlockRootPrecompile; - +using Nethermind.Core.Crypto; namespace Nethermind.Consensus.BeaconBlockRoot; public class BeaconBlockRootHandler : IBeaconBlockRootHandler @@ -24,7 +24,7 @@ public void InitStatefulPrecompiles(Block block, IReleaseSpec spec, IWorldState var timestamp = (UInt256)block.Timestamp; var parentBeaconBlockRoot = block.ParentBeaconBlockRoot; - stateProvider.CreateAccountIfNotExists(BeaconBlockRootPrecompile.Address, 1); + if (parentBeaconBlockRoot is null && block.Header.IsGenesis) parentBeaconBlockRoot = Keccak.Zero; UInt256.Mod(timestamp, HISTORICAL_ROOTS_LENGTH, out UInt256 timestampReduced); UInt256 rootIndex = timestampReduced + HISTORICAL_ROOTS_LENGTH; diff --git a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs index 3472a76a298..4e593141924 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerBase.cs @@ -292,7 +292,7 @@ protected virtual BlockHeader PrepareBlockHeader(BlockHeader parent, { Author = blockAuthor, MixHash = payloadAttributes?.PrevRandao, - ParentBeaconBlockRoot = payloadAttributes?.BeaconParentBlockRoot + ParentBeaconBlockRoot = payloadAttributes?.ParentBeaconBlockRoot }; 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 449fdc1e40d..81ee746f7ec 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs @@ -25,7 +25,7 @@ public class PayloadAttributes public IList? Withdrawals { get; set; } - public Keccak? BeaconParentBlockRoot { get; set; } + public Keccak? ParentBeaconBlockRoot { get; set; } /// Gets or sets the gas limit. /// Used for MEV-Boost only. public long? GasLimit { get; set; } @@ -44,9 +44,9 @@ public string ToString(string indentation) sb.Append($", {nameof(Withdrawals)} count: {Withdrawals.Count}"); } - if (BeaconParentBlockRoot is not null) + if (ParentBeaconBlockRoot is not null) { - sb.Append($", {nameof(BeaconParentBlockRoot)} : {BeaconParentBlockRoot}"); + sb.Append($", {nameof(ParentBeaconBlockRoot)} : {ParentBeaconBlockRoot}"); } sb.Append('}'); @@ -60,7 +60,7 @@ public static class PayloadAttributesExtensions public static string ComputePayloadId(this PayloadAttributes payloadAttributes, BlockHeader parentHeader) { bool hasWithdrawals = payloadAttributes.Withdrawals is not null; - bool hasBeaconParentBlockRoot = payloadAttributes.BeaconParentBlockRoot is not null; + bool hasBeaconParentBlockRoot = payloadAttributes.ParentBeaconBlockRoot is not null; const int preambleLength = Keccak.Size + Keccak.Size + Keccak.Size + Address.ByteLength; Span inputSpan = stackalloc byte[preambleLength + (hasWithdrawals ? Keccak.Size : 0) + (hasBeaconParentBlockRoot ? Keccak.Size : 0)]; @@ -81,7 +81,7 @@ public static string ComputePayloadId(this PayloadAttributes payloadAttributes, if (hasBeaconParentBlockRoot) { - payloadAttributes.BeaconParentBlockRoot.Bytes.CopyTo(inputSpan[(preambleLength + (hasWithdrawals ? Keccak.Size : 0))..]); + payloadAttributes.ParentBeaconBlockRoot.Bytes.CopyTo(inputSpan[(preambleLength + (hasWithdrawals ? Keccak.Size : 0))..]); } ValueKeccak inputHash = ValueKeccak.Compute(inputSpan); @@ -92,7 +92,7 @@ public static string ComputePayloadId(this PayloadAttributes payloadAttributes, public static int GetVersion(this PayloadAttributes executionPayload) => executionPayload switch { - { BeaconParentBlockRoot: not null, Withdrawals: not null } => EngineApiVersions.Cancun, + { ParentBeaconBlockRoot: not null, Withdrawals: not null } => EngineApiVersions.Cancun, { Withdrawals: not null } => EngineApiVersions.Shanghai, _ => EngineApiVersions.Paris }; diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs index 9f5588ce0b0..fab7650deec 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V3.cs @@ -129,7 +129,7 @@ public async Task ForkchoiceUpdatedV3_should_fail_on_wrong_payloadVersion(int ve PrevRandao = TestItem.KeccakH, SuggestedFeeRecipient = TestItem.AddressF, Withdrawals = version >= EngineApiVersions.Shanghai ? new List { TestItem.WithdrawalA_1Eth } : null, - BeaconParentBlockRoot = version >= EngineApiVersions.Cancun ? TestItem.KeccakE : null + ParentBeaconBlockRoot = version >= EngineApiVersions.Cancun ? TestItem.KeccakE : null }; ResultWrapper responseFirst = await rpc.engine_forkchoiceUpdatedV3(forkchoiceState, payloadAttributes); @@ -448,7 +448,7 @@ private async Task SendNewBlockV3(IEngineRpcModule rpc, MergeT PrevRandao = TestItem.KeccakH, SuggestedFeeRecipient = TestItem.AddressF, Withdrawals = new List { TestItem.WithdrawalA_1Eth }, - BeaconParentBlockRoot = spec.IsBeaconBlockRootAvailable ? TestItem.KeccakE : null + ParentBeaconBlockRoot = spec.IsBeaconBlockRootAvailable ? TestItem.KeccakE : null }; Keccak currentHeadHash = chain.BlockTree.HeadHash; ForkchoiceStateV1 forkchoiceState = new(currentHeadHash, currentHeadHash, currentHeadHash); diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs index bc641ad7429..5aa2404d32a 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/IExecutionPayloadParams.cs @@ -61,7 +61,7 @@ public ValidationResult ValidateParams(IReleaseSpec spec, int version, out strin if (_parentBeaconBlockRoot is null) { error = "Parent beacon block root must be set"; - return ValidationResult.Invalid; + return ValidationResult.Fail; } _executionPayload.ParentBeaconBlockRoot = new Keccak(_parentBeaconBlockRoot); From a9a7e36c617a51142b058022de1c5188a308e161 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Tue, 8 Aug 2023 17:17:12 +0100 Subject: [PATCH 36/43] - naming fix --- .../Nethermind.JsonRpc/Modules/Eth/BlockForRpc.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/BlockForRpc.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/BlockForRpc.cs index 73463787df9..e991e3fd6ac 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/BlockForRpc.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Eth/BlockForRpc.cs @@ -61,6 +61,11 @@ public BlockForRpc(Block block, bool includeFullTransactionData, ISpecProvider s BlobGasUsed = block.Header.BlobGasUsed; ExcessBlobGas = block.Header.ExcessBlobGas; } + + if (spec.IsEip4788Enabled) + { + ParentBeaconBlockRoot = block.ParentBeaconBlockRoot; + } } Number = block.Number; @@ -76,7 +81,7 @@ public BlockForRpc(Block block, bool includeFullTransactionData, ISpecProvider s Uncles = block.Uncles.Select(o => o.Hash); Withdrawals = block.Withdrawals; WithdrawalsRoot = block.Header.WithdrawalsRoot; - ParentBeackBlockRoot = block.ParentBeaconBlockRoot; + ParentBeaconBlockRoot = block.ParentBeaconBlockRoot; } public Address Author { get; set; } @@ -133,5 +138,5 @@ public BlockForRpc(Block block, bool includeFullTransactionData, ISpecProvider s public ulong? ExcessBlobGas { get; set; } [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] - public Keccak? ParentBeackBlockRoot { get; set; } + public Keccak? ParentBeaconBlockRoot { get; set; } } From ddb026298f7a3bb80aaa895ddf702f0a63157556 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Wed, 9 Aug 2023 14:27:05 +0100 Subject: [PATCH 37/43] - ignore 0x0b from precompile checks --- src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs b/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs index 6ce10061194..d41e5cc6446 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/AddressExtensions.cs @@ -27,7 +27,7 @@ public static bool IsPrecompile(this Address address, IReleaseSpec releaseSpec) 0x08 => releaseSpec.Bn128Enabled, 0x09 => releaseSpec.BlakeEnabled, 0x0a => releaseSpec.IsEip4844Enabled, - 0x0b => releaseSpec.IsBeaconBlockRootAvailable, + // 0x0b => releaseSpec.IsBeaconBlockRootAvailable, 0x0c => releaseSpec.Bls381Enabled, 0x0d => releaseSpec.Bls381Enabled, 0x0e => releaseSpec.Bls381Enabled, From 1edb45270625180fc7a20e53ee4b69d905953c41 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Thu, 17 Aug 2023 10:02:54 +0100 Subject: [PATCH 38/43] - applied some Alexey's fixes --- .../BeaconBlockRoot/BeaconBlockRootHandler.cs | 20 ++++++++++--------- .../IBeaconBlockRootHandler.cs | 2 +- .../NullBeaconBlockRootHandler.cs | 2 +- .../Processing/BlockProcessor.cs | 3 ++- .../Blockchain/TestBlockchain.cs | 2 +- .../EngineModuleTests.HelperFunctions.cs | 2 +- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs index 814e5cdebb1..df75c096f9d 100644 --- a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs +++ b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs @@ -13,18 +13,18 @@ using Nethermind.State; using static Nethermind.Evm.Precompiles.Stateful.BeaconBlockRootPrecompile; using Nethermind.Core.Crypto; - +using Nethermind.Core.Extensions; namespace Nethermind.Consensus.BeaconBlockRoot; public class BeaconBlockRootHandler : IBeaconBlockRootHandler { - public void InitStatefulPrecompiles(Block block, IReleaseSpec spec, IWorldState stateProvider) + public void UpdateState(Block block, IReleaseSpec spec, IWorldState stateProvider) { - if (!spec.IsBeaconBlockRootAvailable) return; - - var timestamp = (UInt256)block.Timestamp; - var parentBeaconBlockRoot = block.ParentBeaconBlockRoot; + if (!spec.IsBeaconBlockRootAvailable || + block.IsGenesis || + block.Header.ParentBeaconBlockRoot is null) return; - if (parentBeaconBlockRoot is null && block.Header.IsGenesis) parentBeaconBlockRoot = Keccak.Zero; + UInt256 timestamp = (UInt256)block.Timestamp; + Keccak parentBeaconBlockRoot = block.ParentBeaconBlockRoot; UInt256.Mod(timestamp, HISTORICAL_ROOTS_LENGTH, out UInt256 timestampReduced); UInt256 rootIndex = timestampReduced + HISTORICAL_ROOTS_LENGTH; @@ -32,7 +32,9 @@ public void InitStatefulPrecompiles(Block block, IReleaseSpec spec, IWorldState StorageCell tsStorageCell = new(BeaconBlockRootPrecompile.Address, timestampReduced); StorageCell brStorageCell = new(BeaconBlockRootPrecompile.Address, rootIndex); - stateProvider.Set(tsStorageCell, timestamp.ToBigEndian()); - stateProvider.Set(brStorageCell, parentBeaconBlockRoot.Bytes.ToArray()); + + + stateProvider.Set(tsStorageCell, Bytes.WithoutLeadingZeros(timestamp.ToBigEndian()).ToArray()); + stateProvider.Set(brStorageCell, Bytes.WithoutLeadingZeros(parentBeaconBlockRoot.Bytes).ToArray()); } } diff --git a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs index c5df8917040..923239582b5 100644 --- a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs +++ b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs @@ -13,5 +13,5 @@ namespace Nethermind.Consensus.BeaconBlockRoot; public interface IBeaconBlockRootHandler { - void InitStatefulPrecompiles(Block block, IReleaseSpec spec, IWorldState state); + void UpdateState(Block block, IReleaseSpec spec, IWorldState state); } diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs index 692e729113c..b6b55259702 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs @@ -14,7 +14,7 @@ namespace Nethermind.Consensus.AuRa.BeaconBlockRoot; internal class NullBeaconBlockRootHandler : IBeaconBlockRootHandler { - public void InitStatefulPrecompiles(Block block, IReleaseSpec spec, IWorldState state) + public void UpdateState(Block block, IReleaseSpec spec, IWorldState state) { } diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs index 2f749df9848..762133e921a 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs @@ -228,7 +228,8 @@ protected virtual TxReceipt[] ProcessBlock( _receiptsTracer.SetOtherTracer(blockTracer); _receiptsTracer.StartNewBlockTrace(block); - _beaconBlockRootHandler.InitStatefulPrecompiles(block, spec, _stateProvider); + _beaconBlockRootHandler.UpdateState(block, spec, _stateProvider); + _stateProvider.Commit(spec); TxReceipt[] receipts = _blockTransactionsExecutor.ProcessTransactions(block, options, _receiptsTracer, spec); diff --git a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs index 85ac4557efc..7d06fead725 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -326,7 +326,7 @@ protected virtual Block GetGenesisBlock() if (SpecProvider.GenesisSpec.IsBeaconBlockRootAvailable) { - BeaconBlockRootHandler.InitStatefulPrecompiles(genesisBlockBuilder.TestObject, SpecProvider.GenesisSpec, State); + BeaconBlockRootHandler.UpdateState(genesisBlockBuilder.TestObject, SpecProvider.GenesisSpec, State); State.Commit(SpecProvider.GenesisSpec); State.CommitTree(0); diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs index 36f116dcba3..704f857cd7d 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs @@ -95,7 +95,7 @@ private static ExecutionPayloadV3 CreateBlockRequestV3(IReleaseSpec spec, IWorld { var blockRequestV3 = CreateBlockRequestInternal(spec, state, parent, miner, withdrawals, blobGasUsed, excessBlobGas, transactions: transactions, beaconParentBlockRoot: beaconParentBlockRoot); blockRequestV3.TryGetBlock(out Block? block); - _beaconBlockRootHandler.InitStatefulPrecompiles(block!, spec, state); + _beaconBlockRootHandler.UpdateState(block!, spec, state); state.Commit(spec); state.CommitTree(blockRequestV3.BlockNumber); From 4da6ccd3cb81cd93bd0ff81bc000e72d9ae009ae Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Thu, 17 Aug 2023 10:18:54 +0100 Subject: [PATCH 39/43] - removed reference of Precompile from code --- .../AuRaContractGasLimitOverrideTests.cs | 1 - .../Transactions/TxCertifierFilterTests.cs | 1 - .../BlockProcessorTests.cs | 4 +- .../BeaconBlockRoot/BeaconBlockRootHandler.cs | 8 +-- .../Nethermind.Blockchain/GenesisLoader.cs | 2 +- .../Processing/BlockProcessor.cs | 1 - .../Blockchain/TestBlockchain.cs | 9 ++- .../BeaconParentBlockRootPrecompileTests.cs | 2 +- .../Nethermind.Evm/Nethermind.Evm.csproj | 3 + .../Stateful/BeaconBlockRootPrecompile.cs | 56 ------------------- .../Nethermind.Evm/VirtualMachine.cs | 1 - .../EngineModuleTests.HelperFunctions.cs | 1 - 12 files changed, 15 insertions(+), 74 deletions(-) delete mode 100644 src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs diff --git a/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs b/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs index b8cd92cd95d..c5f1a04d732 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Contract/AuRaContractGasLimitOverrideTests.cs @@ -8,7 +8,6 @@ using Nethermind.Abi; using Nethermind.Consensus; using Nethermind.Consensus.AuRa; -using Nethermind.Consensus.AuRa.BeaconBlockRoot; using Nethermind.Consensus.AuRa.Contracts; using Nethermind.Consensus.AuRa.Withdrawals; using Nethermind.Consensus.Processing; diff --git a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs index 9817d8f1359..887961a3c6d 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxCertifierFilterTests.cs @@ -7,7 +7,6 @@ using Nethermind.Abi; using Nethermind.AuRa.Test.Contract; using Nethermind.Consensus.AuRa; -using Nethermind.Consensus.AuRa.BeaconBlockRoot; using Nethermind.Consensus.AuRa.Contracts; using Nethermind.Consensus.AuRa.Transactions; using Nethermind.Consensus.AuRa.Withdrawals; diff --git a/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs index 53455af5f39..6c1956ae658 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs @@ -121,7 +121,7 @@ public void Creates_BeaconRootPrecompile_on_cancun_genesis() .WithParentBeaconBlockRoot(Keccak.Zero) .TestObject; - Assert.IsFalse(stateProvider.AccountExists(Evm.Precompiles.Stateful.BeaconBlockRootPrecompile.Address)); + Assert.IsFalse(stateProvider.AccountExists(BeaconBlockRootHandler.Address)); _ = processor.Process( Keccak.EmptyTreeHash, @@ -129,7 +129,7 @@ public void Creates_BeaconRootPrecompile_on_cancun_genesis() ProcessingOptions.None, NullBlockTracer.Instance); - Assert.IsTrue(stateProvider.AccountExists(Evm.Precompiles.Stateful.BeaconBlockRootPrecompile.Address)); + Assert.IsTrue(stateProvider.AccountExists(BeaconBlockRootHandler.Address)); } [Test, Timeout(Timeout.MaxTestTime)] diff --git a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs index df75c096f9d..e1f1999ad4b 100644 --- a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs +++ b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs @@ -8,15 +8,15 @@ using System.Threading.Tasks; using Nethermind.Core.Specs; using Nethermind.Core; -using Nethermind.Evm.Precompiles.Stateful; using Nethermind.Int256; using Nethermind.State; -using static Nethermind.Evm.Precompiles.Stateful.BeaconBlockRootPrecompile; using Nethermind.Core.Crypto; using Nethermind.Core.Extensions; namespace Nethermind.Consensus.BeaconBlockRoot; public class BeaconBlockRootHandler : IBeaconBlockRootHandler { + public static Address Address { get; } = Address.FromNumber(0x0B); + public static UInt256 HISTORICAL_ROOTS_LENGTH = 98304; public void UpdateState(Block block, IReleaseSpec spec, IWorldState stateProvider) { if (!spec.IsBeaconBlockRootAvailable || @@ -29,8 +29,8 @@ public void UpdateState(Block block, IReleaseSpec spec, IWorldState stateProvide UInt256.Mod(timestamp, HISTORICAL_ROOTS_LENGTH, out UInt256 timestampReduced); UInt256 rootIndex = timestampReduced + HISTORICAL_ROOTS_LENGTH; - StorageCell tsStorageCell = new(BeaconBlockRootPrecompile.Address, timestampReduced); - StorageCell brStorageCell = new(BeaconBlockRootPrecompile.Address, rootIndex); + StorageCell tsStorageCell = new(Address, timestampReduced); + StorageCell brStorageCell = new(Address, rootIndex); diff --git a/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs b/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs index 7e25b52eca9..92a86abb6e3 100644 --- a/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs +++ b/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs @@ -48,7 +48,7 @@ public Block Load() // we no longer need the allocations - 0.5MB RAM, 9000 objects for mainnet _chainSpec.Allocations = null; - _beaconBlockRootHandler?.InitStatefulPrecompiles(genesis, _specProvider.GenesisSpec, _stateProvider); + _beaconBlockRootHandler?.UpdateState(genesis, _specProvider.GenesisSpec, _stateProvider); _stateProvider.Commit(_specProvider.GenesisSpec, true); diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs index 762133e921a..3b04e947ce8 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs @@ -16,7 +16,6 @@ using Nethermind.Core.Specs; using Nethermind.Crypto; using Nethermind.Evm; -using Nethermind.Evm.Precompiles.Stateful; using Nethermind.Evm.Tracing; using Nethermind.Int256; using Nethermind.Logging; diff --git a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs index 7d06fead725..7a06b7b6b08 100644 --- a/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs +++ b/src/Nethermind/Nethermind.Core.Test/Blockchain/TestBlockchain.cs @@ -25,7 +25,6 @@ using Nethermind.Db; using Nethermind.Db.Blooms; using Nethermind.Evm; -using Nethermind.Evm.Precompiles.Stateful; using Nethermind.Evm.TransactionProcessing; using Nethermind.Int256; using Nethermind.Logging; @@ -51,7 +50,7 @@ public class TestBlockchain : IDisposable public ITxPool TxPool { get; set; } = null!; public IDb CodeDb => DbProvider.CodeDb; public IBlockProcessor BlockProcessor { get; set; } = null!; - public IBeaconBlockRootHandler BeaconBlockRootHandler { get; set; } = null!; + public IBeaconBlockRootHandler ParentBeaconBlockRootHandler { get; set; } = null!; public IBlockchainProcessor BlockchainProcessor { get; set; } = null!; public IBlockPreprocessorStep BlockPreprocessorStep { get; set; } = null!; @@ -123,7 +122,7 @@ protected virtual async Task Build(ISpecProvider? specProvider = // Eip4788 precompile state account if (specProvider?.GenesisSpec?.IsBeaconBlockRootAvailable ?? false) { - State.CreateAccount(BeaconBlockRootPrecompile.Address, 1); + State.CreateAccount(BeaconBlockRootHandler.Address, 1); } State.CreateAccount(TestItem.AddressA, (initialValues ?? InitialValue)); @@ -179,7 +178,7 @@ protected virtual async Task Build(ISpecProvider? specProvider = BloomStorage bloomStorage = new(new BloomConfig(), new MemDb(), new InMemoryDictionaryFileStoreFactory()); ReceiptsRecovery receiptsRecovery = new(new EthereumEcdsa(SpecProvider.ChainId, LimboLogs.Instance), SpecProvider); LogFinder = new LogFinder(BlockTree, ReceiptStorage, ReceiptStorage, bloomStorage, LimboLogs.Instance, receiptsRecovery); - BeaconBlockRootHandler = new BeaconBlockRootHandler(); + ParentBeaconBlockRootHandler = new BeaconBlockRootHandler(); BlockProcessor = CreateBlockProcessor(); BlockchainProcessor chainProcessor = new(BlockTree, BlockProcessor, BlockPreprocessorStep, StateReader, LogManager, Consensus.Processing.BlockchainProcessor.Options.Default); @@ -326,7 +325,7 @@ protected virtual Block GetGenesisBlock() if (SpecProvider.GenesisSpec.IsBeaconBlockRootAvailable) { - BeaconBlockRootHandler.UpdateState(genesisBlockBuilder.TestObject, SpecProvider.GenesisSpec, State); + ParentBeaconBlockRootHandler.UpdateState(genesisBlockBuilder.TestObject, SpecProvider.GenesisSpec, State); State.Commit(SpecProvider.GenesisSpec); State.CommitTree(0); diff --git a/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs b/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs index 14da91798b5..131ab43ffcc 100644 --- a/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs +++ b/src/Nethermind/Nethermind.Evm.Test/BeaconParentBlockRootPrecompileTests.cs @@ -45,7 +45,7 @@ public async Task BeaconBlockRoot_Is_Stored_Correctly_and_Only_Valid_PostCancun( { specProvider = new TestSpecProvider(testCase.Spec); TestBlockchain testBlockchain = await base.Build(specProvider, addBlockOnStart: false); - GethLikeBlockTracer? tracer = new(GethTraceOptions.Default); + GethLikeBlockMemoryTracer? tracer = new(GethTraceOptions.Default); Block block = CreateBlock(testBlockchain.State, testCase.Spec); _ = testBlockchain.BlockProcessor.Process( testBlockchain.State.StateRoot, diff --git a/src/Nethermind/Nethermind.Evm/Nethermind.Evm.csproj b/src/Nethermind/Nethermind.Evm/Nethermind.Evm.csproj index bf4f06ca167..949467e8b6c 100644 --- a/src/Nethermind/Nethermind.Evm/Nethermind.Evm.csproj +++ b/src/Nethermind/Nethermind.Evm/Nethermind.Evm.csproj @@ -17,4 +17,7 @@ + + + diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs deleted file mode 100644 index a548c4c5971..00000000000 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Stateful/BeaconBlockRootPrecompile.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using Nethermind.Core; -using Nethermind.Core.Crypto; -using Nethermind.Core.Specs; -using Nethermind.Int256; -using Nethermind.State; - -namespace Nethermind.Evm.Precompiles.Stateful; -public class BeaconBlockRootPrecompile : IPrecompile -{ - public static Address Address { get; } = Address.FromNumber(0x0B); - public static UInt256 HISTORICAL_ROOTS_LENGTH = 98304; - - public static BeaconBlockRootPrecompile Instance => new BeaconBlockRootPrecompile(); - - private byte[] SloadFromStorage(IWorldState state, in UInt256 index) - { - StorageCell storageCell = new(Address, index); - return state.Get(storageCell); - } - - public (ReadOnlyMemory, bool) Run(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec, IWorldState state) - { - Metrics.BeaconBlockRootPrecompile++; - - if (inputData.Length != Keccak.Size) - { - return (Array.Empty(), false); - } - - UInt256 timestamp = new UInt256(inputData.Span, true); - UInt256.Mod(timestamp, HISTORICAL_ROOTS_LENGTH, out UInt256 timestampReduced); - UInt256 recordedTimestamp = new UInt256(SloadFromStorage(state, timestampReduced), true); - - if (recordedTimestamp != timestamp) - { - return (default, true); - } - else - { - UInt256 timestampExtended = timestampReduced + HISTORICAL_ROOTS_LENGTH; - byte[] recordedRoot = SloadFromStorage(state, timestampExtended); - return (recordedRoot, true); - } - } - - public long BaseGasCost(IReleaseSpec releaseSpec) - { - return GasCostOf.BeaconBlockRootPrecompile; - } - - public long DataGasCost(in ReadOnlyMemory inputData, IReleaseSpec releaseSpec) - { - return 0L; - } -} diff --git a/src/Nethermind/Nethermind.Evm/VirtualMachine.cs b/src/Nethermind/Nethermind.Evm/VirtualMachine.cs index 82bd9f5f03a..86118e7dcdb 100644 --- a/src/Nethermind/Nethermind.Evm/VirtualMachine.cs +++ b/src/Nethermind/Nethermind.Evm/VirtualMachine.cs @@ -541,7 +541,6 @@ private void InitializePrecompiledContracts() [MapToG2Precompile.Address] = new(MapToG2Precompile.Instance), [PointEvaluationPrecompile.Address] = new(PointEvaluationPrecompile.Instance), - [BeaconBlockRootPrecompile.Address] = new(BeaconBlockRootPrecompile.Instance), }; } diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs index 704f857cd7d..4c5ef0aaf4e 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs @@ -21,7 +21,6 @@ using Nethermind.Specs.Forks; using Nethermind.State; using Nethermind.Core.Specs; -using Nethermind.Evm.Precompiles.Stateful; using Nethermind.Synchronization.Blocks; using Nethermind.Consensus.BeaconBlockRoot; From dc1b94e735f3bb0d76b808cb96c98c726d4aae36 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Thu, 17 Aug 2023 10:34:53 +0100 Subject: [PATCH 40/43] removed unnecessary refs of BlockRootClass --- ...tractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs | 1 - src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs | 1 - .../Producers/DevBlockproducerTests.cs | 1 - src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs | 1 - .../Nethermind.Clique.Test/CliqueBlockProducerTests.cs | 1 - src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs | 1 - .../Processing/ReadOnlyChainProcessingEnv.cs | 1 - .../Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs | 1 - .../Modules/Trace/ParityStyleTracerTests.cs | 1 - src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs | 1 - .../Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs | 1 - .../InitializationSteps/InitializeBlockchainAuRaMerge.cs | 1 - .../Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs | 1 - .../MevRpcModuleTests.TestMevRpcBlockchain.cs | 1 - .../Nethermind.Synchronization.Test/SyncThreadTests.cs | 1 - 15 files changed, 15 deletions(-) diff --git a/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs b/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs index 0e8a3bbee22..e7726ddbbe0 100644 --- a/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs +++ b/src/Nethermind/Nethermind.AccountAbstraction.Test/AccountAbstractionRpcModuleTests.TestAccountAbstractionRpcBlockchain.cs @@ -38,7 +38,6 @@ using Nethermind.State; using NSubstitute; using Nethermind.Config; -using Nethermind.Consensus.BeaconBlockRoot; namespace Nethermind.AccountAbstraction.Test { diff --git a/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs b/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs index 86a4359df7b..60033b7820c 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/AuraBlockProcessorTests.cs @@ -8,7 +8,6 @@ using Nethermind.Blockchain.Receipts; using Nethermind.Blockchain.Test.Validators; using Nethermind.Consensus.AuRa; -using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Rewards; using Nethermind.Consensus.Transactions; diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs index dc1feb3f289..c8de8362917 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Producers/DevBlockproducerTests.cs @@ -5,7 +5,6 @@ using FluentAssertions; using Nethermind.Blockchain.Receipts; using Nethermind.Config; -using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Producers; using Nethermind.Consensus.Rewards; diff --git a/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs index 92d4b1d13f4..8795add9d9c 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs @@ -7,7 +7,6 @@ using Nethermind.Blockchain.Receipts; using Nethermind.Blockchain.Spec; using Nethermind.Blockchain.Synchronization; -using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Comparers; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Rewards; diff --git a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs index e37d0499fa5..b905d8e6a49 100644 --- a/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs +++ b/src/Nethermind/Nethermind.Clique.Test/CliqueBlockProducerTests.cs @@ -37,7 +37,6 @@ using Nethermind.TxPool; using NUnit.Framework; using Nethermind.Config; -using Nethermind.Consensus.BeaconBlockRoot; namespace Nethermind.Clique.Test { diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs b/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs index 34956b42472..52dc575fab0 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/AuRaBlockProcessor.cs @@ -6,7 +6,6 @@ using Nethermind.Blockchain.Find; using Nethermind.Blockchain.Receipts; using Nethermind.Consensus.AuRa.Validators; -using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Rewards; using Nethermind.Consensus.Transactions; diff --git a/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs b/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs index 17b1d1c0264..da38938699c 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/ReadOnlyChainProcessingEnv.cs @@ -3,7 +3,6 @@ using System; using Nethermind.Blockchain.Receipts; -using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Rewards; using Nethermind.Consensus.Validators; using Nethermind.Consensus.Withdrawals; diff --git a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs index a2c6fb85a83..3d88b53ba6a 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/BlockProducerEnvFactory.cs @@ -4,7 +4,6 @@ using Nethermind.Blockchain; using Nethermind.Blockchain.Receipts; using Nethermind.Config; -using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Comparers; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Rewards; diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs index fc63ad785c9..b956aa649f5 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Trace/ParityStyleTracerTests.cs @@ -33,7 +33,6 @@ using Nethermind.Evm.TransactionProcessing; using Nethermind.Trie.Pruning; using NSubstitute; -using Nethermind.Consensus.BeaconBlockRoot; namespace Nethermind.JsonRpc.Test.Modules.Trace { diff --git a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs index a43ae3613dc..9e675bab24c 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProcessor.cs @@ -5,7 +5,6 @@ using Nethermind.Blockchain.Receipts; using Nethermind.Consensus; using Nethermind.Consensus.AuRa; -using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Rewards; using Nethermind.Consensus.Transactions; diff --git a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs index a7124794e22..fb91848e4ef 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa/AuRaMergeBlockProducerEnvFactory.cs @@ -7,7 +7,6 @@ using Nethermind.Config; using Nethermind.Consensus.AuRa.Config; using Nethermind.Consensus.AuRa.InitializationSteps; -using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Comparers; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Producers; diff --git a/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs b/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs index 73bed01f05e..d599ae32a96 100644 --- a/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs +++ b/src/Nethermind/Nethermind.Merge.AuRa/InitializationSteps/InitializeBlockchainAuRaMerge.cs @@ -7,7 +7,6 @@ using Nethermind.Consensus.AuRa.InitializationSteps; using Nethermind.Consensus.AuRa.Transactions; using Nethermind.Consensus.AuRa.Validators; -using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Transactions; using Nethermind.Core; diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs index d9593b1a2aa..abe7a3f24e6 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs @@ -10,7 +10,6 @@ using Nethermind.Blockchain.Synchronization; using Nethermind.Config; using Nethermind.Consensus; -using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Comparers; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Producers; diff --git a/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs b/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs index 94ec284d6a4..2155ea50b7f 100644 --- a/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs +++ b/src/Nethermind/Nethermind.Mev.Test/MevRpcModuleTests.TestMevRpcBlockchain.cs @@ -9,7 +9,6 @@ using Nethermind.Blockchain; using Nethermind.Config; using Nethermind.Consensus; -using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Comparers; using Nethermind.Consensus.Processing; using Nethermind.Consensus.Producers; diff --git a/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs index b8cb208c9a6..a98b8863f11 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/SyncThreadTests.cs @@ -43,7 +43,6 @@ using BlockTree = Nethermind.Blockchain.BlockTree; using Nethermind.Synchronization.SnapSync; using Nethermind.Config; -using Nethermind.Consensus.BeaconBlockRoot; namespace Nethermind.Synchronization.Test { From 1a718f3234228606b533057f57a4ecacea3705c5 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Thu, 17 Aug 2023 10:37:34 +0100 Subject: [PATCH 41/43] - removing more unnecessary refs --- .../Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs | 1 - .../InitializationSteps/InitializeBlockchainAuRa.cs | 1 - .../InitializationSteps/StartBlockProducerAuRa.cs | 1 - 3 files changed, 3 deletions(-) diff --git a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs index d75d7130308..099792d03c3 100644 --- a/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs +++ b/src/Nethermind/Nethermind.AuRa.Test/Transactions/TxPermissionFilterTest.cs @@ -30,7 +30,6 @@ using Nethermind.TxPool; using NSubstitute; using NUnit.Framework; -using Nethermind.Consensus.AuRa.BeaconBlockRoot; namespace Nethermind.AuRa.Test.Transactions; diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs index 269e6f8b39b..650a82b5dd6 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/InitializeBlockchainAuRa.cs @@ -9,7 +9,6 @@ using Nethermind.Blockchain.Data; using Nethermind.Blockchain.Services; using Nethermind.Config; -using Nethermind.Consensus.AuRa.BeaconBlockRoot; using Nethermind.Consensus.AuRa.Config; using Nethermind.Consensus.AuRa.Contracts; using Nethermind.Consensus.AuRa.Contracts.DataStore; diff --git a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs index 2307baacbe5..c8bd56c76e6 100644 --- a/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs +++ b/src/Nethermind/Nethermind.Consensus.AuRa/InitializationSteps/StartBlockProducerAuRa.cs @@ -10,7 +10,6 @@ using Nethermind.Blockchain; using Nethermind.Blockchain.Data; using Nethermind.Config; -using Nethermind.Consensus.AuRa.BeaconBlockRoot; using Nethermind.Consensus.AuRa.Config; using Nethermind.Consensus.AuRa.Contracts; using Nethermind.Consensus.AuRa.Contracts.DataStore; From 706c8dc0d556473a6ecb266d7f42bc3a8864fea1 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Thu, 17 Aug 2023 10:40:19 +0100 Subject: [PATCH 42/43] - added more of Alexey's fixes --- .../Nethermind.Consensus/Producers/PayloadAttributes.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs index 81ee746f7ec..9f02f3a6944 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs @@ -100,7 +100,7 @@ public static int GetVersion(this PayloadAttributes executionPayload) => public static int ExpectedEngineSpecVersion(this IReleaseSpec spec) => spec switch { - { WithdrawalsEnabled: true, IsBeaconBlockRootAvailable: true } => EngineApiVersions.Cancun, + { WithdrawalsEnabled: true, IsEip4844Enabled: true } => EngineApiVersions.Cancun, { WithdrawalsEnabled: true } => EngineApiVersions.Shanghai, _ => EngineApiVersions.Paris }; @@ -115,10 +115,11 @@ public static bool Validate( int expectedVersion = spec.ExpectedEngineSpecVersion(); error = null; - if(actualVersion != expectedVersion) + if (actualVersion != expectedVersion) { error = $"PayloadAttributesV{expectedVersion} expected"; - } else if(actualVersion > version) + } + else if (actualVersion > version) { error = $"PayloadAttributesV{version} expected"; } From 26ddb4938e43b35a6f524db2aa7e04c5afe365d1 Mon Sep 17 00:00:00 2001 From: Demuirgos Date: Thu, 17 Aug 2023 10:54:09 +0100 Subject: [PATCH 43/43] revert master merge --- .../EngineModuleTests.HelperFunctions.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs index 4c5ef0aaf4e..09b20cdd960 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs @@ -129,8 +129,6 @@ private static ExecutionPayloadV3 CreateBlockRequestV3(IReleaseSpec spec, IWorld blockRequestV3.ExcessBlobGas = excessBlobGas; } - - blockRequest.SetTransactions(transactions ?? Array.Empty()); TryCalculateHash(blockRequest, out Keccak? hash); blockRequest.BlockHash = hash;