Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2 Implement EIP-7623: Increase calldata cost #7573

Draft
wants to merge 571 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
571 commits
Select commit Hold shift + click to select a range
60cc1b7
fix DepositProcessorTests
MarekM25 May 15, 2024
283f63b
fix AUTH call gas costs
MarekM25 May 16, 2024
67ab80f
RLP encoding
ak88 Jun 5, 2024
2843085
start test
ak88 Jun 5, 2024
bc8c3e9
refactor
ak88 Jun 7, 2024
3ed58a3
Pectra: fix merge conflicts (#7170)
rjnrohit Jun 12, 2024
147d69d
Merge branch 'master' into pectra
rjnrohit Jun 12, 2024
79ffe9d
remove duplicate import
rjnrohit Jun 12, 2024
1bb851d
Merge branch 'master' into pectra
rjnrohit Jun 16, 2024
e1d3265
Rename: `ValidatorPublicKey` -> `ValidatorPubKey` (#7172)
rjnrohit Jun 16, 2024
5262378
Remove support of eip3074 from pectra (#7189)
rjnrohit Jun 17, 2024
33652fc
insert code in EOA
ak88 Jun 17, 2024
303a0f6
removed wrong test
ak88 Jun 20, 2024
de4d4d7
cleanup
ak88 Jun 20, 2024
4c591cc
more tests added
ak88 Jun 20, 2024
40903d1
Merge branch 'master' into feature/eip-7702
ak88 Jun 20, 2024
f3c8a7d
more tests
ak88 Jun 20, 2024
c18c3d5
refactor with CodeInfoRepo
ak88 Jun 20, 2024
8a9cd0d
format whitespace
ak88 Jun 20, 2024
bb6f5cf
small refactor
ak88 Jun 23, 2024
bccfd21
refactor and unittest
ak88 Jun 24, 2024
a50c96c
Recover authority together with sender
ak88 Jun 24, 2024
6e91510
added 7702 to metrics
ak88 Jun 24, 2024
23a2936
dont recover if already recovered
ak88 Jun 24, 2024
d1ef9dd
Small changes
ak88 Jun 24, 2024
c1fd043
format whitespace
ak88 Jun 24, 2024
dd08281
fix recover
ak88 Jun 24, 2024
0dcfb3d
Merge branch 'master' into feature/eip-7702
ak88 Jun 24, 2024
0a8346b
removed test
ak88 Jun 24, 2024
e25a17c
Merge branch 'feature/eip-7702' of https://github.com/NethermindEth/n…
ak88 Jun 24, 2024
a869907
update rlp decoding
Jun 25, 2024
e2fb74d
authorizationtuple being nullable
Jun 25, 2024
c062402
unittest fix
ak88 Jun 25, 2024
d40c3c0
Merge branch 'master' into feature/eip-7702
ak88 Jun 25, 2024
949f5a8
Rlp decoder changes
ak88 Jun 25, 2024
12297d4
refactor
ak88 Jun 26, 2024
21c06a7
txpool test fix
ak88 Jun 26, 2024
1926da9
missing
ak88 Jun 26, 2024
18a8951
Rlp unitest
ak88 Jun 26, 2024
7702fa4
some basic refactorings
LukaszRozmej Jun 27, 2024
ef3370d
simplified refactor and RLP fix
ak88 Jun 27, 2024
05ea012
format whitespace
ak88 Jun 27, 2024
06e48c9
cleanup
ak88 Jun 27, 2024
bbd956a
cleanup and review comments
ak88 Jun 27, 2024
0b182c8
fix for old tx tests
ak88 Jun 27, 2024
ca22d59
removed unused field
ak88 Jun 28, 2024
6218545
CodeInfoRepository passing refactor
LukaszRozmej Jun 28, 2024
35276b6
simplify code
LukaszRozmej Jun 28, 2024
ff5a88d
refactor and recover authority in tx pool
ak88 Jun 28, 2024
7efa123
unit test fix
ak88 Jun 29, 2024
3daf9fb
bad sig will skip and not throw
ak88 Jul 3, 2024
eb84a1d
eip 7702 timestamp
ak88 Jul 24, 2024
182b67b
set the actual value of IsEip7702Enabled
smartprogrammer93 Jul 24, 2024
3ff6605
add test tp chainspec tests to make sure it is loaded
smartprogrammer93 Jul 24, 2024
050fe47
Validate nonce then increment after 7702
ak88 Jul 27, 2024
78a82b5
decode rlp auth list fix
ak88 Jul 31, 2024
9b189d4
Resolved all conflicts
MarekM25 Sep 12, 2024
ff9e4cd
fix whitespaces
MarekM25 Sep 12, 2024
8557a10
fix benchmarks.sln build
MarekM25 Sep 12, 2024
03e4997
fix tests
MarekM25 Sep 12, 2024
be5acf1
fix tests
MarekM25 Sep 12, 2024
b7546f3
fix tests
MarekM25 Sep 13, 2024
45e44cf
Prague: Add support for getPayloadBodiesBy Hash + Range (#7133)
rjnrohit Jun 25, 2024
f4db109
Resolved payload bodies
MarekM25 Sep 13, 2024
5f2434c
Removed log message
MarekM25 Sep 13, 2024
d7d0c04
Cleanup the branch
MarekM25 Sep 13, 2024
51c1701
Cleanup
MarekM25 Sep 13, 2024
eebac4f
minor refactor
smartprogrammer93 Sep 14, 2024
c8434ab
Reduce allocation + minors + optimize `ToULongFromBigEndianByteArrayW…
smartprogrammer93 Sep 14, 2024
b653664
fix
smartprogrammer93 Sep 14, 2024
0abb556
Update src/Nethermind/Nethermind.State/Proofs/RequestsTrie.cs
smartprogrammer93 Sep 14, 2024
01deb2a
Update src/Nethermind/Nethermind.Specs/ReleaseSpec.cs
smartprogrammer93 Sep 14, 2024
7d106ea
Merge branch 'master' into pectra_eips
smartprogrammer93 Sep 14, 2024
3d5bde2
fix whitespace and build issue
smartprogrammer93 Sep 14, 2024
2a60176
fix test
smartprogrammer93 Sep 14, 2024
aa0196b
Resolved conflicts
MarekM25 Sep 16, 2024
3e156c9
spec changes start
ak88 Aug 16, 2024
ceeee20
revert nonce increments
ak88 Aug 16, 2024
d4e3298
intrinsic gas
ak88 Aug 16, 2024
58da91d
cherry-picking
MarekM25 Sep 16, 2024
129f134
build fix
ak88 Aug 19, 2024
0237c49
fx unittest
ak88 Aug 20, 2024
2e8eddb
spec changes
ak88 Aug 22, 2024
da3e3bd
unit tests
ak88 Aug 22, 2024
7f7e2ee
Merge branch 'pectra' into feature/eip-7702
ak88 Aug 22, 2024
8badf7d
Build fix
ak88 Aug 22, 2024
3be0b1c
change nonce to ulong
ak88 Aug 22, 2024
ac4fd87
refactor ChargeAccountAccessGas
ak88 Aug 24, 2024
bdf56f9
gas fixes and bug
ak88 Aug 26, 2024
61d59f7
merge fix
ak88 Aug 27, 2024
b5cea7a
build fix
ak88 Aug 28, 2024
403207a
refactor txprocessor to using accessed addresses
ak88 Aug 29, 2024
bdc4dc0
fix
ak88 Sep 1, 2024
93159d2
encoder fix
ak88 Sep 2, 2024
bbc81a4
test strg
ak88 Sep 2, 2024
cb6ac2d
fix extcodehash
ak88 Sep 2, 2024
5301b89
7702 refunds
ak88 Sep 3, 2024
29257b2
Use uint256 for sig values
ak88 Sep 4, 2024
aef10ce
state test fix for auth list
ak88 Sep 4, 2024
9b9eb2e
validate auth sig in txvalidator
ak88 Sep 4, 2024
1053f7a
Revert "Use uint256 for sig values"
ak88 Sep 4, 2024
51856ad
unittest fixes
ak88 Sep 4, 2024
8335b61
unique check auth sig validity
ak88 Sep 4, 2024
d5b8037
test cleanup
ak88 Sep 4, 2024
e996c17
unittest fix
ak88 Sep 4, 2024
2ce9f73
do not allow empty auth list
ak88 Sep 5, 2024
2da8111
tx pool check if sender is delegation
ak88 Sep 5, 2024
22152a8
unittest for TxPool
ak88 Sep 6, 2024
904bdb6
modified hive.json for debugging
MarekM25 Sep 9, 2024
b6f2563
hive test cfg
ak88 Sep 9, 2024
6a77929
cleanup
ak88 Sep 9, 2024
2f1e85c
Auth list in RPC
ak88 Sep 9, 2024
d59d3fa
fix, disallow create tx in SetCode tx type
smartprogrammer93 Sep 10, 2024
189e566
fix chainid
ak88 Sep 12, 2024
0f388d1
revert temp path too long fix
ak88 Sep 12, 2024
c938923
small refactors
LukaszRozmej Sep 16, 2024
291ba9b
more basic refactors and cleanups
LukaszRozmej Sep 16, 2024
046fb36
Resolved conflicts
MarekM25 Sep 17, 2024
a0dbd21
Solving errors
MarekM25 Sep 17, 2024
7ec64d2
Builds error solved
MarekM25 Sep 17, 2024
7baea0b
Resolved conflicts
MarekM25 Sep 17, 2024
3e8726e
fix build errors
MarekM25 Sep 17, 2024
0db830c
cherry pick missing from 7702
ak88 Sep 17, 2024
b90b883
fix whitespaces
MarekM25 Sep 17, 2024
4532047
fix merge tests
MarekM25 Sep 17, 2024
93a7c75
cosmetic
MarekM25 Sep 17, 2024
a739b22
Null handling for requests
MarekM25 Sep 17, 2024
fa10981
tx decoder for setcode
ak88 Sep 17, 2024
7aa7aa8
RPC module tests for 7702
ak88 Sep 11, 2024
c9c1afc
cleanup after missing commit
ak88 Sep 17, 2024
5ac555e
tx validator for setcode refactor
ak88 Sep 18, 2024
7b5f627
fix tests
MarekM25 Sep 18, 2024
2953bca
cosmetic
MarekM25 Sep 18, 2024
f3c2c52
fix whitespace?
MarekM25 Sep 18, 2024
76b8b6f
whitespace?
MarekM25 Sep 18, 2024
540b86c
fix test
MarekM25 Sep 18, 2024
ce64d97
cosmetic
MarekM25 Sep 18, 2024
66bd24e
fix test
MarekM25 Sep 18, 2024
6465805
fix tx pool tests
ak88 Sep 18, 2024
958df8a
use BlockchainId instead
ak88 Sep 18, 2024
3f5e57b
unnecessary using
ak88 Sep 18, 2024
4c564b3
use BlockchainId instead
ak88 Sep 18, 2024
98d5277
Resolved conflicts with payload bodies
MarekM25 Sep 18, 2024
e39c754
Merge branch 'pectra_fix_7702_after_merge' of https://github.com/neth…
MarekM25 Sep 18, 2024
ff823b0
revert proof module
MarekM25 Sep 18, 2024
2653613
fix one more test
MarekM25 Sep 18, 2024
1857a61
fix whitespace
MarekM25 Sep 18, 2024
95fb7fa
whitespaces?
MarekM25 Sep 18, 2024
5c41d0a
fix whitespace
MarekM25 Sep 18, 2024
e8c1782
?fix
MarekM25 Sep 18, 2024
e8011ff
fix
MarekM25 Sep 18, 2024
28839a9
fix Evm.Test
MarekM25 Sep 18, 2024
63e262c
fix
MarekM25 Sep 18, 2024
2fac622
use SpecProvider.ChainId in test
ak88 Sep 18, 2024
6018e7d
Merge branch 'pectra_fix_7702_after_merge' of https://github.com/Neth…
ak88 Sep 18, 2024
d4b36c5
small refactor TransactionProcessorEip7702Tests
ak88 Sep 18, 2024
f3301ad
ignore authorization list if null TransactionForRpc
ak88 Sep 18, 2024
e7a91a2
fix SimulateReadOnlyBlocksProcessingEnv
ak88 Sep 18, 2024
51a63dd
fix EthModuleBenchmarks
ak88 Sep 18, 2024
ed6b5bf
remove unnecessary ?
LukaszRozmej Sep 19, 2024
a249a58
Move engine_getPayloadBodiesByHash to IHandler, no Async needed
LukaszRozmej Sep 19, 2024
b298026
syntatic suggar
LukaszRozmej Sep 19, 2024
638fd41
Merge branch 'master' into pectra_eips
MarekM25 Sep 19, 2024
a911023
Merge branch 'pectra_eips' into pectra_payload_bodies
MarekM25 Sep 19, 2024
bc5130b
Consensus requests change class structure
MarekM25 Sep 19, 2024
d29ca4d
one more field
MarekM25 Sep 19, 2024
1518f27
class to abstract
MarekM25 Sep 19, 2024
3acb335
Review fixes
MarekM25 Sep 19, 2024
650630e
Resolved conflicts
MarekM25 Sep 19, 2024
53043ad
extra test for refunds
ak88 Sep 19, 2024
d3197ec
some cosmetic changes
MarekM25 Sep 19, 2024
15040c9
Merge branch 'pectra_fix_7702_after_merge' of https://github.com/neth…
MarekM25 Sep 19, 2024
4e71d9a
Test null address
ak88 Sep 19, 2024
3361a63
remove unused
ak88 Sep 20, 2024
45bf7bd
enginemoduletest
ak88 Sep 20, 2024
28a0f7c
improve recoversignatures
ak88 Sep 20, 2024
026de88
Merge branch 'new_test' into pectra_fix_7702_after_merge
ak88 Sep 20, 2024
aec7e85
fix test
ak88 Sep 20, 2024
5e59935
if sender recovered from pool also set authority
ak88 Sep 20, 2024
54a59ba
Apply suggestions from code review
ak88 Sep 20, 2024
9c3ec4d
cosmetic
ak88 Sep 20, 2024
6d90306
Merge branch 'pectra_fix_7702_after_merge' of https://github.com/Neth…
ak88 Sep 20, 2024
7f48fd6
a few optimizations
MarekM25 Sep 20, 2024
552b704
Merge branch 'pectra_fix_7702_after_merge' of https://github.com/neth…
MarekM25 Sep 20, 2024
7da0be0
fix
MarekM25 Sep 20, 2024
18a3e0e
cosmetic
MarekM25 Sep 20, 2024
58ae212
cosmetic
MarekM25 Sep 23, 2024
c35e4ea
Resolved conflicts
MarekM25 Sep 23, 2024
581321d
cosmetic cleanup
ak88 Sep 23, 2024
43a99b2
cosmetic
ak88 Sep 24, 2024
757d06f
removed metric
ak88 Sep 24, 2024
1aa8096
cosmetic
MarekM25 Sep 25, 2024
65f06e2
Merge branch 'pectra_fix_7702_after_merge' of https://github.com/neth…
MarekM25 Sep 25, 2024
d124cf7
small optimization
ak88 Sep 25, 2024
f3bce87
small changes from review
ak88 Sep 25, 2024
0e23a9e
changes around CodeInfoRepository
LukaszRozmej Sep 26, 2024
e66c64c
Update src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs
LukaszRozmej Sep 26, 2024
667e168
Update src/Nethermind/Nethermind.Evm/CodeInfoRepository.cs
LukaszRozmej Sep 26, 2024
42ab153
Update src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs
LukaszRozmej Sep 26, 2024
085fa42
Update src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs
LukaszRozmej Sep 26, 2024
a7dd3d9
Update src/Nethermind/Nethermind.Evm/VirtualMachine.cs
LukaszRozmej Sep 26, 2024
0b8062f
Update src/Nethermind/Nethermind.Facade/Eth/TransactionForRpc.cs
LukaszRozmej Sep 26, 2024
49105d2
Update src/Nethermind/Nethermind.State/IReadOnlyStateProviderExtensio…
LukaszRozmej Sep 26, 2024
110a5b8
fixes
LukaszRozmej Sep 26, 2024
c4b083d
avoid newing HashSet
ak88 Sep 26, 2024
1c69596
add NoContractCreationTxValidator, change SetCodeTxValidator to Autho…
LukaszRozmej Sep 26, 2024
8729021
Move code to value hashes
LukaszRozmej Sep 26, 2024
407effa
ReadConsolidationRequests reorder params to have consistency
LukaszRozmej Sep 26, 2024
a7035ce
simplify IntrinsicGasCalculator
LukaszRozmej Sep 26, 2024
d0dd643
simplify AccessListCost
LukaszRozmej Sep 26, 2024
295854f
grab TxExecutionContext by reference
LukaszRozmej Sep 26, 2024
c323bae
Invert VM condition for readability
LukaszRozmej Sep 26, 2024
900ac8b
Simplify RecoverAuthorityFilter
LukaszRozmej Sep 26, 2024
141c565
fix AuthorizationTupleDecoder
LukaszRozmej Sep 26, 2024
8607c8e
remove IRlpObjectDecoder<ConsolidationRequest>
LukaszRozmej Sep 26, 2024
b998979
bring back exceptions in IntrinsicGasCalculator
LukaszRozmej Sep 26, 2024
6a6db8b
fix
LukaszRozmej Sep 26, 2024
794f6da
fix
LukaszRozmej Sep 26, 2024
5f714d1
More CodeInfoRepository changes
LukaszRozmej Sep 26, 2024
fbc6822
More renames
LukaszRozmej Sep 26, 2024
cbde5c8
More refactors
LukaszRozmej Sep 26, 2024
2a9da1c
fixes
LukaszRozmej Sep 26, 2024
254ff42
changes from review
ak88 Sep 27, 2024
76129ad
decoder netty fix
ak88 Sep 27, 2024
70a3390
also check auth sig in recovery
ak88 Sep 27, 2024
ab855fb
move sign func to extension
ak88 Sep 28, 2024
e28f666
changes from review
ak88 Sep 30, 2024
2963ac2
fix tests
ak88 Oct 1, 2024
1be004e
refactor codeinforepo test
ak88 Oct 2, 2024
eeb4ff9
base class for processors
ak88 Sep 30, 2024
096fb43
Merge branch 'master' into pectra_fix_7702_after_merge
ak88 Oct 2, 2024
facba02
merge fix
ak88 Oct 2, 2024
60348e2
comment correction
ak88 Oct 2, 2024
e4c49d3
Merge branch 'master' into pectra_fix_7702_after_merge
ak88 Oct 2, 2024
86c9df2
format whitespace
ak88 Oct 2, 2024
cd151cc
benchmark fix
ak88 Oct 2, 2024
347a63a
small test change
ak88 Oct 2, 2024
482ebce
add floor gas cost
tanishqjasoria Oct 1, 2024
622a48e
transaction validator and gas estimator
tanishqjasoria Oct 1, 2024
0087008
Merge branch 'master' into pectra_fix_7702_after_merge
MarekM25 Oct 3, 2024
b37e703
update
tanishqjasoria Oct 3, 2024
5bb4b4a
update and add tests
tanishqjasoria Oct 3, 2024
73fa69a
add evm tests
tanishqjasoria Oct 3, 2024
53bd962
Merge branch 'pectra_fix_7702_after_merge' into pectra_7623
tanishqjasoria Oct 3, 2024
16c773c
rename
tanishqjasoria Oct 4, 2024
c82b3ce
add token calculations
tanishqjasoria Oct 4, 2024
717641d
Merge branch 'master' into pectra_7623
tanishqjasoria Oct 7, 2024
86500d0
fix merger issues
tanishqjasoria Oct 7, 2024
0b365e5
small fixes
tanishqjasoria Oct 8, 2024
6889fff
another approach
tanishqjasoria Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Nethermind/Nethermind.Consensus/Validators/TxValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,14 @@ public sealed class IntrinsicGasTxValidator : ITxValidator
public static readonly IntrinsicGasTxValidator Instance = new();
private IntrinsicGasTxValidator() { }

public ValidationResult IsWellFormed(Transaction transaction, IReleaseSpec releaseSpec) =>
public ValidationResult IsWellFormed(Transaction transaction, IReleaseSpec releaseSpec)
{
// This is unnecessarily calculated twice - at validation and execution times.
transaction.GasLimit < IntrinsicGasCalculator.Calculate(transaction, releaseSpec)
var staticGas = IntrinsicGasCalculator.Calculate(transaction, releaseSpec);
return transaction.GasLimit < Math.Max(staticGas.IntrinsicGas, staticGas.FloorGas)
? TxErrorMessages.IntrinsicGasTooLow
: ValidationResult.Success;
}
}

public sealed class ReleaseSpecTxValidator(Func<IReleaseSpec, bool> validate) : ITxValidator
Expand Down
5 changes: 5 additions & 0 deletions src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ public interface IReleaseSpec : IEip1559Spec, IReceiptSpec
/// OP Granite
bool IsOpGraniteEnabled { get; }

/// <summary>
/// Increase call data cost
/// </summary>
bool IsEip7623Enabled { get; }

/// <summary>
/// Should transactions be validated against chainId.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class ReleaseSpecDecorator(IReleaseSpec spec) : IReleaseSpec
public virtual bool IsEip6780Enabled => spec.IsEip6780Enabled;
public bool IsEip7702Enabled => spec.IsEip7702Enabled;
public virtual bool IsRip7212Enabled => spec.IsRip7212Enabled;
public bool IsEip7623Enabled => spec.IsEip7623Enabled;
public virtual bool IsOpGraniteEnabled => spec.IsOpGraniteEnabled;
public virtual ulong WithdrawalTimestamp => spec.WithdrawalTimestamp;
public virtual ulong Eip4844TransitionTimestamp => spec.Eip4844TransitionTimestamp;
Expand Down
20 changes: 12 additions & 8 deletions src/Nethermind/Nethermind.Evm.Test/Eip2028Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ private class AfterIstanbul : Eip2028Tests
public void non_zero_transaction_data_cost_should_be_16()
{
Transaction transaction = new Transaction { Data = new byte[] { 1 }, To = Address.Zero };
long cost = IntrinsicGasCalculator.Calculate(transaction, Spec);
cost.Should().Be(GasCostOf.Transaction + GasCostOf.TxDataNonZeroEip2028);
var cost = IntrinsicGasCalculator.Calculate(transaction, Spec);
cost.FloorGas.Should().Be(0);
cost.IntrinsicGas.Should().Be(GasCostOf.Transaction + GasCostOf.TxDataNonZeroEip2028);
}

[Test]
public void zero_transaction_data_cost_should_be_4()
{
Transaction transaction = new Transaction { Data = new byte[] { 0 }, To = Address.Zero };
long cost = IntrinsicGasCalculator.Calculate(transaction, Spec);
cost.Should().Be(GasCostOf.Transaction + GasCostOf.TxDataZero);
var cost = IntrinsicGasCalculator.Calculate(transaction, Spec);
cost.IntrinsicGas.Should().Be(GasCostOf.Transaction + GasCostOf.TxDataZero);
cost.FloorGas.Should().Be(0);
}
}

Expand All @@ -45,16 +47,18 @@ private class BeforeIstanbul : Eip2028Tests
public void non_zero_transaction_data_cost_should_be_68()
{
Transaction transaction = new Transaction { Data = new byte[] { 1 }, To = Address.Zero };
long cost = IntrinsicGasCalculator.Calculate(transaction, Spec);
cost.Should().Be(GasCostOf.Transaction + GasCostOf.TxDataNonZero);
var cost = IntrinsicGasCalculator.Calculate(transaction, Spec);
cost.FloorGas.Should().Be(0);
cost.IntrinsicGas.Should().Be(GasCostOf.Transaction + GasCostOf.TxDataNonZero);
}

[Test]
public void zero_transaction_data_cost_should_be_4()
{
Transaction transaction = new Transaction { Data = new byte[] { 0 }, To = Address.Zero };
long cost = IntrinsicGasCalculator.Calculate(transaction, Spec);
cost.Should().Be(GasCostOf.Transaction + GasCostOf.TxDataZero);
var cost = IntrinsicGasCalculator.Calculate(transaction, Spec);
cost.FloorGas.Should().Be(0);
cost.IntrinsicGas.Should().Be(GasCostOf.Transaction + GasCostOf.TxDataZero);
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions src/Nethermind/Nethermind.Evm.Test/Eip7623Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using FluentAssertions;
using Nethermind.Core;
using Nethermind.Specs;
using NUnit.Framework;

namespace Nethermind.Evm.Test;

[TestFixture]
public class Eip7623Tests: VirtualMachineTestsBase
{
protected override long BlockNumber => MainnetSpecProvider.ParisBlockNumber;
protected override ulong Timestamp => MainnetSpecProvider.PragueBlockTimestamp;

[Test]
public void non_zero_data_transaction_floor_cost_should_be_40()
{
var transaction = new Transaction { Data = new byte[] { 1 }, To = Address.Zero };
var cost = IntrinsicGasCalculator.Calculate(transaction, Spec);
cost.FloorGas.Should().Be(GasCostOf.Transaction + GasCostOf.TotalCostFloorPerTokenEip7623 * 4);
cost.IntrinsicGas.Should().Be(GasCostOf.Transaction + GasCostOf.TxDataNonZeroEip2028);
}

[Test]
public void zero_data_transaction_floor_cost_should_be_10()
{
var transaction = new Transaction { Data = new byte[] { 0 }, To = Address.Zero };
var cost = IntrinsicGasCalculator.Calculate(transaction, Spec);
cost.IntrinsicGas.Should().Be(GasCostOf.Transaction + GasCostOf.TxDataZero);
cost.FloorGas.Should().Be(GasCostOf.Transaction + GasCostOf.TotalCostFloorPerTokenEip7623);
}
}
11 changes: 7 additions & 4 deletions src/Nethermind/Nethermind.Evm.Test/GasPriceExtractorTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Linq;
using FluentAssertions;
using Nethermind.Core;
Expand Down Expand Up @@ -32,8 +33,9 @@ public void Intrinsic_gas_cost_assumption_is_correct()
Rlp rlp = BuildHeader();

Transaction tx = Build.A.Transaction.WithData(rlp.Bytes).TestObject;
long gasCost = IntrinsicGasCalculator.Calculate(tx, Spec);
gasCost.Should().BeLessThan(21000 + 9600);
var gasCost = IntrinsicGasCalculator.Calculate(tx, Spec);
gasCost.FloorGas.Should().Be(0);
gasCost.IntrinsicGas.Should().BeLessThan(21000 + 9600);
}

[Test]
Expand All @@ -42,8 +44,9 @@ public void Keccak_gas_cost_assumption_is_correct()
Rlp rlp = BuildHeader();

Transaction tx = Build.A.Transaction.WithData(rlp.Bytes).TestObject;
long gasCost = IntrinsicGasCalculator.Calculate(tx, Spec);
gasCost.Should().BeLessThan(21000 + 9600);
var gasCost = IntrinsicGasCalculator.Calculate(tx, Spec);
gasCost.FloorGas.Should().Be(0);
gasCost.IntrinsicGas.Should().BeLessThan(21000 + 9600);

byte[] bytecode =
Prepare.EvmCode
Expand Down
60 changes: 34 additions & 26 deletions src/Nethermind/Nethermind.Evm.Test/IntrinsicGasCalculatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ public class IntrinsicGasCalculatorTests
yield return (new List<object> { Address.Zero, (UInt256)1, Address.Zero, (UInt256)1 }, 8600);
}

public static IEnumerable<(byte[] Data, int OldCost, int NewCost)> DataTestCaseSource()
public static IEnumerable<(byte[] Data, int OldCost, int NewCost, int FloorCost)> DataTestCaseSource()
{
yield return (new byte[] { 0 }, 4, 4);
yield return (new byte[] { 1 }, 68, 16);
yield return (new byte[] { 0, 0, 1 }, 76, 24);
yield return (new byte[] { 1, 1, 0 }, 140, 36);
yield return (new byte[] { 0, 0, 1, 1 }, 144, 40);
yield return ([0], 4, 4, 21010);
yield return ([1], 68, 16, 21040);
yield return ([0, 0, 1], 76, 24, 21060);
yield return ([1, 1, 0], 140, 36, 21090);
yield return ([0, 0, 1, 1], 144, 40, 21100);
}
[TestCaseSource(nameof(TestCaseSource))]
public void Intrinsic_cost_is_calculated_properly((Transaction Tx, long Cost, string Description) testCase)
{
IntrinsicGasCalculator.Calculate(testCase.Tx, Berlin.Instance).Should().Be(testCase.Cost);
var gas = IntrinsicGasCalculator.Calculate(testCase.Tx, Berlin.Instance);
gas.IntrinsicGas.Should().Be(testCase.Cost);
gas.FloorGas.Should().Be(0);
}

[TestCaseSource(nameof(AccessTestCaseSource))]
Expand Down Expand Up @@ -74,7 +76,9 @@ void Test(IReleaseSpec spec, bool supportsAccessLists)
}
else
{
IntrinsicGasCalculator.Calculate(tx, spec).Should().Be(21000 + testCase.Cost, spec.Name);
var gas = IntrinsicGasCalculator.Calculate(tx, spec);
gas.IntrinsicGas.Should().Be(21000 + testCase.Cost, spec.Name);
gas.FloorGas.Should().Be(0);
}
}

Expand All @@ -91,31 +95,35 @@ void Test(IReleaseSpec spec, bool supportsAccessLists)
}

[TestCaseSource(nameof(DataTestCaseSource))]
public void Intrinsic_cost_of_data_is_calculated_properly((byte[] Data, int OldCost, int NewCost) testCase)
public void Intrinsic_cost_of_data_is_calculated_properly((byte[] Data, int OldCost, int NewCost, int FloorCost) testCase)
{
Transaction tx = Build.A.Transaction.SignedAndResolved().WithData(testCase.Data).TestObject;

void Test(IReleaseSpec spec, bool isAfterRepricing)
void Test(IReleaseSpec spec, bool isAfterRepricing, bool floorCostEnabled)
{
IntrinsicGasCalculator.Calculate(tx, spec).Should()
var gas = IntrinsicGasCalculator.Calculate(tx, spec);
gas.IntrinsicGas.Should()
.Be(21000 + (isAfterRepricing ? testCase.NewCost : testCase.OldCost), spec.Name,
testCase.Data.ToHexString());
gas.FloorGas.Should().Be(floorCostEnabled ? testCase.FloorCost : 0);
}

Test(Homestead.Instance, false);
Test(Frontier.Instance, false);
Test(SpuriousDragon.Instance, false);
Test(TangerineWhistle.Instance, false);
Test(Byzantium.Instance, false);
Test(Constantinople.Instance, false);
Test(ConstantinopleFix.Instance, false);
Test(Istanbul.Instance, true);
Test(MuirGlacier.Instance, true);
Test(Berlin.Instance, true);
Test(GrayGlacier.Instance, true);
Test(Shanghai.Instance, true);
Test(Cancun.Instance, true);
Test(Homestead.Instance, false, false);
Test(Frontier.Instance, false, false);
Test(SpuriousDragon.Instance, false, false);
Test(TangerineWhistle.Instance, false, false);
Test(Byzantium.Instance, false, false);
Test(Constantinople.Instance, false, false);
Test(ConstantinopleFix.Instance, false, false);
Test(Istanbul.Instance, true, false);
Test(MuirGlacier.Instance, true, false);
Test(Berlin.Instance, true, false);
Test(GrayGlacier.Instance, true, false);
Test(Shanghai.Instance, true, false);
Test(Cancun.Instance, true, false);
Test(Prague.Instance, true, true);
}

public static IEnumerable<(AuthorizationTuple[] contractCode, long expectedCost)> AuthorizationListTestCaseSource()
{
yield return (
Expand Down Expand Up @@ -179,8 +187,8 @@ public void Calculate_TxHasAuthorizationList_ReturnsExpectedCostOfTx((Authorizat
.WithAuthorizationCode(testCase.AuthorizationList)
.TestObject;

IntrinsicGasCalculator.Calculate(tx, Prague.Instance)
.Should().Be(GasCostOf.Transaction + (testCase.ExpectedCost));
var gas = IntrinsicGasCalculator.Calculate(tx, Prague.Instance);
gas.IntrinsicGas.Should().Be(GasCostOf.Transaction + (testCase.ExpectedCost));
}

[Test]
Expand Down
21 changes: 10 additions & 11 deletions src/Nethermind/Nethermind.Evm.Test/TransactionProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public void Can_estimate_with_refund()
Transaction tx = Build.A.Transaction.SignedAndResolved(_ethereumEcdsa, TestItem.PrivateKeyA, _isEip155Enabled).WithCode(initByteCode).WithGasLimit(gasLimit).TestObject;
Block block = Build.A.Block.WithNumber(MainnetSpecProvider.MuirGlacierBlockNumber).WithTransactions(tx).WithGasLimit(2 * gasLimit).TestObject;

long intrinsic = IntrinsicGasCalculator.Calculate(tx, MuirGlacier.Instance);
var staticGas = IntrinsicGasCalculator.Calculate(tx, MuirGlacier.Instance);

GethLikeTxMemoryTracer gethTracer = new(GethTraceOptions.Default);
_transactionProcessor.CallAndRestore(tx, block.Header, gethTracer);
Expand All @@ -404,7 +404,7 @@ public void Can_estimate_with_refund()
GasEstimator estimator = new(_transactionProcessor, _stateProvider, _specProvider, blocksConfig);

long actualIntrinsic = tx.GasLimit - tracer.IntrinsicGasAt;
actualIntrinsic.Should().Be(intrinsic);
actualIntrinsic.Should().Be(staticGas.IntrinsicGas);
IReleaseSpec releaseSpec = Berlin.Instance;
tracer.CalculateAdditionalGasRequired(tx, releaseSpec).Should().Be(RefundOf.SSetReversedEip2200 + GasCostOf.CallStipend - GasCostOf.SStoreNetMeteredEip2200 + 1);
tracer.GasSpent.Should().Be(54764L);
Expand Down Expand Up @@ -432,8 +432,7 @@ public void Can_estimate_with_destroy_refund_and_below_intrinsic_pre_berlin()
Block block = Build.A.Block.WithNumber(MainnetSpecProvider.MuirGlacierBlockNumber).WithTransactions(tx).WithGasLimit(2 * gasLimit).TestObject;

IReleaseSpec releaseSpec = MuirGlacier.Instance;
long intrinsic = IntrinsicGasCalculator.Calculate(tx, releaseSpec);

var staticGas = IntrinsicGasCalculator.Calculate(tx, releaseSpec);
_transactionProcessor.Execute(initTx, block.Header, NullTxTracer.Instance);

EstimateGasTracer tracer = new();
Expand All @@ -446,7 +445,7 @@ public void Can_estimate_with_destroy_refund_and_below_intrinsic_pre_berlin()
GasEstimator estimator = new(_transactionProcessor, _stateProvider, _specProvider, blocksConfig);

long actualIntrinsic = tx.GasLimit - tracer.IntrinsicGasAt;
actualIntrinsic.Should().Be(intrinsic);
actualIntrinsic.Should().Be(staticGas.IntrinsicGas);
tracer.CalculateAdditionalGasRequired(tx, releaseSpec).Should().Be(24080);
tracer.GasSpent.Should().Be(35228L);
long estimate = estimator.Estimate(tx, block.Header, tracer, 0);
Expand Down Expand Up @@ -498,7 +497,7 @@ public void Can_estimate_with_stipend()
Block block = Build.A.Block.WithNumber(MainnetSpecProvider.MuirGlacierBlockNumber).WithTransactions(tx).WithGasLimit(2 * gasLimit).TestObject;

IReleaseSpec releaseSpec = MuirGlacier.Instance;
long intrinsic = IntrinsicGasCalculator.Calculate(tx, releaseSpec);
var staticGas = IntrinsicGasCalculator.Calculate(tx, releaseSpec);

GethLikeTxMemoryTracer gethTracer = new(GethTraceOptions.Default);
_transactionProcessor.CallAndRestore(tx, block.Header, gethTracer);
Expand All @@ -511,7 +510,7 @@ public void Can_estimate_with_stipend()
GasEstimator estimator = new(_transactionProcessor, _stateProvider, _specProvider, blocksConfig);

long actualIntrinsic = tx.GasLimit - tracer.IntrinsicGasAt;
actualIntrinsic.Should().Be(intrinsic);
actualIntrinsic.Should().Be(staticGas.IntrinsicGas);
tracer.CalculateAdditionalGasRequired(tx, releaseSpec).Should().Be(2300);
tracer.GasSpent.Should().Be(85669L);
long estimate = estimator.Estimate(tx, block.Header, tracer, 0);
Expand Down Expand Up @@ -540,7 +539,7 @@ public void Can_estimate_with_stipend_and_refund()
Block block = Build.A.Block.WithNumber(MainnetSpecProvider.MuirGlacierBlockNumber).WithTransactions(tx).WithGasLimit(2 * gasLimit).TestObject;

IReleaseSpec releaseSpec = MuirGlacier.Instance;
long intrinsic = IntrinsicGasCalculator.Calculate(tx, releaseSpec);
var staticGas = IntrinsicGasCalculator.Calculate(tx, releaseSpec);

GethLikeTxMemoryTracer gethTracer = new(GethTraceOptions.Default);
_transactionProcessor.CallAndRestore(tx, block.Header, gethTracer);
Expand All @@ -553,7 +552,7 @@ public void Can_estimate_with_stipend_and_refund()
GasEstimator estimator = new(_transactionProcessor, _stateProvider, _specProvider, blocksConfig);

long actualIntrinsic = tx.GasLimit - tracer.IntrinsicGasAt;
actualIntrinsic.Should().Be(intrinsic);
actualIntrinsic.Should().Be(staticGas.IntrinsicGas);
tracer.CalculateAdditionalGasRequired(tx, releaseSpec).Should().Be(RefundOf.SSetReversedEip2200 + GasCostOf.CallStipend);
tracer.GasSpent.Should().Be(87429L);
long estimate = estimator.Estimate(tx, block.Header, tracer, 0);
Expand All @@ -580,7 +579,7 @@ public void Can_estimate_with_single_call()
Block block = Build.A.Block.WithNumber(MainnetSpecProvider.MuirGlacierBlockNumber).WithTransactions(tx).WithGasLimit(2 * gasLimit).TestObject;

IReleaseSpec releaseSpec = Berlin.Instance;
long intrinsic = IntrinsicGasCalculator.Calculate(tx, releaseSpec);
var staticGas = IntrinsicGasCalculator.Calculate(tx, releaseSpec);

_transactionProcessor.Execute(initTx, block.Header, NullTxTracer.Instance);

Expand All @@ -591,7 +590,7 @@ public void Can_estimate_with_single_call()
GasEstimator estimator = new(_transactionProcessor, _stateProvider, _specProvider, blocksConfig);

long actualIntrinsic = tx.GasLimit - tracer.IntrinsicGasAt;
actualIntrinsic.Should().Be(intrinsic);
actualIntrinsic.Should().Be(staticGas.IntrinsicGas);
tracer.CalculateAdditionalGasRequired(tx, releaseSpec).Should().Be(1);
tracer.GasSpent.Should().Be(54224L);
long estimate = estimator.Estimate(tx, block.Header, tracer, 0);
Expand Down
4 changes: 4 additions & 0 deletions src/Nethermind/Nethermind.Evm/GasCostOf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,9 @@ public static class GasCostOf
public const long TLoad = WarmStateRead; // eip-1153
public const long TStore = WarmStateRead; // eip-1153
public const long PerAuthBaseCost = 2500; // eip-7702
public const long TotalCostFloorPerTokenEip7623 = 10;

public const long TxDataNonZeroMultiplier = TxDataNonZero / TxDataZero;
public const long TxDataNonZeroMultiplierEip2028 = TxDataNonZeroEip2028 / TxDataZero;
}
}
Loading
Loading