diff --git a/src/Nethermind/Ethereum.Test.Base/AccountState.cs b/src/Nethermind/Ethereum.Test.Base/AccountState.cs index 789ccd46b82..dbf7a2e0c7e 100644 --- a/src/Nethermind/Ethereum.Test.Base/AccountState.cs +++ b/src/Nethermind/Ethereum.Test.Base/AccountState.cs @@ -4,13 +4,17 @@ using System.Collections.Generic; using Nethermind.Int256; -namespace Ethereum.Test.Base +namespace Ethereum.Test.Base; + +public class AccountState { - public class AccountState + public byte[]? Code { get; set; } + public UInt256 Balance { get; set; } + public UInt256 Nonce { get; set; } + public Dictionary? Storage { get; set; } + + public bool IsEmptyAccount() { - public byte[] Code { get; set; } - public UInt256 Balance { get; set; } - public UInt256 Nonce { get; set; } - public Dictionary Storage { get; set; } + return Balance.IsZero && Nonce.IsZero && (Code == null || Code.Length == 0) && (Storage == null || Storage.Count == 0); } } diff --git a/src/Nethermind/Ethereum.Test.Base/AccountStateConverter.cs b/src/Nethermind/Ethereum.Test.Base/AccountStateConverter.cs new file mode 100644 index 00000000000..ec1abb1152d --- /dev/null +++ b/src/Nethermind/Ethereum.Test.Base/AccountStateConverter.cs @@ -0,0 +1,65 @@ +using System.Collections.Generic; +using System.Linq; +using Nethermind.Core.Extensions; + +namespace Ethereum.Test.Base; + +using Nethermind.Int256; +using Nethermind.Serialization.Json; +using System; +using System.Text.Json; +using System.Text.Json.Serialization; + +public class AccountStateConverter : JsonConverter +{ + private EthereumJsonSerializer _ethereumJsonSerializer = new(); + + public override AccountState? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + return _ethereumJsonSerializer.Deserialize(ref reader); + } + + public override void Write(Utf8JsonWriter writer, AccountState value, JsonSerializerOptions options) + { + NumberConversion? previousValue = ForcedNumberConversion.ForcedConversion.Value; + try + { + writer.WriteStartObject(); + + ForcedNumberConversion.ForcedConversion.Value = NumberConversion.Hex; + if (value.Balance != UInt256.Zero) + { + writer.WritePropertyName("balance"u8); + JsonSerializer.Serialize(writer, value.Balance, options); + } + + ForcedNumberConversion.ForcedConversion.Value = NumberConversion.Hex; + if (value.Nonce != UInt256.Zero) + { + writer.WritePropertyName("nonce"u8); + JsonSerializer.Serialize(writer, value.Nonce, options); + } + + if (value.Code is not null) + { + writer.WritePropertyName("code"u8); + JsonSerializer.Serialize(writer, value.Code, options); + } + + ForcedNumberConversion.ForcedConversion.Value = NumberConversion.ZeroPaddedHex; + if (value.Storage?.Count > 0) + { + Dictionary storage = + value.Storage.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.ToUInt256()); + writer.WritePropertyName("storage"u8); + JsonSerializer.Serialize(writer, storage, options); + } + + writer.WriteEndObject(); + } + finally + { + ForcedNumberConversion.ForcedConversion.Value = previousValue; + } + } +} diff --git a/src/Nethermind/Ethereum.Test.Base/AccountStateJson.cs b/src/Nethermind/Ethereum.Test.Base/AccountStateJson.cs deleted file mode 100644 index e1585b1a34f..00000000000 --- a/src/Nethermind/Ethereum.Test.Base/AccountStateJson.cs +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited -// SPDX-License-Identifier: LGPL-3.0-only - -using System.Collections.Generic; - -namespace Ethereum.Test.Base -{ - public class AccountStateJson - { - public string? Balance { get; set; } - public string? Code { get; set; } - public string? Nonce { get; set; } - public Dictionary? Storage { get; set; } - } -} diff --git a/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs b/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs index 66df7e618ee..34fa7bb33b7 100644 --- a/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs +++ b/src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs @@ -321,9 +321,12 @@ private void InitializeTestState(BlockchainTest test, IWorldState stateProvider, foreach (KeyValuePair accountState in ((IEnumerable>)test.Pre ?? Array.Empty>())) { - foreach (KeyValuePair storageItem in accountState.Value.Storage) + if (accountState.Value.Storage is not null) { - stateProvider.Set(new StorageCell(accountState.Key, storageItem.Key), storageItem.Value); + foreach (KeyValuePair storageItem in accountState.Value.Storage) + { + stateProvider.Set(new StorageCell(accountState.Key, storageItem.Key), storageItem.Value); + } } stateProvider.CreateAccount(accountState.Key, accountState.Value.Balance, accountState.Value.Nonce); diff --git a/src/Nethermind/Ethereum.Test.Base/BlockchainTestJson.cs b/src/Nethermind/Ethereum.Test.Base/BlockchainTestJson.cs index 02a3ada968b..fdd03858fd8 100644 --- a/src/Nethermind/Ethereum.Test.Base/BlockchainTestJson.cs +++ b/src/Nethermind/Ethereum.Test.Base/BlockchainTestJson.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using System.Collections.Generic; +using Nethermind.Core; using Nethermind.Core.Crypto; using Nethermind.Core.Specs; @@ -24,8 +25,8 @@ public class BlockchainTestJson public TestBlockJson[]? Blocks { get; set; } public TestBlockHeaderJson? GenesisBlockHeader { get; set; } - public Dictionary? Pre { get; set; } - public Dictionary? PostState { get; set; } + public Dictionary? Pre { get; set; } + public Dictionary? PostState { get; set; } public Hash256? PostStateHash { get; set; } diff --git a/src/Nethermind/Ethereum.Test.Base/EthereumTestResult.cs b/src/Nethermind/Ethereum.Test.Base/EthereumTestResult.cs index eecd49c13e9..d09543dd5c1 100644 --- a/src/Nethermind/Ethereum.Test.Base/EthereumTestResult.cs +++ b/src/Nethermind/Ethereum.Test.Base/EthereumTestResult.cs @@ -1,9 +1,13 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only +using System.Collections.Generic; using System.Text.Json.Serialization; - +using Ethereum.Test.Base.T8NUtils; +using Nethermind.Core; using Nethermind.Core.Crypto; +using Nethermind.Evm.Tracing.GethStyle.Custom.Native.Prestate; +using Nethermind.Int256; namespace Ethereum.Test.Base { @@ -37,5 +41,20 @@ public EthereumTestResult(string? name, string? loadFailure) public double TimeInMs { get; set; } public Hash256 StateRoot { get; set; } = Keccak.EmptyTreeHash; + + public T8NResult T8NResult { get; set; } } } + +public class RejectedTx +{ + public RejectedTx(int index, string error) + { + Index = index; + Error = error; + } + + public int Index { get; set; } + public string? Error { get; set; } +} + diff --git a/src/Nethermind/Ethereum.Test.Base/GeneralStateTest.cs b/src/Nethermind/Ethereum.Test.Base/GeneralStateTest.cs index 09158536941..80dabe7c4ca 100644 --- a/src/Nethermind/Ethereum.Test.Base/GeneralStateTest.cs +++ b/src/Nethermind/Ethereum.Test.Base/GeneralStateTest.cs @@ -1,24 +1,33 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only +using System; using System.Collections.Generic; using System.IO; using Ethereum.Test.Base.Interfaces; +using Nethermind.Consensus.Ethash; using Nethermind.Core; using Nethermind.Core.Crypto; using Nethermind.Core.Specs; +using Nethermind.Core.Test.Builders; +using Nethermind.Crypto; +using Nethermind.Evm; +using Nethermind.Evm.Tracing.GethStyle; using Nethermind.Int256; +using Nethermind.Specs; +using Nethermind.Specs.Forks; namespace Ethereum.Test.Base { public class GeneralStateTest : IEthereumTest { + public bool IsT8NTest { get; set; } = false; public string? Category { get; set; } public string? Name { get; set; } public IReleaseSpec? Fork { get; set; } public string? ForkName { get; set; } public Address? CurrentCoinbase { get; set; } - public UInt256 CurrentDifficulty { get; set; } + public UInt256? CurrentDifficulty { get; set; } public UInt256? CurrentBaseFee { get; set; } public long CurrentGasLimit { get; set; } @@ -29,7 +38,7 @@ public class GeneralStateTest : IEthereumTest public Hash256? PostHash { get; set; } public Hash256? PostReceiptsRoot { get; set; } public string? LoadFailure { get; set; } - public Transaction? Transaction { get; set; } + public Transaction[] Transactions { get; set; } = []; public Hash256? CurrentRandom { get; set; } public Hash256? CurrentBeaconRoot { get; set; } public Hash256? CurrentWithdrawalsRoot { get; set; } @@ -39,9 +48,76 @@ public class GeneralStateTest : IEthereumTest public Hash256? RequestsRoot { get; set; } + public Withdrawal[] Withdrawals { get; set; } = []; + public ulong ParentTimestamp { get; set; } // optional? + public UInt256? ParentDifficulty { get; set; } + public Hash256? ParentUncleHash { get; set; } + public Hash256? ParentBeaconBlockRoot { get; set; } + public UInt256? ParentBaseFee { get; set; } + public long ParentGasUsed { get; set; } + public long ParentGasLimit { get; set; } + public Dictionary BlockHashes { get; set; } = []; + public Ommer[] Ommers { get; set; } = []; + public string? StateReward { get; set; } + public ulong StateChainId { get; set; } = MainnetSpecProvider.Instance.ChainId; + public GethTraceOptions GethTraceOptions { get; set; } = GethTraceOptions.Default; + public bool IsTraceEnabled { get; set; } = false; + public bool IsStateTest { get; set; } + public override string ToString() { return $"{Path.GetFileName(Category)}.{Name}_{ForkName}"; } + + public BlockHeader GetBlockHeader() + { + BlockHeader header = new( + PreviousHash, + Keccak.OfAnEmptySequenceRlp, + CurrentCoinbase ?? throw new Exception("CurrentCoinbase is missing"), + CurrentDifficulty ?? UInt256.Zero, + CurrentNumber, + CurrentGasLimit, + CurrentTimestamp, + []); + header.StateRoot = PostHash; + header.Hash = header.CalculateHash(); + header.IsPostMerge = Fork is Paris; + header.MixHash = CurrentRandom; + header.WithdrawalsRoot = CurrentWithdrawalsRoot; + header.ParentBeaconBlockRoot = CurrentBeaconRoot; + header.ExcessBlobGas = CurrentExcessBlobGas ?? (Fork is Cancun ? 0ul : null); + header.BlobGasUsed = BlobGasCalculator.CalculateBlobGas(Transactions); + header.ParentBeaconBlockRoot = ParentBeaconBlockRoot; + + return header; + } + + public BlockHeader? GetParentBlockHeader() + { + if (ParentBlobGasUsed is not null && ParentExcessBlobGas is not null) + { + BlockHeader parent = new( + parentHash: Keccak.Zero, + unclesHash: Keccak.OfAnEmptySequenceRlp, + beneficiary: CurrentCoinbase, + difficulty: ParentDifficulty ?? CurrentDifficulty ?? UInt256.Zero, + number: CurrentNumber - 1, + gasLimit: ParentGasLimit, + timestamp: ParentTimestamp, + extraData: [] + ) + { + BlobGasUsed = (ulong)ParentBlobGasUsed, + ExcessBlobGas = (ulong)ParentExcessBlobGas, + }; + if (ParentBaseFee.HasValue) parent.BaseFeePerGas = ParentBaseFee.Value; + parent.GasUsed = ParentGasUsed; + if (ParentUncleHash != null) parent.UnclesHash = ParentUncleHash; + return parent; + } + + return null; + } } } diff --git a/src/Nethermind/Ethereum.Test.Base/GeneralStateTestJson.cs b/src/Nethermind/Ethereum.Test.Base/GeneralStateTestJson.cs index 40e779f109d..860a2e4459b 100644 --- a/src/Nethermind/Ethereum.Test.Base/GeneralStateTestJson.cs +++ b/src/Nethermind/Ethereum.Test.Base/GeneralStateTestJson.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json.Serialization; +using Nethermind.Core; namespace Ethereum.Test.Base { @@ -12,7 +13,7 @@ public class GeneralStateTestJson public GeneralStateTestInfoJson? Info { get; set; } public GeneralStateTestEnvJson? Env { get; set; } public Dictionary? Post { get; set; } - public Dictionary? Pre { get; set; } + public Dictionary? Pre { get; set; } public string? SealEngine { get; set; } public string? LoadFailure { get; set; } public TransactionJson? Transaction { get; set; } diff --git a/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs b/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs index 47487e7e212..bf8660ce363 100644 --- a/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs +++ b/src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs @@ -4,11 +4,12 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO.Abstractions; +using System.Linq; using Nethermind.Blockchain; using Nethermind.Consensus.Ethash; using Nethermind.Consensus.Validators; using Nethermind.Core; -using Nethermind.Core.Crypto; using Nethermind.Core.Extensions; using Nethermind.Core.Specs; using Nethermind.Core.Test.Builders; @@ -26,6 +27,11 @@ using Nethermind.Trie.Pruning; using NUnit.Framework; using System.Threading.Tasks; +using Ethereum.Test.Base.T8NUtils; +using Nethermind.Blockchain.BeaconBlockRoot; +using Nethermind.Consensus.Rewards; +using Nethermind.Consensus.Withdrawals; +using Nethermind.Evm.Tracing.GethStyle; namespace Ethereum.Test.Base { @@ -34,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 readonly TxValidator _txValidator = new(MainnetSpecProvider.Instance.ChainId); + private TxValidator? _txValidator; [SetUp] public void Setup() @@ -50,31 +56,67 @@ 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, NullTxTracer.Instance); + return RunTest(test, NullTxTracer.Instance, isGnosis); } - protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer) + protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer, bool isGnosis = false) { TestContext.Out.Write($"Running {test.Name} at {DateTime.UtcNow:HH:mm:ss.ffffff}"); Assert.That(test.LoadFailure, Is.Null, "test data loading failure"); + _txValidator = new TxValidator(test.StateChainId); + IDb stateDb = new MemDb(); IDb codeDb = new MemDb(); + 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)); + if (specProvider.GenesisSpec != GnosisSpecProvider.Instance.GenesisSpec) + { + Assert.Fail("Expected genesis spec to be Frontier for blockchain tests"); + } + } + 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); - 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)); + BlockHeader header = test.GetBlockHeader(); + BlockHeader? parentHeader = test.GetParentBlockHeader(); - if (specProvider.GenesisSpec != Frontier.Instance) + if (test.Fork.IsEip1559Enabled) { - Assert.Fail("Expected genesis spec to be Frontier for blockchain tests"); + test.CurrentBaseFee = header.BaseFeePerGas = CalculateBaseFeePerGas(test, parentHeader); } + if (parentHeader != null) + { + header.ExcessBlobGas = BlobGasCalculator.CalculateExcessBlobGas(parentHeader, spec); + } + + var blockhashProvider = GetBlockHashProvider(test, header, parentHeader); + TrieStore trieStore = new(stateDb, _logManager); WorldState stateProvider = new(trieStore, codeDb, _logManager); - IBlockhashProvider blockhashProvider = new TestBlockhashProvider(); CodeInfoRepository codeInfoRepository = new(); IVirtualMachine virtualMachine = new VirtualMachine( blockhashProvider, @@ -89,72 +131,111 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer) codeInfoRepository, _logManager); - InitializeTestState(test, stateProvider, specProvider); - - BlockHeader header = new( - test.PreviousHash, - Keccak.OfAnEmptySequenceRlp, - test.CurrentCoinbase, - test.CurrentDifficulty, - test.CurrentNumber, - test.CurrentGasLimit, - test.CurrentTimestamp, - []); - header.BaseFeePerGas = test.Fork.IsEip1559Enabled ? test.CurrentBaseFee ?? _defaultBaseFeeForStateTest : UInt256.Zero; - header.StateRoot = test.PostHash; - header.Hash = header.CalculateHash(); - header.IsPostMerge = test.CurrentRandom is not null; - header.MixHash = test.CurrentRandom; - header.WithdrawalsRoot = test.CurrentWithdrawalsRoot; - header.ParentBeaconBlockRoot = test.CurrentBeaconRoot; - header.ExcessBlobGas = test.CurrentExcessBlobGas ?? (test.Fork is Cancun ? 0ul : null); - header.BlobGasUsed = BlobGasCalculator.CalculateBlobGas(test.Transaction); - header.RequestsRoot = test.RequestsRoot; + InitializeTestPreState(test.Pre, stateProvider, specProvider); + + var ecdsa = new EthereumEcdsa(specProvider.ChainId); + foreach (var transaction in test.Transactions) + { + transaction.ChainId ??= test.StateChainId; + transaction.SenderAddress ??= ecdsa.RecoverAddress(transaction); + } Stopwatch stopwatch = Stopwatch.StartNew(); - IReleaseSpec? spec = specProvider.GetSpec((ForkActivation)test.CurrentNumber); - if (test.Transaction.ChainId is null) - test.Transaction.ChainId = MainnetSpecProvider.Instance.ChainId; - if (test.ParentBlobGasUsed is not null && test.ParentExcessBlobGas is not null) - { - BlockHeader parent = new( - parentHash: Keccak.Zero, - unclesHash: Keccak.OfAnEmptySequenceRlp, - beneficiary: test.CurrentCoinbase, - difficulty: test.CurrentDifficulty, - number: test.CurrentNumber - 1, - gasLimit: test.CurrentGasLimit, - timestamp: test.CurrentTimestamp, - extraData: [] - ) - { - BlobGasUsed = (ulong)test.ParentBlobGasUsed, - ExcessBlobGas = (ulong)test.ParentExcessBlobGas, - }; - header.ExcessBlobGas = BlobGasCalculator.CalculateExcessBlobGas(parent, spec); + BlockHeader[] uncles = test.Ommers + .Select(ommer => Build.A.BlockHeader + .WithNumber(test.CurrentNumber - ommer.Delta) + .WithBeneficiary(ommer.Address) + .TestObject) + .ToArray(); + + Block block = Build.A.Block.WithHeader(header).WithTransactions(test.Transactions) + .WithWithdrawals(test.Withdrawals).WithUncles(uncles).TestObject; + + if (!test.IsStateTest) + { + var withdrawalProcessor = new WithdrawalProcessor(stateProvider, _logManager); + withdrawalProcessor.ProcessWithdrawals(block, spec); } + else if (test.Withdrawals.Length > 0) + { + throw new T8NException("withdrawals are not supported in state tests", ExitCodes.ErrorEVM); + } + + CalculateReward(test.StateReward, test.IsStateTest, block, stateProvider, spec); + BlockReceiptsTracer blockReceiptsTracer = new BlockReceiptsTracer(); + StorageTxTracer storageTxTracer = new(); + if (test.IsT8NTest) + { + CompositeBlockTracer compositeBlockTracer = new(); + compositeBlockTracer.Add(storageTxTracer); + if (test.IsTraceEnabled) + { + GethLikeBlockFileTracer gethLikeBlockFileTracer = + new(block, test.GethTraceOptions, new FileSystem()); + compositeBlockTracer.Add(gethLikeBlockFileTracer); + } - Block block = Build.A.Block.WithTransactions(test.Transaction).WithHeader(header).TestObject; + blockReceiptsTracer.SetOtherTracer(compositeBlockTracer); + } - ValidationResult txIsValid = _txValidator.IsWellFormed(test.Transaction, spec); + blockReceiptsTracer.StartNewBlockTrace(block); - if (txIsValid) + BeaconBlockRootHandler beaconBlockRootHandler = new(transactionProcessor, stateProvider); + if (!test.IsStateTest && test.ParentBeaconBlockRoot != null) { - transactionProcessor.Execute(test.Transaction, new BlockExecutionContext(header), txTracer); + beaconBlockRootHandler.StoreBeaconRoot(block, spec, storageTxTracer); } - else + + int txIndex = 0; + TransactionExecutionReport transactionExecutionReport = new(); + + foreach (var tx in test.Transactions) { - _logger.Info($"Skipping invalid tx with error: {txIsValid.Error}"); + ValidationResult txIsValid = _txValidator.IsWellFormed(tx, spec); + if (txIsValid) + { + blockReceiptsTracer.StartNewTxTrace(tx); + TransactionResult transactionResult = transactionProcessor + .Execute(tx, new BlockExecutionContext(header), + test.IsT8NTest ? blockReceiptsTracer : txTracer); + blockReceiptsTracer.EndTxTrace(); + + if (!test.IsT8NTest) continue; + transactionExecutionReport.ValidTransactions.Add(tx); + if (transactionResult.Success) + { + transactionExecutionReport.SuccessfulTransactions.Add(tx); + blockReceiptsTracer.LastReceipt.PostTransactionState = null; + blockReceiptsTracer.LastReceipt.BlockHash = null; + blockReceiptsTracer.LastReceipt.BlockNumber = 0; + transactionExecutionReport.SuccessfulTransactionReceipts.Add(blockReceiptsTracer.LastReceipt); + } + 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)))); + stateProvider.Reset(); + } + + txIndex++; + } + else if (txIsValid.Error != null) + { + transactionExecutionReport.RejectedTransactionReceipts.Add(new RejectedTx(txIndex, GethErrorMappings.GetErrorMapping(txIsValid.Error))); + } } + blockReceiptsTracer.EndBlockTrace(); + stopwatch.Stop(); stateProvider.Commit(specProvider.GetSpec((ForkActivation)1)); - stateProvider.CommitTree(1); + stateProvider.CommitTree(test.CurrentNumber); // '@winsvega added a 0-wei reward to the miner , so we had to add that into the state test execution phase. He needed it for retesteth.' - if (!stateProvider.AccountExists(test.CurrentCoinbase)) + if (test.CurrentCoinbase != null && !stateProvider.AccountExists(test.CurrentCoinbase)) { stateProvider.CreateAccount(test.CurrentCoinbase, 0); } @@ -168,23 +249,60 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer) testResult.TimeInMs = stopwatch.Elapsed.TotalMilliseconds; testResult.StateRoot = stateProvider.StateRoot; - // Assert.Zero(differences.Count, "differences"); + if (test.IsT8NTest) + { + testResult.T8NResult = T8NResult.ConstructT8NResult(stateProvider, block, test, storageTxTracer, + blockReceiptsTracer, specProvider, header, transactionExecutionReport); + } + return testResult; } - private static void InitializeTestState(GeneralStateTest test, WorldState stateProvider, ISpecProvider specProvider) + private static IBlockhashProvider GetBlockHashProvider(GeneralStateTest test, BlockHeader header, + BlockHeader? parent) { - foreach (KeyValuePair accountState in test.Pre) + if (!test.IsT8NTest) { - foreach (KeyValuePair storageItem in accountState.Value.Storage) + return new TestBlockhashProvider(); + } + + var t8NBlockHashProvider = new T8NBlockHashProvider(); + + if (header.Hash != null) t8NBlockHashProvider.Insert(header.Hash, header.Number); + if (parent?.Hash != null) t8NBlockHashProvider.Insert(parent.Hash, parent.Number); + foreach (var blockHash in test.BlockHashes) + { + t8NBlockHashProvider.Insert(blockHash.Value, long.Parse(blockHash.Key)); + } + + return t8NBlockHashProvider; + } + + private static UInt256 CalculateBaseFeePerGas(GeneralStateTest test, BlockHeader? parentHeader) + { + if (test.CurrentBaseFee.HasValue) return test.CurrentBaseFee.Value; + return test.IsT8NTest ? BaseFeeCalculator.Calculate(parentHeader, test.Fork) : _defaultBaseFeeForStateTest; + } + + private static void InitializeTestPreState(Dictionary pre, WorldState stateProvider, + ISpecProvider specProvider) + { + foreach (KeyValuePair accountState in pre) + { + if (accountState.Value.Storage is not null) { - stateProvider.Set(new StorageCell(accountState.Key, storageItem.Key), - storageItem.Value.WithoutLeadingZeros().ToArray()); + foreach (KeyValuePair storageItem in accountState.Value.Storage) + { + stateProvider.Set(new StorageCell(accountState.Key, storageItem.Key), + storageItem.Value.WithoutLeadingZeros().ToArray()); + } } - stateProvider.CreateAccount(accountState.Key, accountState.Value.Balance); - stateProvider.InsertCode(accountState.Key, accountState.Value.Code, specProvider.GenesisSpec); - stateProvider.SetNonce(accountState.Key, accountState.Value.Nonce); + stateProvider.CreateAccount(accountState.Key, accountState.Value.Balance, accountState.Value.Nonce); + if (accountState.Value.Code is not null) + { + stateProvider.InsertCode(accountState.Key, accountState.Value.Code, specProvider.GenesisSpec); + } } stateProvider.Commit(specProvider.GenesisSpec); @@ -200,17 +318,41 @@ 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) + { + if (stateReward == null || isStateTest) return; + + var rewardCalculator = new RewardCalculator(UInt256.Parse(stateReward)); + BlockReward[] rewards = rewardCalculator.CalculateRewards(block); + + foreach (BlockReward reward in rewards) + { + if (!stateProvider.AccountExists(reward.Address)) + { + stateProvider.CreateAccount(reward.Address, reward.Value); + } + else + { + stateProvider.AddToBalance(reward.Address, reward.Value, spec); + } + } + } + private List RunAssertions(GeneralStateTest test, IWorldState stateProvider) { List differences = []; + if (test.IsT8NTest) return differences; if (test.PostHash != stateProvider.StateRoot) { differences.Add($"STATE ROOT exp: {test.PostHash}, actual: {stateProvider.StateRoot}"); diff --git a/src/Nethermind/Ethereum.Test.Base/JsonToEthereumTest.cs b/src/Nethermind/Ethereum.Test.Base/JsonToEthereumTest.cs index 7d41065cd52..9aa676a21df 100644 --- a/src/Nethermind/Ethereum.Test.Base/JsonToEthereumTest.cs +++ b/src/Nethermind/Ethereum.Test.Base/JsonToEthereumTest.cs @@ -21,13 +21,13 @@ namespace Ethereum.Test.Base { public static class JsonToEthereumTest { - private static IReleaseSpec ParseSpec(string network) + public static IReleaseSpec ParseSpec(string network) { network = network.Replace("EIP150", "TangerineWhistle"); network = network.Replace("EIP158", "SpuriousDragon"); network = network.Replace("DAO", "Dao"); - network = network.Replace("Merged", "GrayGlacier"); - network = network.Replace("Merge", "GrayGlacier"); + network = network.Replace("Merged", "Paris"); + network = network.Replace("Merge", "Paris"); network = network.Replace("London+3540+3670", "Shanghai"); network = network.Replace("GrayGlacier+3540+3670", "Shanghai"); network = network.Replace("GrayGlacier+3860", "Shanghai"); @@ -56,6 +56,7 @@ private static IReleaseSpec ParseSpec(string network) "Berlin" => Berlin.Instance, "London" => London.Instance, "GrayGlacier" => GrayGlacier.Instance, + "ArrowGlacier" => ArrowGlacier.Instance, "Shanghai" => Shanghai.Instance, "Cancun" => Cancun.Instance, "Paris" => Paris.Instance, @@ -178,7 +179,7 @@ public static Transaction Convert(PostStateJson postStateJson, TransactionJson t return transaction; } - private static void ProcessAccessList(AccessListItemJson[]? accessList, AccessList.Builder builder) + public static void ProcessAccessList(AccessListItemJson[]? accessList, AccessList.Builder builder) { foreach (AccessListItemJson accessListItemJson in accessList ?? Array.Empty()) { @@ -204,20 +205,6 @@ public static Transaction Convert(LegacyTransactionJson transactionJson) return transaction; } - private static AccountState Convert(AccountStateJson accountStateJson) - { - AccountState state = new(); - state.Balance = accountStateJson.Balance is not null ? Bytes.FromHexString(accountStateJson.Balance).ToUInt256() : 0; - state.Code = accountStateJson.Code is not null ? Bytes.FromHexString(accountStateJson.Code) : Array.Empty(); - state.Nonce = accountStateJson.Nonce is not null ? Bytes.FromHexString(accountStateJson.Nonce).ToUInt256() : 0; - state.Storage = accountStateJson.Storage is not null - ? accountStateJson.Storage.ToDictionary( - p => Bytes.FromHexString(p.Key).ToUInt256(), - p => Bytes.FromHexString(p.Value)) - : new(); - return state; - } - public static IEnumerable Convert(string name, GeneralStateTestJson testJson) { if (testJson.LoadFailure is not null) @@ -256,8 +243,8 @@ public static IEnumerable Convert(string name, GeneralStateTes test.ParentExcessBlobGas = testJson.Env.ParentExcessBlobGas; test.PostReceiptsRoot = stateJson.Logs; test.PostHash = stateJson.Hash; - test.Pre = testJson.Pre.ToDictionary(p => new Address(p.Key), p => Convert(p.Value)); - test.Transaction = Convert(stateJson, testJson.Transaction); + test.Pre = testJson.Pre.ToDictionary(p => p.Key, p => p.Value); + test.Transactions = [Convert(stateJson, testJson.Transaction)]; blockchainTests.Add(test); ++iterationNumber; @@ -283,7 +270,7 @@ public static BlockchainTest Convert(string name, BlockchainTestJson testJson) test.GenesisRlp = testJson.GenesisRlp is null ? null : new Rlp(Bytes.FromHexString(testJson.GenesisRlp)); test.GenesisBlockHeader = testJson.GenesisBlockHeader; test.Blocks = testJson.Blocks; - test.Pre = testJson.Pre.ToDictionary(p => new Address(p.Key), p => Convert(p.Value)); + test.Pre = testJson.Pre.ToDictionary(p => p.Key, p => p.Value); HalfBlockchainTestJson half = testJson as HalfBlockchainTestJson; if (half is not null) @@ -292,7 +279,7 @@ public static BlockchainTest Convert(string name, BlockchainTestJson testJson) } else { - test.PostState = testJson.PostState?.ToDictionary(p => new Address(p.Key), p => Convert(p.Value)); + test.PostState = testJson.PostState?.ToDictionary(p => p.Key, p => p.Value); test.PostStateRoot = testJson.PostStateHash; } diff --git a/src/Nethermind/Ethereum.Test.Base/Ommer.cs b/src/Nethermind/Ethereum.Test.Base/Ommer.cs new file mode 100644 index 00000000000..1e1c7115ab5 --- /dev/null +++ b/src/Nethermind/Ethereum.Test.Base/Ommer.cs @@ -0,0 +1,9 @@ +using Nethermind.Core; + +namespace Ethereum.Test.Base; + +public class Ommer +{ + public int Delta { get; set; } + public Address Address { get; set; } +} diff --git a/src/Nethermind/Ethereum.Test.Base/T8NUtils/ExitCodes.cs b/src/Nethermind/Ethereum.Test.Base/T8NUtils/ExitCodes.cs new file mode 100644 index 00000000000..59c711d3a6a --- /dev/null +++ b/src/Nethermind/Ethereum.Test.Base/T8NUtils/ExitCodes.cs @@ -0,0 +1,13 @@ +namespace Ethereum.Test.Base; + +public class ExitCodes +{ + public const int ErrorEVM = 2; + public const int ErrorConfig = 3; + + public const int ErrorMissingBlockhash = 4; + + public const int ErrorJson = 10; + public const int ErrorIO = 11; + public const int ErrorRlp = 12; +} diff --git a/src/Nethermind/Ethereum.Test.Base/T8NUtils/GethErrorMappings.cs b/src/Nethermind/Ethereum.Test.Base/T8NUtils/GethErrorMappings.cs new file mode 100644 index 00000000000..3d0ab901336 --- /dev/null +++ b/src/Nethermind/Ethereum.Test.Base/T8NUtils/GethErrorMappings.cs @@ -0,0 +1,21 @@ +namespace Ethereum.Test.Base.T8NUtils; + +// mapping Nethermind core error messages to geth errors +public class GethErrorMappings +{ + private const string WrongTransactionNonceError = "wrong transaction nonce"; + private const string WrongTransactionNonceGethError = "nonce too low: address {0}, tx: {1} state: {2}"; + + private const string MissingTxToError = "TxMissingTo: Must be set."; + private const string MissingTxToGethError = "rlp: input string too short for common.Address, decoding into (types.Transaction)(types.BlobTx).To"; + + public static string GetErrorMapping(string error, params object[] arguments) + { + return error switch + { + WrongTransactionNonceError => string.Format(WrongTransactionNonceGethError, arguments), + MissingTxToError => string.Format(MissingTxToGethError), + _ => error + }; + } +} diff --git a/src/Nethermind/Ethereum.Test.Base/T8NUtils/T8NBlockHashProvider.cs b/src/Nethermind/Ethereum.Test.Base/T8NUtils/T8NBlockHashProvider.cs new file mode 100644 index 00000000000..3474f9b2a98 --- /dev/null +++ b/src/Nethermind/Ethereum.Test.Base/T8NUtils/T8NBlockHashProvider.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using Nethermind.Core; +using Nethermind.Core.Crypto; +using Nethermind.Evm; + +namespace Ethereum.Test.Base.T8NUtils; + +public class T8NBlockHashProvider : IBlockhashProvider +{ + private readonly Dictionary _blockHashes = new(); + public Hash256 GetBlockhash(BlockHeader currentBlock, in long number) + { + return _blockHashes.GetValueOrDefault(number, null) + ?? throw new T8NException($"BlockHash for block {number} not provided", ExitCodes.ErrorMissingBlockhash); + } + + public void Insert(Hash256 blockHash, long number) + { + _blockHashes[number] = blockHash; + } +} diff --git a/src/Nethermind/Ethereum.Test.Base/T8NUtils/T8NException.cs b/src/Nethermind/Ethereum.Test.Base/T8NUtils/T8NException.cs new file mode 100644 index 00000000000..650f2d7a3ea --- /dev/null +++ b/src/Nethermind/Ethereum.Test.Base/T8NUtils/T8NException.cs @@ -0,0 +1,19 @@ +using System; +using Nethermind.Core.Exceptions; + +namespace Ethereum.Test.Base.T8NUtils; + +public class T8NException : Exception, IExceptionWithExitCode +{ + public T8NException(Exception e, int exitCode) : base(e.Message) + { + ExitCode = exitCode; + } + + public T8NException(string message, int exitCode) : base(message) + { + ExitCode = exitCode; + } + + public int ExitCode { get; } +} diff --git a/src/Nethermind/Ethereum.Test.Base/T8NUtils/T8NResult.cs b/src/Nethermind/Ethereum.Test.Base/T8NUtils/T8NResult.cs new file mode 100644 index 00000000000..019b84ab184 --- /dev/null +++ b/src/Nethermind/Ethereum.Test.Base/T8NUtils/T8NResult.cs @@ -0,0 +1,117 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text.Json.Serialization; +using Microsoft.IdentityModel.Tokens; +using Nethermind.Core; +using Nethermind.Core.Crypto; +using Nethermind.Core.Specs; +using Nethermind.Evm; +using Nethermind.Evm.Tracing; +using Nethermind.Evm.Tracing.GethStyle.Custom; +using Nethermind.Int256; +using Nethermind.Serialization.Rlp; +using Nethermind.State; +using Nethermind.State.Proofs; + +namespace Ethereum.Test.Base.T8NUtils; + +public class T8NResult +{ + public Hash256? TxRoot { get; set; } + public Hash256? ReceiptsRoot { get; set; } + public Hash256? WithdrawalsRoot { get; set; } + public Hash256? LogsHash { get; set; } + public Bloom? LogsBloom { get; set; } + public TxReceipt[]? Receipts { get; set; } + public RejectedTx[]? Rejected { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + public UInt256? CurrentDifficulty { get; set; } + public UInt256? GasUsed { get; set; } + public UInt256? CurrentBaseFee { get; set; } + public UInt256? CurrentExcessBlobGas { get; set; } + public UInt256? BlobGasUsed { get; set; } + public Dictionary Accounts { get; set; } + public byte[] TransactionsRlp { get; set; } + + private static readonly ReceiptMessageDecoder _receiptMessageDecoder = new(); + + public static T8NResult ConstructT8NResult(WorldState stateProvider, + Block block, + GeneralStateTest test, + StorageTxTracer storageTracer, + BlockReceiptsTracer blockReceiptsTracer, + ISpecProvider specProvider, + BlockHeader header, + TransactionExecutionReport txReport) + { + T8NResult t8NResult = new(); + + IReceiptSpec receiptSpec = specProvider.GetSpec(header); + + Hash256 txRoot = TxTrie.CalculateRoot(txReport.SuccessfulTransactions.ToArray()); + Hash256 receiptsRoot = ReceiptTrie.CalculateRoot(receiptSpec, + txReport.SuccessfulTransactionReceipts.ToArray(), _receiptMessageDecoder); + + var logEntries = txReport.SuccessfulTransactionReceipts + .SelectMany(receipt => receipt.Logs ?? Enumerable.Empty()) + .ToArray(); + var bloom = new Bloom(logEntries); + + var gasUsed = blockReceiptsTracer.TxReceipts.Count == 0 ? 0 : (ulong)blockReceiptsTracer.LastReceipt.GasUsedTotal; + + ulong? blobGasUsed = test.Fork.IsEip4844Enabled + ? BlobGasCalculator.CalculateBlobGas(txReport.ValidTransactions.ToArray()) + : null; + + t8NResult.TxRoot = txRoot; + t8NResult.ReceiptsRoot = receiptsRoot; + t8NResult.LogsBloom = bloom; + t8NResult.LogsHash = Keccak.Compute(Rlp.OfEmptySequence.Bytes); + t8NResult.Receipts = txReport.SuccessfulTransactionReceipts.ToArray(); + t8NResult.Rejected = txReport.RejectedTransactionReceipts.Count == 0 + ? null + : txReport.RejectedTransactionReceipts.ToArray(); + t8NResult.CurrentDifficulty = test.CurrentDifficulty; + t8NResult.GasUsed = new UInt256(gasUsed); + t8NResult.CurrentBaseFee = test.CurrentBaseFee; + t8NResult.WithdrawalsRoot = block.WithdrawalsRoot; + t8NResult.CurrentExcessBlobGas = header.ExcessBlobGas; + t8NResult.BlobGasUsed = blobGasUsed; + + var accounts = test.Pre.Keys.ToDictionary(address => address, + address => GetAccountState(address, stateProvider, storageTracer.Storages)); + foreach (var ommer in test.Ommers) + { + accounts.Add(ommer.Address, GetAccountState(ommer.Address, stateProvider, storageTracer.Storages)); + } + + if (header.Beneficiary != null) + { + accounts.Add(header.Beneficiary, GetAccountState(header.Beneficiary, stateProvider, storageTracer.Storages)); + } + + t8NResult.Accounts = accounts.Where(account => !account.Value.IsEmptyAccount()).ToDictionary(); + t8NResult.TransactionsRlp = Rlp.Encode(txReport.SuccessfulTransactions.ToArray()).Bytes; + + return t8NResult; + } + + private static AccountState GetAccountState(Address address, WorldState stateProvider, Dictionary> storages) + { + var account = stateProvider.GetAccount(address); + var code = stateProvider.GetCode(address); + var accountState = new AccountState + { + Nonce = account.Nonce, + Balance = account.Balance, + Code = code.Length == 0 ? null : code + }; + + if (storages.TryGetValue(address, out var storage)) + { + accountState.Storage = storage; + } + + return accountState; + } +} diff --git a/src/Nethermind/Ethereum.Test.Base/T8NUtils/TransactionExecutionReport.cs b/src/Nethermind/Ethereum.Test.Base/T8NUtils/TransactionExecutionReport.cs new file mode 100644 index 00000000000..8ddfe041287 --- /dev/null +++ b/src/Nethermind/Ethereum.Test.Base/T8NUtils/TransactionExecutionReport.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using Nethermind.Core; + +namespace Ethereum.Test.Base.T8NUtils; + +public class TransactionExecutionReport +{ + public List RejectedTransactionReceipts { get; set; } = []; + public List ValidTransactions { get; set; } = []; + public List SuccessfulTransactions { get; set; } = []; + public List SuccessfulTransactionReceipts { get; set; } = []; +} diff --git a/src/Nethermind/Ethereum.Test.Base/TestBlockhashProvider.cs b/src/Nethermind/Ethereum.Test.Base/TestBlockhashProvider.cs index 786ddde0b16..fb32889dea4 100644 --- a/src/Nethermind/Ethereum.Test.Base/TestBlockhashProvider.cs +++ b/src/Nethermind/Ethereum.Test.Base/TestBlockhashProvider.cs @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited // SPDX-License-Identifier: LGPL-3.0-only +using System.Collections.Generic; +using System.IO; using Nethermind.Core; using Nethermind.Core.Crypto; using Nethermind.Evm; diff --git a/src/Nethermind/Nethermind.Blockchain.Test/BeaconBlockRootHandlerTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/BeaconBlockRootHandlerTests.cs index 8f3e5461c7d..0f97d159030 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/BeaconBlockRootHandlerTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/BeaconBlockRootHandlerTests.cs @@ -124,7 +124,7 @@ public void Test_StoreBeaconRoot_AccessListIsNull() BlockHeader header = Build.A.BlockHeader.TestObject; Block block = Build.A.Block.WithHeader(header).TestObject; - _beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance); + _beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance, NullTxTracer.Instance); _transactionProcessor.DidNotReceive().Execute(Arg.Any(), Arg.Any(), Arg.Any()); } @@ -136,7 +136,7 @@ public void Test_StoreBeaconRoot_AccessListNotNull() Block block = Build.A.Block.WithHeader(header).TestObject; _worldState.AccountExists(Arg.Any
()).Returns(true); - _beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance); + _beaconBlockRootHandler.StoreBeaconRoot(block, Cancun.Instance, NullTxTracer.Instance); Transaction transaction = new() { diff --git a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs index a9a519e4492..de9ebcc8bbf 100644 --- a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs +++ b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs @@ -42,7 +42,7 @@ public class BeaconBlockRootHandler(ITransactionProcessor processor, IWorldState return (eip4788ContractAddress, builder.Build()); } - public void StoreBeaconRoot(Block block, IReleaseSpec spec) + public void StoreBeaconRoot(Block block, IReleaseSpec spec, ITxTracer txTracer) { (Address? toAddress, AccessList? accessList) = BeaconRootsAccessList(block, spec, includeStorageCells: false); @@ -62,7 +62,7 @@ public void StoreBeaconRoot(Block block, IReleaseSpec spec) transaction.Hash = transaction.CalculateHash(); - processor.Execute(transaction, header, NullTxTracer.Instance); + processor.Execute(transaction, header, txTracer); } } } diff --git a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs index 05aea2133ea..5c9f64a0c04 100644 --- a/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs +++ b/src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs @@ -4,11 +4,12 @@ using Nethermind.Core; using Nethermind.Core.Eip2930; using Nethermind.Core.Specs; +using Nethermind.Evm.Tracing; using Nethermind.State; namespace Nethermind.Blockchain.BeaconBlockRoot; public interface IBeaconBlockRootHandler { (Address? toAddress, AccessList? accessList) BeaconRootsAccessList(Block block, IReleaseSpec spec, bool includeStorageCells = true); - void StoreBeaconRoot(Block block, IReleaseSpec spec); + void StoreBeaconRoot(Block block, IReleaseSpec spec, ITxTracer txTracer); } diff --git a/src/Nethermind/Nethermind.Consensus.Ethash/EthashDifficultyCalculator.cs b/src/Nethermind/Nethermind.Consensus.Ethash/EthashDifficultyCalculator.cs index aedb99cc03c..9cd8ba25f6c 100644 --- a/src/Nethermind/Nethermind.Consensus.Ethash/EthashDifficultyCalculator.cs +++ b/src/Nethermind/Nethermind.Consensus.Ethash/EthashDifficultyCalculator.cs @@ -10,6 +10,7 @@ [assembly: InternalsVisibleTo("Ethereum.Test.Base")] [assembly: InternalsVisibleTo("Ethereum.Difficulty.Test")] +[assembly: InternalsVisibleTo("Evm")] namespace Nethermind.Consensus.Ethash { diff --git a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs index a152ed5e551..01bc288e9f6 100644 --- a/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs +++ b/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs @@ -345,7 +345,7 @@ private void StoreBeaconRoot(Block block, IReleaseSpec spec) { try { - _beaconBlockRootHandler.StoreBeaconRoot(block, spec); + _beaconBlockRootHandler.StoreBeaconRoot(block, spec, NullTxTracer.Instance); } catch (Exception e) { diff --git a/src/Nethermind/Nethermind.Consensus/Rewards/RewardCalculator.cs b/src/Nethermind/Nethermind.Consensus/Rewards/RewardCalculator.cs index bd0f6cad29e..e34f527ef75 100644 --- a/src/Nethermind/Nethermind.Consensus/Rewards/RewardCalculator.cs +++ b/src/Nethermind/Nethermind.Consensus/Rewards/RewardCalculator.cs @@ -11,17 +11,31 @@ namespace Nethermind.Consensus.Rewards { public class RewardCalculator : IRewardCalculator, IRewardCalculatorSource { - private readonly ISpecProvider _specProvider; + private readonly ISpecProvider? _specProvider; + private readonly UInt256? _blockReward; public RewardCalculator(ISpecProvider? specProvider) { _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider)); } + public RewardCalculator(UInt256? blockReward) + { + _blockReward = blockReward; + } + private UInt256 GetBlockReward(Block block) { - IReleaseSpec spec = _specProvider.GetSpec(block.Header); - return spec.BlockReward; + if (_specProvider != null) + { + IReleaseSpec spec = _specProvider.GetSpec(block.Header); + return spec.BlockReward; + } + if (_blockReward.HasValue) + { + return _blockReward.Value; + } + throw new ArgumentNullException(nameof(_specProvider)); } public BlockReward[] CalculateRewards(Block block) diff --git a/src/Nethermind/Nethermind.Core.Test/Builders/TransactionBuilder.cs b/src/Nethermind/Nethermind.Core.Test/Builders/TransactionBuilder.cs index 2246e7c319d..6710cb896e7 100644 --- a/src/Nethermind/Nethermind.Core.Test/Builders/TransactionBuilder.cs +++ b/src/Nethermind/Nethermind.Core.Test/Builders/TransactionBuilder.cs @@ -251,12 +251,12 @@ public TransactionBuilder Signed(IEthereumEcdsa ecdsa, PrivateKey privateKey, return this; } - public TransactionBuilder Signed(PrivateKey? privateKey = null) + public TransactionBuilder Signed(PrivateKey? privateKey = null, bool isEip155Enabled = true) { privateKey ??= TestItem.IgnoredPrivateKey; EthereumEcdsa ecdsa = new(TestObjectInternal.ChainId ?? TestBlockchainIds.ChainId); - return Signed(ecdsa, privateKey, isEip155Enabled: true); + return Signed(ecdsa, privateKey, isEip155Enabled); } // TODO: auto create ecdsa here diff --git a/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/Custom/Native/NativeTracerContext.cs b/src/Nethermind/Nethermind.Evm/Tracing/GethStyle/Custom/Native/NativeTracerContext.cs deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/Nethermind/Nethermind.Evm/Tracing/StorageTxTracer.cs b/src/Nethermind/Nethermind.Evm/Tracing/StorageTxTracer.cs new file mode 100644 index 00000000000..82fc0e1aa19 --- /dev/null +++ b/src/Nethermind/Nethermind.Evm/Tracing/StorageTxTracer.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using Nethermind.Core; +using Nethermind.Int256; + +namespace Nethermind.Evm.Tracing; + +public class StorageTxTracer : TxTracer, IBlockTracer +{ + public Dictionary> Storages = new(); + public bool IsTracingRewards => false; + public override bool IsTracingOpLevelStorage => true; + + public override void SetOperationStorage(Address address, UInt256 storageIndex, ReadOnlySpan newValue, + ReadOnlySpan currentValue) + { + if (!Storages.TryGetValue(address, out _)) + { + Storages[address] = []; + } + + Storages[address][storageIndex] = newValue.ToArray(); + } + + + public void ReportReward(Address author, string rewardType, UInt256 rewardValue) { } + + public void StartNewBlockTrace(Block block) { } + + public ITxTracer StartNewTxTrace(Transaction? tx) => this; + + public void EndTxTrace() { } + + public void EndBlockTrace() { } +} diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs index abfce411741..72baf781716 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.HelperFunctions.cs @@ -24,6 +24,7 @@ using Microsoft.CodeAnalysis; using Nethermind.Blockchain.BeaconBlockRoot; using Nethermind.Core.Specs; +using Nethermind.Evm.Tracing; namespace Nethermind.Merge.Plugin.Test { @@ -154,7 +155,7 @@ private static ExecutionPayloadV4 CreateBlockRequestV4(MergeTestBlockchain chain blockRequestV4.TryGetBlock(out Block? block); var beaconBlockRootHandler = new BeaconBlockRootHandler(chain.TxProcessor, chain.WorldStateManager.GlobalWorldState); - beaconBlockRootHandler.StoreBeaconRoot(block!, chain.SpecProvider.GetSpec(block!.Header)); + beaconBlockRootHandler.StoreBeaconRoot(block!, chain.SpecProvider.GetSpec(block!.Header), NullTxTracer.Instance); Snapshot before = chain.State.TakeSnapshot(); var blockHashStore = new BlockhashStore(chain.SpecProvider, chain.State); blockHashStore.ApplyBlockhashStateChanges(block!.Header); diff --git a/src/Nethermind/Nethermind.Test.Runner/StateTestRunner.cs b/src/Nethermind/Nethermind.Test.Runner/StateTestRunner.cs index b44812e2d8e..eeb69a50faf 100644 --- a/src/Nethermind/Nethermind.Test.Runner/StateTestRunner.cs +++ b/src/Nethermind/Nethermind.Test.Runner/StateTestRunner.cs @@ -91,7 +91,10 @@ public IEnumerable RunTests() var txTrace = txTracer.BuildResult(); txTrace.Result.Time = result.TimeInMs; txTrace.State.StateRoot = result.StateRoot; - txTrace.Result.GasUsed -= IntrinsicGasCalculator.Calculate(test.Transaction, test.Fork); + foreach (var transaction in test.Transactions) + { + txTrace.Result.GasUsed -= IntrinsicGasCalculator.Calculate(transaction, test.Fork); + } WriteErr(txTrace); } diff --git a/tools/Evm.Test/Evm.Test.csproj b/tools/Evm.Test/Evm.Test.csproj new file mode 100644 index 00000000000..78b47f11a74 --- /dev/null +++ b/tools/Evm.Test/Evm.Test.csproj @@ -0,0 +1,41 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + + ..\Evm\bin\Debug\net8.0\Evm.dll + + + + + + + + + + + + + PreserveNewest + + + + diff --git a/tools/Evm.Test/T8NTests.cs b/tools/Evm.Test/T8NTests.cs new file mode 100644 index 00000000000..5ca0f161e95 --- /dev/null +++ b/tools/Evm.Test/T8NTests.cs @@ -0,0 +1,282 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Evm.JsonTypes; +using Nethermind.Serialization.Json; +using Newtonsoft.Json.Linq; + +namespace Evm.Test; +using T8NTool; + +public class InputParams +{ + public readonly string Alloc; + public readonly string Env; + public readonly string Txs; + public readonly string StateFork; + public readonly string? StateReward; + + public InputParams(string basedir, string alloc, string env, string txs, string stateFork, string? stateReward = null) + { + Alloc = basedir + alloc; + Env = basedir + env; + Txs = basedir + txs; + StateFork = stateFork; + StateReward = stateReward; + } +} + +public class OutputParams +{ + public string? Alloc; + public string? Result; + public string? Body; + + public OutputParams(string? alloc = null, string? result = null, string? body = null) + { + Alloc = alloc; + Result = result; + Body = body; + } +} + +public class T8NTests +{ + private T8NTool _t8NTool; + private readonly EthereumJsonSerializer _ethereumJsonSerializer = new(); + + [SetUp] + public void Setup() + { + _t8NTool = new T8NTool(); + } + + [Test] + public void Test1() + { + Execute( + new InputParams("testdata/1/", "alloc.json", "env.json", "txs.json", "Frontier+1346"), + new OutputParams(alloc: "stdout", result: "stdout"), + expectedExitCode: 3); + } + + [Test] + public void Test2() + { + Execute( + new InputParams("testdata/1/", "alloc.json", "env.json", "txs.json", "Byzantium"), + new OutputParams(alloc: "stdout", result: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/1/exp.json"); + } + + [Test] + public void Test3() + { + Execute( + new InputParams("testdata/3/", "alloc.json", "env.json", "txs.json", "Berlin"), + new OutputParams(alloc: "stdout", result: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/3/exp.json"); + } + + [Test] + public void Test4() + { + Execute( + new InputParams("testdata/4/", "alloc.json", "env.json", "txs.json", "Berlin"), + new OutputParams(alloc: "stdout", result: "stdout"), + expectedExitCode: 4); + } + + [Test] + public void Test5() + { + Execute( + new InputParams("testdata/5/", "alloc.json", "env.json", "txs.json", "Byzantium", "0x80"), + new OutputParams(alloc: "stdout", result: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/5/exp.json"); + } + + [Test] + public void Test6() + { + Execute( + new InputParams("testdata/13/", "alloc.json", "env.json", "txs.json", "London"), + new OutputParams(body: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/13/exp.json"); + } + + [Test] + public void Test7() + { + Execute( + new InputParams("testdata/13/", "alloc.json", "env.json", "signed_txs.rlp", "London"), + new OutputParams(result: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/13/exp2.json"); + } + + [Test] + public void Test8() + { + Execute( + new InputParams("testdata/14/", "alloc.json", "env.json", "txs.json", "London"), + new OutputParams(result: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/14/exp.json"); + } + + [Test] + public void Test9() + { + Execute( + new InputParams("testdata/14/", "alloc.json", "env.uncles.json", "txs.json", "London"), + new OutputParams(result: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/14/exp2.json"); + } + + [Test] + public void Test10() + { + Execute( + new InputParams("testdata/14/", "alloc.json", "env.uncles.json", "txs.json", "Berlin"), + new OutputParams(result: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/14/exp_berlin.json"); + } + + [Test] + public void Test11() + { + Execute( + new InputParams("testdata/19/", "alloc.json", "env.json", "txs.json", "London"), + new OutputParams(result: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/19/exp_london.json"); + } + + [Test] + public void Test12() + { + Execute( + new InputParams("testdata/19/", "alloc.json", "env.json", "txs.json", "ArrowGlacier"), + new OutputParams(result: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/19/exp_arrowglacier.json"); + } + + [Test] + public void Test13() + { + Execute( + new InputParams("testdata/19/", "alloc.json", "env.json", "txs.json", "GrayGlacier"), + new OutputParams(result: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/19/exp_grayglacier.json"); + } + + [Test] + public void Test14() + { + Execute( + new InputParams("testdata/23/", "alloc.json", "env.json", "txs.json", "Berlin"), + new OutputParams(result: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/23/exp.json"); + } + + [Test] + public void Test15() + { + Execute( + new InputParams("testdata/24/", "alloc.json", "env.json", "txs.json", "Merge"), + new OutputParams(result: "stdout", alloc: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/24/exp.json"); + } + + [Test] + public void Test16() + { + Execute( + new InputParams("testdata/24/", "alloc.json", "env-missingrandom.json", "txs.json", "Merge"), + new OutputParams(result: "stdout", alloc: "stdout"), + expectedExitCode: 3); + } + + [Test] + public void Test17() + { + Execute( + new InputParams("testdata/26/", "alloc.json", "env.json", "txs.json", "Shanghai"), + new OutputParams(result: "stdout", alloc: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/26/exp.json"); + } + + [Test] + public void Test18() + { + Execute( + new InputParams("testdata/28/", "alloc.json", "env.json", "txs.rlp", "Cancun"), + new OutputParams(result: "stdout", alloc: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/28/exp.json"); + } + + [Test] + public void Test19() + { + Execute( + new InputParams("testdata/29/", "alloc.json", "env.json", "txs.json", "Cancun"), + new OutputParams(result: "stdout", alloc: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/29/exp.json"); + } + + [Test] + public void Test20() + { + Execute( + new InputParams("testdata/30/", "alloc.json", "env.json", "txs_more.rlp", "Cancun"), + new OutputParams(result: "stdout", alloc: "stdout"), + expectedExitCode: 0, + expectedOutputFile: "testdata/30/exp.json"); + } + + private void Execute(InputParams inputParams, OutputParams outputParams, int expectedExitCode, string? expectedOutputFile = null) + { + var output = _t8NTool.Execute( + inputParams.Alloc, + inputParams.Env, + inputParams.Txs, + null, + outputParams.Alloc, + outputParams.Body, + outputParams.Result, + 1, + inputParams.StateFork, + inputParams.StateReward, + TraceOptions.Default + ); + + Assert.That(output.ExitCode, Is.EqualTo(expectedExitCode)); + + if (expectedOutputFile == null) return; + + var outputString = _ethereumJsonSerializer.Serialize(output, true); + var fileContent = File.ReadAllText(expectedOutputFile); + Assert.That(AreEqual(fileContent, outputString)); + } + + private static bool AreEqual(string json1, string json2) + { + JToken expected = JToken.Parse(json1); + JToken actual = JToken.Parse(json2); + return JToken.DeepEquals(actual, expected); + } +} diff --git a/tools/Evm.Test/testdata/1/alloc.json b/tools/Evm.Test/testdata/1/alloc.json new file mode 100644 index 00000000000..cef1a25ff01 --- /dev/null +++ b/tools/Evm.Test/testdata/1/alloc.json @@ -0,0 +1,12 @@ +{ + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x5ffd4878be161d74", + "code": "0x", + "nonce": "0xac", + "storage": {} + }, + "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192":{ + "balance": "0xfeedbead", + "nonce" : "0x00" + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/1/env.json b/tools/Evm.Test/testdata/1/env.json new file mode 100644 index 00000000000..dd60abd205a --- /dev/null +++ b/tools/Evm.Test/testdata/1/env.json @@ -0,0 +1,7 @@ +{ + "currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "currentDifficulty": "0x20000", + "currentGasLimit": "0x750a163df65e8a", + "currentNumber": "1", + "currentTimestamp": "1000" +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/1/exp.json b/tools/Evm.Test/testdata/1/exp.json new file mode 100644 index 00000000000..d1351e5b76b --- /dev/null +++ b/tools/Evm.Test/testdata/1/exp.json @@ -0,0 +1,45 @@ +{ + "alloc": { + "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192": { + "balance": "0xfeed1a9d", + "nonce": "0x1" + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x5ffd4878be161d74", + "nonce": "0xac" + }, + "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0xa410" + } + }, + "result": { + "stateRoot": "0x84208a19bc2b46ada7445180c1db162be5b39b9abc8c0a54b05d32943eae4e13", + "txRoot": "0xc4761fd7b87ff2364c7c60b6c5c8d02e522e815328aaea3f20e3b7b7ef52c42d", + "receiptsRoot": "0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [ + { + "root": "0x", + "status": "0x1", + "cumulativeGasUsed": "0x5208", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0x0557bacce3375c98d806609b8d5043072f0b6a8bae45ae5a67a00d3a1a18d673", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x5208", + "effectiveGasPrice": null, + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x0" + } + ], + "rejected": [ + { + "index": 1, + "error": "nonce too low: address 0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192, tx: 0 state: 1" + } + ], + "currentDifficulty": "0x20000", + "gasUsed": "0x5208" + } +} diff --git a/tools/Evm.Test/testdata/1/txs.json b/tools/Evm.Test/testdata/1/txs.json new file mode 100644 index 00000000000..50b31ff31bc --- /dev/null +++ b/tools/Evm.Test/testdata/1/txs.json @@ -0,0 +1,26 @@ +[ + { + "gas": "0x5208", + "gasPrice": "0x2", + "hash": "0x0557bacce3375c98d806609b8d5043072f0b6a8bae45ae5a67a00d3a1a18d673", + "input": "0x", + "nonce": "0x0", + "r": "0x9500e8ba27d3c33ca7764e107410f44cbd8c19794bde214d694683a7aa998cdb", + "s": "0x7235ae07e4bd6e0206d102b1f8979d6adab280466b6a82d2208ee08951f1f600", + "to": "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192", + "v": "0x1b", + "value": "0x1" + }, + { + "gas": "0x5208", + "gasPrice": "0x2", + "hash": "0x0557bacce3375c98d806609b8d5043072f0b6a8bae45ae5a67a00d3a1a18d673", + "input": "0x", + "nonce": "0x0", + "r": "0x9500e8ba27d3c33ca7764e107410f44cbd8c19794bde214d694683a7aa998cdb", + "s": "0x7235ae07e4bd6e0206d102b1f8979d6adab280466b6a82d2208ee08951f1f600", + "to": "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192", + "v": "0x1b", + "value": "0x1" + } +] diff --git a/tools/Evm.Test/testdata/10/alloc.json b/tools/Evm.Test/testdata/10/alloc.json new file mode 100644 index 00000000000..6e98e7513c4 --- /dev/null +++ b/tools/Evm.Test/testdata/10/alloc.json @@ -0,0 +1,23 @@ +{ + "0x1111111111111111111111111111111111111111" : { + "balance" : "0x010000000000", + "code" : "0xfe", + "nonce" : "0x01", + "storage" : { + } + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0x010000000000", + "code" : "0x", + "nonce" : "0x01", + "storage" : { + } + }, + "0xd02d72e067e77158444ef2020ff2d325f929b363" : { + "balance" : "0x01000000000000", + "code" : "0x", + "nonce" : "0x01", + "storage" : { + } + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/10/env.json b/tools/Evm.Test/testdata/10/env.json new file mode 100644 index 00000000000..3a82d46a774 --- /dev/null +++ b/tools/Evm.Test/testdata/10/env.json @@ -0,0 +1,12 @@ +{ + "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "0x020000", + "currentNumber" : "0x01", + "currentTimestamp" : "0x079e", + "previousHash" : "0xcb23ee65a163121f640673b41788ee94633941405f95009999b502eedfbbfd4f", + "currentGasLimit" : "0x40000000", + "currentBaseFee" : "0x036b", + "blockHashes" : { + "0" : "0xcb23ee65a163121f640673b41788ee94633941405f95009999b502eedfbbfd4f" + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/10/readme.md b/tools/Evm.Test/testdata/10/readme.md new file mode 100644 index 00000000000..afa37872381 --- /dev/null +++ b/tools/Evm.Test/testdata/10/readme.md @@ -0,0 +1,85 @@ +## EIP-1559 testing + +This test contains testcases for EIP-1559, which were reported by Ori as misbehaving. + +``` +[user@work evm]$ dir=./testdata/10 && ./evm t8n --state.fork=London --input.alloc=$dir/alloc.json --input.txs=$dir/txs.json --input.env=$dir/env.json --output.alloc=stdout --output.result=stdout 2>&1 +INFO [05-09|22:11:59.436] rejected tx index=3 hash=db07bf..ede1e8 from=0xd02d72E067e77158444ef2020Ff2d325f929B363 error="gas limit reached" +``` +Output: +```json +{ + "alloc": { + "0x1111111111111111111111111111111111111111": { + "code": "0xfe", + "balance": "0x10000000000", + "nonce": "0x1" + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x10000000000", + "nonce": "0x1" + }, + "0xd02d72e067e77158444ef2020ff2d325f929b363": { + "balance": "0xff5beffffc95", + "nonce": "0x4" + } + }, + "result": { + "stateRoot": "0xf91a7ec08e4bfea88719aab34deabb000c86902360532b52afa9599d41f2bb8b", + "txRoot": "0xda925f2306a52fa24c15d5cd212d736ee016415fd8dd0c45fd368de7917d64bb", + "receiptsRoot": "0x439a25f7fc424c10fb1f89800e4aa1df74156b137239d9ac3eaa7c911c353cd5", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [ + { + "type": "0x2", + "root": "0x", + "status": "0x0", + "cumulativeGasUsed": "0x10000001", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0x88980f6efcc5358d9c359663e7b9414722d430497637340ea056b076bc206701", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x10000001", + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x0" + }, + { + "type": "0x2", + "root": "0x", + "status": "0x0", + "cumulativeGasUsed": "0x20000001", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0xd7bf3886f4e2aef74d525ae072c680f3846f550254401b67cbfda4a233757582", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x10000000", + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x1" + }, + { + "type": "0x2", + "root": "0x", + "status": "0x0", + "cumulativeGasUsed": "0x30000001", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0x50308296760f01f1eeec7500e9e73cad67469249b1f59e9a9f55e6625a4923db", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x10000000", + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x2" + } + ], + "rejected": [ + { + "index": 3, + "error": "gas limit reached" + } + ], + "currentDifficulty": "0x20000", + "gasUsed": "0x30000001", + "currentBaseFee": "0x36b" + } +} +``` diff --git a/tools/Evm.Test/testdata/10/txs.json b/tools/Evm.Test/testdata/10/txs.json new file mode 100644 index 00000000000..f7c9baa26da --- /dev/null +++ b/tools/Evm.Test/testdata/10/txs.json @@ -0,0 +1,70 @@ +[ + { + "input" : "0x", + "gas" : "0x10000001", + "nonce" : "0x1", + "to" : "0x1111111111111111111111111111111111111111", + "value" : "0x0", + "v" : "0x0", + "r" : "0x7a45f00bcde9036b026cdf1628b023cd8a31a95c62b5e4dbbee2fa7debe668fb", + "s" : "0x3cc9d6f2cd00a045b0263f2d6dad7d60938d5d13d061af4969f95928aa934d4a", + "secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298", + "chainId" : "0x1", + "type" : "0x2", + "maxFeePerGas" : "0xfa0", + "maxPriorityFeePerGas" : "0x0", + "accessList" : [ + ] + }, + { + "input" : "0x", + "gas" : "0x10000000", + "nonce" : "0x2", + "to" : "0x1111111111111111111111111111111111111111", + "value" : "0x0", + "v" : "0x0", + "r" : "0x4c564b94b0281a8210eeec2dd1fe2e16ff1c1903a8c3a1078d735d7f8208b2af", + "s" : "0x56432b2593e6de95db1cb997b7385217aca03f1615327e231734446b39f266d", + "secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298", + "chainId" : "0x1", + "type" : "0x2", + "maxFeePerGas" : "0xfa0", + "maxPriorityFeePerGas" : "0x0", + "accessList" : [ + ] + }, + { + "input" : "0x", + "gas" : "0x10000000", + "nonce" : "0x3", + "to" : "0x1111111111111111111111111111111111111111", + "value" : "0x0", + "v" : "0x0", + "r" : "0x2ed2ef52f924f59d4a21e1f2a50d3b1109303ce5e32334a7ece9b46f4fbc2a57", + "s" : "0x2980257129cbd3da987226f323d50ba3975a834d165e0681f991b75615605c44", + "secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298", + "chainId" : "0x1", + "type" : "0x2", + "maxFeePerGas" : "0xfa0", + "maxPriorityFeePerGas" : "0x0", + "accessList" : [ + ] + }, + { + "input" : "0x", + "gas" : "0x10000000", + "nonce" : "0x4", + "to" : "0x1111111111111111111111111111111111111111", + "value" : "0x0", + "v" : "0x0", + "r" : "0x5df7d7f8f8e15b36fc9f189cacb625040fad10398d08fc90812595922a2c49b2", + "s" : "0x565fc1803f77a84d754ffe3c5363ab54a8d93a06ea1bb9d4c73c73a282b35917", + "secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298", + "chainId" : "0x1", + "type" : "0x2", + "maxFeePerGas" : "0xfa0", + "maxPriorityFeePerGas" : "0x0", + "accessList" : [ + ] + } +] \ No newline at end of file diff --git a/tools/Evm.Test/testdata/11/alloc.json b/tools/Evm.Test/testdata/11/alloc.json new file mode 100644 index 00000000000..86938230fa7 --- /dev/null +++ b/tools/Evm.Test/testdata/11/alloc.json @@ -0,0 +1,25 @@ +{ + "0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x61ffff5060046000f3", + "nonce" : "0x01", + "storage" : { + } + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x", + "nonce" : "0x00", + "storage" : { + "0x00" : "0x00" + } + }, + "0xb94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0x00", + "code" : "0x6001600055", + "nonce" : "0x00", + "storage" : { + } + } +} + diff --git a/tools/Evm.Test/testdata/11/env.json b/tools/Evm.Test/testdata/11/env.json new file mode 100644 index 00000000000..37dedf09475 --- /dev/null +++ b/tools/Evm.Test/testdata/11/env.json @@ -0,0 +1,12 @@ +{ + "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "0x020000", + "currentNumber" : "0x01", + "currentTimestamp" : "0x03e8", + "previousHash" : "0xfda4419b3660e99f37e536dae1ab081c180136bb38c837a93e93d9aab58553b2", + "currentGasLimit" : "0x0f4240", + "blockHashes" : { + "0" : "0xfda4419b3660e99f37e536dae1ab081c180136bb38c837a93e93d9aab58553b2" + } +} + diff --git a/tools/Evm.Test/testdata/11/readme.md b/tools/Evm.Test/testdata/11/readme.md new file mode 100644 index 00000000000..d499f8e99fa --- /dev/null +++ b/tools/Evm.Test/testdata/11/readme.md @@ -0,0 +1,13 @@ +## Test missing basefee + +In this test, the `currentBaseFee` is missing from the env portion. +On a live blockchain, the basefee is present in the header, and verified as part of header validation. + +In `evm t8n`, we don't have blocks, so it needs to be added in the `env`instead. + +When it's missing, an error is expected. + +``` +dir=./testdata/11 && ./evm t8n --state.fork=London --input.alloc=$dir/alloc.json --input.txs=$dir/txs.json --input.env=$dir/env.json --output.alloc=stdout --output.result=stdout 2>&1>/dev/null +ERROR(3): EIP-1559 config but missing 'currentBaseFee' in env section +``` \ No newline at end of file diff --git a/tools/Evm.Test/testdata/11/txs.json b/tools/Evm.Test/testdata/11/txs.json new file mode 100644 index 00000000000..c54b0a1f5b4 --- /dev/null +++ b/tools/Evm.Test/testdata/11/txs.json @@ -0,0 +1,14 @@ +[ + { + "input" : "0x38600060013960015160005560006000f3", + "gas" : "0x61a80", + "gasPrice" : "0x1", + "nonce" : "0x0", + "value" : "0x186a0", + "v" : "0x1c", + "r" : "0x2e1391fd903387f1cc2b51df083805fb4bbb0d4710a2cdf4a044d191ff7be63e", + "s" : "0x7f10a933c42ab74927db02b1db009e923d9d2ab24ac24d63c399f2fe5d9c9b22", + "secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" + } +] + diff --git a/tools/Evm.Test/testdata/12/alloc.json b/tools/Evm.Test/testdata/12/alloc.json new file mode 100644 index 00000000000..3ed96894fbc --- /dev/null +++ b/tools/Evm.Test/testdata/12/alloc.json @@ -0,0 +1,11 @@ +{ + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "84000000", + "code" : "0x", + "nonce" : "0x00", + "storage" : { + "0x00" : "0x00" + } + } +} + diff --git a/tools/Evm.Test/testdata/12/env.json b/tools/Evm.Test/testdata/12/env.json new file mode 100644 index 00000000000..8ae5465369c --- /dev/null +++ b/tools/Evm.Test/testdata/12/env.json @@ -0,0 +1,10 @@ +{ + "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "0x020000", + "currentNumber" : "0x01", + "currentTimestamp" : "0x03e8", + "previousHash" : "0xfda4419b3660e99f37e536dae1ab081c180136bb38c837a93e93d9aab58553b2", + "currentGasLimit" : "0x0f4240", + "currentBaseFee" : "0x20" +} + diff --git a/tools/Evm.Test/testdata/12/readme.md b/tools/Evm.Test/testdata/12/readme.md new file mode 100644 index 00000000000..e3195be48ba --- /dev/null +++ b/tools/Evm.Test/testdata/12/readme.md @@ -0,0 +1,43 @@ +## Test 1559 balance + gasCap + +This test contains an EIP-1559 consensus issue which happened on Ropsten, where +`geth` did not properly account for the value transfer while doing the check on `max_fee_per_gas * gas_limit`. + +Before the issue was fixed, this invocation allowed the transaction to pass into a block: +``` +dir=./testdata/12 && ./evm t8n --state.fork=London --input.alloc=$dir/alloc.json --input.txs=$dir/txs.json --input.env=$dir/env.json --output.alloc=stdout --output.result=stdout +``` + +With the fix applied, the result is: +``` +dir=./testdata/12 && ./evm t8n --state.fork=London --input.alloc=$dir/alloc.json --input.txs=$dir/txs.json --input.env=$dir/env.json --output.alloc=stdout --output.result=stdout +INFO [03-09|10:43:12.649] rejected tx index=0 hash=ccc996..d83435 from=0xa94f5374Fce5edBC8E2a8697C15331677e6EbF0B error="insufficient funds for gas * price + value: address 0xa94f5374Fce5edBC8E2a8697C15331677e6EbF0B have 84000000 want 84000032" +INFO [03-09|10:43:12.650] Trie dumping started root=e05f81..6597a5 +INFO [03-09|10:43:12.650] Trie dumping complete accounts=1 elapsed="46.393µs" +{ + "alloc": { + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x501bd00" + } + }, + "result": { + "stateRoot": "0xe05f81f8244a76503ceec6f88abfcd03047a612a1001217f37d30984536597a5", + "txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [], + "rejected": [ + { + "index": 0, + "error": "insufficient funds for gas * price + value: address 0xa94f5374Fce5edBC8E2a8697C15331677e6EbF0B have 84000000 want 84000032" + } + ], + "currentDifficulty": "0x20000", + "gasUsed": "0x0", + "currentBaseFee": "0x20" + } +} +``` + +The transaction is rejected. \ No newline at end of file diff --git a/tools/Evm.Test/testdata/12/txs.json b/tools/Evm.Test/testdata/12/txs.json new file mode 100644 index 00000000000..cd683f271c7 --- /dev/null +++ b/tools/Evm.Test/testdata/12/txs.json @@ -0,0 +1,20 @@ +[ + { + "input" : "0x", + "gas" : "0x5208", + "nonce" : "0x0", + "to" : "0x1111111111111111111111111111111111111111", + "value" : "0x20", + "v" : "0x0", + "r" : "0x0", + "s" : "0x0", + "secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "chainId" : "0x1", + "type" : "0x2", + "maxFeePerGas" : "0xfa0", + "maxPriorityFeePerGas" : "0x20", + "accessList" : [ + ] + } +] + diff --git a/tools/Evm.Test/testdata/13/alloc.json b/tools/Evm.Test/testdata/13/alloc.json new file mode 100644 index 00000000000..6e98e7513c4 --- /dev/null +++ b/tools/Evm.Test/testdata/13/alloc.json @@ -0,0 +1,23 @@ +{ + "0x1111111111111111111111111111111111111111" : { + "balance" : "0x010000000000", + "code" : "0xfe", + "nonce" : "0x01", + "storage" : { + } + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0x010000000000", + "code" : "0x", + "nonce" : "0x01", + "storage" : { + } + }, + "0xd02d72e067e77158444ef2020ff2d325f929b363" : { + "balance" : "0x01000000000000", + "code" : "0x", + "nonce" : "0x01", + "storage" : { + } + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/13/env.json b/tools/Evm.Test/testdata/13/env.json new file mode 100644 index 00000000000..3a82d46a774 --- /dev/null +++ b/tools/Evm.Test/testdata/13/env.json @@ -0,0 +1,12 @@ +{ + "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "0x020000", + "currentNumber" : "0x01", + "currentTimestamp" : "0x079e", + "previousHash" : "0xcb23ee65a163121f640673b41788ee94633941405f95009999b502eedfbbfd4f", + "currentGasLimit" : "0x40000000", + "currentBaseFee" : "0x036b", + "blockHashes" : { + "0" : "0xcb23ee65a163121f640673b41788ee94633941405f95009999b502eedfbbfd4f" + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/13/exp.json b/tools/Evm.Test/testdata/13/exp.json new file mode 100644 index 00000000000..2b049dfb290 --- /dev/null +++ b/tools/Evm.Test/testdata/13/exp.json @@ -0,0 +1,3 @@ +{ + "body": "0xf8d2b86702f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904b86702f864010280820fa08284d09411111111111111111111111111111111111111118080c080a0d4ec563b6568cd42d998fc4134b36933c6568d01533b5adf08769270243c6c7fa072bf7c21eac6bbeae5143371eef26d5e279637f3bd73482b55979d76d935b1e9" +} diff --git a/tools/Evm.Test/testdata/13/exp2.json b/tools/Evm.Test/testdata/13/exp2.json new file mode 100644 index 00000000000..babce35929a --- /dev/null +++ b/tools/Evm.Test/testdata/13/exp2.json @@ -0,0 +1,42 @@ +{ + "result": { + "stateRoot": "0xe4b924a6adb5959fccf769d5b7bb2f6359e26d1e76a2443c5a91a36d826aef61", + "txRoot": "0x013509c8563d41c0ae4bf38f2d6d19fc6512a1d0d6be045079c8c9f68bf45f9d", + "receiptsRoot": "0xa532a08aa9f62431d6fe5d924951b8efb86ed3c54d06fee77788c3767dd13420", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [ + { + "type": "0x2", + "root": "0x", + "status": "0x0", + "cumulativeGasUsed": "0x84d0", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0xa98a24882ea90916c6a86da650fbc6b14238e46f0af04a131ce92be897507476", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x84d0", + "effectiveGasPrice": null, + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x0" + }, + { + "type": "0x2", + "root": "0x", + "status": "0x0", + "cumulativeGasUsed": "0x109a0", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0x36bad80acce7040c45fd32764b5c2b2d2e6f778669fb41791f73f546d56e739a", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x84d0", + "effectiveGasPrice": null, + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x1" + } + ], + "currentDifficulty": "0x20000", + "gasUsed": "0x109a0", + "currentBaseFee": "0x36b" + } +} diff --git a/tools/Evm.Test/testdata/13/readme.md b/tools/Evm.Test/testdata/13/readme.md new file mode 100644 index 00000000000..889975d47e0 --- /dev/null +++ b/tools/Evm.Test/testdata/13/readme.md @@ -0,0 +1,4 @@ +## Input transactions in RLP form + +This testdata folder is used to exemplify how transaction input can be provided in rlp form. +Please see the README in `evm` folder for how this is performed. \ No newline at end of file diff --git a/tools/Evm.Test/testdata/13/signed_txs.rlp b/tools/Evm.Test/testdata/13/signed_txs.rlp new file mode 100644 index 00000000000..9d1157ea45d --- /dev/null +++ b/tools/Evm.Test/testdata/13/signed_txs.rlp @@ -0,0 +1 @@ +"0xf8d2b86702f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904b86702f864010280820fa08284d09411111111111111111111111111111111111111118080c080a0d4ec563b6568cd42d998fc4134b36933c6568d01533b5adf08769270243c6c7fa072bf7c21eac6bbeae5143371eef26d5e279637f3bd73482b55979d76d935b1e9" \ No newline at end of file diff --git a/tools/Evm.Test/testdata/13/txs.json b/tools/Evm.Test/testdata/13/txs.json new file mode 100644 index 00000000000..c45ef1e13d1 --- /dev/null +++ b/tools/Evm.Test/testdata/13/txs.json @@ -0,0 +1,34 @@ +[ + { + "input" : "0x", + "gas" : "0x84d0", + "nonce" : "0x1", + "to" : "0x1111111111111111111111111111111111111111", + "value" : "0x0", + "v" : "0x0", + "r" : "0x0", + "s" : "0x0", + "secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298", + "chainId" : "0x1", + "type" : "0x2", + "maxFeePerGas" : "0xfa0", + "maxPriorityFeePerGas" : "0x0", + "accessList" : [] + }, + { + "input" : "0x", + "gas" : "0x84d0", + "nonce" : "0x2", + "to" : "0x1111111111111111111111111111111111111111", + "value" : "0x0", + "v" : "0x0", + "r" : "0x0", + "s" : "0x0", + "secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298", + "chainId" : "0x1", + "type" : "0x2", + "maxFeePerGas" : "0xfa0", + "maxPriorityFeePerGas" : "0x0", + "accessList" : [] + } +] \ No newline at end of file diff --git a/tools/Evm.Test/testdata/14/alloc.json b/tools/Evm.Test/testdata/14/alloc.json new file mode 100644 index 00000000000..cef1a25ff01 --- /dev/null +++ b/tools/Evm.Test/testdata/14/alloc.json @@ -0,0 +1,12 @@ +{ + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x5ffd4878be161d74", + "code": "0x", + "nonce": "0xac", + "storage": {} + }, + "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192":{ + "balance": "0xfeedbead", + "nonce" : "0x00" + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/14/env.json b/tools/Evm.Test/testdata/14/env.json new file mode 100644 index 00000000000..0bf1c5cf48a --- /dev/null +++ b/tools/Evm.Test/testdata/14/env.json @@ -0,0 +1,9 @@ +{ + "currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "currentGasLimit": "0x750a163df65e8a", + "currentBaseFee": "0x500", + "currentNumber": "12800000", + "currentTimestamp": "100015", + "parentTimestamp" : "99999", + "parentDifficulty" : "0x2000000000000" +} diff --git a/tools/Evm.Test/testdata/14/env.uncles.json b/tools/Evm.Test/testdata/14/env.uncles.json new file mode 100644 index 00000000000..83811b95ec1 --- /dev/null +++ b/tools/Evm.Test/testdata/14/env.uncles.json @@ -0,0 +1,10 @@ +{ + "currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "currentGasLimit": "0x750a163df65e8a", + "currentBaseFee": "0x500", + "currentNumber": "12800000", + "currentTimestamp": "100035", + "parentTimestamp" : "99999", + "parentDifficulty" : "0x2000000000000", + "parentUncleHash" : "0x000000000000000000000000000000000000000000000000000000000000beef" +} diff --git a/tools/Evm.Test/testdata/14/exp.json b/tools/Evm.Test/testdata/14/exp.json new file mode 100644 index 00000000000..26d49173ce6 --- /dev/null +++ b/tools/Evm.Test/testdata/14/exp.json @@ -0,0 +1,13 @@ +{ + "result": { + "stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc", + "txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "currentDifficulty": "0x2000020000000", + "receipts": [], + "gasUsed": "0x0", + "currentBaseFee": "0x500" + } +} diff --git a/tools/Evm.Test/testdata/14/exp2.json b/tools/Evm.Test/testdata/14/exp2.json new file mode 100644 index 00000000000..cd75b47d5a5 --- /dev/null +++ b/tools/Evm.Test/testdata/14/exp2.json @@ -0,0 +1,13 @@ +{ + "result": { + "stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc", + "txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [], + "currentDifficulty": "0x1ff8020000000", + "gasUsed": "0x0", + "currentBaseFee": "0x500" + } +} diff --git a/tools/Evm.Test/testdata/14/exp_berlin.json b/tools/Evm.Test/testdata/14/exp_berlin.json new file mode 100644 index 00000000000..5c00ef130a9 --- /dev/null +++ b/tools/Evm.Test/testdata/14/exp_berlin.json @@ -0,0 +1,13 @@ +{ + "result": { + "stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc", + "txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [], + "currentDifficulty": "0x1ff9000000000", + "gasUsed": "0x0", + "currentBaseFee": "0x500" + } +} diff --git a/tools/Evm.Test/testdata/14/readme.md b/tools/Evm.Test/testdata/14/readme.md new file mode 100644 index 00000000000..40dd75486ee --- /dev/null +++ b/tools/Evm.Test/testdata/14/readme.md @@ -0,0 +1,45 @@ +## Difficulty calculation + +This test shows how the `evm t8n` can be used to calculate the (ethash) difficulty, if none is provided by the caller. + +Calculating it (with an empty set of txs) using `London` rules (and no provided unclehash for the parent block): +``` +[user@work evm]$ ./evm t8n --input.alloc=./testdata/14/alloc.json --input.txs=./testdata/14/txs.json --input.env=./testdata/14/env.json --output.result=stdout --state.fork=London +INFO [03-09|10:43:57.070] Trie dumping started root=6f0588..7f4bdc +INFO [03-09|10:43:57.070] Trie dumping complete accounts=2 elapsed="214.663µs" +INFO [03-09|10:43:57.071] Wrote file file=alloc.json +{ + "result": { + "stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc", + "txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [], + "currentDifficulty": "0x2000020000000", + "gasUsed": "0x0", + "currentBaseFee": "0x500" + } +} +``` +Same thing, but this time providing a non-empty (and non-`emptyKeccak`) unclehash, which leads to a slightly different result: +``` +[user@work evm]$ ./evm t8n --input.alloc=./testdata/14/alloc.json --input.txs=./testdata/14/txs.json --input.env=./testdata/14/env.uncles.json --output.result=stdout --state.fork=London +INFO [03-09|10:44:20.511] Trie dumping started root=6f0588..7f4bdc +INFO [03-09|10:44:20.511] Trie dumping complete accounts=2 elapsed="184.319µs" +INFO [03-09|10:44:20.512] Wrote file file=alloc.json +{ + "result": { + "stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc", + "txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [], + "currentDifficulty": "0x1ff8020000000", + "gasUsed": "0x0", + "currentBaseFee": "0x500" + } +} +``` + diff --git a/tools/Evm.Test/testdata/14/txs.json b/tools/Evm.Test/testdata/14/txs.json new file mode 100644 index 00000000000..fe51488c706 --- /dev/null +++ b/tools/Evm.Test/testdata/14/txs.json @@ -0,0 +1 @@ +[] diff --git a/tools/Evm.Test/testdata/15/blockheader.rlp b/tools/Evm.Test/testdata/15/blockheader.rlp new file mode 100644 index 00000000000..1124e8e2da9 --- /dev/null +++ b/tools/Evm.Test/testdata/15/blockheader.rlp @@ -0,0 +1 @@ +"0xf901f0a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007b0101020383010203a00000000000000000000000000000000000000000000000000000000000000000880000000000000000" \ No newline at end of file diff --git a/tools/Evm.Test/testdata/15/exp.json b/tools/Evm.Test/testdata/15/exp.json new file mode 100644 index 00000000000..1893fdfc08c --- /dev/null +++ b/tools/Evm.Test/testdata/15/exp.json @@ -0,0 +1,10 @@ +[ + { + "error": "transaction type not supported", + "hash": "0xa98a24882ea90916c6a86da650fbc6b14238e46f0af04a131ce92be897507476" + }, + { + "error": "transaction type not supported", + "hash": "0x36bad80acce7040c45fd32764b5c2b2d2e6f778669fb41791f73f546d56e739a" + } +] \ No newline at end of file diff --git a/tools/Evm.Test/testdata/15/exp2.json b/tools/Evm.Test/testdata/15/exp2.json new file mode 100644 index 00000000000..dd5e8a358ce --- /dev/null +++ b/tools/Evm.Test/testdata/15/exp2.json @@ -0,0 +1,12 @@ +[ + { + "address": "0xd02d72e067e77158444ef2020ff2d325f929b363", + "hash": "0xa98a24882ea90916c6a86da650fbc6b14238e46f0af04a131ce92be897507476", + "intrinsicGas": "0x5208" + }, + { + "address": "0xd02d72e067e77158444ef2020ff2d325f929b363", + "hash": "0x36bad80acce7040c45fd32764b5c2b2d2e6f778669fb41791f73f546d56e739a", + "intrinsicGas": "0x5208" + } +] diff --git a/tools/Evm.Test/testdata/15/exp3.json b/tools/Evm.Test/testdata/15/exp3.json new file mode 100644 index 00000000000..d7606a20736 --- /dev/null +++ b/tools/Evm.Test/testdata/15/exp3.json @@ -0,0 +1,47 @@ +[ + { + "error": "transaction type not supported" + }, + { + "error": "transaction type not supported" + }, + { + "error": "transaction type not supported" + }, + { + "error": "transaction type not supported" + }, + { + "error": "transaction type not supported" + }, + { + "error": "transaction type not supported" + }, + { + "error": "transaction type not supported" + }, + { + "error": "typed transaction too short" + }, + { + "error": "typed transaction too short" + }, + { + "error": "typed transaction too short" + }, + { + "error": "typed transaction too short" + }, + { + "error": "typed transaction too short" + }, + { + "error": "rlp: expected input list for types.AccessListTx" + }, + { + "error": "transaction type not supported" + }, + { + "error": "transaction type not supported" + } +] diff --git a/tools/Evm.Test/testdata/15/signed_txs.rlp b/tools/Evm.Test/testdata/15/signed_txs.rlp new file mode 100644 index 00000000000..9d1157ea45d --- /dev/null +++ b/tools/Evm.Test/testdata/15/signed_txs.rlp @@ -0,0 +1 @@ +"0xf8d2b86702f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904b86702f864010280820fa08284d09411111111111111111111111111111111111111118080c080a0d4ec563b6568cd42d998fc4134b36933c6568d01533b5adf08769270243c6c7fa072bf7c21eac6bbeae5143371eef26d5e279637f3bd73482b55979d76d935b1e9" \ No newline at end of file diff --git a/tools/Evm.Test/testdata/15/signed_txs.rlp.json b/tools/Evm.Test/testdata/15/signed_txs.rlp.json new file mode 100644 index 00000000000..187f40f24ac --- /dev/null +++ b/tools/Evm.Test/testdata/15/signed_txs.rlp.json @@ -0,0 +1,4 @@ +{ + "txsRlp" : "0xf8d2b86702f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904b86702f864010280820fa08284d09411111111111111111111111111111111111111118080c080a0d4ec563b6568cd42d998fc4134b36933c6568d01533b5adf08769270243c6c7fa072bf7c21eac6bbeae5143371eef26d5e279637f3bd73482b55979d76d935b1e9" +} + diff --git a/tools/Evm.Test/testdata/16/exp.json b/tools/Evm.Test/testdata/16/exp.json new file mode 100644 index 00000000000..137ade65135 --- /dev/null +++ b/tools/Evm.Test/testdata/16/exp.json @@ -0,0 +1,13 @@ +[ + { + "address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "hash": "0x7cc3d1a8540a44736750f03bb4d85c0113be4b3472a71bf82241a3b261b479e6", + "intrinsicGas": "0x5208" + }, + { + "error": "intrinsic gas too low: have 82, want 21000", + "address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "hash": "0x3b2d2609e4361562edb9169314f4c05afc6dbf5d706bf9dda5abe242ab76a22b", + "intrinsicGas": "0x5208" + } +] \ No newline at end of file diff --git a/tools/Evm.Test/testdata/16/signed_txs.rlp b/tools/Evm.Test/testdata/16/signed_txs.rlp new file mode 100644 index 00000000000..952ced21301 --- /dev/null +++ b/tools/Evm.Test/testdata/16/signed_txs.rlp @@ -0,0 +1 @@ +"0xf8cab86401f8610180018252089411111111111111111111111111111111111111112080c001a0937f65ef1deece46c473b99962678fb7c38425cf303d1e8fa9717eb4b9d012b5a01940c5a5647c4940217ffde1051a5fd92ec8551e275c1787f81f50a2ad84de43b86201f85f018001529411111111111111111111111111111111111111112080c001a0241c3aec732205542a87fef8c76346741e85480bce5a42d05a9a73dac892f84ca04f52e2dfce57f3a02ed10e085e1a154edf38a726da34127c85fc53b4921759c8" \ No newline at end of file diff --git a/tools/Evm.Test/testdata/16/unsigned_txs.json b/tools/Evm.Test/testdata/16/unsigned_txs.json new file mode 100644 index 00000000000..f619589406e --- /dev/null +++ b/tools/Evm.Test/testdata/16/unsigned_txs.json @@ -0,0 +1,34 @@ +[ + { + "input" : "0x", + "gas" : "0x5208", + "nonce" : "0x0", + "to" : "0x1111111111111111111111111111111111111111", + "value" : "0x20", + "v" : "0x0", + "r" : "0x0", + "s" : "0x0", + "secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "chainId" : "0x1", + "type" : "0x1", + "gasPrice": "0x1", + "accessList" : [ + ] + }, + { + "input" : "0x", + "gas" : "0x52", + "nonce" : "0x0", + "to" : "0x1111111111111111111111111111111111111111", + "value" : "0x20", + "v" : "0x0", + "r" : "0x0", + "s" : "0x0", + "secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "chainId" : "0x1", + "type" : "0x1", + "gasPrice": "0x1", + "accessList" : [ + ] + } +] diff --git a/tools/Evm.Test/testdata/17/exp.json b/tools/Evm.Test/testdata/17/exp.json new file mode 100644 index 00000000000..485906041b5 --- /dev/null +++ b/tools/Evm.Test/testdata/17/exp.json @@ -0,0 +1,22 @@ + [ + { + "error": "value exceeds 256 bits", + "address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "hash": "0xfbd91685dcbf8172f0e8c53e2ddbb4d26707840da6b51a74371f62a33868fd82", + "intrinsicGas": "0x5208" + }, + { + "error": "gasPrice exceeds 256 bits", + "address": "0x1b57ccef1fe5fb73f1e64530fb4ebd9cf1655964", + "hash": "0x45dc05035cada83748e4c1fe617220106b331eca054f44c2304d5654a9fb29d5", + "intrinsicGas": "0x5208" + }, + { + "error": "invalid transaction v, r, s values", + "hash": "0xf06691c2a803ab7f3c81d06a0c0a896f80f311105c599fc59a9fdbc669356d35" + }, + { + "error": "invalid transaction v, r, s values", + "hash": "0x84703b697ad5b0db25e4f1f98fb6b1adce85b9edb2232eeba9cedd8c6601694b" + } +] \ No newline at end of file diff --git a/tools/Evm.Test/testdata/17/rlpdata.txt b/tools/Evm.Test/testdata/17/rlpdata.txt new file mode 100644 index 00000000000..874461fd76b --- /dev/null +++ b/tools/Evm.Test/testdata/17/rlpdata.txt @@ -0,0 +1,46 @@ +[ + [ + "", + "d", + 5208, + d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0, + 010000000000000000000000000000000000000000000000000000000000000001, + "", + 1b, + c16787a8e25e941d67691954642876c08f00996163ae7dfadbbfd6cd436f549d, + 6180e5626cae31590f40641fe8f63734316c4bfeb4cdfab6714198c1044d2e28, + ], + [ + "", + 010000000000000000000000000000000000000000000000000000000000000001, + 5208, + d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0, + 11, + "", + 1b, + c16787a8e25e941d67691954642876c08f00996163ae7dfadbbfd6cd436f549d, + 6180e5626cae31590f40641fe8f63734316c4bfeb4cdfab6714198c1044d2e28, + ], + [ + "", + 11, + 5208, + d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0, + 11, + "", + 1b, + c16787a8e25e941d67691954642876c08f00996163ae7dfadbbfd6cd436f549daa, + 6180e5626cae31590f40641fe8f63734316c4bfeb4cdfab6714198c1044d2e28, + ], + [ + "", + 11, + 5208, + d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0, + 11, + "", + 1b, + c16787a8e25e941d67691954642876c08f00996163ae7dfadbbfd6cd436f549d, + 6180e5626cae31590f40641fe8f63734316c4bfeb4cdfab6714198c1044d2e28bb, + ], +] diff --git a/tools/Evm.Test/testdata/17/signed_txs.rlp b/tools/Evm.Test/testdata/17/signed_txs.rlp new file mode 100644 index 00000000000..0e351fb03c1 --- /dev/null +++ b/tools/Evm.Test/testdata/17/signed_txs.rlp @@ -0,0 +1 @@ +"0xf901c8f880806482520894d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0a1010000000000000000000000000000000000000000000000000000000000000001801ba0c16787a8e25e941d67691954642876c08f00996163ae7dfadbbfd6cd436f549da06180e5626cae31590f40641fe8f63734316c4bfeb4cdfab6714198c1044d2e28f88080a101000000000000000000000000000000000000000000000000000000000000000182520894d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d011801ba0c16787a8e25e941d67691954642876c08f00996163ae7dfadbbfd6cd436f549da06180e5626cae31590f40641fe8f63734316c4bfeb4cdfab6714198c1044d2e28f860801182520894d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d011801ba1c16787a8e25e941d67691954642876c08f00996163ae7dfadbbfd6cd436f549daaa06180e5626cae31590f40641fe8f63734316c4bfeb4cdfab6714198c1044d2e28f860801182520894d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d011801ba0c16787a8e25e941d67691954642876c08f00996163ae7dfadbbfd6cd436f549da16180e5626cae31590f40641fe8f63734316c4bfeb4cdfab6714198c1044d2e28bb" \ No newline at end of file diff --git a/tools/Evm.Test/testdata/18/README.md b/tools/Evm.Test/testdata/18/README.md new file mode 100644 index 00000000000..360a9bba015 --- /dev/null +++ b/tools/Evm.Test/testdata/18/README.md @@ -0,0 +1,9 @@ +# Invalid rlp + +This folder contains a sample of invalid RLP, and it's expected +that the t9n handles this properly: + +``` +$ go run . t9n --input.txs=./testdata/18/invalid.rlp --state.fork=London +ERROR(11): rlp: value size exceeds available input length +``` \ No newline at end of file diff --git a/tools/Evm.Test/testdata/18/invalid.rlp b/tools/Evm.Test/testdata/18/invalid.rlp new file mode 100644 index 00000000000..7ff2824caf0 --- /dev/null +++ b/tools/Evm.Test/testdata/18/invalid.rlp @@ -0,0 +1 @@ +"0xf852328001825208870b9331677e6ebf0a801ca098ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4aa03887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3" \ No newline at end of file diff --git a/tools/Evm.Test/testdata/19/alloc.json b/tools/Evm.Test/testdata/19/alloc.json new file mode 100644 index 00000000000..cef1a25ff01 --- /dev/null +++ b/tools/Evm.Test/testdata/19/alloc.json @@ -0,0 +1,12 @@ +{ + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x5ffd4878be161d74", + "code": "0x", + "nonce": "0xac", + "storage": {} + }, + "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192":{ + "balance": "0xfeedbead", + "nonce" : "0x00" + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/19/env.json b/tools/Evm.Test/testdata/19/env.json new file mode 100644 index 00000000000..0c64392aff5 --- /dev/null +++ b/tools/Evm.Test/testdata/19/env.json @@ -0,0 +1,9 @@ +{ + "currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "currentGasLimit": "0x750a163df65e8a", + "currentBaseFee": "0x500", + "currentNumber": "13000000", + "currentTimestamp": "100015", + "parentTimestamp" : "99999", + "parentDifficulty" : "0x2000000000000" +} diff --git a/tools/Evm.Test/testdata/19/exp_arrowglacier.json b/tools/Evm.Test/testdata/19/exp_arrowglacier.json new file mode 100644 index 00000000000..dd49f7d02ea --- /dev/null +++ b/tools/Evm.Test/testdata/19/exp_arrowglacier.json @@ -0,0 +1,13 @@ +{ + "result": { + "stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc", + "txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "currentDifficulty": "0x2000000200000", + "receipts": [], + "gasUsed": "0x0", + "currentBaseFee": "0x500" + } +} diff --git a/tools/Evm.Test/testdata/19/exp_grayglacier.json b/tools/Evm.Test/testdata/19/exp_grayglacier.json new file mode 100644 index 00000000000..86fd8e6c137 --- /dev/null +++ b/tools/Evm.Test/testdata/19/exp_grayglacier.json @@ -0,0 +1,13 @@ +{ + "result": { + "stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc", + "txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [], + "currentDifficulty": "0x2000000004000", + "gasUsed": "0x0", + "currentBaseFee": "0x500" + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/19/exp_london.json b/tools/Evm.Test/testdata/19/exp_london.json new file mode 100644 index 00000000000..9e9a17da900 --- /dev/null +++ b/tools/Evm.Test/testdata/19/exp_london.json @@ -0,0 +1,13 @@ +{ + "result": { + "stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc", + "txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "currentDifficulty": "0x2000080000000", + "receipts": [], + "gasUsed": "0x0", + "currentBaseFee": "0x500" + } +} diff --git a/tools/Evm.Test/testdata/19/readme.md b/tools/Evm.Test/testdata/19/readme.md new file mode 100644 index 00000000000..9c7c4b3656b --- /dev/null +++ b/tools/Evm.Test/testdata/19/readme.md @@ -0,0 +1,25 @@ +## Difficulty calculation + +This test shows how the `evm t8n` can be used to calculate the (ethash) difficulty, if none is provided by the caller, +this time on `GrayGlacier` (Eip 5133). + +Calculating it (with an empty set of txs) using `GrayGlacier` rules (and no provided unclehash for the parent block): +``` +[user@work evm]$ ./evm t8n --input.alloc=./testdata/19/alloc.json --input.txs=./testdata/19/txs.json --input.env=./testdata/19/env.json --output.result=stdout --state.fork=GrayGlacier +INFO [03-09|10:45:26.777] Trie dumping started root=6f0588..7f4bdc +INFO [03-09|10:45:26.777] Trie dumping complete accounts=2 elapsed="176.471µs" +INFO [03-09|10:45:26.777] Wrote file file=alloc.json +{ + "result": { + "stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc", + "txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [], + "currentDifficulty": "0x2000000004000", + "gasUsed": "0x0", + "currentBaseFee": "0x500" + } +} +``` \ No newline at end of file diff --git a/tools/Evm.Test/testdata/19/txs.json b/tools/Evm.Test/testdata/19/txs.json new file mode 100644 index 00000000000..fe51488c706 --- /dev/null +++ b/tools/Evm.Test/testdata/19/txs.json @@ -0,0 +1 @@ +[] diff --git a/tools/Evm.Test/testdata/2/alloc.json b/tools/Evm.Test/testdata/2/alloc.json new file mode 100644 index 00000000000..a9720afc936 --- /dev/null +++ b/tools/Evm.Test/testdata/2/alloc.json @@ -0,0 +1,16 @@ +{ + "0x095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x6001600053600160006001f0ff00", + "nonce" : "0x00", + "storage" : { + } + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x", + "nonce" : "0x00", + "storage" : { + } + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/2/env.json b/tools/Evm.Test/testdata/2/env.json new file mode 100644 index 00000000000..ebadd3f06ac --- /dev/null +++ b/tools/Evm.Test/testdata/2/env.json @@ -0,0 +1,7 @@ +{ + "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "0x020000", + "currentGasLimit" : "0x3b9aca00", + "currentNumber" : "0x01", + "currentTimestamp" : "0x03e8" +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/2/readme.md b/tools/Evm.Test/testdata/2/readme.md new file mode 100644 index 00000000000..4bcf0f0fa0c --- /dev/null +++ b/tools/Evm.Test/testdata/2/readme.md @@ -0,0 +1 @@ +These files exemplify a selfdestruct to the `0`-address. \ No newline at end of file diff --git a/tools/Evm.Test/testdata/2/txs.json b/tools/Evm.Test/testdata/2/txs.json new file mode 100644 index 00000000000..30444585888 --- /dev/null +++ b/tools/Evm.Test/testdata/2/txs.json @@ -0,0 +1,14 @@ +[ + { + "input" : "0x", + "gas" : "0x5f5e100", + "gasPrice" : "0x1", + "nonce" : "0x0", + "to" : "0x095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "0x186a0", + "v" : "0x1b", + "r" : "0x88544c93a564b4c28d2ffac2074a0c55fdd4658fe0d215596ed2e32e3ef7f56b", + "s" : "0x7fb4075d54190f825d7c47bb820284757b34fd6293904a93cddb1d3aa961ac28", + "hash" : "0x72fadbef39cd251a437eea619cfeda752271a5faaaa2147df012e112159ffb81" + } +] \ No newline at end of file diff --git a/tools/Evm.Test/testdata/20/exp.json b/tools/Evm.Test/testdata/20/exp.json new file mode 100644 index 00000000000..7bec6cefd69 --- /dev/null +++ b/tools/Evm.Test/testdata/20/exp.json @@ -0,0 +1,4 @@ +{ + "rlp": "0xf902d9f90211a0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794e997a23b159e2e2a5ce72333262972374b15425ca0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277e99476574682f76312e302e312f6c696e75782f676f312e342e32a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf8897435673d874f7c8f8c2f85f8002825208948a8eafb1cf62bfbeb1741769dae1a9dd4799619201801ba09500e8ba27d3c33ca7764e107410f44cbd8c19794bde214d694683a7aa998cdba07235ae07e4bd6e0206d102b1f8979d6adab280466b6a82d2208ee08951f1f600f85f8002825208948a8eafb1cf62bfbeb1741769dae1a9dd4799619201801ba09500e8ba27d3c33ca7764e107410f44cbd8c19794bde214d694683a7aa998cdba07235ae07e4bd6e0206d102b1f8979d6adab280466b6a82d2208ee08951f1f600c0", + "hash": "0xaba9a3b6a4e96e9ecffcadaa5a2ae0589359455617535cd86589fe1dd26fe899" +} diff --git a/tools/Evm.Test/testdata/20/header.json b/tools/Evm.Test/testdata/20/header.json new file mode 100644 index 00000000000..fb9b7fc5639 --- /dev/null +++ b/tools/Evm.Test/testdata/20/header.json @@ -0,0 +1,14 @@ +{ + "parentHash": "0xd6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34e", + "miner": "0xe997a23b159e2e2a5ce72333262972374b15425c", + "stateRoot": "0x325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2e", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "difficulty": "0x1000", + "number": "0xc3be", + "gasLimit": "0x50785", + "gasUsed": "0x0", + "timestamp": "0x55c5277e", + "extraData": "0x476574682f76312e302e312f6c696e75782f676f312e342e32", + "mixHash": "0x5865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf", + "nonce": "0x97435673d874f7c8" +} diff --git a/tools/Evm.Test/testdata/20/ommers.json b/tools/Evm.Test/testdata/20/ommers.json new file mode 100644 index 00000000000..fe51488c706 --- /dev/null +++ b/tools/Evm.Test/testdata/20/ommers.json @@ -0,0 +1 @@ +[] diff --git a/tools/Evm.Test/testdata/20/readme.md b/tools/Evm.Test/testdata/20/readme.md new file mode 100644 index 00000000000..2c448a96e6e --- /dev/null +++ b/tools/Evm.Test/testdata/20/readme.md @@ -0,0 +1,11 @@ +# Block building + +This test shows how `b11r` can be used to assemble an unsealed block. + +```console +$ go run . b11r --input.header=testdata/20/header.json --input.txs=testdata/20/txs.rlp --input.ommers=testdata/20/ommers.json --output.block=stdout +{ + "rlp": "0xf90216f90211a0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794e997a23b159e2e2a5ce72333262972374b15425ca0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277e99476574682f76312e302e312f6c696e75782f676f312e342e32a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf8897435673d874f7c8c0c0", + "hash": "0xaba9a3b6a4e96e9ecffcadaa5a2ae0589359455617535cd86589fe1dd26fe899" +} +``` diff --git a/tools/Evm.Test/testdata/20/txs.rlp b/tools/Evm.Test/testdata/20/txs.rlp new file mode 100644 index 00000000000..3599ff06542 --- /dev/null +++ b/tools/Evm.Test/testdata/20/txs.rlp @@ -0,0 +1 @@ +"0xf8c2f85f8002825208948a8eafb1cf62bfbeb1741769dae1a9dd4799619201801ba09500e8ba27d3c33ca7764e107410f44cbd8c19794bde214d694683a7aa998cdba07235ae07e4bd6e0206d102b1f8979d6adab280466b6a82d2208ee08951f1f600f85f8002825208948a8eafb1cf62bfbeb1741769dae1a9dd4799619201801ba09500e8ba27d3c33ca7764e107410f44cbd8c19794bde214d694683a7aa998cdba07235ae07e4bd6e0206d102b1f8979d6adab280466b6a82d2208ee08951f1f600" \ No newline at end of file diff --git a/tools/Evm.Test/testdata/21/clique.json b/tools/Evm.Test/testdata/21/clique.json new file mode 100644 index 00000000000..84fa259a0d6 --- /dev/null +++ b/tools/Evm.Test/testdata/21/clique.json @@ -0,0 +1,6 @@ +{ + "secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "voted": "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "authorize": false, + "vanity": "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +} diff --git a/tools/Evm.Test/testdata/21/exp-clique.json b/tools/Evm.Test/testdata/21/exp-clique.json new file mode 100644 index 00000000000..c990ba8aa6b --- /dev/null +++ b/tools/Evm.Test/testdata/21/exp-clique.json @@ -0,0 +1,4 @@ +{ + "rlp": "0xf9025ff9025aa0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347942adc25665018aa1fe0e6bc666dac8fc2697ff9baa0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277eb861aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac540a67aaee364005841da84f488f6b6d0116dfb5103d091402c81a163d5f66666595e37f56f196d8c5c98da714dbfae68d6b7e1790cc734a20ec6ce52213ad800a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf88ffffffffffffffffc0c0", + "hash": "0x71c59102cc805dbe8741e1210ebe229a321eff144ac7276006fefe39e8357dc7" +} diff --git a/tools/Evm.Test/testdata/21/exp.json b/tools/Evm.Test/testdata/21/exp.json new file mode 100644 index 00000000000..b3e5e7a8311 --- /dev/null +++ b/tools/Evm.Test/testdata/21/exp.json @@ -0,0 +1,4 @@ +{ + "rlp": "0xf901fdf901f8a0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277e80a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf880000000000000000c0c0", + "hash": "0x801411e9f6609a659825690d13e4f75a3cfe9143952fa2d9573f3b0a5eb9ebbb" +} diff --git a/tools/Evm.Test/testdata/21/header.json b/tools/Evm.Test/testdata/21/header.json new file mode 100644 index 00000000000..62abe3cc2cc --- /dev/null +++ b/tools/Evm.Test/testdata/21/header.json @@ -0,0 +1,11 @@ +{ + "parentHash": "0xd6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34e", + "stateRoot": "0x325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2e", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "difficulty": "0x1000", + "number": "0xc3be", + "gasLimit": "0x50785", + "gasUsed": "0x0", + "timestamp": "0x55c5277e", + "mixHash": "0x5865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf" +} diff --git a/tools/Evm.Test/testdata/21/ommers.json b/tools/Evm.Test/testdata/21/ommers.json new file mode 100644 index 00000000000..fe51488c706 --- /dev/null +++ b/tools/Evm.Test/testdata/21/ommers.json @@ -0,0 +1 @@ +[] diff --git a/tools/Evm.Test/testdata/21/readme.md b/tools/Evm.Test/testdata/21/readme.md new file mode 100644 index 00000000000..b70f106ffcd --- /dev/null +++ b/tools/Evm.Test/testdata/21/readme.md @@ -0,0 +1,23 @@ +# Sealed block building + +This test shows how `b11r` can be used to assemble a sealed block. + +## Ethash + +```console +$ go run . b11r --input.header=testdata/21/header.json --input.txs=testdata/21/txs.rlp --input.ommers=testdata/21/ommers.json --seal.ethash --seal.ethash.mode=test --output.block=stdout +{ + "rlp": "0xf901fdf901f8a0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277e80a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf880000000000000000c0c0", + "hash": "0x801411e9f6609a659825690d13e4f75a3cfe9143952fa2d9573f3b0a5eb9ebbb" +} +``` + +## Clique + +```console +$ go run . b11r --input.header=testdata/21/header.json --input.txs=testdata/21/txs.rlp --input.ommers=testdata/21/ommers.json --seal.clique=testdata/21/clique.json --output.block=stdout +{ + "rlp": "0xf9025ff9025aa0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347942adc25665018aa1fe0e6bc666dac8fc2697ff9baa0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277eb861aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac540a67aaee364005841da84f488f6b6d0116dfb5103d091402c81a163d5f66666595e37f56f196d8c5c98da714dbfae68d6b7e1790cc734a20ec6ce52213ad800a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf88ffffffffffffffffc0c0", + "hash": "0x71c59102cc805dbe8741e1210ebe229a321eff144ac7276006fefe39e8357dc7" +} +``` diff --git a/tools/Evm.Test/testdata/21/txs.rlp b/tools/Evm.Test/testdata/21/txs.rlp new file mode 100644 index 00000000000..e815397b333 --- /dev/null +++ b/tools/Evm.Test/testdata/21/txs.rlp @@ -0,0 +1 @@ +"c0" diff --git a/tools/Evm.Test/testdata/22/exp-clique.json b/tools/Evm.Test/testdata/22/exp-clique.json new file mode 100644 index 00000000000..c990ba8aa6b --- /dev/null +++ b/tools/Evm.Test/testdata/22/exp-clique.json @@ -0,0 +1,4 @@ +{ + "rlp": "0xf9025ff9025aa0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347942adc25665018aa1fe0e6bc666dac8fc2697ff9baa0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277eb861aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac540a67aaee364005841da84f488f6b6d0116dfb5103d091402c81a163d5f66666595e37f56f196d8c5c98da714dbfae68d6b7e1790cc734a20ec6ce52213ad800a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf88ffffffffffffffffc0c0", + "hash": "0x71c59102cc805dbe8741e1210ebe229a321eff144ac7276006fefe39e8357dc7" +} diff --git a/tools/Evm.Test/testdata/22/exp.json b/tools/Evm.Test/testdata/22/exp.json new file mode 100644 index 00000000000..14fd81997d5 --- /dev/null +++ b/tools/Evm.Test/testdata/22/exp.json @@ -0,0 +1,4 @@ +{ + "rlp": "0xf905f5f901f8a0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea06eb9f0c3cd68c9e97134e6725d12b1f1d8f0644458da6870a37ff84c908fb1e7940000000000000000000000000000000000000000a0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277e80a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf880000000000000000c0f903f6f901f8a0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277e80a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf880000000000000000f901f8a0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277e80a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf880000000000000000", + "hash": "0xd9a81c8fcd57a7f2a0d2c375eff6ad192c30c3729a271303f0a9a7e1b357e755" +} diff --git a/tools/Evm.Test/testdata/22/header.json b/tools/Evm.Test/testdata/22/header.json new file mode 100644 index 00000000000..62abe3cc2cc --- /dev/null +++ b/tools/Evm.Test/testdata/22/header.json @@ -0,0 +1,11 @@ +{ + "parentHash": "0xd6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34e", + "stateRoot": "0x325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2e", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "difficulty": "0x1000", + "number": "0xc3be", + "gasLimit": "0x50785", + "gasUsed": "0x0", + "timestamp": "0x55c5277e", + "mixHash": "0x5865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf" +} diff --git a/tools/Evm.Test/testdata/22/ommers.json b/tools/Evm.Test/testdata/22/ommers.json new file mode 100644 index 00000000000..997015b3ced --- /dev/null +++ b/tools/Evm.Test/testdata/22/ommers.json @@ -0,0 +1 @@ +["0xf901fdf901f8a0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277e80a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf880000000000000000c0c0","0xf901fdf901f8a0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277e80a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf880000000000000000c0c0"] diff --git a/tools/Evm.Test/testdata/22/readme.md b/tools/Evm.Test/testdata/22/readme.md new file mode 100644 index 00000000000..2cac8a2434a --- /dev/null +++ b/tools/Evm.Test/testdata/22/readme.md @@ -0,0 +1,11 @@ +# Building blocks with ommers + +This test shows how `b11r` can chain together ommer assembles into a canonical block. + +```console +$ echo "{ \"ommers\": [`go run . b11r --input.header=testdata/22/header.json --input.txs=testdata/22/txs.rlp --output.block=stdout | jq '.[\"rlp\"]'`,`go run . b11r --input.header=testdata/22/header.json --input.txs=testdata/22/txs.rlp --output.block=stdout | jq '.[\"rlp\"]'`]}" | go run . b11r --input.header=testdata/22/header.json --input.txs=testdata/22/txs.rlp --input.ommers=stdin --output.block=stdout +{ + "rlp": "0xf905f5f901f8a0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea06eb9f0c3cd68c9e97134e6725d12b1f1d8f0644458da6870a37ff84c908fb1e7940000000000000000000000000000000000000000a0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277e80a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf880000000000000000c0f903f6f901f8a0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277e80a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf880000000000000000f901f8a0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277e80a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf880000000000000000", + "hash": "0xd9a81c8fcd57a7f2a0d2c375eff6ad192c30c3729a271303f0a9a7e1b357e755" +} +``` diff --git a/tools/Evm.Test/testdata/22/txs.rlp b/tools/Evm.Test/testdata/22/txs.rlp new file mode 100644 index 00000000000..e815397b333 --- /dev/null +++ b/tools/Evm.Test/testdata/22/txs.rlp @@ -0,0 +1 @@ +"c0" diff --git a/tools/Evm.Test/testdata/23/alloc.json b/tools/Evm.Test/testdata/23/alloc.json new file mode 100644 index 00000000000..239b3553f98 --- /dev/null +++ b/tools/Evm.Test/testdata/23/alloc.json @@ -0,0 +1,16 @@ +{ + "0x095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x6001", + "nonce" : "0x00", + "storage" : { + } + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x", + "nonce" : "0x00", + "storage" : { + } + } +} diff --git a/tools/Evm.Test/testdata/23/env.json b/tools/Evm.Test/testdata/23/env.json new file mode 100644 index 00000000000..1b46321512a --- /dev/null +++ b/tools/Evm.Test/testdata/23/env.json @@ -0,0 +1,7 @@ +{ + "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "0x020000", + "currentGasLimit" : "0x3b9aca00", + "currentNumber" : "0x05", + "currentTimestamp" : "0x03e8" +} diff --git a/tools/Evm.Test/testdata/23/exp.json b/tools/Evm.Test/testdata/23/exp.json new file mode 100644 index 00000000000..22dde0a27c4 --- /dev/null +++ b/tools/Evm.Test/testdata/23/exp.json @@ -0,0 +1,26 @@ +{ + "result": { + "stateRoot": "0x65334305e4accfa18352deb24f007b837b5036425b0712cf0e65a43bfa95154d", + "txRoot": "0x75e61774a2ff58cbe32653420256c7f44bc715715a423b0b746d5c622979af6b", + "receiptsRoot": "0xf951f9396af203499cc7d379715a9110323de73967c5700e2f424725446a3c76", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [ + { + "root": "0x", + "status": "0x1", + "cumulativeGasUsed": "0x520b", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0x72fadbef39cd251a437eea619cfeda752271a5faaaa2147df012e112159ffb81", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x520b", + "effectiveGasPrice": null, + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x0" + } + ], + "currentDifficulty": "0x20000", + "gasUsed": "0x520b" + } +} diff --git a/tools/Evm.Test/testdata/23/readme.md b/tools/Evm.Test/testdata/23/readme.md new file mode 100644 index 00000000000..f31b64de2fc --- /dev/null +++ b/tools/Evm.Test/testdata/23/readme.md @@ -0,0 +1 @@ +These files exemplify how to sign a transaction using the pre-EIP155 scheme. diff --git a/tools/Evm.Test/testdata/23/txs.json b/tools/Evm.Test/testdata/23/txs.json new file mode 100644 index 00000000000..22f3840f84b --- /dev/null +++ b/tools/Evm.Test/testdata/23/txs.json @@ -0,0 +1,15 @@ +[ + { + "input" : "0x", + "gas" : "0x5f5e100", + "gasPrice" : "0x1", + "nonce" : "0x0", + "to" : "0x095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "0x186a0", + "v" : "0x0", + "r" : "0x0", + "s" : "0x0", + "secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "protected": false + } +] diff --git a/tools/Evm.Test/testdata/24/alloc.json b/tools/Evm.Test/testdata/24/alloc.json new file mode 100644 index 00000000000..73a9a03c0b9 --- /dev/null +++ b/tools/Evm.Test/testdata/24/alloc.json @@ -0,0 +1,14 @@ +{ + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x5ffd4878be161d74", + "code": "0x", + "nonce": "0xac", + "storage": {} + }, + "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192":{ + "balance": "0xfeedbead", + "nonce" : "0x00", + "code" : "0x44600055", + "_comment": "The code is 'sstore(0, random)'" + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/24/env-missingrandom.json b/tools/Evm.Test/testdata/24/env-missingrandom.json new file mode 100644 index 00000000000..db49fd3fce4 --- /dev/null +++ b/tools/Evm.Test/testdata/24/env-missingrandom.json @@ -0,0 +1,9 @@ +{ + "currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "currentDifficulty": null, + "currentRandom": null, + "currentGasLimit": "0x750a163df65e8a", + "currentBaseFee": "0x500", + "currentNumber": "1", + "currentTimestamp": "1000" +} diff --git a/tools/Evm.Test/testdata/24/env.json b/tools/Evm.Test/testdata/24/env.json new file mode 100644 index 00000000000..262cc2528c2 --- /dev/null +++ b/tools/Evm.Test/testdata/24/env.json @@ -0,0 +1,9 @@ +{ + "currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "currentDifficulty": null, + "currentRandom": "0xdeadc0de", + "currentGasLimit": "0x750a163df65e8a", + "currentBaseFee": "0x500", + "currentNumber": "1", + "currentTimestamp": "1000" +} diff --git a/tools/Evm.Test/testdata/24/exp.json b/tools/Evm.Test/testdata/24/exp.json new file mode 100644 index 00000000000..ac571d149b5 --- /dev/null +++ b/tools/Evm.Test/testdata/24/exp.json @@ -0,0 +1,56 @@ +{ + "alloc": { + "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192": { + "code": "0x44600055", + "storage": { + "0x0000000000000000000000000000000000000000000000000000000000000000": "0x00000000000000000000000000000000000000000000000000000000deadc0de" + }, + "balance": "0xfeedbeaf" + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x5ffd4878b803f972", + "nonce": "0xae" + }, + "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x1030600" + } + }, + "result": { + "stateRoot": "0x9e4224c6bba343d5b0fdbe9200cc66a7ef2068240d901ae516e634c45a043c15", + "txRoot": "0x16cd3a7daa6686ceebadf53b7af2bc6919eccb730907f0e74a95a4423c209593", + "receiptsRoot": "0x22b85cda738345a9880260b2a71e144aab1ca9485f5db4fd251008350fc124c8", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [ + { + "root": "0x", + "status": "0x1", + "cumulativeGasUsed": "0xa861", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0x92ea4a28224d033afb20e0cc2b290d4c7c2d61f6a4800a680e4e19ac962ee941", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0xa861", + "effectiveGasPrice": null, + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x0" + }, + { + "root": "0x", + "status": "0x1", + "cumulativeGasUsed": "0x10306", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0x16b1d912f1d664f3f60f4e1b5f296f3c82a64a1a253117b4851d18bc03c4f1da", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x5aa5", + "effectiveGasPrice": null, + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x1" + } + ], + "currentDifficulty": null, + "gasUsed": "0x10306", + "currentBaseFee": "0x500" + } +} diff --git a/tools/Evm.Test/testdata/24/txs.json b/tools/Evm.Test/testdata/24/txs.json new file mode 100644 index 00000000000..99c2068f1a7 --- /dev/null +++ b/tools/Evm.Test/testdata/24/txs.json @@ -0,0 +1,28 @@ +[ + { + "gas": "0x186a0", + "gasPrice": "0x600", + "hash": "0x0557bacce3375c98d806609b8d5043072f0b6a8bae45ae5a67a00d3a1a18d673", + "input": "0x", + "nonce": "0xac", + "to": "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192", + "value": "0x1", + "v" : "0x0", + "r" : "0x0", + "s" : "0x0", + "secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" + }, + { + "gas": "0x186a0", + "gasPrice": "0x600", + "hash": "0x0557bacce3375c98d806609b8d5043072f0b6a8bae45ae5a67a00d3a1a18d673", + "input": "0x", + "nonce": "0xad", + "to": "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192", + "value": "0x1", + "v" : "0x0", + "r" : "0x0", + "s" : "0x0", + "secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" + } +] diff --git a/tools/Evm.Test/testdata/25/alloc.json b/tools/Evm.Test/testdata/25/alloc.json new file mode 100644 index 00000000000..d66366718e5 --- /dev/null +++ b/tools/Evm.Test/testdata/25/alloc.json @@ -0,0 +1,8 @@ +{ + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x5ffd4878be161d74", + "code": "0x", + "nonce": "0xac", + "storage": {} + } +} diff --git a/tools/Evm.Test/testdata/25/env.json b/tools/Evm.Test/testdata/25/env.json new file mode 100644 index 00000000000..bb2c9e0d7d6 --- /dev/null +++ b/tools/Evm.Test/testdata/25/env.json @@ -0,0 +1,11 @@ +{ + "currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "currentDifficulty": null, + "currentRandom": "0xdeadc0de", + "currentGasLimit": "0x750a163df65e8a", + "parentBaseFee": "0x500", + "parentGasUsed": "0x0", + "parentGasLimit": "0x750a163df65e8a", + "currentNumber": "1", + "currentTimestamp": "1000" +} diff --git a/tools/Evm.Test/testdata/25/exp.json b/tools/Evm.Test/testdata/25/exp.json new file mode 100644 index 00000000000..1cb521794c7 --- /dev/null +++ b/tools/Evm.Test/testdata/25/exp.json @@ -0,0 +1,39 @@ +{ + "alloc": { + "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192": { + "balance": "0x1" + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x5ffd4878bc29ed73", + "nonce": "0xad" + }, + "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x854d00" + } + }, + "result": { + "stateRoot": "0x5139609e39f4d158a7d1ad1800908eb0349cea9b500a8273a6cf0a7e4392639b", + "txRoot": "0x572690baf4898c2972446e56ecf0aa2a027c08a863927d2dce34472f0c5496fe", + "receiptsRoot": "0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [ + { + "root": "0x", + "status": "0x1", + "cumulativeGasUsed": "0x5208", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0x92ea4a28224d033afb20e0cc2b290d4c7c2d61f6a4800a680e4e19ac962ee941", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x5208", + "effectiveGasPrice": null, + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x0" + } + ], + "currentDifficulty": null, + "gasUsed": "0x5208", + "currentBaseFee": "0x460" + } +} diff --git a/tools/Evm.Test/testdata/25/txs.json b/tools/Evm.Test/testdata/25/txs.json new file mode 100644 index 00000000000..acb4035fd1e --- /dev/null +++ b/tools/Evm.Test/testdata/25/txs.json @@ -0,0 +1,15 @@ +[ + { + "gas": "0x186a0", + "gasPrice": "0x600", + "hash": "0x0557bacce3375c98d806609b8d5043072f0b6a8bae45ae5a67a00d3a1a18d673", + "input": "0x", + "nonce": "0xac", + "to": "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192", + "value": "0x1", + "v" : "0x0", + "r" : "0x0", + "s" : "0x0", + "secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" + } +] diff --git a/tools/Evm.Test/testdata/26/alloc.json b/tools/Evm.Test/testdata/26/alloc.json new file mode 100644 index 00000000000..d67655a8a8e --- /dev/null +++ b/tools/Evm.Test/testdata/26/alloc.json @@ -0,0 +1,8 @@ +{ + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x0", + "code": "0x", + "nonce": "0xac", + "storage": {} + } +} diff --git a/tools/Evm.Test/testdata/26/env.json b/tools/Evm.Test/testdata/26/env.json new file mode 100644 index 00000000000..03d817b93bc --- /dev/null +++ b/tools/Evm.Test/testdata/26/env.json @@ -0,0 +1,17 @@ +{ + "currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "currentDifficulty": null, + "currentRandom": "0xdeadc0de", + "currentGasLimit": "0x750a163df65e8a", + "currentBaseFee": "0x500", + "currentNumber": "1", + "currentTimestamp": "1000", + "withdrawals": [ + { + "index": "0x42", + "validatorIndex": "0x42", + "address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "amount": "0x2a" + } + ] +} diff --git a/tools/Evm.Test/testdata/26/exp.json b/tools/Evm.Test/testdata/26/exp.json new file mode 100644 index 00000000000..4815e5cb65e --- /dev/null +++ b/tools/Evm.Test/testdata/26/exp.json @@ -0,0 +1,20 @@ +{ + "alloc": { + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x9c7652400", + "nonce": "0xac" + } + }, + "result": { + "stateRoot": "0x6e061c2f6513af27d267a0e3b07cb9a10f1ba3a0f65ab648d3a17c36e15021d2", + "txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [], + "currentDifficulty": null, + "gasUsed": "0x0", + "currentBaseFee": "0x500", + "withdrawalsRoot": "0x4921c0162c359755b2ae714a0978a1dad2eb8edce7ff9b38b9b6fc4cbc547eb5" + } +} diff --git a/tools/Evm.Test/testdata/26/txs.json b/tools/Evm.Test/testdata/26/txs.json new file mode 100644 index 00000000000..fe51488c706 --- /dev/null +++ b/tools/Evm.Test/testdata/26/txs.json @@ -0,0 +1 @@ +[] diff --git a/tools/Evm.Test/testdata/27/exp.json b/tools/Evm.Test/testdata/27/exp.json new file mode 100644 index 00000000000..5975a9c25af --- /dev/null +++ b/tools/Evm.Test/testdata/27/exp.json @@ -0,0 +1,4 @@ +{ + "rlp": "0xf90239f9021aa0d6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082100082c3be83050785808455c5277e80a05865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf88000000000000000080a04921c0162c359755b2ae714a0978a1dad2eb8edce7ff9b38b9b6fc4cbc547eb5c0c0d9d8424394a94f5374fce5edbc8e2a8697c15331677e6ebf0b2a", + "hash": "0xdc42abd3698499675819e0a85cc1266f16da90277509b867446a6b25fa2b9d87" +} diff --git a/tools/Evm.Test/testdata/27/header.json b/tools/Evm.Test/testdata/27/header.json new file mode 100644 index 00000000000..4ed7eaca09d --- /dev/null +++ b/tools/Evm.Test/testdata/27/header.json @@ -0,0 +1,12 @@ +{ + "parentHash": "0xd6d785d33cbecf30f30d07e00e226af58f72efdf385d46bc3e6326c23b11e34e", + "stateRoot": "0x325aea6db48e9d737cddf59034843e99f05bec269453be83c9b9a981a232cc2e", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "difficulty": "0x1000", + "number": "0xc3be", + "gasLimit": "0x50785", + "gasUsed": "0x0", + "timestamp": "0x55c5277e", + "mixHash": "0x5865e417635a26db6d1d39ac70d1abf373e5398b3c6fd506acd038fa1334eedf", + "withdrawalsRoot": "0x4921c0162c359755b2ae714a0978a1dad2eb8edce7ff9b38b9b6fc4cbc547eb5" +} diff --git a/tools/Evm.Test/testdata/27/ommers.json b/tools/Evm.Test/testdata/27/ommers.json new file mode 100644 index 00000000000..fe51488c706 --- /dev/null +++ b/tools/Evm.Test/testdata/27/ommers.json @@ -0,0 +1 @@ +[] diff --git a/tools/Evm.Test/testdata/27/txs.rlp b/tools/Evm.Test/testdata/27/txs.rlp new file mode 100644 index 00000000000..e815397b333 --- /dev/null +++ b/tools/Evm.Test/testdata/27/txs.rlp @@ -0,0 +1 @@ +"c0" diff --git a/tools/Evm.Test/testdata/27/withdrawals.json b/tools/Evm.Test/testdata/27/withdrawals.json new file mode 100644 index 00000000000..6634aff089b --- /dev/null +++ b/tools/Evm.Test/testdata/27/withdrawals.json @@ -0,0 +1,8 @@ +[ + { + "index": "0x42", + "validatorIndex": "0x43", + "address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "amount": "0x2a" + } +] diff --git a/tools/Evm.Test/testdata/28/alloc.json b/tools/Evm.Test/testdata/28/alloc.json new file mode 100644 index 00000000000..680a89f4edb --- /dev/null +++ b/tools/Evm.Test/testdata/28/alloc.json @@ -0,0 +1,16 @@ +{ + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0x016345785d8a0000", + "code" : "0x", + "nonce" : "0x00", + "storage" : { + } + }, + "0xb94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0x016345785d8a0000", + "code" : "0x60004960015500", + "nonce" : "0x00", + "storage" : { + } + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/28/env.json b/tools/Evm.Test/testdata/28/env.json new file mode 100644 index 00000000000..82f22ac62f4 --- /dev/null +++ b/tools/Evm.Test/testdata/28/env.json @@ -0,0 +1,22 @@ +{ + "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentNumber" : "0x01", + "currentTimestamp" : "0x079e", + "currentGasLimit" : "0x7fffffffffffffff", + "previousHash" : "0x3a9b485972e7353edd9152712492f0c58d89ef80623686b6bf947a4a6dce6cb6", + "currentBlobGasUsed" : "0x00", + "parentTimestamp" : "0x03b6", + "parentDifficulty" : "0x00", + "parentUncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "currentRandom" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "withdrawals" : [], + "parentBaseFee" : "0x0a", + "parentGasUsed" : "0x00", + "parentGasLimit" : "0x7fffffffffffffff", + "parentExcessBlobGas" : "0x00", + "parentBlobGasUsed" : "0x00", + "blockHashes" : { + "0" : "0x3a9b485972e7353edd9152712492f0c58d89ef80623686b6bf947a4a6dce6cb6" + }, + "parentBeaconBlockRoot": "0x0000beac00beac00beac00beac00beac00beac00beac00beac00beac00beac00" +} diff --git a/tools/Evm.Test/testdata/28/exp.json b/tools/Evm.Test/testdata/28/exp.json new file mode 100644 index 00000000000..75c715e9722 --- /dev/null +++ b/tools/Evm.Test/testdata/28/exp.json @@ -0,0 +1,47 @@ +{ + "alloc": { + "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": { + "balance": "0x150ca" + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x16345785d80c3a9", + "nonce": "0x1" + }, + "0xb94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "code": "0x60004960015500", + "storage": { + "0x0000000000000000000000000000000000000000000000000000000000000001": "0x01a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" + }, + "balance": "0x16345785d8a0000" + } + }, + "result": { + "stateRoot": "0xa40cb3fab01848e922a48bd24191815df9f721ad4b60376edac75161517663e8", + "txRoot": "0x4409cc4b699384ba5f8248d92b784713610c5ff9c1de51e9239da0dac76de9ce", + "receiptsRoot": "0xbff643da765981266133094092d98c81d2ac8e9a83a7bbda46c3d736f1f874ac", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [ + { + "type": "0x3", + "root": "0x", + "status": "0x1", + "cumulativeGasUsed": "0xa865", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0x7508d7139d002a4b3a26a4f12dec0d87cb46075c78bf77a38b569a133b509262", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0xa865", + "effectiveGasPrice": null, + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x0" + } + ], + "currentDifficulty": null, + "gasUsed": "0xa865", + "currentBaseFee": "0x9", + "withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "currentExcessBlobGas": "0x0", + "blobGasUsed": "0x20000" + } +} diff --git a/tools/Evm.Test/testdata/28/txs.rlp b/tools/Evm.Test/testdata/28/txs.rlp new file mode 100644 index 00000000000..8df20e3aa27 --- /dev/null +++ b/tools/Evm.Test/testdata/28/txs.rlp @@ -0,0 +1 @@ +"0xf88bb88903f8860180026483061a8094b94f5374fce5edbc8e2a8697c15331677e6ebf0b8080c00ae1a001a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d801a025e16bb498552165016751911c3608d79000ab89dc3100776e729e6ea13091c7a03acacff7fc0cff6eda8a927dec93ca17765e1ee6cbc06c5954ce102e097c01d2" \ No newline at end of file diff --git a/tools/Evm.Test/testdata/29/alloc.json b/tools/Evm.Test/testdata/29/alloc.json new file mode 100644 index 00000000000..1fa224ea0f1 --- /dev/null +++ b/tools/Evm.Test/testdata/29/alloc.json @@ -0,0 +1,16 @@ +{ + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0x016345785d8a0000", + "code" : "0x", + "nonce" : "0x00", + "storage" : { + } + }, + "0x000f3df6d732807ef1319fb7b8bb8522d0beac02" : { + "balance" : "0x1", + "code" : "0x3373fffffffffffffffffffffffffffffffffffffffe14604457602036146024575f5ffd5b620180005f350680545f35146037575f5ffd5b6201800001545f5260205ff35b6201800042064281555f359062018000015500", + "nonce" : "0x00", + "storage" : { + } + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/29/env.json b/tools/Evm.Test/testdata/29/env.json new file mode 100644 index 00000000000..e752a909ad3 --- /dev/null +++ b/tools/Evm.Test/testdata/29/env.json @@ -0,0 +1,20 @@ +{ + "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentNumber" : "0x01", + "currentTimestamp" : "0x079e", + "currentGasLimit" : "0x7fffffffffffffff", + "previousHash" : "0x3a9b485972e7353edd9152712492f0c58d89ef80623686b6bf947a4a6dce6cb6", + "currentBlobGasUsed" : "0x00", + "parentTimestamp" : "0x03b6", + "parentDifficulty" : "0x00", + "parentUncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "currentRandom" : "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "withdrawals" : [ + ], + "parentBaseFee" : "0x0a", + "parentGasUsed" : "0x00", + "parentGasLimit" : "0x7fffffffffffffff", + "parentExcessBlobGas" : "0x00", + "parentBlobGasUsed" : "0x00", + "parentBeaconBlockRoot": "0x0000beac00beac00beac00beac00beac00beac00beac00beac00beac00beac00" +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/29/exp.json b/tools/Evm.Test/testdata/29/exp.json new file mode 100644 index 00000000000..c4c001ec14e --- /dev/null +++ b/tools/Evm.Test/testdata/29/exp.json @@ -0,0 +1,45 @@ +{ + "alloc": { + "0x000f3df6d732807ef1319fb7b8bb8522d0beac02": { + "code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604457602036146024575f5ffd5b620180005f350680545f35146037575f5ffd5b6201800001545f5260205ff35b6201800042064281555f359062018000015500", + "storage": { + "0x000000000000000000000000000000000000000000000000000000000000079e": "0x000000000000000000000000000000000000000000000000000000000000079e", + "0x000000000000000000000000000000000000000000000000000000000001879e": "0x0000beac00beac00beac00beac00beac00beac00beac00beac00beac00beac00" + }, + "balance": "0x1" + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x16345785d871db8", + "nonce": "0x1" + } + }, + "result": { + "stateRoot": "0x19a4f821a7c0a6f4c934f9acb0fe9ce5417b68086e12513ecbc3e3f57e01573c", + "txRoot": "0x248074fabe112f7d93917f292b64932394f835bb98da91f21501574d58ec92ab", + "receiptsRoot": "0xf78dfb743fbd92ade140711c8bbc542b5e307f0ab7984eff35d751969fe57efa", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [ + { + "type": "0x2", + "root": "0x", + "status": "0x1", + "cumulativeGasUsed": "0x5208", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0x84f70aba406a55628a0620f26d260f90aeb6ccc55fed6ec2ac13dd4f727032ed", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x5208", + "effectiveGasPrice": null, + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x0" + } + ], + "currentDifficulty": null, + "gasUsed": "0x5208", + "currentBaseFee": "0x9", + "withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "currentExcessBlobGas": "0x0", + "blobGasUsed": "0x0" + } +} diff --git a/tools/Evm.Test/testdata/29/readme.md b/tools/Evm.Test/testdata/29/readme.md new file mode 100644 index 00000000000..ab02ce9cf8d --- /dev/null +++ b/tools/Evm.Test/testdata/29/readme.md @@ -0,0 +1,29 @@ +## EIP 4788 + +This test contains testcases for EIP-4788. The 4788-contract is +located at address `0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02`, and this test executes a simple transaction. It also +implicitly invokes the system tx, which sets calls the contract and sets the +storage values + +``` +$ dir=./testdata/29/ && go run . t8n --state.fork=Cancun --input.alloc=$dir/alloc.json --input.txs=$dir/txs.json --input.env=$dir/env.json --output.alloc=stdout +INFO [09-27|15:34:53.049] Trie dumping started root=19a4f8..01573c +INFO [09-27|15:34:53.049] Trie dumping complete accounts=2 elapsed="192.759µs" +INFO [09-27|15:34:53.050] Wrote file file=result.json +{ + "alloc": { + "0x000f3df6d732807ef1319fb7b8bb8522d0beac02": { + "code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604457602036146024575f5ffd5b620180005f350680545f35146037575f5ffd5b6201800001545f5260205ff35b6201800042064281555f359062018000015500", + "storage": { + "0x000000000000000000000000000000000000000000000000000000000000079e": "0x000000000000000000000000000000000000000000000000000000000000079e", + "0x000000000000000000000000000000000000000000000000000000000001879e": "0x0000beac00beac00beac00beac00beac00beac00beac00beac00beac00beac00" + }, + "balance": "0x1" + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x16345785d871db8", + "nonce": "0x1" + } + } +} +``` diff --git a/tools/Evm.Test/testdata/29/txs.json b/tools/Evm.Test/testdata/29/txs.json new file mode 100644 index 00000000000..d6743cc4d24 --- /dev/null +++ b/tools/Evm.Test/testdata/29/txs.json @@ -0,0 +1,19 @@ +[ + { + "input" : "0x", + "gas" : "0x10000000", + "nonce" : "0x0", + "to" : "0x1111111111111111111111111111111111111111", + "value" : "0x0", + "secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", + "chainId" : "0x1", + "type" : "0x2", + "v": "0x0", + "r": "0x0", + "s": "0x0", + "maxFeePerGas" : "0xfa0", + "maxPriorityFeePerGas" : "0x0", + "accessList" : [ + ] + } +] \ No newline at end of file diff --git a/tools/Evm.Test/testdata/3/alloc.json b/tools/Evm.Test/testdata/3/alloc.json new file mode 100644 index 00000000000..dca318ee546 --- /dev/null +++ b/tools/Evm.Test/testdata/3/alloc.json @@ -0,0 +1,16 @@ +{ + "0x095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x600140", + "nonce" : "0x00", + "storage" : { + } + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x", + "nonce" : "0x00", + "storage" : { + } + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/3/env.json b/tools/Evm.Test/testdata/3/env.json new file mode 100644 index 00000000000..e283eff4615 --- /dev/null +++ b/tools/Evm.Test/testdata/3/env.json @@ -0,0 +1,8 @@ +{ + "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "0x020000", + "currentGasLimit" : "0x3b9aca00", + "currentNumber" : "0x05", + "currentTimestamp" : "0x03e8", + "blockHashes" : { "1" : "0xdac58aa524e50956d0c0bae7f3f8bb9d35381365d07804dd5b48a5a297c06af4"} +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/3/exp.json b/tools/Evm.Test/testdata/3/exp.json new file mode 100644 index 00000000000..7230dca2cf3 --- /dev/null +++ b/tools/Evm.Test/testdata/3/exp.json @@ -0,0 +1,39 @@ +{ + "alloc": { + "0x095e7baea6a6c7c4c2dfeb977efac326af552d87": { + "code": "0x600140", + "balance": "0xde0b6b3a76586a0" + }, + "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": { + "balance": "0x521f" + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0xde0b6b3a7622741", + "nonce": "0x1" + } + }, + "result": { + "stateRoot": "0xb7341da3f9f762a6884eaa186c32942734c146b609efee11c4b0214c44857ea1", + "txRoot": "0x75e61774a2ff58cbe32653420256c7f44bc715715a423b0b746d5c622979af6b", + "receiptsRoot": "0xd0d26df80374a327c025d405ebadc752b1bbd089d864801ae78ab704bcad8086", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [ + { + "root": "0x", + "status": "0x1", + "cumulativeGasUsed": "0x521f", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0x72fadbef39cd251a437eea619cfeda752271a5faaaa2147df012e112159ffb81", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x521f", + "effectiveGasPrice": null, + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x0" + } + ], + "currentDifficulty": "0x20000", + "gasUsed": "0x521f" + } +} diff --git a/tools/Evm.Test/testdata/3/readme.md b/tools/Evm.Test/testdata/3/readme.md new file mode 100644 index 00000000000..246c58ef3bf --- /dev/null +++ b/tools/Evm.Test/testdata/3/readme.md @@ -0,0 +1,2 @@ +These files exemplify a transition where a transaction (executed on block 5) requests +the blockhash for block `1`. diff --git a/tools/Evm.Test/testdata/3/txs.json b/tools/Evm.Test/testdata/3/txs.json new file mode 100644 index 00000000000..30444585888 --- /dev/null +++ b/tools/Evm.Test/testdata/3/txs.json @@ -0,0 +1,14 @@ +[ + { + "input" : "0x", + "gas" : "0x5f5e100", + "gasPrice" : "0x1", + "nonce" : "0x0", + "to" : "0x095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "0x186a0", + "v" : "0x1b", + "r" : "0x88544c93a564b4c28d2ffac2074a0c55fdd4658fe0d215596ed2e32e3ef7f56b", + "s" : "0x7fb4075d54190f825d7c47bb820284757b34fd6293904a93cddb1d3aa961ac28", + "hash" : "0x72fadbef39cd251a437eea619cfeda752271a5faaaa2147df012e112159ffb81" + } +] \ No newline at end of file diff --git a/tools/Evm.Test/testdata/30/README.txt b/tools/Evm.Test/testdata/30/README.txt new file mode 100644 index 00000000000..84c92de8530 --- /dev/null +++ b/tools/Evm.Test/testdata/30/README.txt @@ -0,0 +1,77 @@ +This example comes from https://github.com/ethereum/go-ethereum/issues/27730. +The input transactions contain three transactions, number `0` and `2` are taken from +`testdata/13`, whereas number `1` is taken from #27730. + +The problematic second transaction cannot be RLP-decoded, and the expectation is +that that particular transaction should be rejected, but number `0` and `1` should +still be accepted. + +``` +$ go run . t8n --input.alloc=./testdata/30/alloc.json --input.txs=./testdata/30/txs_more.rlp --input.env=./testdata/30/env.json --output.result=stdout --output.alloc=stdout --state.fork=Cancun +WARN [10-22|15:38:03.283] rejected tx index=1 error="rlp: input string too short for common.Address, decoding into (types.Transaction)(types.BlobTx).To" +INFO [10-22|15:38:03.284] Trie dumping started root=348312..915c93 +INFO [10-22|15:38:03.284] Trie dumping complete accounts=3 elapsed="160.831µs" +{ + "alloc": { + "0x095e7baea6a6c7c4c2dfeb977efac326af552d87": { + "code": "0x60004960005500", + "balance": "0xde0b6b3a7640000" + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0xde0b6b3a7640000" + }, + "0xd02d72e067e77158444ef2020ff2d325f929b363": { + "balance": "0xfffffffb8390", + "nonce": "0x3" + } + }, + "result": { + "stateRoot": "0x3483124b6710486c9fb3e07975669c66924697c88cccdcc166af5e1218915c93", + "txRoot": "0x013509c8563d41c0ae4bf38f2d6d19fc6512a1d0d6be045079c8c9f68bf45f9d", + "receiptsRoot": "0x75308898d571eafb5cd8cde8278bf5b3d13c5f6ec074926de3bb895b519264e1", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [ + { + "type": "0x2", + "root": "0x", + "status": "0x1", + "cumulativeGasUsed": "0x5208", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0xa98a24882ea90916c6a86da650fbc6b14238e46f0af04a131ce92be897507476", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x5208", + "effectiveGasPrice": null, + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x0" + }, + { + "type": "0x2", + "root": "0x", + "status": "0x1", + "cumulativeGasUsed": "0xa410", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0x36bad80acce7040c45fd32764b5c2b2d2e6f778669fb41791f73f546d56e739a", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x5208", + "effectiveGasPrice": null, + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x1" + } + ], + "rejected": [ + { + "index": 1, + "error": "rlp: input string too short for common.Address, decoding into (types.Transaction)(types.BlobTx).To" + } + ], + "currentDifficulty": null, + "gasUsed": "0xa410", + "currentBaseFee": "0x7", + "withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + } +} + +``` \ No newline at end of file diff --git a/tools/Evm.Test/testdata/30/alloc.json b/tools/Evm.Test/testdata/30/alloc.json new file mode 100644 index 00000000000..6bc93d25521 --- /dev/null +++ b/tools/Evm.Test/testdata/30/alloc.json @@ -0,0 +1,23 @@ +{ + "0x095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x60004960005500", + "nonce" : "0x00", + "storage" : { + } + }, + "0xd02d72e067e77158444ef2020ff2d325f929b363" : { + "balance": "0x01000000000000", + "code": "0x", + "nonce": "0x01", + "storage": { + } + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x", + "nonce" : "0x00", + "storage" : { + } + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/30/env.json b/tools/Evm.Test/testdata/30/env.json new file mode 100644 index 00000000000..4acd9794be8 --- /dev/null +++ b/tools/Evm.Test/testdata/30/env.json @@ -0,0 +1,23 @@ +{ + "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentNumber" : "0x01", + "currentTimestamp" : "0x03e8", + "currentGasLimit" : "0x1000000000", + "previousHash" : "0xe4e2a30b340bec696242b67584264f878600dce98354ae0b6328740fd4ff18da", + "currentDataGasUsed" : "0x2000", + "parentTimestamp" : "0x00", + "parentDifficulty" : "0x00", + "parentUncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "parentBeaconBlockRoot" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "currentRandom" : "0x0000000000000000000000000000000000000000000000000000000000020000", + "withdrawals" : [ + ], + "parentBaseFee" : "0x08", + "parentGasUsed" : "0x00", + "parentGasLimit" : "0x1000000000", + "parentExcessBlobGas" : "0x1000", + "parentBlobGasUsed" : "0x2000", + "blockHashes" : { + "0" : "0xe4e2a30b340bec696242b67584264f878600dce98354ae0b6328740fd4ff18da" + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/30/exp.json b/tools/Evm.Test/testdata/30/exp.json new file mode 100644 index 00000000000..f0b19c6b3d3 --- /dev/null +++ b/tools/Evm.Test/testdata/30/exp.json @@ -0,0 +1,64 @@ +{ + "alloc": { + "0x095e7baea6a6c7c4c2dfeb977efac326af552d87": { + "code": "0x60004960005500", + "balance": "0xde0b6b3a7640000" + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0xde0b6b3a7640000" + }, + "0xd02d72e067e77158444ef2020ff2d325f929b363": { + "balance": "0xfffffffb8390", + "nonce": "0x3" + } + }, + "result": { + "stateRoot": "0x3483124b6710486c9fb3e07975669c66924697c88cccdcc166af5e1218915c93", + "txRoot": "0x013509c8563d41c0ae4bf38f2d6d19fc6512a1d0d6be045079c8c9f68bf45f9d", + "receiptsRoot": "0x75308898d571eafb5cd8cde8278bf5b3d13c5f6ec074926de3bb895b519264e1", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [ + { + "type": "0x2", + "root": "0x", + "status": "0x1", + "cumulativeGasUsed": "0x5208", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0xa98a24882ea90916c6a86da650fbc6b14238e46f0af04a131ce92be897507476", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x5208", + "effectiveGasPrice": null, + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x0" + }, + { + "type": "0x2", + "root": "0x", + "status": "0x1", + "cumulativeGasUsed": "0xa410", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "logs": null, + "transactionHash": "0x36bad80acce7040c45fd32764b5c2b2d2e6f778669fb41791f73f546d56e739a", + "contractAddress": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x5208", + "effectiveGasPrice": null, + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionIndex": "0x1" + } + ], + "rejected": [ + { + "index": 1, + "error": "rlp: input string too short for common.Address, decoding into (types.Transaction)(types.BlobTx).To" + } + ], + "currentDifficulty": null, + "gasUsed": "0xa410", + "currentBaseFee": "0x7", + "withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "currentExcessBlobGas": "0x0", + "blobGasUsed": "0x0" + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/30/txs.rlp b/tools/Evm.Test/testdata/30/txs.rlp new file mode 100644 index 00000000000..620c1a13ac7 --- /dev/null +++ b/tools/Evm.Test/testdata/30/txs.rlp @@ -0,0 +1 @@ +"0xf8dbb8d903f8d601800285012a05f200833d090080830186a000f85bf85994095e7baea6a6c7c4c2dfeb977efac326af552d87f842a00000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000010ae1a001a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d880a0fc12b67159a3567f8bdbc49e0be369a2e20e09d57a51c41310543a4128409464a02de0cfe5495c4f58ff60645ceda0afd67a4c90a70bc89fe207269435b35e5b67" \ No newline at end of file diff --git a/tools/Evm.Test/testdata/30/txs_more.rlp b/tools/Evm.Test/testdata/30/txs_more.rlp new file mode 100644 index 00000000000..35af8d1f230 --- /dev/null +++ b/tools/Evm.Test/testdata/30/txs_more.rlp @@ -0,0 +1 @@ +"0xf901adb86702f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904b8d903f8d601800285012a05f200833d090080830186a000f85bf85994095e7baea6a6c7c4c2dfeb977efac326af552d87f842a00000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000010ae1a001a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d880a0fc12b67159a3567f8bdbc49e0be369a2e20e09d57a51c41310543a4128409464a02de0cfe5495c4f58ff60645ceda0afd67a4c90a70bc89fe207269435b35e5b67b86702f864010280820fa08284d09411111111111111111111111111111111111111118080c080a0d4ec563b6568cd42d998fc4134b36933c6568d01533b5adf08769270243c6c7fa072bf7c21eac6bbeae5143371eef26d5e279637f3bd73482b55979d76d935b1e9" \ No newline at end of file diff --git a/tools/Evm.Test/testdata/31/README.md b/tools/Evm.Test/testdata/31/README.md new file mode 100644 index 00000000000..305e4f52da0 --- /dev/null +++ b/tools/Evm.Test/testdata/31/README.md @@ -0,0 +1 @@ +This test does some EVM execution, and can be used to test the tracers and trace-outputs. diff --git a/tools/Evm.Test/testdata/31/alloc.json b/tools/Evm.Test/testdata/31/alloc.json new file mode 100644 index 00000000000..bad5481c4a3 --- /dev/null +++ b/tools/Evm.Test/testdata/31/alloc.json @@ -0,0 +1,16 @@ +{ + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0x016345785d8a0000", + "code" : "0x", + "nonce" : "0x00", + "storage" : { + } + }, + "0x1111111111111111111111111111111111111111" : { + "balance" : "0x1", + "code" : "0x604060406040604000", + "nonce" : "0x00", + "storage" : { + } + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/31/env.json b/tools/Evm.Test/testdata/31/env.json new file mode 100644 index 00000000000..09b5f12d883 --- /dev/null +++ b/tools/Evm.Test/testdata/31/env.json @@ -0,0 +1,20 @@ +{ + "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentNumber" : "0x01", + "currentTimestamp" : "0x03e8", + "currentGasLimit" : "0x1000000000", + "previousHash" : "0xe4e2a30b340bec696242b67584264f878600dce98354ae0b6328740fd4ff18da", + "currentDataGasUsed" : "0x2000", + "parentTimestamp" : "0x00", + "parentDifficulty" : "0x00", + "parentUncleHash" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "parentBeaconBlockRoot" : "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "currentRandom" : "0x0000000000000000000000000000000000000000000000000000000000020000", + "withdrawals" : [ + ], + "parentBaseFee" : "0x08", + "parentGasUsed" : "0x00", + "parentGasLimit" : "0x1000000000", + "parentExcessBlobGas" : "0x1000", + "parentBlobGasUsed" : "0x2000" +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/31/txs.json b/tools/Evm.Test/testdata/31/txs.json new file mode 100644 index 00000000000..473c1526f40 --- /dev/null +++ b/tools/Evm.Test/testdata/31/txs.json @@ -0,0 +1,14 @@ +[ + { + "gas": "0x186a0", + "gasPrice": "0x600", + "input": "0x", + "nonce": "0x0", + "to": "0x1111111111111111111111111111111111111111", + "value": "0x1", + "v" : "0x0", + "r" : "0x0", + "s" : "0x0", + "secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" + } +] diff --git a/tools/Evm.Test/testdata/32/README.md b/tools/Evm.Test/testdata/32/README.md new file mode 100644 index 00000000000..508ac970dd5 --- /dev/null +++ b/tools/Evm.Test/testdata/32/README.md @@ -0,0 +1 @@ +This test does some EVM execution, and can be used to test callframes emitted by the tracer when they are enabled. diff --git a/tools/Evm.Test/testdata/32/alloc.json b/tools/Evm.Test/testdata/32/alloc.json new file mode 100644 index 00000000000..0cd44939552 --- /dev/null +++ b/tools/Evm.Test/testdata/32/alloc.json @@ -0,0 +1,30 @@ +{ + "0x8a0a19589531694250d570040a0c4b74576919b8": { + "nonce": "0x00", + "balance": "0x0de0b6b3a7640000", + "code": "0x600060006000600060007310000000000000000000000000000000000000015af1600155600060006000600060007310000000000000000000000000000000000000025af16002553d600060003e600051600355", + "storage": { + "0x01": "0x0100", + "0x02": "0x0100", + "0x03": "0x0100" + } + }, + "0x1000000000000000000000000000000000000001": { + "nonce": "0x00", + "balance": "0x29a2241af62c0000", + "code": "0x6103e8ff", + "storage": {} + }, + "0x1000000000000000000000000000000000000002": { + "nonce": "0x00", + "balance": "0x4563918244f40000", + "code": "0x600060006000600060647310000000000000000000000000000000000000015af1600f0160005260206000fd", + "storage": {} + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "nonce": "0x00", + "balance": "0x6124fee993bc0000", + "code": "0x", + "storage": {} + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/32/env.json b/tools/Evm.Test/testdata/32/env.json new file mode 100644 index 00000000000..4f0833e711f --- /dev/null +++ b/tools/Evm.Test/testdata/32/env.json @@ -0,0 +1,12 @@ +{ + "currentCoinbase": "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentGasLimit": "71794957647893862", + "currentNumber": "1", + "currentTimestamp": "1000", + "currentRandom": "0", + "currentDifficulty": "0", + "blockHashes": {}, + "ommers": [], + "currentBaseFee": "7", + "parentUncleHash": "0x0000000000000000000000000000000000000000000000000000000000000000" +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/32/txs.json b/tools/Evm.Test/testdata/32/txs.json new file mode 100644 index 00000000000..0530fd60e62 --- /dev/null +++ b/tools/Evm.Test/testdata/32/txs.json @@ -0,0 +1,17 @@ +[ + { + "type": "0x0", + "chainId": "0x0", + "nonce": "0x0", + "gasPrice": "0xa", + "gas": "0x7a120", + "to": "0x8a0a19589531694250d570040a0c4b74576919b8", + "value": "0x0", + "input": "0x", + "v": "0x1c", + "r": "0x9a207ad45b7fc2aa5f8e72a30487f2b0bc489778e6d022f19036efdf2a922a17", + "s": "0x640d4da05078b5a4aa561f1b4d58176ea828bfa0f88d27d14459c1d789e1a1eb", + "sender": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" + } +] \ No newline at end of file diff --git a/tools/Evm.Test/testdata/4/alloc.json b/tools/Evm.Test/testdata/4/alloc.json new file mode 100644 index 00000000000..fadf2bdc4ec --- /dev/null +++ b/tools/Evm.Test/testdata/4/alloc.json @@ -0,0 +1,16 @@ +{ + "0x095e7baea6a6c7c4c2dfeb977efac326af552d87" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x600340", + "nonce" : "0x00", + "storage" : { + } + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x", + "nonce" : "0x00", + "storage" : { + } + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/4/env.json b/tools/Evm.Test/testdata/4/env.json new file mode 100644 index 00000000000..e283eff4615 --- /dev/null +++ b/tools/Evm.Test/testdata/4/env.json @@ -0,0 +1,8 @@ +{ + "currentCoinbase" : "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "0x020000", + "currentGasLimit" : "0x3b9aca00", + "currentNumber" : "0x05", + "currentTimestamp" : "0x03e8", + "blockHashes" : { "1" : "0xdac58aa524e50956d0c0bae7f3f8bb9d35381365d07804dd5b48a5a297c06af4"} +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/4/readme.md b/tools/Evm.Test/testdata/4/readme.md new file mode 100644 index 00000000000..eede41a9fd3 --- /dev/null +++ b/tools/Evm.Test/testdata/4/readme.md @@ -0,0 +1,3 @@ +These files exemplify a transition where a transaction (executed on block 5) requests +the blockhash for block `4`, but where the hash for that block is missing. +It's expected that executing these should cause `exit` with errorcode `4`. diff --git a/tools/Evm.Test/testdata/4/txs.json b/tools/Evm.Test/testdata/4/txs.json new file mode 100644 index 00000000000..30444585888 --- /dev/null +++ b/tools/Evm.Test/testdata/4/txs.json @@ -0,0 +1,14 @@ +[ + { + "input" : "0x", + "gas" : "0x5f5e100", + "gasPrice" : "0x1", + "nonce" : "0x0", + "to" : "0x095e7baea6a6c7c4c2dfeb977efac326af552d87", + "value" : "0x186a0", + "v" : "0x1b", + "r" : "0x88544c93a564b4c28d2ffac2074a0c55fdd4658fe0d215596ed2e32e3ef7f56b", + "s" : "0x7fb4075d54190f825d7c47bb820284757b34fd6293904a93cddb1d3aa961ac28", + "hash" : "0x72fadbef39cd251a437eea619cfeda752271a5faaaa2147df012e112159ffb81" + } +] \ No newline at end of file diff --git a/tools/Evm.Test/testdata/5/alloc.json b/tools/Evm.Test/testdata/5/alloc.json new file mode 100644 index 00000000000..9e26dfeeb6e --- /dev/null +++ b/tools/Evm.Test/testdata/5/alloc.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/5/env.json b/tools/Evm.Test/testdata/5/env.json new file mode 100644 index 00000000000..1085f63e629 --- /dev/null +++ b/tools/Evm.Test/testdata/5/env.json @@ -0,0 +1,11 @@ +{ + "currentCoinbase": "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "currentDifficulty": "0x20000", + "currentGasLimit": "0x750a163df65e8a", + "currentNumber": "1", + "currentTimestamp": "1000", + "ommers": [ + {"delta": 1, "address": "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" }, + {"delta": 2, "address": "0xcccccccccccccccccccccccccccccccccccccccc" } + ] +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/5/exp.json b/tools/Evm.Test/testdata/5/exp.json new file mode 100644 index 00000000000..7d715672c50 --- /dev/null +++ b/tools/Evm.Test/testdata/5/exp.json @@ -0,0 +1,23 @@ +{ + "alloc": { + "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": { + "balance": "0x88" + }, + "0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb": { + "balance": "0x70" + }, + "0xcccccccccccccccccccccccccccccccccccccccc": { + "balance": "0x60" + } + }, + "result": { + "stateRoot": "0xa7312add33811645c6aa65d928a1a4f49d65d448801912c069a0aa8fe9c1f393", + "txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "receipts": [], + "currentDifficulty": "0x20000", + "gasUsed": "0x0" + } +} diff --git a/tools/Evm.Test/testdata/5/readme.md b/tools/Evm.Test/testdata/5/readme.md new file mode 100644 index 00000000000..1a84afaab64 --- /dev/null +++ b/tools/Evm.Test/testdata/5/readme.md @@ -0,0 +1 @@ +These files exemplify a transition where there are no transactions, two ommers, at block `N-1` (delta 1) and `N-2` (delta 2). \ No newline at end of file diff --git a/tools/Evm.Test/testdata/5/txs.json b/tools/Evm.Test/testdata/5/txs.json new file mode 100644 index 00000000000..fe51488c706 --- /dev/null +++ b/tools/Evm.Test/testdata/5/txs.json @@ -0,0 +1 @@ +[] diff --git a/tools/Evm.Test/testdata/7/alloc.json b/tools/Evm.Test/testdata/7/alloc.json new file mode 100644 index 00000000000..cef1a25ff01 --- /dev/null +++ b/tools/Evm.Test/testdata/7/alloc.json @@ -0,0 +1,12 @@ +{ + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x5ffd4878be161d74", + "code": "0x", + "nonce": "0xac", + "storage": {} + }, + "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192":{ + "balance": "0xfeedbead", + "nonce" : "0x00" + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/7/env.json b/tools/Evm.Test/testdata/7/env.json new file mode 100644 index 00000000000..8fd9bc041b8 --- /dev/null +++ b/tools/Evm.Test/testdata/7/env.json @@ -0,0 +1,7 @@ +{ + "currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "currentDifficulty": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffff020000", + "currentGasLimit": "0x750a163df65e8a", + "currentNumber": "5", + "currentTimestamp": "1000" +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/7/readme.md b/tools/Evm.Test/testdata/7/readme.md new file mode 100644 index 00000000000..59e0dbef99b --- /dev/null +++ b/tools/Evm.Test/testdata/7/readme.md @@ -0,0 +1,375 @@ +This is a test for HomesteadToDao, checking if the +DAO-transition works + +Example: +``` + ./evm t8n --input.alloc=./testdata/7/alloc.json --input.txs=./testdata/7/txs.json --input.env=./testdata/7/env.json --output.alloc=stdout --state.fork=HomesteadToDaoAt5 +INFO [03-09|10:47:37.255] Trie dumping started root=157847..2891b7 +INFO [03-09|10:47:37.256] Trie dumping complete accounts=120 elapsed="715.635µs" +INFO [03-09|10:47:37.256] Wrote file file=result.json +{ + "alloc": { + "0x005f5cee7a43331d5a3d3eec71305925a62f34b6": { + "balance": "0x0" + }, + "0x0101f3be8ebb4bbd39a2e3b9a3639d4259832fd9": { + "balance": "0x0" + }, + "0x057b56736d32b86616a10f619859c6cd6f59092a": { + "balance": "0x0" + }, + "0x06706dd3f2c9abf0a21ddcc6941d9b86f0596936": { + "balance": "0x0" + }, + "0x0737a6b837f97f46ebade41b9bc3e1c509c85c53": { + "balance": "0x0" + }, + "0x07f5c1e1bc2c93e0402f23341973a0e043f7bf8a": { + "balance": "0x0" + }, + "0x0e0da70933f4c7849fc0d203f5d1d43b9ae4532d": { + "balance": "0x0" + }, + "0x0ff30d6de14a8224aa97b78aea5388d1c51c1f00": { + "balance": "0x0" + }, + "0x12e626b0eebfe86a56d633b9864e389b45dcb260": { + "balance": "0x0" + }, + "0x1591fc0f688c81fbeb17f5426a162a7024d430c2": { + "balance": "0x0" + }, + "0x17802f43a0137c506ba92291391a8a8f207f487d": { + "balance": "0x0" + }, + "0x1975bd06d486162d5dc297798dfc41edd5d160a7": { + "balance": "0x0" + }, + "0x1ca6abd14d30affe533b24d7a21bff4c2d5e1f3b": { + "balance": "0x0" + }, + "0x1cba23d343a983e9b5cfd19496b9a9701ada385f": { + "balance": "0x0" + }, + "0x200450f06520bdd6c527622a273333384d870efb": { + "balance": "0x0" + }, + "0x21c7fdb9ed8d291d79ffd82eb2c4356ec0d81241": { + "balance": "0x0" + }, + "0x23b75c2f6791eef49c69684db4c6c1f93bf49a50": { + "balance": "0x0" + }, + "0x24c4d950dfd4dd1902bbed3508144a54542bba94": { + "balance": "0x0" + }, + "0x253488078a4edf4d6f42f113d1e62836a942cf1a": { + "balance": "0x0" + }, + "0x27b137a85656544b1ccb5a0f2e561a5703c6a68f": { + "balance": "0x0" + }, + "0x2a5ed960395e2a49b1c758cef4aa15213cfd874c": { + "balance": "0x0" + }, + "0x2b3455ec7fedf16e646268bf88846bd7a2319bb2": { + "balance": "0x0" + }, + "0x2c19c7f9ae8b751e37aeb2d93a699722395ae18f": { + "balance": "0x0" + }, + "0x304a554a310c7e546dfe434669c62820b7d83490": { + "balance": "0x0" + }, + "0x319f70bab6845585f412ec7724b744fec6095c85": { + "balance": "0x0" + }, + "0x35a051a0010aba705c9008d7a7eff6fb88f6ea7b": { + "balance": "0x0" + }, + "0x3ba4d81db016dc2890c81f3acec2454bff5aada5": { + "balance": "0x0" + }, + "0x3c02a7bc0391e86d91b7d144e61c2c01a25a79c5": { + "balance": "0x0" + }, + "0x40b803a9abce16f50f36a77ba41180eb90023925": { + "balance": "0x0" + }, + "0x440c59b325d2997a134c2c7c60a8c61611212bad": { + "balance": "0x0" + }, + "0x4486a3d68fac6967006d7a517b889fd3f98c102b": { + "balance": "0x0" + }, + "0x4613f3bca5c44ea06337a9e439fbc6d42e501d0a": { + "balance": "0x0" + }, + "0x47e7aa56d6bdf3f36be34619660de61275420af8": { + "balance": "0x0" + }, + "0x4863226780fe7c0356454236d3b1c8792785748d": { + "balance": "0x0" + }, + "0x492ea3bb0f3315521c31f273e565b868fc090f17": { + "balance": "0x0" + }, + "0x4cb31628079fb14e4bc3cd5e30c2f7489b00960c": { + "balance": "0x0" + }, + "0x4deb0033bb26bc534b197e61d19e0733e5679784": { + "balance": "0x0" + }, + "0x4fa802324e929786dbda3b8820dc7834e9134a2a": { + "balance": "0x0" + }, + "0x4fd6ace747f06ece9c49699c7cabc62d02211f75": { + "balance": "0x0" + }, + "0x51e0ddd9998364a2eb38588679f0d2c42653e4a6": { + "balance": "0x0" + }, + "0x52c5317c848ba20c7504cb2c8052abd1fde29d03": { + "balance": "0x0" + }, + "0x542a9515200d14b68e934e9830d91645a980dd7a": { + "balance": "0x0" + }, + "0x5524c55fb03cf21f549444ccbecb664d0acad706": { + "balance": "0x0" + }, + "0x579a80d909f346fbfb1189493f521d7f48d52238": { + "balance": "0x0" + }, + "0x58b95c9a9d5d26825e70a82b6adb139d3fd829eb": { + "balance": "0x0" + }, + "0x5c6e67ccd5849c0d29219c4f95f1a7a93b3f5dc5": { + "balance": "0x0" + }, + "0x5c8536898fbb74fc7445814902fd08422eac56d0": { + "balance": "0x0" + }, + "0x5d2b2e6fcbe3b11d26b525e085ff818dae332479": { + "balance": "0x0" + }, + "0x5dc28b15dffed94048d73806ce4b7a4612a1d48f": { + "balance": "0x0" + }, + "0x5f9f3392e9f62f63b8eac0beb55541fc8627f42c": { + "balance": "0x0" + }, + "0x6131c42fa982e56929107413a9d526fd99405560": { + "balance": "0x0" + }, + "0x6231b6d0d5e77fe001c2a460bd9584fee60d409b": { + "balance": "0x0" + }, + "0x627a0a960c079c21c34f7612d5d230e01b4ad4c7": { + "balance": "0x0" + }, + "0x63ed5a272de2f6d968408b4acb9024f4cc208ebf": { + "balance": "0x0" + }, + "0x6966ab0d485353095148a2155858910e0965b6f9": { + "balance": "0x0" + }, + "0x6b0c4d41ba9ab8d8cfb5d379c69a612f2ced8ecb": { + "balance": "0x0" + }, + "0x6d87578288b6cb5549d5076a207456a1f6a63dc0": { + "balance": "0x0" + }, + "0x6f6704e5a10332af6672e50b3d9754dc460dfa4d": { + "balance": "0x0" + }, + "0x7602b46df5390e432ef1c307d4f2c9ff6d65cc97": { + "balance": "0x0" + }, + "0x779543a0491a837ca36ce8c635d6154e3c4911a6": { + "balance": "0x0" + }, + "0x77ca7b50b6cd7e2f3fa008e24ab793fd56cb15f6": { + "balance": "0x0" + }, + "0x782495b7b3355efb2833d56ecb34dc22ad7dfcc4": { + "balance": "0x0" + }, + "0x807640a13483f8ac783c557fcdf27be11ea4ac7a": { + "balance": "0x0" + }, + "0x8163e7fb499e90f8544ea62bbf80d21cd26d9efd": { + "balance": "0x0" + }, + "0x84ef4b2357079cd7a7c69fd7a37cd0609a679106": { + "balance": "0x0" + }, + "0x86af3e9626fce1957c82e88cbf04ddf3a2ed7915": { + "balance": "0x0" + }, + "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192": { + "balance": "0xfeedbead" + }, + "0x8d9edb3054ce5c5774a420ac37ebae0ac02343c6": { + "balance": "0x0" + }, + "0x914d1b8b43e92723e64fd0a06f5bdb8dd9b10c79": { + "balance": "0x0" + }, + "0x97f43a37f595ab5dd318fb46e7a155eae057317a": { + "balance": "0x0" + }, + "0x9aa008f65de0b923a2a4f02012ad034a5e2e2192": { + "balance": "0x0" + }, + "0x9c15b54878ba618f494b38f0ae7443db6af648ba": { + "balance": "0x0" + }, + "0x9c50426be05db97f5d64fc54bf89eff947f0a321": { + "balance": "0x0" + }, + "0x9da397b9e80755301a3b32173283a91c0ef6c87e": { + "balance": "0x0" + }, + "0x9ea779f907f0b315b364b0cfc39a0fde5b02a416": { + "balance": "0x0" + }, + "0x9f27daea7aca0aa0446220b98d028715e3bc803d": { + "balance": "0x0" + }, + "0x9fcd2deaff372a39cc679d5c5e4de7bafb0b1339": { + "balance": "0x0" + }, + "0xa2f1ccba9395d7fcb155bba8bc92db9bafaeade7": { + "balance": "0x0" + }, + "0xa3acf3a1e16b1d7c315e23510fdd7847b48234f6": { + "balance": "0x0" + }, + "0xa5dc5acd6a7968a4554d89d65e59b7fd3bff0f90": { + "balance": "0x0" + }, + "0xa82f360a8d3455c5c41366975bde739c37bfeb8a": { + "balance": "0x0" + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x5ffd4878be161d74", + "nonce": "0xac" + }, + "0xac1ecab32727358dba8962a0f3b261731aad9723": { + "balance": "0x0" + }, + "0xaccc230e8a6e5be9160b8cdf2864dd2a001c28b6": { + "balance": "0x0" + }, + "0xacd87e28b0c9d1254e868b81cba4cc20d9a32225": { + "balance": "0x0" + }, + "0xadf80daec7ba8dcf15392f1ac611fff65d94f880": { + "balance": "0x0" + }, + "0xaeeb8ff27288bdabc0fa5ebb731b6f409507516c": { + "balance": "0x0" + }, + "0xb136707642a4ea12fb4bae820f03d2562ebff487": { + "balance": "0x0" + }, + "0xb2c6f0dfbb716ac562e2d85d6cb2f8d5ee87603e": { + "balance": "0x0" + }, + "0xb3fb0e5aba0e20e5c49d252dfd30e102b171a425": { + "balance": "0x0" + }, + "0xb52042c8ca3f8aa246fa79c3feaa3d959347c0ab": { + "balance": "0x0" + }, + "0xb9637156d330c0d605a791f1c31ba5890582fe1c": { + "balance": "0x0" + }, + "0xbb9bc244d798123fde783fcc1c72d3bb8c189413": { + "balance": "0x0" + }, + "0xbc07118b9ac290e4622f5e77a0853539789effbe": { + "balance": "0x0" + }, + "0xbcf899e6c7d9d5a215ab1e3444c86806fa854c76": { + "balance": "0x0" + }, + "0xbe8539bfe837b67d1282b2b1d61c3f723966f049": { + "balance": "0x0" + }, + "0xbf4ed7b27f1d666546e30d74d50d173d20bca754": { + "balance": "0x0" + }, + "0xc4bbd073882dd2add2424cf47d35213405b01324": { + "balance": "0x0" + }, + "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x0" + }, + "0xca544e5c4687d109611d0f8f928b53a25af72448": { + "balance": "0x0" + }, + "0xcbb9d3703e651b0d496cdefb8b92c25aeb2171f7": { + "balance": "0x0" + }, + "0xcc34673c6c40e791051898567a1222daf90be287": { + "balance": "0x0" + }, + "0xceaeb481747ca6c540a000c1f3641f8cef161fa7": { + "balance": "0x0" + }, + "0xd131637d5275fd1a68a3200f4ad25c71a2a9522e": { + "balance": "0x0" + }, + "0xd164b088bd9108b60d0ca3751da4bceb207b0782": { + "balance": "0x0" + }, + "0xd1ac8b1ef1b69ff51d1d401a476e7e612414f091": { + "balance": "0x0" + }, + "0xd343b217de44030afaa275f54d31a9317c7f441e": { + "balance": "0x0" + }, + "0xd4fe7bc31cedb7bfb8a345f31e668033056b2728": { + "balance": "0x0" + }, + "0xd9aef3a1e38a39c16b31d1ace71bca8ef58d315b": { + "balance": "0x0" + }, + "0xda2fef9e4a3230988ff17df2165440f37e8b1708": { + "balance": "0x0" + }, + "0xdbe9b615a3ae8709af8b93336ce9b477e4ac0940": { + "balance": "0x0" + }, + "0xe308bd1ac5fda103967359b2712dd89deffb7973": { + "balance": "0x0" + }, + "0xe4ae1efdfc53b73893af49113d8694a057b9c0d1": { + "balance": "0x0" + }, + "0xec8e57756626fdc07c63ad2eafbd28d08e7b0ca5": { + "balance": "0x0" + }, + "0xecd135fa4f61a655311e86238c92adcd779555d2": { + "balance": "0x0" + }, + "0xf0b1aa0eb660754448a7937c022e30aa692fe0c5": { + "balance": "0x0" + }, + "0xf1385fb24aad0cd7432824085e42aff90886fef5": { + "balance": "0x0" + }, + "0xf14c14075d6c4ed84b86798af0956deef67365b5": { + "balance": "0x0" + }, + "0xf4c64518ea10f995918a454158c6b61407ea345c": { + "balance": "0x0" + }, + "0xfe24cdd8648121a43a7c86d289be4dd2951ed49f": { + "balance": "0x0" + } + } +} +``` \ No newline at end of file diff --git a/tools/Evm.Test/testdata/7/txs.json b/tools/Evm.Test/testdata/7/txs.json new file mode 100644 index 00000000000..fe51488c706 --- /dev/null +++ b/tools/Evm.Test/testdata/7/txs.json @@ -0,0 +1 @@ +[] diff --git a/tools/Evm.Test/testdata/8/alloc.json b/tools/Evm.Test/testdata/8/alloc.json new file mode 100644 index 00000000000..1d1b5f86c6e --- /dev/null +++ b/tools/Evm.Test/testdata/8/alloc.json @@ -0,0 +1,11 @@ +{ + "0x000000000000000000000000000000000000aaaa": { + "balance": "0x03", + "code": "0x5854505854", + "nonce": "0x1" + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x100000", + "nonce": "0x00" + } +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/8/env.json b/tools/Evm.Test/testdata/8/env.json new file mode 100644 index 00000000000..8b919347246 --- /dev/null +++ b/tools/Evm.Test/testdata/8/env.json @@ -0,0 +1,7 @@ +{ + "currentCoinbase": "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty": "0x20000", + "currentGasLimit": "0x1000000000", + "currentNumber": "0x1000000", + "currentTimestamp": "0x04" +} \ No newline at end of file diff --git a/tools/Evm.Test/testdata/8/readme.md b/tools/Evm.Test/testdata/8/readme.md new file mode 100644 index 00000000000..85aae189243 --- /dev/null +++ b/tools/Evm.Test/testdata/8/readme.md @@ -0,0 +1,59 @@ +## EIP-2930 testing + +This test contains testcases for EIP-2930, which uses transactions with access lists. + +### Prestate + +The alloc portion contains one contract (`0x000000000000000000000000000000000000aaaa`), containing the +following code: `0x5854505854`: `PC ;SLOAD; POP; PC; SLOAD`. + +Essentially, this contract does `SLOAD(0)` and `SLOAD(3)`. + +The alloc also contains some funds on `0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b`. + +## Transactions + +There are three transactions, each invokes the contract above. + +1. ACL-transaction, which contains some non-used slots +2. Regular transaction +3. ACL-transaction, which contains the slots `1` and `3` in `0x000000000000000000000000000000000000aaaa` + +## Execution + +Running it yields: +``` +dir=./testdata/8 && ./evm t8n --state.fork=Berlin --input.alloc=$dir/alloc.json --input.txs=$dir/txs.json --input.env=$dir/env.json --trace 2>/dev/null && cat trace-* | grep SLOAD +{"pc":1,"op":84,"gas":"0x484be","gasCost":"0x834","memSize":0,"stack":["0x0"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":4,"op":84,"gas":"0x47c86","gasCost":"0x834","memSize":0,"stack":["0x3"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":1,"op":84,"gas":"0x49cf6","gasCost":"0x834","memSize":0,"stack":["0x0"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":4,"op":84,"gas":"0x494be","gasCost":"0x834","memSize":0,"stack":["0x3"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":1,"op":84,"gas":"0x484be","gasCost":"0x64","memSize":0,"stack":["0x0"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":4,"op":84,"gas":"0x48456","gasCost":"0x64","memSize":0,"stack":["0x3"],"depth":1,"refund":0,"opName":"SLOAD"} +``` + +Similarly, we can provide the input transactions via `stdin` instead of as file: + +``` +$ dir=./testdata/8 \ + && cat $dir/txs.json | jq "{txs: .}" \ + | ./evm t8n --state.fork=Berlin \ + --input.alloc=$dir/alloc.json \ + --input.txs=stdin \ + --input.env=$dir/env.json \ + --trace \ + 2>/dev/null \ + && cat trace-* | grep SLOAD +{"pc":1,"op":84,"gas":"0x484be","gasCost":"0x834","memSize":0,"stack":["0x0"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":4,"op":84,"gas":"0x47c86","gasCost":"0x834","memSize":0,"stack":["0x3"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":1,"op":84,"gas":"0x49cf6","gasCost":"0x834","memSize":0,"stack":["0x0"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":4,"op":84,"gas":"0x494be","gasCost":"0x834","memSize":0,"stack":["0x3"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":1,"op":84,"gas":"0x484be","gasCost":"0x64","memSize":0,"stack":["0x0"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":4,"op":84,"gas":"0x48456","gasCost":"0x64","memSize":0,"stack":["0x3"],"depth":1,"refund":0,"opName":"SLOAD"} +``` + +If we try to execute it on older rules: +``` +$ dir=./testdata/8 && ./evm t8n --state.fork=Istanbul --input.alloc=$dir/alloc.json --input.txs=$dir/txs.json --input.env=$dir/env.json +ERROR(10): failed signing transactions: ERROR(10): tx 0: failed to sign tx: transaction type not supported +``` diff --git a/tools/Evm.Test/testdata/8/txs.json b/tools/Evm.Test/testdata/8/txs.json new file mode 100644 index 00000000000..35142ba234b --- /dev/null +++ b/tools/Evm.Test/testdata/8/txs.json @@ -0,0 +1,58 @@ +[ + { + "gas": "0x4ef00", + "gasPrice": "0x1", + "chainId": "0x1", + "input": "0x", + "nonce": "0x0", + "to": "0x000000000000000000000000000000000000aaaa", + "value": "0x1", + "type" : "0x1", + "accessList": [ + {"address": "0x0000000000000000000000000000000000000000", + "storageKeys": [ + "0x0000000000000000000000000000000000000000000000000000000000000000", + "0x0000000000000000000000000000000000000000000000000000000000000000" + ] + } + ], + "v": "0x0", + "r": "0x0", + "s": "0x0", + "secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" + }, + { + "gas": "0x4ef00", + "gasPrice": "0x1", + "input": "0x", + "nonce": "0x1", + "to": "0x000000000000000000000000000000000000aaaa", + "value": "0x2", + "v": "0x0", + "r": "0x0", + "s": "0x0", + "secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" + }, + { + "gas": "0x4ef00", + "gasPrice": "0x1", + "chainId": "0x1", + "input": "0x", + "nonce": "0x2", + "to": "0x000000000000000000000000000000000000aaaa", + "value": "0x1", + "type" : "0x1", + "accessList": [ + {"address": "0x000000000000000000000000000000000000aaaa", + "storageKeys": [ + "0x0000000000000000000000000000000000000000000000000000000000000000", + "0x0000000000000000000000000000000000000000000000000000000000000003" + ] + } + ], + "v": "0x0", + "r": "0x0", + "s": "0x0", + "secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" + } +] diff --git a/tools/Evm.Test/testdata/9/alloc.json b/tools/Evm.Test/testdata/9/alloc.json new file mode 100644 index 00000000000..c14e38e8451 --- /dev/null +++ b/tools/Evm.Test/testdata/9/alloc.json @@ -0,0 +1,11 @@ +{ + "0x000000000000000000000000000000000000aaaa": { + "balance": "0x03", + "code": "0x58585454", + "nonce": "0x1" + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x100000000000000", + "nonce": "0x00" + } +} diff --git a/tools/Evm.Test/testdata/9/env.json b/tools/Evm.Test/testdata/9/env.json new file mode 100644 index 00000000000..082bff778a3 --- /dev/null +++ b/tools/Evm.Test/testdata/9/env.json @@ -0,0 +1,8 @@ +{ + "currentCoinbase": "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty": "0x20000", + "currentGasLimit": "0x1000000000", + "currentBaseFee": "0x3B9ACA00", + "currentNumber": "0x1000000", + "currentTimestamp": "0x04" +} diff --git a/tools/Evm.Test/testdata/9/readme.md b/tools/Evm.Test/testdata/9/readme.md new file mode 100644 index 00000000000..357e200682f --- /dev/null +++ b/tools/Evm.Test/testdata/9/readme.md @@ -0,0 +1,79 @@ +## EIP-1559 testing + +This test contains testcases for EIP-1559, which uses a new transaction type and has a new block parameter. + +### Prestate + +The alloc portion contains one contract (`0x000000000000000000000000000000000000aaaa`), containing the +following code: `0x58585454`: `PC; PC; SLOAD; SLOAD`. + +Essentially, this contract does `SLOAD(0)` and `SLOAD(1)`. + +The alloc also contains some funds on `0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b`. + +## Transactions + +There are two transactions, each invokes the contract above. + +1. EIP-1559 ACL-transaction, which contains the `0x0` slot for `0xaaaa` +2. Legacy transaction + +## Execution + +Running it yields: +``` +$ dir=./testdata/9 && ./evm t8n --state.fork=London --input.alloc=$dir/alloc.json --input.txs=$dir/txs.json --input.env=$dir/env.json --trace 2>/dev/null && cat trace-* | grep SLOAD +{"pc":1,"op":84,"gas":"0x484be","gasCost":"0x834","memSize":0,"stack":["0x0"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":4,"op":84,"gas":"0x47c86","gasCost":"0x834","memSize":0,"stack":["0x3"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":2,"op":84,"gas":"0x48c28","gasCost":"0x834","memSize":0,"stack":["0x0","0x1"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":3,"op":84,"gas":"0x483f4","gasCost":"0x64","memSize":0,"stack":["0x0","0x0"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":1,"op":84,"gas":"0x49cf6","gasCost":"0x834","memSize":0,"stack":["0x0"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":4,"op":84,"gas":"0x494be","gasCost":"0x834","memSize":0,"stack":["0x3"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":2,"op":84,"gas":"0x49cf4","gasCost":"0x834","memSize":0,"stack":["0x0","0x1"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":3,"op":84,"gas":"0x494c0","gasCost":"0x834","memSize":0,"stack":["0x0","0x0"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":1,"op":84,"gas":"0x484be","gasCost":"0x64","memSize":0,"stack":["0x0"],"depth":1,"refund":0,"opName":"SLOAD"} +{"pc":4,"op":84,"gas":"0x48456","gasCost":"0x64","memSize":0,"stack":["0x3"],"depth":1,"refund":0,"opName":"SLOAD"} +``` + +We can also get the post-alloc: +``` +$ dir=./testdata/9 && ./evm t8n --state.fork=London --input.alloc=$dir/alloc.json --input.txs=$dir/txs.json --input.env=$dir/env.json --output.alloc=stdout 2>/dev/null +{ + "alloc": { + "0x000000000000000000000000000000000000aaaa": { + "code": "0x58585454", + "balance": "0x3", + "nonce": "0x1" + }, + "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": { + "balance": "0x5bb10ddef6e0" + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0xff745ee8832120", + "nonce": "0x2" + } + } +} +``` + +If we try to execute it on older rules: +``` +dir=./testdata/9 && ./evm t8n --state.fork=Berlin --input.alloc=$dir/alloc.json --input.txs=$dir/txs.json --input.env=$dir/env.json --output.alloc=stdout +ERROR(10): Failed signing transactions: ERROR(10): Tx 0: failed to sign tx: transaction type not supported +``` + +It fails, due to the `evm t8n` cannot sign them in with the given signer. We can bypass that, however, +by feeding it presigned transactions, located in `txs_signed.json`. + +``` +dir=./testdata/9 && ./evm t8n --state.fork=Berlin --input.alloc=$dir/alloc.json --input.txs=$dir/txs_signed.json --input.env=$dir/env.json +WARN [03-09|11:06:22.065] rejected tx index=0 hash=334e09..f8dce5 error="transaction type not supported" +INFO [03-09|11:06:22.066] rejected tx index=1 hash=a9c6c6..fa4036 from=0xa94f5374Fce5edBC8E2a8697C15331677e6EbF0B error="nonce too high: address 0xa94f5374Fce5edBC8E2a8697C15331677e6EbF0B, tx: 1 state: 0" +INFO [03-09|11:06:22.066] Trie dumping started root=6eebe9..a0fda5 +INFO [03-09|11:06:22.066] Trie dumping complete accounts=2 elapsed="55.844µs" +INFO [03-09|11:06:22.066] Wrote file file=alloc.json +INFO [03-09|11:06:22.066] Wrote file file=result.json +``` + +Number `0` is not applicable, and therefore number `1` has wrong nonce, and both are rejected. + diff --git a/tools/Evm.Test/testdata/9/txs.json b/tools/Evm.Test/testdata/9/txs.json new file mode 100644 index 00000000000..740abce079d --- /dev/null +++ b/tools/Evm.Test/testdata/9/txs.json @@ -0,0 +1,37 @@ +[ + { + "gas": "0x4ef00", + "maxPriorityFeePerGas": "0x2", + "maxFeePerGas": "0x12A05F200", + "chainId": "0x1", + "input": "0x", + "nonce": "0x0", + "to": "0x000000000000000000000000000000000000aaaa", + "value": "0x0", + "type" : "0x2", + "accessList": [ + {"address": "0x000000000000000000000000000000000000aaaa", + "storageKeys": [ + "0x0000000000000000000000000000000000000000000000000000000000000000" + ] + } + ], + "v": "0x0", + "r": "0x0", + "s": "0x0", + "secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" + }, + { + "gas": "0x4ef00", + "gasPrice": "0x12A05F200", + "chainId": "0x1", + "input": "0x", + "nonce": "0x1", + "to": "0x000000000000000000000000000000000000aaaa", + "value": "0x0", + "v": "0x0", + "r": "0x0", + "s": "0x0", + "secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" + } +] diff --git a/tools/Evm.Test/testdata/9/txs_signed.json b/tools/Evm.Test/testdata/9/txs_signed.json new file mode 100644 index 00000000000..dcddf011b44 --- /dev/null +++ b/tools/Evm.Test/testdata/9/txs_signed.json @@ -0,0 +1,37 @@ +[ + { + "gas": "0x4ef00", + "maxFeePerGas": "0x2", + "maxPriorityFeePerGas": "0x12A05F200", + "chainId": "0x1", + "input": "0x", + "nonce": "0x0", + "to": "0x000000000000000000000000000000000000aaaa", + "value": "0x0", + "type" : "0x2", + "accessList": [ + {"address": "0x000000000000000000000000000000000000aaaa", + "storageKeys": [ + "0x0000000000000000000000000000000000000000000000000000000000000000" + ] + } + ], + "v": "0x1", + "r": "0xd77c8ff989789b5d9d99254cbae2e2996dc7e6215cba4d55254c14e6d6b9f314", + "s": "0x5cc021481e7e6bb444bbb87ab32071e8fd0a8d1e125c7bb352d2879bd7ff5c0a", + "secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" + }, + { + "gas": "0x4ef00", + "gasPrice": "0x12A05F200", + "chainId": "0x1", + "input": "0x", + "nonce": "0x1", + "to": "0x000000000000000000000000000000000000aaaa", + "value": "0x0", + "v": "0x25", + "r": "0xbee5ec9f6650020266bf3455a852eece2b073a2fa918c4d1836a1af69c2aa50c", + "s": "0x556c897a58dbc007a6b09814e1fba7502adb76effd2146da4365816926f387ce", + "secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" + } +] diff --git a/tools/evm/Evm.csproj b/tools/evm/Evm.csproj new file mode 100644 index 00000000000..7d5757e9680 --- /dev/null +++ b/tools/evm/Evm.csproj @@ -0,0 +1,25 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + + + + + + + + diff --git a/tools/evm/Evm.sln b/tools/evm/Evm.sln new file mode 100644 index 00000000000..5bef2b9f239 --- /dev/null +++ b/tools/evm/Evm.sln @@ -0,0 +1,18 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "evm", "Evm.csproj", "{AAA9AF72-46AE-4535-9698-610C9E94AE06}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AAA9AF72-46AE-4535-9698-610C9E94AE06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AAA9AF72-46AE-4535-9698-610C9E94AE06}.Debug|Any CPU.Build.0 = Debug|Any CPU + {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/JsonTypes/EnvInfo.cs b/tools/evm/JsonTypes/EnvInfo.cs new file mode 100644 index 00000000000..31f6251ac90 --- /dev/null +++ b/tools/evm/JsonTypes/EnvInfo.cs @@ -0,0 +1,126 @@ +using Ethereum.Test.Base; +using Ethereum.Test.Base.T8NUtils; +using Nethermind.Consensus.Ethash; +using Nethermind.Core; +using Nethermind.Core.Crypto; +using Nethermind.Core.Specs; +using Nethermind.Int256; +using Nethermind.Specs.Forks; + +namespace Evm.JsonTypes +{ + public class EnvInfo + { + public Address? CurrentCoinbase { get; set; } + public long CurrentGasLimit { get; set; } + public ulong CurrentTimestamp { get; set; } + public long CurrentNumber { get; set; } + + public Withdrawal[]? Withdrawals { get; set; } + + public byte[]? CurrentRandom { get; set; } + public ulong ParentTimestamp { get; set; } + public UInt256? ParentDifficulty { get; set; } + public UInt256? CurrentBaseFee { get; set; } + public UInt256? CurrentDifficulty { get; set; } + public Hash256? ParentUncleHash { get; set; } + public Hash256? ParentBeaconBlockRoot { get; set; } + public UInt256? ParentBaseFee { get; set; } + public long ParentGasUsed { get; set; } + public long ParentGasLimit { get; set; } + public ulong? ParentExcessBlobGas { get; set; } + public ulong? CurrentExcessBlobGas { get; set; } + public ulong? ParentBlobGasUsed { get; set; } + public Dictionary BlockHashes { get; set; } = []; + public Ommer[] Ommers { get; set; } = []; + + public bool IsStateTest { get; set; } + + public Hash256? GetCurrentRandomHash256() + { + if (CurrentRandom == null) return null; + + if (CurrentRandom.Length < Hash256.Size) + { + var currentRandomWithLeadingZeros = new byte[Hash256.Size]; + Array.Copy(CurrentRandom, 0, currentRandomWithLeadingZeros, Hash256.Size - CurrentRandom.Length, + CurrentRandom.Length); + CurrentRandom = currentRandomWithLeadingZeros; + } + + return new Hash256(CurrentRandom); + } + + public void ApplyChecks(ISpecProvider specProvider, IReleaseSpec spec) + { + ApplyLondonChecks(spec); + ApplyShanghaiChecks(spec); + ApplyCancunChecks(spec); + ApplyMergeChecks(specProvider); + } + + private void ApplyLondonChecks(IReleaseSpec spec) + { + if (spec is not London) return; + if (CurrentBaseFee != null) return; + + if (!ParentBaseFee.HasValue || CurrentNumber == 0) + { + throw new T8NException("EIP-1559 config but missing 'currentBaseFee' in env section", ExitCodes.ErrorConfig); + } + } + + private void ApplyShanghaiChecks(IReleaseSpec spec) + { + if (spec is not Shanghai) return; + if (Withdrawals == null) + { + throw new T8NException("Shanghai config but missing 'withdrawals' in env section", ExitCodes.ErrorConfig); + } + } + + private void ApplyCancunChecks(IReleaseSpec spec) + { + if (spec is not Cancun) + { + ParentBeaconBlockRoot = null; + return; + } + + if (ParentBeaconBlockRoot == null) + { + throw new T8NException("post-cancun env requires parentBeaconBlockRoot to be set", ExitCodes.ErrorConfig); + } + } + + private void ApplyMergeChecks(ISpecProvider specProvider) + { + if (specProvider.TerminalTotalDifficulty?.IsZero ?? false) + { + if (CurrentRandom == null) throw new T8NException("post-merge requires currentRandom to be defined in env", ExitCodes.ErrorConfig); + if (CurrentDifficulty?.IsZero ?? false) throw new T8NException("post-merge difficulty must be zero (or omitted) in env", ExitCodes.ErrorConfig); + return; + } + if (CurrentDifficulty != null) return; + if (!ParentDifficulty.HasValue) + { + throw new T8NException( + "currentDifficulty was not provided, and cannot be calculated due to missing parentDifficulty", ExitCodes.ErrorConfig); + } + + if (CurrentNumber == 0) + { + throw new T8NException("currentDifficulty needs to be provided for block number 0", ExitCodes.ErrorConfig); + } + + if (CurrentTimestamp <= ParentTimestamp) + { + throw new T8NException($"currentDifficulty cannot be calculated -- currentTime ({CurrentTimestamp}) needs to be after parent time ({ParentTimestamp})", ExitCodes.ErrorConfig); + } + + EthashDifficultyCalculator difficultyCalculator = new(specProvider); + + CurrentDifficulty = difficultyCalculator.Calculate(ParentDifficulty.Value, ParentTimestamp, CurrentTimestamp, CurrentNumber, ParentUncleHash is not null); + } + } +} diff --git a/tools/evm/JsonTypes/PostState.cs b/tools/evm/JsonTypes/PostState.cs new file mode 100644 index 00000000000..60965748449 --- /dev/null +++ b/tools/evm/JsonTypes/PostState.cs @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System.Text.Json.Serialization; +using Nethermind.Core; +using Nethermind.Core.Crypto; +using Nethermind.Int256; + +namespace Evm.JsonTypes; + +public class PostState +{ + public Hash256? StateRoot { get; set; } + public Hash256? TxRoot { get; set; } + public Hash256? ReceiptsRoot { get; set; } + public Hash256? WithdrawalsRoot { get; set; } + public Hash256? LogsHash { get; set; } + public Bloom? LogsBloom { get; set; } + public TxReceipt[]? Receipts { get; set; } + public RejectedTx[]? Rejected { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + public UInt256? CurrentDifficulty { get; set; } + public UInt256? GasUsed { get; set; } + public UInt256? CurrentBaseFee { get; set; } + public UInt256? CurrentExcessBlobGas { get; set; } + public UInt256? BlobGasUsed { get; set; } +} diff --git a/tools/evm/JsonTypes/T8NExecutionResult.cs b/tools/evm/JsonTypes/T8NExecutionResult.cs new file mode 100644 index 00000000000..6f9588262c5 --- /dev/null +++ b/tools/evm/JsonTypes/T8NExecutionResult.cs @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Ethereum.Test.Base; +using Nethermind.Core; + +namespace Evm.JsonTypes; + +public class T8NExecutionResult +{ + public readonly PostState PostState; + public readonly Dictionary Alloc; + public readonly byte[] Body; + + public T8NExecutionResult(PostState postState, Dictionary alloc, byte[] body) + { + PostState = postState; + Alloc = alloc; + Body = body; + } +} diff --git a/tools/evm/JsonTypes/T8NOutput.cs b/tools/evm/JsonTypes/T8NOutput.cs new file mode 100644 index 00000000000..5d2d56f4daf --- /dev/null +++ b/tools/evm/JsonTypes/T8NOutput.cs @@ -0,0 +1,24 @@ +using System.Text.Json.Serialization; +using Ethereum.Test.Base; +using Nethermind.Core; +using Nethermind.Evm.Tracing.GethStyle.Custom.Native.Prestate; + +namespace Evm.JsonTypes; + +public class T8NOutput +{ + public Dictionary? Alloc { get; set; } + public PostState? Result { get; set; } + public byte[]? Body { get; set; } + public string? ErrorMessage { get; set; } + [JsonIgnore] + public int ExitCode { get; set; } + + public T8NOutput() { } + + public T8NOutput(string errorMessage, int exitCode) + { + ErrorMessage = errorMessage; + ExitCode = exitCode; + } +} diff --git a/tools/evm/JsonTypes/TraceOptions.cs b/tools/evm/JsonTypes/TraceOptions.cs new file mode 100644 index 00000000000..6817b5f079c --- /dev/null +++ b/tools/evm/JsonTypes/TraceOptions.cs @@ -0,0 +1,11 @@ +namespace Evm.JsonTypes; + +public class TraceOptions +{ + public bool IsEnabled { get; set; } + public bool Memory { get; set; } + public bool NoStack { get; set; } + public bool ReturnData { get; set; } + + public static readonly TraceOptions Default = new(); +} \ No newline at end of file diff --git a/tools/evm/JsonTypes/TransactionInfo.cs b/tools/evm/JsonTypes/TransactionInfo.cs new file mode 100644 index 00000000000..53616b3fc42 --- /dev/null +++ b/tools/evm/JsonTypes/TransactionInfo.cs @@ -0,0 +1,79 @@ +using Ethereum.Test.Base; +using Nethermind.Core; +using Nethermind.Core.Eip2930; +using Nethermind.Core.Crypto; +using Nethermind.Core.Test.Builders; +using Nethermind.Crypto; +using Nethermind.Int256; + +namespace Evm.JsonTypes +{ + public class TransactionInfo + { + public byte[]? Input { get; set; } + public long Gas { get; set; } + public string? Hash { get; set; } + public UInt256 Nonce { get; set; } + public Address To { get; set; } + public UInt256 Value { get; set; } + public ulong V { get; set; } + public byte[]? R { get; set; } + public byte[]? S { get; set; } + public byte[]? SecretKey { get; set; } + public ulong? ChainId { get; set; } + public TxType Type { get; set; } = TxType.Legacy; + public UInt256? MaxFeePerGas { get; set; } + public UInt256 GasPrice { get; set; } + public UInt256? MaxPriorityFeePerGas { get; set; } + public AccessListItemJson[]? AccessList { get; set; } + public bool? Protected { get; set; } + + public Transaction ConvertToTx() + { + TransactionBuilder transactionBuilder = new(); + + transactionBuilder.WithValue(Value); + if (Input != null) + { + transactionBuilder.WithData(Input); + } + transactionBuilder.WithTo(To); + transactionBuilder.WithNonce(Nonce); + transactionBuilder.WithGasLimit(Gas); + transactionBuilder.WithType(Type); + transactionBuilder.WithGasPrice(GasPrice); + if (AccessList != null) + { + AccessList.Builder builder = new(); + JsonToEthereumTest.ProcessAccessList(AccessList, builder); + transactionBuilder.WithAccessList(builder.Build()); + } + + if (MaxFeePerGas.HasValue) + { + transactionBuilder.WithMaxFeePerGas(MaxFeePerGas.Value); + } + if (MaxPriorityFeePerGas.HasValue) + { + transactionBuilder.WithMaxPriorityFeePerGas(MaxPriorityFeePerGas.Value); + } + + if (ChainId.HasValue) + { + transactionBuilder.WithChainId(ChainId.Value); + } + if (SecretKey != null) + { + var privateKey = new PrivateKey(SecretKey); + transactionBuilder.WithSenderAddress(privateKey.Address); + transactionBuilder.Signed(privateKey, Protected ?? true); + } + else + { + transactionBuilder.WithSignature(new Signature(R, S, V)); + } + + return transactionBuilder.TestObject; + } + } +} diff --git a/tools/evm/Program.cs b/tools/evm/Program.cs new file mode 100644 index 00000000000..bd3f09bf228 --- /dev/null +++ b/tools/evm/Program.cs @@ -0,0 +1,92 @@ +using System.CommandLine; +using Evm.JsonTypes; + +namespace Evm +{ + public static class Program + { + public static async Task Main(string[] args) + { + var rootCmd = new RootCommand(); + rootCmd.Name = "evm"; + ConfigureT8NCommand(ref rootCmd); + + await rootCmd.InvokeAsync(args); + } + + static void ConfigureT8NCommand(ref RootCommand rootCmd) + { + var inputAllocOpt = new Option("--input.alloc", description: "Input allocations", getDefaultValue: () => "alloc.json"); + var inputEnvOpt = new Option("--input.env", description: "Input environment", getDefaultValue: () => "env.json"); + var inputTxsOpt = new Option("--input.txs", description: "Input transactions", getDefaultValue: () => "txs.json"); + var outputAllocOpt = new Option("--output.alloc", description: "Output allocations", getDefaultValue: () => "alloc.json"); + var outputBaseDirOpt = new Option("--output.basedir", description: "Output base directory"); + var outputBodyOpt = new Option("--output.body", description: "Output body"); + var outputResultOpt = new Option("--output.result", description: "Output result", getDefaultValue: () => "result.json"); + var stateChainIdOpt = new Option("--state.chainid", description: "State chain id", getDefaultValue: () => 1); + var stateForkOpt = new Option("--state.fork", description: "State fork", getDefaultValue: () => "GrayGlacier"); + var stateRewardOpt = new Option("--state.reward", description: "State reward"); + var traceMemoryOpt = new Option("--trace.memory", description: "Trace memory", getDefaultValue: () => false); + 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 cmd = new Command("t8n", "EVM State Transition command") + { + inputAllocOpt, + inputEnvOpt, + inputTxsOpt, + outputAllocOpt, + outputBaseDirOpt, + outputBodyOpt, + outputResultOpt, + stateChainIdOpt, + stateForkOpt, + stateRewardOpt, + traceOpt, + traceMemoryOpt, + traceNoStackOpt, + traceReturnDataOpt, + }; + + cmd.AddAlias("transition"); + rootCmd.Add(cmd); + + var t8NTool = new T8NTool.T8NTool(); + + cmd.SetHandler( + async (context) => + { + // Note: https://learn.microsoft.com/en-us/dotnet/standard/commandline/model-binding#parameter-binding-more-than-16-options-and-arguments + // t8n accepts less options (15) than 16 but command extension methods supports max 8 anyway + var traceOpts = new TraceOptions + { + IsEnabled = context.ParseResult.GetValueForOption(traceOpt), + Memory = context.ParseResult.GetValueForOption(traceMemoryOpt), + NoStack = context.ParseResult.GetValueForOption(traceNoStackOpt), + ReturnData = context.ParseResult.GetValueForOption(traceReturnDataOpt), + }; + + await Task.Run(() => + { + var output = t8NTool.Execute( + context.ParseResult.GetValueForOption(inputAllocOpt), + context.ParseResult.GetValueForOption(inputEnvOpt), + context.ParseResult.GetValueForOption(inputTxsOpt), + context.ParseResult.GetValueForOption(outputBaseDirOpt), + context.ParseResult.GetValueForOption(outputAllocOpt), + context.ParseResult.GetValueForOption(outputBodyOpt), + context.ParseResult.GetValueForOption(outputResultOpt), + context.ParseResult.GetValueForOption(stateChainIdOpt), + context.ParseResult.GetValueForOption(stateForkOpt), + context.ParseResult.GetValueForOption(stateRewardOpt), + traceOpts + ); + Environment.ExitCode = output.ExitCode; + }); + }); + } + } + + +} diff --git a/tools/evm/T8NTool/InputProcessor.cs b/tools/evm/T8NTool/InputProcessor.cs new file mode 100644 index 00000000000..b36659fc291 --- /dev/null +++ b/tools/evm/T8NTool/InputProcessor.cs @@ -0,0 +1,111 @@ +using Ethereum.Test.Base; +using Ethereum.Test.Base.T8NUtils; +using Evm.JsonTypes; +using Nethermind.Core; +using Nethermind.Core.Extensions; +using Nethermind.Core.Specs; +using Nethermind.Evm.Tracing.GethStyle; +using Nethermind.Serialization.Json; +using Nethermind.Serialization.Rlp; +using Nethermind.Specs; +using Nethermind.Specs.Forks; +using Nethermind.Specs.Test; + +namespace Evm.T8NTool; + +public class InputProcessor +{ + private static readonly EthereumJsonSerializer EthereumJsonSerializer = new(); + private static readonly TxDecoder TxDecoder = TxDecoder.Instance; + + public static GeneralStateTest ConvertToGeneralStateTest(string inputAlloc, + string inputEnv, + string inputTxs, + string stateFork, + string? stateReward, + ulong stateChainId, + bool isGnosis, + TraceOptions traceOptions) + { + GethTraceOptions gethTraceOptions = new GethTraceOptions + { + EnableMemory = traceOptions.Memory, + DisableStack = traceOptions.NoStack + }; + Dictionary allocJson = + EthereumJsonSerializer.Deserialize>(File.ReadAllText(inputAlloc)); + EnvInfo envInfo = EthereumJsonSerializer.Deserialize(File.ReadAllText(inputEnv)); + + Transaction[] transactions; + var txFileContent = File.ReadAllText(inputTxs); + if (inputTxs.EndsWith(".json")) + { + var txInfoList = EthereumJsonSerializer.Deserialize(txFileContent); + transactions = txInfoList.Select(txInfo => txInfo.ConvertToTx()).ToArray(); + } + else if (inputTxs.EndsWith(".rlp")) + { + string rlpRaw = txFileContent.Replace("\"", "").Replace("\n", ""); + RlpStream rlp = new(Bytes.FromHexString(rlpRaw)); + transactions = TxDecoder.DecodeArray(rlp); + } + else + { + throw new T8NException("Transactions file support only rlp, json formats", ExitCodes.ErrorConfig); + } + + IReleaseSpec spec; + try + { + spec = JsonToEthereumTest.ParseSpec(stateFork); + } + catch (NotSupportedException e) + { + throw new T8NException(e, ExitCodes.ErrorConfig); + } + + ISpecProvider specProvider = isGnosis ? GnosisSpecProvider.Instance + : new CustomSpecProvider(((ForkActivation)0, Frontier.Instance), ((ForkActivation)1, spec)); + + if (spec is Paris) + { + specProvider.UpdateMergeTransitionInfo(envInfo.CurrentNumber, 0); + } + + envInfo.ApplyChecks(specProvider, spec); + + GeneralStateTest generalStateTest = new(); + generalStateTest.IsT8NTest = true; + generalStateTest.Fork = spec; + generalStateTest.Pre = allocJson; + generalStateTest.Transactions = transactions; + generalStateTest.StateChainId = isGnosis ? GnosisSpecProvider.Instance.ChainId : MainnetSpecProvider.Instance.ChainId; + + generalStateTest.CurrentCoinbase = envInfo.CurrentCoinbase; + generalStateTest.CurrentGasLimit = envInfo.CurrentGasLimit; + generalStateTest.CurrentTimestamp = envInfo.CurrentTimestamp; + generalStateTest.CurrentNumber = envInfo.CurrentNumber; + generalStateTest.Withdrawals = envInfo.Withdrawals; + generalStateTest.CurrentRandom = envInfo.GetCurrentRandomHash256(); + generalStateTest.ParentTimestamp = envInfo.ParentTimestamp; + generalStateTest.ParentDifficulty = envInfo.ParentDifficulty; + generalStateTest.CurrentBaseFee = envInfo.CurrentBaseFee; + generalStateTest.CurrentDifficulty = envInfo.CurrentDifficulty; + generalStateTest.ParentUncleHash = envInfo.ParentUncleHash; + generalStateTest.ParentBeaconBlockRoot = envInfo.ParentBeaconBlockRoot; + generalStateTest.ParentBaseFee = envInfo.ParentBaseFee; + generalStateTest.ParentGasUsed = envInfo.ParentGasUsed; + generalStateTest.ParentGasLimit = envInfo.ParentGasLimit; + generalStateTest.ParentExcessBlobGas = envInfo.ParentExcessBlobGas; + generalStateTest.CurrentExcessBlobGas = envInfo.CurrentExcessBlobGas; + generalStateTest.ParentBlobGasUsed = envInfo.ParentBlobGasUsed; + generalStateTest.Ommers = envInfo.Ommers; + generalStateTest.StateReward = stateReward; + generalStateTest.BlockHashes = envInfo.BlockHashes; + generalStateTest.StateChainId = stateChainId; + generalStateTest.GethTraceOptions = gethTraceOptions; + generalStateTest.IsStateTest = envInfo.IsStateTest; + + return generalStateTest; + } +} diff --git a/tools/evm/T8NTool/ReceiptJsonConverter.cs b/tools/evm/T8NTool/ReceiptJsonConverter.cs new file mode 100644 index 00000000000..5c4bd5a5c2d --- /dev/null +++ b/tools/evm/T8NTool/ReceiptJsonConverter.cs @@ -0,0 +1,65 @@ +using System.Globalization; +using System.Runtime.InteropServices; +using Nethermind.Core.Crypto; +using Nethermind.Core.Extensions; +using Nethermind.Int256; +using Nethermind.Serialization.Json; + +namespace Evm.T8NTool; + +using System.Text.Json; +using System.Text.Json.Serialization; +using Nethermind.Core; + +public class ReceiptJsonConverter : JsonConverter +{ + private readonly EthereumJsonSerializer _ethereumJsonSerializer = new(); + + public override TxReceipt Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + return _ethereumJsonSerializer.Deserialize(ref reader); + } + + public override void Write(Utf8JsonWriter writer, TxReceipt receipt, JsonSerializerOptions options) + { + writer.WriteStartObject(); + + if (receipt.TxType != TxType.Legacy) + { + writer.WritePropertyName("type"); + JsonSerializer.Serialize(writer, receipt.TxType, options); + } + writer.WritePropertyName("root"); + ByteArrayConverter.Convert(writer, receipt.PostTransactionState != null ? receipt.PostTransactionState.Bytes : Bytes.ZeroByte.ToArray()); + var status = receipt.StatusCode; + writer.WritePropertyName("status"); + if (status == 0) + { + writer.WriteRawValue("\"0x0\""u8, skipInputValidation: true); + } + else + { + ByteArrayConverter.Convert(writer, MemoryMarshal.CreateReadOnlySpan(ref status, 1)); + } + + writer.WritePropertyName("cumulativeGasUsed"); + JsonSerializer.Serialize(writer, receipt.GasUsedTotal, options); + writer.WritePropertyName("logsBloom"); + JsonSerializer.Serialize(writer, receipt.Bloom, options); + writer.WriteNull("logs"); + writer.WritePropertyName("transactionHash"); + JsonSerializer.Serialize(writer, receipt.TxHash, options); + writer.WritePropertyName("contractAddress"); + JsonSerializer.Serialize(writer, receipt.ContractAddress ?? Address.Zero, options); + writer.WritePropertyName("gasUsed"); + JsonSerializer.Serialize(writer, receipt.GasUsed, options); + writer.WriteNull("effectiveGasPrice"); + writer.WritePropertyName("blockHash"); + JsonSerializer.Serialize(writer, receipt.BlockHash ?? Keccak.Zero, options); + + writer.WritePropertyName("transactionIndex"); + JsonSerializer.Serialize(writer, UInt256.Parse(receipt.Index.ToString(), NumberStyles.Integer), options); + + writer.WriteEndObject(); + } +} diff --git a/tools/evm/T8NTool/T8NTool.cs b/tools/evm/T8NTool/T8NTool.cs new file mode 100644 index 00000000000..6e62c9c8965 --- /dev/null +++ b/tools/evm/T8NTool/T8NTool.cs @@ -0,0 +1,129 @@ +using System.Text.Json; +using Ethereum.Test.Base; +using Ethereum.Test.Base.T8NUtils; +using Evm.JsonTypes; +using Nethermind.Serialization.Json; +using Nethermind.Specs; + +namespace Evm.T8NTool; + +public class T8NTool : GeneralStateTestBase +{ + private readonly EthereumJsonSerializer _ethereumJsonSerializer; + + public T8NTool() + { + _ethereumJsonSerializer = new EthereumJsonSerializer(); + EthereumJsonSerializer.AddConverter(new ReceiptJsonConverter()); + EthereumJsonSerializer.AddConverter(new AccountStateConverter()); + } + + public T8NOutput Execute( + string inputAlloc, + string inputEnv, + string inputTxs, + string? outputBasedir, + string outputAlloc, + string? outputBody, + string outputResult, + ulong stateChainId, + string stateFork, + string? stateReward, + TraceOptions traceOptions) + { + T8NOutput t8NOutput = new(); + try + { + var isGnosis = GnosisSpecProvider.Instance.ChainId == stateChainId; + var t8NExecutionResult = Execute(inputAlloc, inputEnv, inputTxs, stateFork, stateReward, stateChainId, + isGnosis, traceOptions); + + if (outputAlloc == "stdout") t8NOutput.Alloc = t8NExecutionResult.Alloc; + else WriteToFile(outputAlloc, outputBasedir, t8NExecutionResult.Alloc); + + if (outputResult == "stdout") t8NOutput.Result = t8NExecutionResult.PostState; + else WriteToFile(outputResult, outputBasedir, t8NExecutionResult.PostState); + + if (outputBody == "stdout") t8NOutput.Body = t8NExecutionResult.Body; + else if (outputBody != null) WriteToFile(outputBody, outputBasedir, t8NExecutionResult.Body); + + if (t8NOutput.Body != null || t8NOutput.Alloc != null || t8NOutput.Result != null) + { + Console.WriteLine(_ethereumJsonSerializer.Serialize(t8NOutput, true)); + } + } + catch (T8NException e) + { + t8NOutput = new T8NOutput(e.Message, e.ExitCode); + } + catch (IOException e) + { + t8NOutput = new T8NOutput(e.Message, ExitCodes.ErrorIO); + } + catch (JsonException e) + { + t8NOutput = new T8NOutput(e.Message, ExitCodes.ErrorJson); + } + catch (Exception e) + { + t8NOutput = new T8NOutput(e.Message, ExitCodes.ErrorEVM); + } + finally + { + if (t8NOutput.ErrorMessage != null) + { + Console.WriteLine(t8NOutput.ErrorMessage); + } + } + + return t8NOutput; + } + + private T8NExecutionResult Execute( + string inputAlloc, + string inputEnv, + string inputTxs, + string stateFork, + string? stateReward, + ulong stateChainId, + bool isGnosis, + TraceOptions traceOptions) + { + var generalStateTest = InputProcessor.ConvertToGeneralStateTest(inputAlloc, inputEnv, inputTxs, stateFork, + stateReward, stateChainId, isGnosis, traceOptions); + + var res = RunTest(generalStateTest, isGnosis); + + PostState postState = new PostState(); + postState.StateRoot = res.StateRoot; + postState.TxRoot = res.T8NResult.TxRoot; + postState.ReceiptsRoot = res.T8NResult.ReceiptsRoot; + postState.WithdrawalsRoot = res.T8NResult.WithdrawalsRoot; + postState.LogsHash = res.T8NResult.LogsHash; + postState.LogsBloom = res.T8NResult.LogsBloom; + postState.Receipts = res.T8NResult.Receipts; + postState.Rejected = res.T8NResult.Rejected; + postState.CurrentDifficulty = res.T8NResult.CurrentDifficulty; + postState.GasUsed = res.T8NResult.GasUsed; + postState.CurrentBaseFee = res.T8NResult.CurrentBaseFee; + postState.CurrentExcessBlobGas = res.T8NResult.CurrentExcessBlobGas; + postState.BlobGasUsed = res.T8NResult.BlobGasUsed; + + return new T8NExecutionResult(postState, res.T8NResult.Accounts, res.T8NResult.TransactionsRlp); + } + + private void WriteToFile(string filename, string? basedir, object outputObject) + { + if (basedir is not null) + { + basedir = basedir.TrimEnd('/'); + basedir += '/'; + } + + var fileInfo = new FileInfo(basedir + filename); + + Directory.CreateDirectory(fileInfo.DirectoryName!); + using StreamWriter writer = new(fileInfo.FullName); + writer.Write(_ethereumJsonSerializer.Serialize(outputObject, true)); + } +}