Skip to content

eip-7883 implementation #8489

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

Merged
merged 40 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
3a0be32
bump pricing
marcindsobczak Nov 18, 2024
dd05498
disable precompile cache
marcindsobczak Nov 19, 2024
6a5e345
min gas at 300
marcindsobczak Nov 19, 2024
8e2aa66
400 is the new min
marcindsobczak Dec 3, 2024
7de750b
divide by 2
marcindsobczak Dec 3, 2024
4188e8c
min gas 500
marcindsobczak Dec 4, 2024
1fa07d5
min gas 600
marcindsobczak Dec 4, 2024
4da7700
divide by 2
marcindsobczak Dec 4, 2024
fed68e9
min gas 500
marcindsobczak Dec 4, 2024
04dd929
increase words cost if >32 bytes
marcindsobczak Dec 5, 2024
843de06
Merge remote-tracking branch 'origin/master' into test/precompile500wx2
marcindsobczak Jan 8, 2025
685a0cb
Merge remote-tracking branch 'origin/master' into test/precompile500w…
marcindsobczak Mar 6, 2025
e9f1a72
add eip activation
yerke26 Apr 8, 2025
8492ae8
fix whitespace
yerke26 Apr 9, 2025
9ddf52e
add tests
yerke26 Apr 9, 2025
dc91923
Merge branch 'master' into test/precompile500wx2up
yerke26 Apr 9, 2025
6fad146
add more tests
yerke26 Apr 10, 2025
c108ece
Merge branch 'master' into test/precompile500wx2up
yerke26 Apr 10, 2025
9950f82
fix whitespaces
yerke26 Apr 10, 2025
7249c9a
Merge remote-tracking branch 'origin/test/precompile500wx2up' into te…
yerke26 Apr 10, 2025
3bed928
minor refactoring
yerke26 Apr 15, 2025
8988740
Merge branch 'master' into test/precompile500wx2up
yerke26 Apr 15, 2025
44a31d4
Merge remote-tracking branch 'origin/master' into test/precompile500w…
flcl42 May 20, 2025
dd6412c
Add GasCostOf constant
flcl42 May 20, 2025
16b87c4
Merge remote-tracking branch 'origin/master' into test/precompile500w…
flcl42 May 20, 2025
1d73f09
Name numbers
flcl42 May 20, 2025
f81d3b3
Merge remote-tracking branch 'origin/master' into test/precompile500w…
flcl42 May 23, 2025
3bed66e
Merge remote-tracking branch 'origin/master' into test/precompile500w…
flcl42 May 26, 2025
ccf0337
Merge branch 'master' into test/precompile500wx2up
MarekM25 May 26, 2025
28aeef9
cosmetic
MarekM25 May 26, 2025
5a1ac57
Merge branch 'test/precompile500wx2up' of https://github.com/nethermi…
MarekM25 May 26, 2025
f04321d
Add json -> spec -> prov loading test for timestamps
flcl42 May 27, 2025
14502c6
Merge branch 'test/precompile500wx2up' of github.com:NethermindEth/ne…
flcl42 May 27, 2025
7c9ad9c
Fix test
flcl42 May 27, 2025
a158cc3
Fix testing platform by getting rid of internals
flcl42 May 27, 2025
eee1373
Merge remote-tracking branch 'origin/master' into test/precompile500w…
flcl42 May 27, 2025
d8b19e9
Reuse
flcl42 May 27, 2025
dee7093
Merge remote-tracking branch 'origin/master' into test/precompile500w…
flcl42 May 27, 2025
ae80103
Add names
flcl42 May 27, 2025
fb2f765
Disable EOF
flcl42 May 27, 2025
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
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 @@ -337,6 +337,11 @@ public interface IReleaseSpec : IEip1559Spec, IReceiptSpec
/// </summary>
bool IsEip7623Enabled { get; }

/// <summary>
/// Increase ModExp Gas Cost
/// </summary>
bool IsEip7883Enabled { get; }

