From b879be227be6c791aff7e0782f39b9a457f3f80c Mon Sep 17 00:00:00 2001 From: Marcos Maceo Date: Fri, 9 Aug 2024 15:14:26 +0400 Subject: [PATCH 1/7] feat: add gnosis as optional for test cases run --- .../Ethereum.Test.Base/GeneralTestBase.cs | 83 +++++++++++++++---- .../Withdrawals/WithdrawalProcessor.cs | 5 ++ .../Nethermind.Core/BlockchainIds.cs | 4 +- .../Nethermind.Specs/GnosisSpecProvider.cs | 2 +- tools/evm/Evm.sln | 2 + tools/evm/Program.cs | 3 + tools/evm/T8NTool/InputProcessor.cs | 10 ++- tools/evm/T8NTool/T8NTool.cs | 16 +++- 8 files changed, 99 insertions(+), 26 deletions(-) diff --git a/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs b/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs index 88f4c82f131..21f0ee78cb4 100644 --- a/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs +++ b/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs @@ -41,7 +41,7 @@ public abstract class GeneralStateTestBase private static ILogger _logger = new(new ConsoleAsyncLogger(LogLevel.Info)); private static ILogManager _logManager = LimboLogs.Instance; private static readonly UInt256 _defaultBaseFeeForStateTest = 0xA; - private readonly TxValidator _txValidator = new(MainnetSpecProvider.Instance.ChainId); + private TxValidator _txValidator = new(MainnetSpecProvider.Instance.ChainId); private readonly BeaconBlockRootHandler _beaconBlockRootHandler = new(); [SetUp] @@ -60,25 +60,55 @@ protected static void Setup(ILogManager logManager) protected EthereumTestResult RunTest(GeneralStateTest test) { - return RunTest(test, NullTxTracer.Instance); + return RunTest(test, false, NullTxTracer.Instance); + } + + protected EthereumTestResult RunTest(GeneralStateTest test, bool isGnosis) + { + if (isGnosis) + { + _txValidator = new TxValidator(GnosisSpecProvider.Instance.ChainId); + } + + return RunTest(test, isGnosis, NullTxTracer.Instance); } protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer) + { + return RunTest(test, false, txTracer); + } + + protected EthereumTestResult RunTest(GeneralStateTest test, bool isGnosis, ITxTracer txTracer) { TestContext.Write($"Running {test.Name} at {DateTime.UtcNow:HH:mm:ss.ffffff}"); + Console.WriteLine("Passing over here"); Assert.IsNull(test.LoadFailure, "test data loading failure"); IDb stateDb = new MemDb(); IDb codeDb = new MemDb(); - - ISpecProvider specProvider = new CustomSpecProvider( - ((ForkActivation)0, Frontier.Instance), // TODO: this thing took a lot of time to find after it was removed!, genesis block is always initialized with Frontier - ((ForkActivation)1, test.Fork)); + ISpecProvider specProvider; + if (isGnosis) + { + specProvider = new CustomSpecProvider( + ((ForkActivation)0, + GnosisSpecProvider.Instance + .GenesisSpec), // TODO: this thing took a lot of time to find after it was removed!, genesis block is always initialized with Frontier + ((ForkActivation)1, test.Fork)); + } + else + { + specProvider = new CustomSpecProvider( + ((ForkActivation)0, + Frontier + .Instance), // TODO: this thing took a lot of time to find after it was removed!, genesis block is always initialized with Frontier + ((ForkActivation)1, test.Fork)); + } if (specProvider.GenesisSpec != Frontier.Instance) { Assert.Fail("Expected genesis spec to be Frontier for blockchain tests"); } + IReleaseSpec? spec = specProvider.GetSpec((ForkActivation)test.CurrentNumber); BlockHeader header = test.GetBlockHeader(); @@ -88,6 +118,7 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer) { test.CurrentBaseFee = header.BaseFeePerGas = CalculateBaseFeePerGas(test, parentHeader); } + if (parentHeader != null) { header.ExcessBlobGas = BlobGasCalculator.CalculateExcessBlobGas(parentHeader, spec); @@ -152,11 +183,14 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer) compositeBlockTracer.Add(storageTxTracer); if (test.IsTraceEnabled) { - GethLikeBlockFileTracer gethLikeBlockFileTracer = new(block, test.GethTraceOptions, new FileSystem()); + GethLikeBlockFileTracer gethLikeBlockFileTracer = + new(block, test.GethTraceOptions, new FileSystem()); compositeBlockTracer.Add(gethLikeBlockFileTracer); } + blockReceiptsTracer.SetOtherTracer(compositeBlockTracer); } + blockReceiptsTracer.StartNewBlockTrace(block); if (!test.IsStateTest && test.ParentBeaconBlockRoot != null) @@ -169,12 +203,14 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer) foreach (var tx in test.Transactions) { - bool isValid = _txValidator.IsWellFormed(tx, spec, out string error) && IsValidBlock(block, specProvider); + bool isValid = _txValidator.IsWellFormed(tx, spec, out string error) && + IsValidBlock(block, specProvider); if (isValid) { blockReceiptsTracer.StartNewTxTrace(tx); TransactionResult transactionResult = transactionProcessor - .Execute(tx, new BlockExecutionContext(header), test.IsT8NTest ? blockReceiptsTracer : txTracer); + .Execute(tx, new BlockExecutionContext(header), + test.IsT8NTest ? blockReceiptsTracer : txTracer); blockReceiptsTracer.EndTxTrace(); if (!test.IsT8NTest) continue; @@ -189,16 +225,21 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer) } else if (transactionResult.Error != null) { - transactionExecutionReport.RejectedTransactionReceipts.Add(new RejectedTx(txIndex, GethErrorMappings.GetErrorMapping(transactionResult.Error, tx.SenderAddress.ToString(true), tx.Nonce, stateProvider.GetNonce(tx.SenderAddress)))); + transactionExecutionReport.RejectedTransactionReceipts.Add(new RejectedTx(txIndex, + GethErrorMappings.GetErrorMapping(transactionResult.Error, tx.SenderAddress.ToString(true), + tx.Nonce, stateProvider.GetNonce(tx.SenderAddress)))); stateProvider.Reset(); } + txIndex++; } else if (error != null) { - transactionExecutionReport.RejectedTransactionReceipts.Add(new RejectedTx(txIndex, GethErrorMappings.GetErrorMapping(error))); + transactionExecutionReport.RejectedTransactionReceipts.Add(new RejectedTx(txIndex, + GethErrorMappings.GetErrorMapping(error))); } } + blockReceiptsTracer.EndBlockTrace(); stopwatch.Stop(); @@ -223,18 +264,21 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer) if (test.IsT8NTest) { - testResult.T8NResult = T8NResult.ConstructT8NResult(stateProvider, block, test, storageTxTracer, blockReceiptsTracer, specProvider, header, transactionExecutionReport); + testResult.T8NResult = T8NResult.ConstructT8NResult(stateProvider, block, test, storageTxTracer, + blockReceiptsTracer, specProvider, header, transactionExecutionReport); } return testResult; } - private static IBlockhashProvider GetBlockHashProvider(GeneralStateTest test, BlockHeader header, BlockHeader? parent) + private static IBlockhashProvider GetBlockHashProvider(GeneralStateTest test, BlockHeader header, + BlockHeader? parent) { if (!test.IsT8NTest) { return new TestBlockhashProvider(); } + var t8NBlockHashProvider = new T8NBlockHashProvider(); if (header.Hash != null) t8NBlockHashProvider.Insert(header.Hash, header.Number); @@ -243,6 +287,7 @@ private static IBlockhashProvider GetBlockHashProvider(GeneralStateTest test, Bl { t8NBlockHashProvider.Insert(blockHash.Value, long.Parse(blockHash.Key)); } + return t8NBlockHashProvider; } @@ -252,7 +297,8 @@ private static UInt256 CalculateBaseFeePerGas(GeneralStateTest test, BlockHeader return test.IsT8NTest ? BaseFeeCalculator.Calculate(parentHeader, test.Fork) : _defaultBaseFeeForStateTest; } - private static void InitializeTestPreState(Dictionary pre, WorldState stateProvider, ISpecProvider specProvider) + private static void InitializeTestPreState(Dictionary pre, WorldState stateProvider, + ISpecProvider specProvider) { foreach (KeyValuePair accountState in pre) { @@ -285,15 +331,18 @@ private bool IsValidBlock(Block block, ISpecProvider specProvider) .TestObject; var difficultyCalculator = new EthashDifficultyCalculator(specProvider); - var sealer = new EthashSealValidator(_logManager, difficultyCalculator, new CryptoRandom(), new Ethash(_logManager), Timestamper.Default); + var sealer = new EthashSealValidator(_logManager, difficultyCalculator, new CryptoRandom(), + new Ethash(_logManager), Timestamper.Default); IHeaderValidator headerValidator = new HeaderValidator(blockTree, sealer, specProvider, _logManager); IUnclesValidator unclesValidator = new UnclesValidator(blockTree, headerValidator, _logManager); - IBlockValidator blockValidator = new BlockValidator(_txValidator, headerValidator, unclesValidator, specProvider, _logManager); + IBlockValidator blockValidator = new BlockValidator(_txValidator, headerValidator, unclesValidator, + specProvider, _logManager); return blockValidator.ValidateOrphanedBlock(block, out _); } - private static void CalculateReward(string? stateReward, bool isStateTest, Block block, WorldState stateProvider, IReleaseSpec spec) + private static void CalculateReward(string? stateReward, bool isStateTest, Block block, + WorldState stateProvider, IReleaseSpec spec) { if (stateReward == null || isStateTest) return; diff --git a/src/Nethermind/Nethermind.Consensus/Withdrawals/WithdrawalProcessor.cs b/src/Nethermind/Nethermind.Consensus/Withdrawals/WithdrawalProcessor.cs index e315c5a5a8e..86ba335b0d7 100644 --- a/src/Nethermind/Nethermind.Consensus/Withdrawals/WithdrawalProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Withdrawals/WithdrawalProcessor.cs @@ -25,7 +25,12 @@ public WithdrawalProcessor(IWorldState stateProvider, ILogManager logManager) public void ProcessWithdrawals(Block block, IReleaseSpec spec) { if (!spec.WithdrawalsEnabled) + { + Console.WriteLine("Withdrawals not enabled"); return; + } + + Console.WriteLine("Withdrawals enabled"); if (_logger.IsTrace) _logger.Trace($"Applying withdrawals for block {block}"); diff --git a/src/Nethermind/Nethermind.Core/BlockchainIds.cs b/src/Nethermind/Nethermind.Core/BlockchainIds.cs index d2ec8c54276..2e9f94765fb 100644 --- a/src/Nethermind/Nethermind.Core/BlockchainIds.cs +++ b/src/Nethermind/Nethermind.Core/BlockchainIds.cs @@ -64,7 +64,7 @@ public static string GetBlockchainName(ulong networkId) public static class TestBlockchainIds { - public const int NetworkId = 4261; - public const int ChainId = 1; + public const int NetworkId = 100; + public const int ChainId = 100; } } diff --git a/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs b/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs index e79bf4fe228..7218eefbb29 100644 --- a/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs +++ b/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs @@ -51,7 +51,7 @@ public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalD public ForkActivation? MergeBlockNumber { get; private set; } public ulong TimestampFork => ShanghaiTimestamp; public UInt256? TerminalTotalDifficulty { get; private set; } = UInt256.Parse("8626000000000000000000058750000000000000000000"); - public IReleaseSpec GenesisSpec => Byzantium.Instance; + public IReleaseSpec GenesisSpec => Cancun.Instance; public long? DaoBlockNumber => null; public ulong NetworkId => BlockchainIds.Gnosis; public ulong ChainId => BlockchainIds.Gnosis; diff --git a/tools/evm/Evm.sln b/tools/evm/Evm.sln index c1b98c47b93..5bef2b9f239 100644 --- a/tools/evm/Evm.sln +++ b/tools/evm/Evm.sln @@ -13,4 +13,6 @@ Global {AAA9AF72-46AE-4535-9698-610C9E94AE06}.Release|Any CPU.ActiveCfg = Release|Any CPU {AAA9AF72-46AE-4535-9698-610C9E94AE06}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection + GlobalSection(NestedProjects) = preSolution + EndGlobalSection EndGlobal diff --git a/tools/evm/Program.cs b/tools/evm/Program.cs index 9e17b9c0b0a..2a3f712490b 100644 --- a/tools/evm/Program.cs +++ b/tools/evm/Program.cs @@ -36,6 +36,7 @@ static void ConfigureT8NCommand(ref RootCommand rootCmd) var traceOpt = new Option("--trace", description: "Configures the use of the JSON opcode tracer. This tracer emits traces to files as trace--.jsonl", getDefaultValue: () => false); var traceNoStackOpt = new Option("--trace.noStack", description: "Trace no stack", getDefaultValue: () => false); var traceReturnDataOpt = new Option("--trace.returnData", description: "Trace return data", getDefaultValue: () => false); + var isGnosisTests = new Option("--run.gnosis", description: "If set to true, will run under Gnosis spec", getDefaultValue: () => false); var cmd = new Command("t8n", "EVM State Transition command") { @@ -53,6 +54,7 @@ static void ConfigureT8NCommand(ref RootCommand rootCmd) traceMemoryOpt, traceNoStackOpt, traceReturnDataOpt, + isGnosisTests }; cmd.AddAlias("transition"); @@ -86,6 +88,7 @@ await Task.Run(() => context.ParseResult.GetValueForOption(stateChainIdOpt), context.ParseResult.GetValueForOption(stateForkOpt), context.ParseResult.GetValueForOption(stateRewardOpt), + context.ParseResult.GetValueForOption(isGnosisTests), traceOpts ); Environment.ExitCode = output.ExitCode; diff --git a/tools/evm/T8NTool/InputProcessor.cs b/tools/evm/T8NTool/InputProcessor.cs index 45dee7f3365..b8b4c28f7a7 100644 --- a/tools/evm/T8NTool/InputProcessor.cs +++ b/tools/evm/T8NTool/InputProcessor.cs @@ -7,6 +7,7 @@ using Nethermind.Evm.Tracing.GethStyle; using Nethermind.Serialization.Json; using Nethermind.Serialization.Rlp; +using Nethermind.Specs; using Nethermind.Specs.Forks; using Nethermind.Specs.Test; @@ -23,6 +24,7 @@ public static GeneralStateTest ConvertToGeneralStateTest(string inputAlloc, string stateFork, string? stateReward, ulong stateChainId, + bool isGnosis, TraceOptions traceOptions) { GethTraceOptions gethTraceOptions = new GethTraceOptions @@ -30,7 +32,8 @@ public static GeneralStateTest ConvertToGeneralStateTest(string inputAlloc, EnableMemory = traceOptions.Memory, DisableStack = traceOptions.NoStack }; - Dictionary allocJson = EthereumJsonSerializer.Deserialize>(File.ReadAllText(inputAlloc)); + Dictionary allocJson = + EthereumJsonSerializer.Deserialize>(File.ReadAllText(inputAlloc)); EnvInfo envInfo = EthereumJsonSerializer.Deserialize(File.ReadAllText(inputEnv)); Transaction[] transactions; @@ -61,11 +64,12 @@ public static GeneralStateTest ConvertToGeneralStateTest(string inputAlloc, throw new T8NException(e, ExitCodes.ErrorConfig); } - ISpecProvider specProvider = new CustomSpecProvider(((ForkActivation)0, Frontier.Instance), ((ForkActivation)1, spec)); + ISpecProvider specProvider = GnosisSpecProvider.Instance; if (spec is Paris) { specProvider.UpdateMergeTransitionInfo(envInfo.CurrentNumber, 0); } + envInfo.ApplyChecks(specProvider, spec); GeneralStateTest generalStateTest = new(); @@ -73,13 +77,13 @@ public static GeneralStateTest ConvertToGeneralStateTest(string inputAlloc, generalStateTest.Fork = spec; generalStateTest.Pre = allocJson; generalStateTest.Transactions = transactions; + generalStateTest.StateChainId = isGnosis ? GnosisSpecProvider.Instance.ChainId : FrontierSpecProvider.Instance.ChainId; generalStateTest.CurrentCoinbase = envInfo.CurrentCoinbase; generalStateTest.CurrentGasLimit = envInfo.CurrentGasLimit; generalStateTest.CurrentTimestamp = envInfo.CurrentTimestamp; generalStateTest.CurrentNumber = envInfo.CurrentNumber; generalStateTest.Withdrawals = envInfo.Withdrawals; - generalStateTest.Withdrawals = envInfo.Withdrawals; generalStateTest.CurrentRandom = envInfo.GetCurrentRandomHash256(); generalStateTest.ParentTimestamp = envInfo.ParentTimestamp; generalStateTest.ParentDifficulty = envInfo.ParentDifficulty; diff --git a/tools/evm/T8NTool/T8NTool.cs b/tools/evm/T8NTool/T8NTool.cs index eba84679173..5acd99453e4 100644 --- a/tools/evm/T8NTool/T8NTool.cs +++ b/tools/evm/T8NTool/T8NTool.cs @@ -3,6 +3,7 @@ using Ethereum.Test.Base.T8NUtils; using Evm.JsonTypes; using Nethermind.Serialization.Json; +using Nethermind.Specs; namespace Evm.T8NTool; @@ -28,12 +29,18 @@ public T8NOutput Execute( ulong stateChainId, string stateFork, string? stateReward, + bool isGnosis, TraceOptions traceOptions) { T8NOutput t8NOutput = new(); try { - var t8NExecutionResult = Execute(inputAlloc, inputEnv, inputTxs, stateFork, stateReward, stateChainId, traceOptions); + if (isGnosis) + { + stateChainId = GnosisSpecProvider.Instance.ChainId; + } + var t8NExecutionResult = Execute(inputAlloc, inputEnv, inputTxs, stateFork, stateReward, stateChainId, + isGnosis, traceOptions); if (outputAlloc == "stdout") t8NOutput.Alloc = t8NExecutionResult.Alloc; else if (outputAlloc != null) WriteToFile(outputAlloc, outputBasedir, t8NExecutionResult.Alloc); @@ -72,6 +79,7 @@ public T8NOutput Execute( Console.WriteLine(t8NOutput.ErrorMessage); } } + return t8NOutput; } @@ -82,11 +90,13 @@ private T8NExecutionResult Execute( string stateFork, string? stateReward, ulong stateChainId, + bool isGnosis, TraceOptions traceOptions) { - var generalStateTest = InputProcessor.ConvertToGeneralStateTest(inputAlloc, inputEnv, inputTxs, stateFork, stateReward, stateChainId, traceOptions); + var generalStateTest = InputProcessor.ConvertToGeneralStateTest(inputAlloc, inputEnv, inputTxs, stateFork, + stateReward, stateChainId, isGnosis, traceOptions); - var res = RunTest(generalStateTest); + var res = RunTest(generalStateTest, isGnosis); PostState postState = new PostState(); postState.StateRoot = res.StateRoot; From 2a284919c0696a44db6de586226314dcad174e76 Mon Sep 17 00:00:00 2001 From: Marcos Maceo Date: Fri, 9 Aug 2024 15:28:24 +0400 Subject: [PATCH 2/7] fix: remove debug log --- src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs b/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs index 21f0ee78cb4..15ba88e20a8 100644 --- a/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs +++ b/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs @@ -81,7 +81,6 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer) protected EthereumTestResult RunTest(GeneralStateTest test, bool isGnosis, ITxTracer txTracer) { TestContext.Write($"Running {test.Name} at {DateTime.UtcNow:HH:mm:ss.ffffff}"); - Console.WriteLine("Passing over here"); Assert.IsNull(test.LoadFailure, "test data loading failure"); IDb stateDb = new MemDb(); From 7959cb71882d17af8e4ed1033d308ac5a1c5d443 Mon Sep 17 00:00:00 2001 From: Marcos Maceo Date: Fri, 9 Aug 2024 15:39:40 +0400 Subject: [PATCH 3/7] fix: remove other debug log --- .../Nethermind.Consensus/Withdrawals/WithdrawalProcessor.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Withdrawals/WithdrawalProcessor.cs b/src/Nethermind/Nethermind.Consensus/Withdrawals/WithdrawalProcessor.cs index 86ba335b0d7..e315c5a5a8e 100644 --- a/src/Nethermind/Nethermind.Consensus/Withdrawals/WithdrawalProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Withdrawals/WithdrawalProcessor.cs @@ -25,12 +25,7 @@ public WithdrawalProcessor(IWorldState stateProvider, ILogManager logManager) public void ProcessWithdrawals(Block block, IReleaseSpec spec) { if (!spec.WithdrawalsEnabled) - { - Console.WriteLine("Withdrawals not enabled"); return; - } - - Console.WriteLine("Withdrawals enabled"); if (_logger.IsTrace) _logger.Trace($"Applying withdrawals for block {block}"); From 8447331435f94aa125993cc65c39ac662c26efc0 Mon Sep 17 00:00:00 2001 From: yerke26 Date: Mon, 12 Aug 2024 20:52:49 +0500 Subject: [PATCH 4/7] small fixes --- .../Ethereum.Test.Base/GeneralTestBase.cs | 26 +++++-------------- tools/Evm.Test/T8NTests.cs | 1 + tools/evm/T8NTool/InputProcessor.cs | 6 +++-- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs b/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs index 15ba88e20a8..8a346832eb2 100644 --- a/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs +++ b/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs @@ -28,7 +28,6 @@ using NUnit.Framework; using System.Threading.Tasks; using Ethereum.Test.Base.T8NUtils; -using Microsoft.IdentityModel.Tokens; using Nethermind.Consensus.BeaconBlockRoot; using Nethermind.Consensus.Rewards; using Nethermind.Consensus.Withdrawals; @@ -41,7 +40,7 @@ public abstract class GeneralStateTestBase private static ILogger _logger = new(new ConsoleAsyncLogger(LogLevel.Info)); private static ILogManager _logManager = LimboLogs.Instance; private static readonly UInt256 _defaultBaseFeeForStateTest = 0xA; - private TxValidator _txValidator = new(MainnetSpecProvider.Instance.ChainId); + private TxValidator? _txValidator; private readonly BeaconBlockRootHandler _beaconBlockRootHandler = new(); [SetUp] @@ -58,31 +57,18 @@ protected static void Setup(ILogManager logManager) _logger = _logManager.GetClassLogger(); } - protected EthereumTestResult RunTest(GeneralStateTest test) + protected EthereumTestResult RunTest(GeneralStateTest test, bool isGnosis = false) { - return RunTest(test, false, NullTxTracer.Instance); + return RunTest(test, NullTxTracer.Instance, isGnosis); } - protected EthereumTestResult RunTest(GeneralStateTest test, bool isGnosis) - { - if (isGnosis) - { - _txValidator = new TxValidator(GnosisSpecProvider.Instance.ChainId); - } - - return RunTest(test, isGnosis, NullTxTracer.Instance); - } - - protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer) - { - return RunTest(test, false, txTracer); - } - - protected EthereumTestResult RunTest(GeneralStateTest test, bool isGnosis, ITxTracer txTracer) + protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer, bool isGnosis = false) { TestContext.Write($"Running {test.Name} at {DateTime.UtcNow:HH:mm:ss.ffffff}"); Assert.IsNull(test.LoadFailure, "test data loading failure"); + _txValidator = new TxValidator(test.StateChainId); + IDb stateDb = new MemDb(); IDb codeDb = new MemDb(); ISpecProvider specProvider; diff --git a/tools/Evm.Test/T8NTests.cs b/tools/Evm.Test/T8NTests.cs index 5ca0f161e95..44580e51fd1 100644 --- a/tools/Evm.Test/T8NTests.cs +++ b/tools/Evm.Test/T8NTests.cs @@ -261,6 +261,7 @@ private void Execute(InputParams inputParams, OutputParams outputParams, int exp 1, inputParams.StateFork, inputParams.StateReward, + false, TraceOptions.Default ); diff --git a/tools/evm/T8NTool/InputProcessor.cs b/tools/evm/T8NTool/InputProcessor.cs index b8b4c28f7a7..f84c956de5a 100644 --- a/tools/evm/T8NTool/InputProcessor.cs +++ b/tools/evm/T8NTool/InputProcessor.cs @@ -64,7 +64,9 @@ public static GeneralStateTest ConvertToGeneralStateTest(string inputAlloc, throw new T8NException(e, ExitCodes.ErrorConfig); } - ISpecProvider specProvider = GnosisSpecProvider.Instance; + ISpecProvider specProvider = isGnosis ? GnosisSpecProvider.Instance + : new CustomSpecProvider(((ForkActivation)0, Frontier.Instance), ((ForkActivation)1, spec)); + if (spec is Paris) { specProvider.UpdateMergeTransitionInfo(envInfo.CurrentNumber, 0); @@ -77,7 +79,7 @@ public static GeneralStateTest ConvertToGeneralStateTest(string inputAlloc, generalStateTest.Fork = spec; generalStateTest.Pre = allocJson; generalStateTest.Transactions = transactions; - generalStateTest.StateChainId = isGnosis ? GnosisSpecProvider.Instance.ChainId : FrontierSpecProvider.Instance.ChainId; + generalStateTest.StateChainId = isGnosis ? GnosisSpecProvider.Instance.ChainId : MainnetSpecProvider.Instance.ChainId; generalStateTest.CurrentCoinbase = envInfo.CurrentCoinbase; generalStateTest.CurrentGasLimit = envInfo.CurrentGasLimit; From 6dad0202211650de077389435ac2c05166ede7af Mon Sep 17 00:00:00 2001 From: yerke26 Date: Mon, 19 Aug 2024 03:23:40 +0500 Subject: [PATCH 5/7] fix Ethereum tests --- src/Nethermind/Nethermind.Core/BlockchainIds.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Core/BlockchainIds.cs b/src/Nethermind/Nethermind.Core/BlockchainIds.cs index 2e9f94765fb..d2ec8c54276 100644 --- a/src/Nethermind/Nethermind.Core/BlockchainIds.cs +++ b/src/Nethermind/Nethermind.Core/BlockchainIds.cs @@ -64,7 +64,7 @@ public static string GetBlockchainName(ulong networkId) public static class TestBlockchainIds { - public const int NetworkId = 100; - public const int ChainId = 100; + public const int NetworkId = 4261; + public const int ChainId = 1; } } From a318835d6e7fd567cb52321a10ae23fd745b18c9 Mon Sep 17 00:00:00 2001 From: yerke26 Date: Mon, 19 Aug 2024 03:27:24 +0500 Subject: [PATCH 6/7] fix Ethereum tests --- src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs b/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs index 7218eefbb29..e79bf4fe228 100644 --- a/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs +++ b/src/Nethermind/Nethermind.Specs/GnosisSpecProvider.cs @@ -51,7 +51,7 @@ public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalD public ForkActivation? MergeBlockNumber { get; private set; } public ulong TimestampFork => ShanghaiTimestamp; public UInt256? TerminalTotalDifficulty { get; private set; } = UInt256.Parse("8626000000000000000000058750000000000000000000"); - public IReleaseSpec GenesisSpec => Cancun.Instance; + public IReleaseSpec GenesisSpec => Byzantium.Instance; public long? DaoBlockNumber => null; public ulong NetworkId => BlockchainIds.Gnosis; public ulong ChainId => BlockchainIds.Gnosis; From 5f2b7940e000387b2a3fe450c89934dec867022f Mon Sep 17 00:00:00 2001 From: yerke26 Date: Wed, 16 Oct 2024 11:51:07 +0300 Subject: [PATCH 7/7] remove isGnosis flag --- tools/evm/Program.cs | 9 --------- tools/evm/T8NTool/T8NTool.cs | 6 +----- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/tools/evm/Program.cs b/tools/evm/Program.cs index 2a3f712490b..f2256bc84c8 100644 --- a/tools/evm/Program.cs +++ b/tools/evm/Program.cs @@ -1,11 +1,5 @@ using System.CommandLine; using Evm.JsonTypes; -using Evm.T8NTool; -using Nethermind.Core.Exceptions; -using Nethermind.Core.Extensions; -using Nethermind.Evm; -using Nethermind.Serialization.Rlp; -using Nethermind.Specs.Forks; namespace Evm { @@ -36,7 +30,6 @@ static void ConfigureT8NCommand(ref RootCommand rootCmd) var traceOpt = new Option("--trace", description: "Configures the use of the JSON opcode tracer. This tracer emits traces to files as trace--.jsonl", getDefaultValue: () => false); var traceNoStackOpt = new Option("--trace.noStack", description: "Trace no stack", getDefaultValue: () => false); var traceReturnDataOpt = new Option("--trace.returnData", description: "Trace return data", getDefaultValue: () => false); - var isGnosisTests = new Option("--run.gnosis", description: "If set to true, will run under Gnosis spec", getDefaultValue: () => false); var cmd = new Command("t8n", "EVM State Transition command") { @@ -54,7 +47,6 @@ static void ConfigureT8NCommand(ref RootCommand rootCmd) traceMemoryOpt, traceNoStackOpt, traceReturnDataOpt, - isGnosisTests }; cmd.AddAlias("transition"); @@ -88,7 +80,6 @@ await Task.Run(() => context.ParseResult.GetValueForOption(stateChainIdOpt), context.ParseResult.GetValueForOption(stateForkOpt), context.ParseResult.GetValueForOption(stateRewardOpt), - context.ParseResult.GetValueForOption(isGnosisTests), traceOpts ); Environment.ExitCode = output.ExitCode; diff --git a/tools/evm/T8NTool/T8NTool.cs b/tools/evm/T8NTool/T8NTool.cs index 5acd99453e4..fc101494f14 100644 --- a/tools/evm/T8NTool/T8NTool.cs +++ b/tools/evm/T8NTool/T8NTool.cs @@ -29,16 +29,12 @@ public T8NOutput Execute( ulong stateChainId, string stateFork, string? stateReward, - bool isGnosis, TraceOptions traceOptions) { T8NOutput t8NOutput = new(); try { - if (isGnosis) - { - stateChainId = GnosisSpecProvider.Instance.ChainId; - } + var isGnosis = GnosisSpecProvider.Instance.ChainId == stateChainId; var t8NExecutionResult = Execute(inputAlloc, inputEnv, inputTxs, stateFork, stateReward, stateChainId, isGnosis, traceOptions);