From 355df52e63de6faba72e1f5d5fd3d6593a287a2a Mon Sep 17 00:00:00 2001 From: MarekM25 Date: Sat, 14 Jan 2023 20:48:15 +0100 Subject: [PATCH 1/5] 3860 badBlock fix --- .../TransactionSelectorTests.cs | 20 +++--- .../TransactionsExecutorTests.cs | 70 +++++++++++++++++-- .../Validators/TxValidatorTests.cs | 23 ++++++ .../Validators/TxValidator.cs | 8 ++- .../Builders/TransactionBuilder.cs | 2 +- .../TransactionProcessor.cs | 2 +- 6 files changed, 104 insertions(+), 21 deletions(-) diff --git a/src/Nethermind/Nethermind.Blockchain.Test/TransactionSelectorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/TransactionSelectorTests.cs index 12693cfd75a..05440a7ac0c 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/TransactionSelectorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/TransactionSelectorTests.cs @@ -71,7 +71,7 @@ public static IEnumerable Eip1559LegacyTransactionTestCases ProperTransactionsSelectedTestCase balanceCheckWithTxValue = new() { - Eip1559Enabled = true, + ReleaseSpec = London.Instance, BaseFee = 5, AccountStates = { { TestItem.AddressA, (300, 1) } }, Transactions = @@ -111,7 +111,7 @@ public static IEnumerable Eip1559TestCases ProperTransactionsSelectedTestCase balanceCheckWithTxValue = new() { - Eip1559Enabled = true, + ReleaseSpec = London.Instance, BaseFee = 5, AccountStates = { { TestItem.AddressA, (400, 1) } }, Transactions = @@ -129,7 +129,7 @@ public static IEnumerable Eip1559TestCases ProperTransactionsSelectedTestCase balanceCheckWithGasPremium = new() { - Eip1559Enabled = true, + ReleaseSpec = London.Instance, BaseFee = 5, AccountStates = { { TestItem.AddressA, (400, 1) } }, Transactions = @@ -182,10 +182,7 @@ void SetAccountStates(IEnumerable
missingAddresses) IBlockTree blockTree = Substitute.For(); Block block = Build.A.Block.WithNumber(0).TestObject; blockTree.Head.Returns(block); - IReleaseSpec spec = new ReleaseSpec() - { - IsEip1559Enabled = testCase.Eip1559Enabled - }; + IReleaseSpec spec = testCase.ReleaseSpec; specProvider.GetSpec(Arg.Any(), Arg.Any()).Returns(spec); specProvider.GetSpec(Arg.Any()).Returns(spec); specProvider.GetSpec(Arg.Any()).Returns(spec); @@ -233,7 +230,7 @@ public class ProperTransactionsSelectedTestCase public List ExpectedSelectedTransactions { get; } = new(); public UInt256 MinGasPriceForMining { get; set; } = 1; - public bool Eip1559Enabled { get; set; } + public IReleaseSpec ReleaseSpec { get; set; } public UInt256 BaseFee { get; set; } @@ -250,13 +247,14 @@ public class ProperTransactionsSelectedTestCase Build.A.Transaction.WithSenderAddress(TestItem.AddressA).WithNonce(2).WithValue(10) .WithGasPrice(10).WithGasLimit(10).SignedAndResolved(TestItem.PrivateKeyA).TestObject }, - GasLimit = 10000000 + GasLimit = 10000000, + ReleaseSpec = Berlin.Instance }; public static ProperTransactionsSelectedTestCase Eip1559DefaultLegacyTransactions => new() { - Eip1559Enabled = true, + ReleaseSpec = London.Instance, BaseFee = 1.GWei(), AccountStates = { { TestItem.AddressA, (1000, 1) } }, Transactions = @@ -274,7 +272,7 @@ public class ProperTransactionsSelectedTestCase public static ProperTransactionsSelectedTestCase Eip1559Default => new() { - Eip1559Enabled = true, + ReleaseSpec = London.Instance, BaseFee = 1.GWei(), AccountStates = { { TestItem.AddressA, (1000, 1) } }, Transactions = diff --git a/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs index acc0c2d2568..d934602e332 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs @@ -11,6 +11,7 @@ using Nethermind.Consensus.Processing; using Nethermind.Consensus.Producers; using Nethermind.Core; +using Nethermind.Core.Extensions; using Nethermind.Core.Specs; using Nethermind.Core.Test.Builders; using Nethermind.Db; @@ -85,6 +86,7 @@ public static IEnumerable ProperTransactionsSelectedTestCases ProperTransactionsSelectedTestCase complexCase = new() { + ReleaseSpec = Berlin.Instance, AccountStates = { {TestItem.AddressA, (1000, 1)}, @@ -134,7 +136,7 @@ public static IEnumerable ProperTransactionsSelectedTestCases ProperTransactionsSelectedTestCase baseFeeBalanceCheck = new() { - Eip1559Enabled = true, + ReleaseSpec = London.Instance, BaseFee = 5, AccountStates = { { TestItem.AddressA, (1000, 1) } }, Transactions = @@ -154,7 +156,7 @@ public static IEnumerable ProperTransactionsSelectedTestCases ProperTransactionsSelectedTestCase balanceBelowMaxFeeTimesGasLimit = new() { - Eip1559Enabled = true, + ReleaseSpec = London.Instance, BaseFee = 5, AccountStates = { { TestItem.AddressA, (400, 1) } }, Transactions = @@ -169,7 +171,7 @@ public static IEnumerable ProperTransactionsSelectedTestCases ProperTransactionsSelectedTestCase balanceFailingWithMaxFeePerGasCheck = new() { - Eip1559Enabled = true, + ReleaseSpec = London.Instance, BaseFee = 5, AccountStates = { { TestItem.AddressA, (400, 1) } }, Transactions = @@ -185,7 +187,28 @@ public static IEnumerable ProperTransactionsSelectedTestCases } } + public static IEnumerable Eip3860TestCases + { + get + { + ProperTransactionsSelectedTestCase balanceBelowMaxFeeTimesGasLimit = new() + { + ReleaseSpec = Shanghai.Instance, + BaseFee = 5, + AccountStates = { { TestItem.AddressA, (400, 1) } }, + Transactions = + { + Build.A.Transaction.WithSenderAddress(TestItem.AddressA).WithNonce(1) + .WithMaxFeePerGas(45).WithMaxPriorityFeePerGas(25).WithGasLimit(10).WithType(TxType.EIP1559).WithValue(60).SignedAndResolved(TestItem.PrivateKeyA).TestObject + }, + GasLimit = 10000000 + }; + yield return new TestCaseData(balanceBelowMaxFeeTimesGasLimit).SetName("EIP3860 Transactions"); + } + } + [TestCaseSource(nameof(ProperTransactionsSelectedTestCases))] + [TestCaseSource(nameof(Eip3860TestCases))] public void Proper_transactions_selected(ProperTransactionsSelectedTestCase testCase) { MemDb stateDb = new(); @@ -195,10 +218,7 @@ public void Proper_transactions_selected(ProperTransactionsSelectedTestCase test IStorageProvider storageProvider = Substitute.For(); ISpecProvider specProvider = Substitute.For(); - IReleaseSpec spec = new ReleaseSpec() - { - IsEip1559Enabled = testCase.Eip1559Enabled - }; + IReleaseSpec spec = testCase.ReleaseSpec; specProvider.GetSpec(Arg.Any(), Arg.Any()).Returns(spec); specProvider.GetSpec(Arg.Any()).Returns(spec); specProvider.GetSpec(Arg.Any()).Returns(spec); @@ -263,5 +283,41 @@ void SetAccountStates(IEnumerable
missingAddresses) txExecutor.ProcessTransactions(blockToProduce, ProcessingOptions.ProducingBlock, receiptsTracer, spec); blockToProduce.Transactions.Should().BeEquivalentTo(testCase.ExpectedSelectedTransactions); } + // + // [Test] + // public void Cannot_pick_transaction_with_initicode_above_maxinitcode_when_EIP3860_enabled() + // { + // MemDb stateDb = new(); + // MemDb codeDb = new(); + // TrieStore trieStore = new(stateDb, LimboLogs.Instance); + // StateProvider stateProvider = new(trieStore, codeDb, LimboLogs.Instance); + // IStorageProvider storageProvider = Substitute.For(); + // ISpecProvider specProvider = Substitute.For(); + // ITransactionProcessor transactionProcessor = Substitute.For(); + // var txArray = + // { + // Build.A.Transaction.WithSenderAddress(TestItem.AddressA).WithNonce(3) + // .WithGasPrice(60).WithGasLimit(10).SignedAndResolved(TestItem.PrivateKeyA).TestObject, + // Build.A.Transaction.WithSenderAddress(TestItem.AddressA).WithNonce(1) + // .WithGasPrice(30).WithGasLimit(10).SignedAndResolved(TestItem.PrivateKeyA).TestObject, + // Build.A.Transaction.WithSenderAddress(TestItem.AddressA).WithNonce(2) + // .WithGasPrice(20).WithGasLimit(10).SignedAndResolved(TestItem.PrivateKeyA).TestObject + // }; + // BlockProcessor.BlockProductionTransactionsExecutor txExecutor = + // new( + // transactionProcessor, + // stateProvider, + // storageProvider, + // specProvider, + // LimboLogs.Instance); + // Block block = Build.A.Block + // .WithNumber(0) + // .WithTransactions(txArray) + // .TestObject; + // BlockToProduce blockToProduce = new(block.Header, block.Transactions, block.Uncles); + // txExecutor.ProcessTransactions(blockToProduce, ProcessingOptions.ProducingBlock, NullTxTracer.Instance, spec); + // blockToProduce.Transactions.Should().BeEquivalentTo(testCase.ExpectedSelectedTransactions); + // + // } } } diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Validators/TxValidatorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Validators/TxValidatorTests.cs index 5e7c58067ac..95dae5700de 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Validators/TxValidatorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Validators/TxValidatorTests.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using System.Collections.Generic; +using System.Linq; using FluentAssertions; using Nethermind.Consensus.Validators; using Nethermind.Core; @@ -215,5 +216,27 @@ public bool MaxFeePerGas_is_required_to_be_greater_than_MaxPriorityFeePerGas(TxT TxValidator txValidator = new(ChainId.Mainnet); return txValidator.IsWellFormed(tx, London.Instance); } + + [TestCase(true)] + [TestCase(false)] + public void Transaction_with_init_code_above_max_value_is_rejected_when_eip3860Enabled(bool eip3860Enabled) + { + IReleaseSpec releaseSpec = eip3860Enabled ? Shanghai.Instance : GrayGlacier.Instance; + byte[] initCode = Enumerable.Repeat((byte)0x20, (int)releaseSpec.MaxInitCodeSize + 1).ToArray(); + byte[] sigData = new byte[65]; + sigData[31] = 1; // correct r + sigData[63] = 1; // correct s + sigData[64] = 27; + Signature signature = new(sigData); + Transaction tx = Build.A.Transaction + .WithSignature(signature) + .WithGasLimit(int.MaxValue) + .WithChainId(ChainId.Mainnet) + .To(null) + .WithData(initCode).TestObject; + + TxValidator txValidator = new(1); + txValidator.IsWellFormed(tx, releaseSpec).Should().Be(!eip3860Enabled); + } } } diff --git a/src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs b/src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs index 294b3eaf9e4..e54db725bf9 100644 --- a/src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs +++ b/src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs @@ -38,7 +38,13 @@ public bool IsWellFormed(Transaction transaction, IReleaseSpec releaseSpec) while for an init it will be empty */ ValidateSignature(transaction.Signature, releaseSpec) && ValidateChainId(transaction) && - Validate1559GasFields(transaction, releaseSpec); + Validate1559GasFields(transaction, releaseSpec) && + Validate3860Rules(transaction, releaseSpec); + } + + private bool Validate3860Rules(Transaction transaction, IReleaseSpec releaseSpec) + { + return !(transaction.IsContractCreation && releaseSpec.IsEip3860Enabled && (transaction.Data?.Length ?? 0) > releaseSpec.MaxInitCodeSize); } private bool ValidateTxType(Transaction transaction, IReleaseSpec releaseSpec) diff --git a/src/Nethermind/Nethermind.Core.Test/Builders/TransactionBuilder.cs b/src/Nethermind/Nethermind.Core.Test/Builders/TransactionBuilder.cs index 583b60536d1..cf156cdf9c0 100644 --- a/src/Nethermind/Nethermind.Core.Test/Builders/TransactionBuilder.cs +++ b/src/Nethermind/Nethermind.Core.Test/Builders/TransactionBuilder.cs @@ -45,7 +45,7 @@ public TransactionBuilder WithTo(Address? address) return this; } - public TransactionBuilder To(Address address) + public TransactionBuilder To(Address? address) { TestObjectInternal.To = address; return this; diff --git a/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs b/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs index f1c8e05af4c..265f3f03eed 100644 --- a/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs +++ b/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs @@ -191,7 +191,7 @@ private void Execute(Transaction transaction, BlockHeader block, ITxTracer txTra } } - if (transaction.IsContractCreation && spec.IsEip3860Enabled && transaction.Data.Length > spec.MaxInitCodeSize) + if (transaction.IsContractCreation && spec.IsEip3860Enabled && (transaction.Data?.Length ?? 0) > spec.MaxInitCodeSize) { TraceLogInvalidTx(transaction, $"CREATE_TRANSACTION_SIZE_EXCEEDS_MAX_INIT_CODE_SIZE {transaction.Data.Length} > {spec.MaxInitCodeSize}"); QuickFail(transaction, block, txTracer, eip658NotEnabled, "eip-3860 - transaction size over max init code size"); From 6d1ee18c14d9aa68725cc83f0a22e48ee49a67af Mon Sep 17 00:00:00 2001 From: MarekM25 Date: Mon, 16 Jan 2023 11:16:55 +0100 Subject: [PATCH 2/5] cosmetic --- .../TransactionsExecutorTests.cs | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs index d934602e332..dbe12abb732 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs @@ -283,41 +283,5 @@ void SetAccountStates(IEnumerable
missingAddresses) txExecutor.ProcessTransactions(blockToProduce, ProcessingOptions.ProducingBlock, receiptsTracer, spec); blockToProduce.Transactions.Should().BeEquivalentTo(testCase.ExpectedSelectedTransactions); } - // - // [Test] - // public void Cannot_pick_transaction_with_initicode_above_maxinitcode_when_EIP3860_enabled() - // { - // MemDb stateDb = new(); - // MemDb codeDb = new(); - // TrieStore trieStore = new(stateDb, LimboLogs.Instance); - // StateProvider stateProvider = new(trieStore, codeDb, LimboLogs.Instance); - // IStorageProvider storageProvider = Substitute.For(); - // ISpecProvider specProvider = Substitute.For(); - // ITransactionProcessor transactionProcessor = Substitute.For(); - // var txArray = - // { - // Build.A.Transaction.WithSenderAddress(TestItem.AddressA).WithNonce(3) - // .WithGasPrice(60).WithGasLimit(10).SignedAndResolved(TestItem.PrivateKeyA).TestObject, - // Build.A.Transaction.WithSenderAddress(TestItem.AddressA).WithNonce(1) - // .WithGasPrice(30).WithGasLimit(10).SignedAndResolved(TestItem.PrivateKeyA).TestObject, - // Build.A.Transaction.WithSenderAddress(TestItem.AddressA).WithNonce(2) - // .WithGasPrice(20).WithGasLimit(10).SignedAndResolved(TestItem.PrivateKeyA).TestObject - // }; - // BlockProcessor.BlockProductionTransactionsExecutor txExecutor = - // new( - // transactionProcessor, - // stateProvider, - // storageProvider, - // specProvider, - // LimboLogs.Instance); - // Block block = Build.A.Block - // .WithNumber(0) - // .WithTransactions(txArray) - // .TestObject; - // BlockToProduce blockToProduce = new(block.Header, block.Transactions, block.Uncles); - // txExecutor.ProcessTransactions(blockToProduce, ProcessingOptions.ProducingBlock, NullTxTracer.Instance, spec); - // blockToProduce.Transactions.Should().BeEquivalentTo(testCase.ExpectedSelectedTransactions); - // - // } } } From 9b3af6b14d4c8939865154440ddd43a3f47fbe64 Mon Sep 17 00:00:00 2001 From: MarekM25 Date: Mon, 16 Jan 2023 11:17:47 +0100 Subject: [PATCH 3/5] cosmetic cleanup --- .../TransactionsExecutorTests.cs | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs index dbe12abb732..89babd14fc9 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/TransactionsExecutorTests.cs @@ -187,28 +187,7 @@ public static IEnumerable ProperTransactionsSelectedTestCases } } - public static IEnumerable Eip3860TestCases - { - get - { - ProperTransactionsSelectedTestCase balanceBelowMaxFeeTimesGasLimit = new() - { - ReleaseSpec = Shanghai.Instance, - BaseFee = 5, - AccountStates = { { TestItem.AddressA, (400, 1) } }, - Transactions = - { - Build.A.Transaction.WithSenderAddress(TestItem.AddressA).WithNonce(1) - .WithMaxFeePerGas(45).WithMaxPriorityFeePerGas(25).WithGasLimit(10).WithType(TxType.EIP1559).WithValue(60).SignedAndResolved(TestItem.PrivateKeyA).TestObject - }, - GasLimit = 10000000 - }; - yield return new TestCaseData(balanceBelowMaxFeeTimesGasLimit).SetName("EIP3860 Transactions"); - } - } - [TestCaseSource(nameof(ProperTransactionsSelectedTestCases))] - [TestCaseSource(nameof(Eip3860TestCases))] public void Proper_transactions_selected(ProperTransactionsSelectedTestCase testCase) { MemDb stateDb = new(); From 1205348b1c99648fe62580447b0a38867c89554a Mon Sep 17 00:00:00 2001 From: MarekM25 Date: Mon, 16 Jan 2023 12:30:26 +0100 Subject: [PATCH 4/5] cosmetic changes --- .../Validators/TxValidatorTests.cs | 12 +++++++----- .../Nethermind.Consensus/Validators/TxValidator.cs | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Nethermind/Nethermind.Blockchain.Test/Validators/TxValidatorTests.cs b/src/Nethermind/Nethermind.Blockchain.Test/Validators/TxValidatorTests.cs index 95dae5700de..308ade6eb5b 100644 --- a/src/Nethermind/Nethermind.Blockchain.Test/Validators/TxValidatorTests.cs +++ b/src/Nethermind/Nethermind.Blockchain.Test/Validators/TxValidatorTests.cs @@ -217,12 +217,14 @@ public bool MaxFeePerGas_is_required_to_be_greater_than_MaxPriorityFeePerGas(TxT return txValidator.IsWellFormed(tx, London.Instance); } - [TestCase(true)] - [TestCase(false)] - public void Transaction_with_init_code_above_max_value_is_rejected_when_eip3860Enabled(bool eip3860Enabled) + [TestCase(true, 1, false)] + [TestCase(false, 1, true)] + [TestCase(true, -1, true)] + [TestCase(false, -1, true)] + public void Transaction_with_init_code_above_max_value_is_rejected_when_eip3860Enabled(bool eip3860Enabled, int dataSizeAboveInitCode, bool expectedResult) { IReleaseSpec releaseSpec = eip3860Enabled ? Shanghai.Instance : GrayGlacier.Instance; - byte[] initCode = Enumerable.Repeat((byte)0x20, (int)releaseSpec.MaxInitCodeSize + 1).ToArray(); + byte[] initCode = Enumerable.Repeat((byte)0x20, (int)releaseSpec.MaxInitCodeSize + dataSizeAboveInitCode).ToArray(); byte[] sigData = new byte[65]; sigData[31] = 1; // correct r sigData[63] = 1; // correct s @@ -236,7 +238,7 @@ public void Transaction_with_init_code_above_max_value_is_rejected_when_eip3860E .WithData(initCode).TestObject; TxValidator txValidator = new(1); - txValidator.IsWellFormed(tx, releaseSpec).Should().Be(!eip3860Enabled); + txValidator.IsWellFormed(tx, releaseSpec).Should().Be(expectedResult); } } } diff --git a/src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs b/src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs index e54db725bf9..b3afb94b9ae 100644 --- a/src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs +++ b/src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs @@ -44,7 +44,8 @@ public bool IsWellFormed(Transaction transaction, IReleaseSpec releaseSpec) private bool Validate3860Rules(Transaction transaction, IReleaseSpec releaseSpec) { - return !(transaction.IsContractCreation && releaseSpec.IsEip3860Enabled && (transaction.Data?.Length ?? 0) > releaseSpec.MaxInitCodeSize); + bool aboveInitCode = transaction.IsContractCreation && releaseSpec.IsEip3860Enabled && (transaction.Data?.Length ?? 0) > releaseSpec.MaxInitCodeSize; + return !aboveInitCode; } private bool ValidateTxType(Transaction transaction, IReleaseSpec releaseSpec) From 45cc89115f4618fccebffb08c7eba3b518ca13a4 Mon Sep 17 00:00:00 2001 From: MarekM25 Date: Mon, 16 Jan 2023 17:01:59 +0100 Subject: [PATCH 5/5] review changes --- src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs | 2 +- src/Nethermind/Nethermind.Core/Transaction.cs | 2 ++ src/Nethermind/Nethermind.Evm/IntrinsicGasCalculator.cs | 4 ++-- .../TransactionProcessing/TransactionProcessor.cs | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs b/src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs index b3afb94b9ae..dcad09099ea 100644 --- a/src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs +++ b/src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs @@ -44,7 +44,7 @@ public bool IsWellFormed(Transaction transaction, IReleaseSpec releaseSpec) private bool Validate3860Rules(Transaction transaction, IReleaseSpec releaseSpec) { - bool aboveInitCode = transaction.IsContractCreation && releaseSpec.IsEip3860Enabled && (transaction.Data?.Length ?? 0) > releaseSpec.MaxInitCodeSize; + bool aboveInitCode = transaction.IsContractCreation && releaseSpec.IsEip3860Enabled && transaction.DataLength > releaseSpec.MaxInitCodeSize; return !aboveInitCode; } diff --git a/src/Nethermind/Nethermind.Core/Transaction.cs b/src/Nethermind/Nethermind.Core/Transaction.cs index 0d7d9eb3dd4..547411cf8cf 100644 --- a/src/Nethermind/Nethermind.Core/Transaction.cs +++ b/src/Nethermind/Nethermind.Core/Transaction.cs @@ -43,6 +43,8 @@ public class Transaction public PublicKey? DeliveredBy { get; set; } // tks: this is added so we do not send the pending tx back to original sources, not used yet public UInt256 Timestamp { get; set; } + public int DataLength => Data?.Length ?? 0; + public AccessList? AccessList { get; set; } // eip2930 /// diff --git a/src/Nethermind/Nethermind.Evm/IntrinsicGasCalculator.cs b/src/Nethermind/Nethermind.Evm/IntrinsicGasCalculator.cs index 2894b9e3255..248f0855796 100644 --- a/src/Nethermind/Nethermind.Evm/IntrinsicGasCalculator.cs +++ b/src/Nethermind/Nethermind.Evm/IntrinsicGasCalculator.cs @@ -39,7 +39,7 @@ private static long DataCost(Transaction transaction, IReleaseSpec releaseSpec) long dataCost = 0; if (transaction.Data is not null) { - for (int i = 0; i < transaction.Data.Length; i++) + for (int i = 0; i < transaction.DataLength; i++) { dataCost += transaction.Data[i] == 0 ? GasCostOf.TxDataZero : txDataNonZeroGasCost; } @@ -47,7 +47,7 @@ private static long DataCost(Transaction transaction, IReleaseSpec releaseSpec) if (transaction.IsContractCreation && releaseSpec.IsEip3860Enabled) { - dataCost += EvmPooledMemory.Div32Ceiling((UInt256)transaction.Data.Length) * GasCostOf.InitCodeWord; + dataCost += EvmPooledMemory.Div32Ceiling((UInt256)transaction.DataLength) * GasCostOf.InitCodeWord; } return dataCost; diff --git a/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs b/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs index 265f3f03eed..c03675aceb4 100644 --- a/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs +++ b/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs @@ -191,9 +191,9 @@ private void Execute(Transaction transaction, BlockHeader block, ITxTracer txTra } } - if (transaction.IsContractCreation && spec.IsEip3860Enabled && (transaction.Data?.Length ?? 0) > spec.MaxInitCodeSize) + if (transaction.IsContractCreation && spec.IsEip3860Enabled && (transaction.DataLength) > spec.MaxInitCodeSize) { - TraceLogInvalidTx(transaction, $"CREATE_TRANSACTION_SIZE_EXCEEDS_MAX_INIT_CODE_SIZE {transaction.Data.Length} > {spec.MaxInitCodeSize}"); + TraceLogInvalidTx(transaction, $"CREATE_TRANSACTION_SIZE_EXCEEDS_MAX_INIT_CODE_SIZE {transaction.DataLength} > {spec.MaxInitCodeSize}"); QuickFail(transaction, block, txTracer, eip658NotEnabled, "eip-3860 - transaction size over max init code size"); return; }