/// <summary>
/// Should transactions be validated against chainId.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class ReleaseSpecDecorator(IReleaseSpec spec) : IReleaseSpec
public virtual bool IsOpHoloceneEnabled => spec.IsOpHoloceneEnabled;
public virtual bool IsOntakeEnabled => spec.IsOntakeEnabled;
public virtual bool IsEip7623Enabled => spec.IsEip7623Enabled;
public bool IsEip7883Enabled => spec.IsEip7883Enabled;
public virtual ulong WithdrawalTimestamp => spec.WithdrawalTimestamp;
public virtual ulong Eip4844TransitionTimestamp => spec.Eip4844TransitionTimestamp;
public virtual bool IsEip158IgnoredAccount(Address address) => spec.IsEip158IgnoredAccount(address);
Expand Down
16 changes: 9 additions & 7 deletions src/Nethermind/Nethermind.Evm/Precompiles/ModExpPrecompile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public long DataGasCost(ReadOnlyMemory<byte> inputData, IReleaseSpec releaseSpec
UInt256 expLength = new(extendedInput.Slice(32, 32), true);
UInt256 modulusLength = new(extendedInput.Slice(64, 32), true);

UInt256 complexity = MultComplexity(baseLength, modulusLength);
UInt256 complexity = MultComplexity(baseLength, modulusLength, releaseSpec);

UInt256 expLengthUpTo32 = UInt256.Min(32, expLength);
UInt256 startIndex = 96 + baseLength; //+ expLength - expLengthUpTo32; // Geth takes head here, why?
UInt256 exp = new(inputData.Span.SliceWithZeroPaddingEmptyOnError((int)startIndex, (int)expLengthUpTo32), true);
UInt256 iterationCount = CalculateIterationCount(expLength, exp);
UInt256 iterationCount = CalculateIterationCount(expLength, exp, releaseSpec);
bool overflow = UInt256.MultiplyOverflow(complexity, iterationCount, out UInt256 result);
result /= 3;
return result > long.MaxValue || overflow ? long.MaxValue : Math.Max(200L, (long)result);
return result > long.MaxValue || overflow ? long.MaxValue : Math.Max(releaseSpec.IsEip7883Enabled ? 500L : 200L, (long)result);
}
catch (OverflowException)
{
Expand Down Expand Up @@ -173,12 +173,12 @@ public static (byte[], bool) OldRun(byte[] inputData)
/// return words**2
/// </summary>
/// <returns></returns>
private static UInt256 MultComplexity(in UInt256 baseLength, in UInt256 modulusLength)
private static UInt256 MultComplexity(in UInt256 baseLength, in UInt256 modulusLength, IReleaseSpec spec)
{
UInt256 maxLength = UInt256.Max(baseLength, modulusLength);
UInt256.Mod(maxLength, 8, out UInt256 mod8);
UInt256 words = (maxLength / 8) + ((mod8.IsZero) ? UInt256.Zero : UInt256.One);
return words * words;
return maxLength > 32 && spec.IsEip7883Enabled ? 2 * words * words : words * words;
}

/// <summary>
Expand All @@ -191,8 +191,9 @@ private static UInt256 MultComplexity(in UInt256 baseLength, in UInt256 modulusL
/// </summary>
/// <param name="exponentLength"></param>
/// <param name="exponent"></param>
/// <param name="spec"></param>
/// <returns></returns>
private static UInt256 CalculateIterationCount(UInt256 exponentLength, UInt256 exponent)
private static UInt256 CalculateIterationCount(UInt256 exponentLength, UInt256 exponent, IReleaseSpec spec)
{
try
{
Expand All @@ -209,7 +210,8 @@ private static UInt256 CalculateIterationCount(UInt256 exponentLength, UInt256 e
bitLength--;
}

bool overflow = UInt256.MultiplyOverflow((exponentLength - 32), 8, out UInt256 multiplicationResult);
var multiplier = (UInt256) (spec.IsEip7883Enabled ? 16 : 8);
bool overflow = UInt256.MultiplyOverflow(exponentLength - 32, multiplier, out UInt256 multiplicationResult);
overflow |= UInt256.AddOverflow(multiplicationResult, (UInt256)bitLength, out iterationCount);
if (overflow)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public bool IsOntakeEnabled
}
public bool IsEip7623Enabled => _spec.IsEip7623Enabled;

public bool IsEip7883Enabled => _spec.IsEip7883Enabled;

public bool IsEip3607Enabled { get; set; }

public bool IsEip158IgnoredAccount(Address address) => _spec.IsEip158IgnoredAccount(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public class ChainParameters
public ulong? OpGraniteTransitionTimestamp { get; set; }
public ulong? OpHoloceneTransitionTimestamp { get; set; }
public ulong? Eip7623TransitionTimestamp { get; set; }
public ulong? Eip7883TransitionTimestamp { get; set; }

public Dictionary<string, ChainSpecBlobCountJson> BlobSchedule { get; set; } = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ private ReleaseSpec CreateReleaseSpec(ChainSpec chainSpec, long releaseStartBloc
releaseSpec.IsEip7251Enabled = (chainSpec.Parameters.Eip7251TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp;
releaseSpec.Eip7251ContractAddress = chainSpec.Parameters.Eip7251ContractAddress;
releaseSpec.IsEip7623Enabled = (chainSpec.Parameters.Eip7623TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp;
releaseSpec.IsEip7883Enabled = (chainSpec.Parameters.Eip7883TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp;

releaseSpec.IsOntakeEnabled = (chainSpec.Parameters.OntakeTransition ?? long.MaxValue) <= releaseStartBlock;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ bool GetForInnerPathExistence(KeyValuePair<string, JsonElement> o) =>
() => chainSpecJson.Params.ChainId == BlockchainIds.Mainnet ? Eip6110Constants.MainnetDepositContractAddress : null),
Eip7002TransitionTimestamp = chainSpecJson.Params.Eip7002TransitionTimestamp,
Eip7623TransitionTimestamp = chainSpecJson.Params.Eip7623TransitionTimestamp,
Eip7883TransitionTimestamp = chainSpecJson.Params.Eip7883TransitionTimestamp,
Eip7002ContractAddress = chainSpecJson.Params.Eip7002ContractAddress ?? Eip7002Constants.WithdrawalRequestPredeployAddress,
Eip7251TransitionTimestamp = chainSpecJson.Params.Eip7251TransitionTimestamp,
Eip7251ContractAddress = chainSpecJson.Params.Eip7251ContractAddress ?? Eip7251Constants.ConsolidationRequestPredeployAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ internal class ChainSpecParamsJson
public Address Eip7251ContractAddress { get; set; }
public ulong? Rip7212TransitionTimestamp { get; set; }
public ulong? Eip7702TransitionTimestamp { get; set; }
public ulong? Eip7883TransitionTimestamp { get; set; }
public ulong? OpGraniteTransitionTimestamp { get; set; }
public ulong? OpHoloceneTransitionTimestamp { get; set; }
public Dictionary<string, ChainSpecBlobCountJson> BlobSchedule { get; set; } = [];
Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Specs/ReleaseSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public bool IsEip1559Enabled
public bool IsOpGraniteEnabled { get; set; }
public bool IsOpHoloceneEnabled { get; set; }
public bool IsEip7623Enabled { get; set; }
public bool IsEip7883Enabled { get; set; }
public bool IsEip5656Enabled { get; set; }
public bool IsEip6780Enabled { get; set; }
public bool IsEip4788Enabled { get; set; }
Expand Down
Loading