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

Implement EIP-7843 #7981

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
82fc1a9
start implementing eip7843
Marchhill Dec 30, 2024
2efd109
restore accidental changes
Marchhill Dec 30, 2024
ddd03fe
add precompile context and slot precompile files
Marchhill Dec 30, 2024
24bfed6
remove slot length stuff
Marchhill Dec 30, 2024
2b749ae
reset more accidental changes
Marchhill Dec 30, 2024
6f50553
fix tests & release spec
Marchhill Dec 31, 2024
27bf630
add slot number to block header and payloadattributes
Marchhill Dec 31, 2024
886317b
use payloadattributes slot number in shutter block building
Marchhill Dec 31, 2024
ee4988e
update usings and add TestPrecompileContext
Marchhill Dec 31, 2024
a7f9098
fix block handler tests
Marchhill Dec 31, 2024
74c7d7a
fix whitespace
Marchhill Dec 31, 2024
45268fb
fix precompile benchmarks
Marchhill Dec 31, 2024
20f5165
remove slot number from execution payload
Marchhill Jan 1, 2025
5c7a513
try to implement in newPayload parameter
Marchhill Jan 1, 2025
0a17173
add files
Marchhill Jan 1, 2025
cbe4bce
use whole executionenvironment in precompilecontext
Marchhill Jan 1, 2025
7962c06
add to block execution context
Marchhill Jan 1, 2025
57de0d9
move to newPayload instead of block header
Marchhill Jan 1, 2025
4f9d221
undo small changes
Marchhill Jan 2, 2025
5bf98d0
use slot number in shutter block handler
Marchhill Jan 2, 2025
7a92e05
fix, add to chainspec
Marchhill Jan 2, 2025
cdc86b0
shutter fallback to timestamp if slotnumber not in payloadattributes
Marchhill Jan 2, 2025
e3a0817
pass slot number in when producing block
Marchhill Jan 2, 2025
5cb46b2
fix payloadattributes order
Marchhill Jan 4, 2025
94b5b93
fix whitespace
Marchhill Jan 4, 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
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Consensus/EngineApiVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public static class EngineApiVersions
public const int Shanghai = 2;
public const int Cancun = 3;
public const int Prague = 4;
public const int Osaka = 5;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public TxReceipt[] ProcessTransactions(Block block, ProcessingOptions processing
return receiptsTracer.TxReceipts.ToArray();
}

protected virtual BlockExecutionContext CreateBlockExecutionContext(Block block) => new(block.Header);
protected virtual BlockExecutionContext CreateBlockExecutionContext(Block block) => new(block.Header, block.SlotNumber);

protected virtual void ProcessTransaction(in BlockExecutionContext blkCtx, Transaction currentTx, int index, BlockReceiptsTracer receiptsTracer, ProcessingOptions processingOptions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ protected virtual Block PrepareBlock(BlockHeader parent, PayloadAttributes? payl

IEnumerable<Transaction> transactions = _txSource.GetTransactions(parent, header.GasLimit, payloadAttributes);

return new BlockToProduce(header, transactions, Array.Empty<BlockHeader>(), payloadAttributes?.Withdrawals);
return new BlockToProduce(
header,
transactions,
Array.Empty<BlockHeader>(),
payloadAttributes?.Withdrawals,
payloadAttributes?.SlotNumber);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ public class BlockToProduce : Block
public BlockToProduce(BlockHeader blockHeader,
IEnumerable<Transaction> transactions,
IEnumerable<BlockHeader> uncles,
IEnumerable<Withdrawal>? withdrawals = null)
IEnumerable<Withdrawal>? withdrawals = null,
ulong? slotNumber = null)
: base(blockHeader, Array.Empty<Transaction>(), uncles, withdrawals)
{
Transactions = transactions;
SlotNumber = slotNumber;
}

public override Block WithReplacedHeader(BlockHeader newHeader) => new BlockToProduce(newHeader, Transactions, Uncles, Withdrawals);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class PayloadAttributes

public Hash256? ParentBeaconBlockRoot { get; set; }

public ulong? SlotNumber { get; set; }

public virtual long? GetGasLimit() => null;

public override string ToString() => ToString(string.Empty);
Expand All @@ -47,6 +49,11 @@ public string ToString(string indentation)
sb.Append($", {nameof(ParentBeaconBlockRoot)} : {ParentBeaconBlockRoot}");
}

if (SlotNumber is not null)
{
sb.Append($", {nameof(SlotNumber)}: {SlotNumber}");
}

sb.Append('}');

return sb.ToString();
Expand All @@ -71,7 +78,8 @@ protected virtual int ComputePayloadIdMembersSize() =>
+ Keccak.Size // prev randao
+ Address.Size // suggested fee recipient
+ (Withdrawals is null ? 0 : Keccak.Size) // withdrawals root hash
+ (ParentBeaconBlockRoot is null ? 0 : Keccak.Size); // parent beacon block root
+ (ParentBeaconBlockRoot is null ? 0 : Keccak.Size) // parent beacon block root
+ (SlotNumber is null ? 0 : sizeof(ulong)); // slot number

protected static string ComputePayloadId(Span<byte> inputSpan)
{
Expand Down Expand Up @@ -110,6 +118,12 @@ protected virtual int WritePayloadIdMembers(BlockHeader parentHeader, Span<byte>
position += Keccak.Size;
}

if (SlotNumber is not null)
{
BinaryPrimitives.WriteUInt64BigEndian(inputSpan.Slice(position, sizeof(ulong)), SlotNumber.Value);
position += sizeof(ulong);
}

return position;
}

Expand Down Expand Up @@ -166,6 +180,7 @@ public static class PayloadAttributesExtensions
public static int GetVersion(this PayloadAttributes executionPayload) =>
executionPayload switch
{
{ SlotNumber: not null } => EngineApiVersions.Osaka, // todo: set based on fork
{ ParentBeaconBlockRoot: not null, Withdrawals: not null } => EngineApiVersions.Cancun,
{ Withdrawals: not null } => EngineApiVersions.Shanghai,
_ => EngineApiVersions.Paris
Expand Down
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.Core/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ public Transaction[] Transactions

public Hash256? RequestsHash => Header.RequestsHash; // do not add setter here

[JsonIgnore]
public ulong? SlotNumber { get; set; }

[JsonIgnore]
public byte[][]? ExecutionRequests { get; set; }

Expand Down
7 changes: 7 additions & 0 deletions src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ public interface IReleaseSpec : IEip1559Spec, IReceiptSpec

public bool Bls381Enabled => IsEip2537Enabled;

public bool SlotEnabled => IsEip7843Enabled;

public bool ChargeForTopLevelCreate => IsEip2Enabled;

public bool FailOnOutOfGasCodeDeposit => IsEip2Enabled;
Expand Down Expand Up @@ -418,6 +420,11 @@ public interface IReleaseSpec : IEip1559Spec, IReceiptSpec

bool IsAuthorizationListEnabled => IsEip7702Enabled;

/// <summary>
/// EIP-7843: Slot precompile
/// </summary>
bool IsEip7843Enabled { get; }

public bool RequestsEnabled => ConsolidationRequestsEnabled || WithdrawalRequestsEnabled || DepositsEnabled;
}
}
2 changes: 2 additions & 0 deletions src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,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 virtual bool IsEip7843Enabled => spec.IsEip7843Enabled;
public virtual bool IsOpGraniteEnabled => spec.IsOpGraniteEnabled;
public virtual bool IsOpHoloceneEnabled => spec.IsOpHoloceneEnabled;
public virtual bool IsOntakeEnabled => spec.IsOntakeEnabled;
Expand All @@ -100,6 +101,7 @@ public class ReleaseSpecDecorator(IReleaseSpec spec) : IReleaseSpec
public virtual bool Bn128Enabled => spec.Bn128Enabled;
public virtual bool BlakeEnabled => spec.BlakeEnabled;
public virtual bool Bls381Enabled => spec.Bls381Enabled;
public virtual bool SlotEnabled => spec.SlotEnabled;
public virtual bool ChargeForTopLevelCreate => spec.ChargeForTopLevelCreate;
public virtual bool FailOnOutOfGasCodeDeposit => spec.FailOnOutOfGasCodeDeposit;
public virtual bool UseShanghaiDDosProtection => spec.UseShanghaiDDosProtection;
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Evm.Test/BlsG1AddPrecompileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public void Test()

foreach ((byte[] input, ReadOnlyMemory<byte> expectedResult) in Inputs)
{
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, MuirGlacier.Instance);
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, TestPrecompileContext.Instance);
output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray());
success.Should().BeTrue();
}

foreach ((byte[] input, ReadOnlyMemory<byte> expectedResult) in BadInputs)
{
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, MuirGlacier.Instance);
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, TestPrecompileContext.Instance);
output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray());
success.Should().BeFalse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Nethermind.Core.Extensions;
using Nethermind.Evm.Precompiles;
using Nethermind.Evm.Precompiles.Bls;
using Nethermind.Specs.Forks;
using NUnit.Framework;

namespace Nethermind.Evm.Test;
Expand All @@ -20,7 +19,7 @@ public void Test()
foreach ((byte[] input, ReadOnlyMemory<byte> expectedResult) in Inputs)
{
IPrecompile precompile = G1MSMPrecompile.Instance;
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, Prague.Instance);
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, TestPrecompileContext.Instance);
output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray());
success.Should().BeTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Nethermind.Core.Extensions;
using Nethermind.Evm.Precompiles;
using Nethermind.Evm.Precompiles.Bls;
using Nethermind.Specs.Forks;
using NUnit.Framework;

namespace Nethermind.Evm.Test;
Expand All @@ -20,7 +19,7 @@ public void Test()
foreach ((byte[] input, ReadOnlyMemory<byte> expectedResult) in Inputs)
{
IPrecompile precompile = G2AddPrecompile.Instance;
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, MuirGlacier.Instance);
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, TestPrecompileContext.Instance);
output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray());
success.Should().BeTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Nethermind.Evm.Precompiles;
using Nethermind.Evm.Precompiles.Bls;
using NUnit.Framework;
using Nethermind.Specs.Forks;

namespace Nethermind.Evm.Test;

Expand All @@ -20,7 +19,7 @@ public void Test()
foreach ((byte[] input, ReadOnlyMemory<byte> expectedResult) in Inputs)
{
IPrecompile precompile = G2MSMPrecompile.Instance;
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, Prague.Instance);
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, TestPrecompileContext.Instance);
output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray());
success.Should().BeTrue();
}
Expand Down
3 changes: 1 addition & 2 deletions src/Nethermind/Nethermind.Evm.Test/BlsMapFp2ToG2Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Nethermind.Core.Extensions;
using Nethermind.Evm.Precompiles;
using Nethermind.Evm.Precompiles.Bls;
using Nethermind.Specs.Forks;
using NUnit.Framework;

namespace Nethermind.Evm.Test;
Expand All @@ -20,7 +19,7 @@ public void Test()
foreach ((byte[] input, ReadOnlyMemory<byte> expectedResult) in Inputs)
{
IPrecompile precompile = MapFp2ToG2Precompile.Instance;
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, MuirGlacier.Instance);
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, TestPrecompileContext.Instance);

output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray());
success.Should().BeTrue();
Expand Down
3 changes: 1 addition & 2 deletions src/Nethermind/Nethermind.Evm.Test/BlsMapFpToG1Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Nethermind.Core.Extensions;
using Nethermind.Evm.Precompiles;
using Nethermind.Evm.Precompiles.Bls;
using Nethermind.Specs.Forks;
using NUnit.Framework;

namespace Nethermind.Evm.Test;
Expand All @@ -20,7 +19,7 @@ public void Test()
foreach ((byte[] input, ReadOnlyMemory<byte> expectedResult) in Inputs)
{
IPrecompile precompile = MapFpToG1Precompile.Instance;
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, MuirGlacier.Instance);
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, TestPrecompileContext.Instance);

output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray());
success.Should().BeTrue();
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Evm.Test/BlsMulG1PrecompileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public void Test()

foreach ((byte[] input, ReadOnlyMemory<byte> expectedResult) in Inputs)
{
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, MuirGlacier.Instance);
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, TestPrecompileContext.Instance);
output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray());
success.Should().BeTrue();
}

foreach ((byte[] input, ReadOnlyMemory<byte> expectedResult) in BadInputs)
{
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, MuirGlacier.Instance);
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, TestPrecompileContext.Instance);
output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray());
success.Should().BeFalse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Nethermind.Core.Extensions;
using Nethermind.Evm.Precompiles;
using Nethermind.Evm.Precompiles.Bls;
using Nethermind.Specs.Forks;
using NUnit.Framework;

namespace Nethermind.Evm.Test;
Expand All @@ -20,7 +19,7 @@ public void Test()
foreach ((byte[] input, ReadOnlyMemory<byte> expectedResult) in Inputs)
{
IPrecompile precompile = G2MulPrecompile.Instance;
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, MuirGlacier.Instance);
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, TestPrecompileContext.Instance);
output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray());
success.Should().BeTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Test()
foreach ((byte[] input, ReadOnlyMemory<byte> expectedResult) in Inputs)
{
IPrecompile precompile = PairingCheckPrecompile.Instance;
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, MuirGlacier.Instance);
(ReadOnlyMemory<byte> output, bool success) = precompile.Run(input, TestPrecompileContext.Instance);

output.ToArray().Should().BeEquivalentTo(expectedResult.ToArray());
success.Should().BeTrue();
Expand Down
3 changes: 1 addition & 2 deletions src/Nethermind/Nethermind.Evm.Test/BnAddPrecompileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Nethermind.Core.Extensions;
using Nethermind.Evm.Precompiles;
using Nethermind.Evm.Precompiles.Snarks;
using Nethermind.Specs.Forks;
using NUnit.Framework;

namespace Nethermind.Evm.Test;
Expand All @@ -31,7 +30,7 @@ public void Test()
for (int i = 0; i < inputs.Length; i++)
{
IPrecompile precompile = Bn254AddPrecompile.Instance;
_ = precompile.Run(inputs[i], MuirGlacier.Instance);
_ = precompile.Run(inputs[i], TestPrecompileContext.Instance);
}
}
}
3 changes: 1 addition & 2 deletions src/Nethermind/Nethermind.Evm.Test/BnMulPrecompileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Nethermind.Core.Extensions;
using Nethermind.Evm.Precompiles;
using Nethermind.Evm.Precompiles.Snarks;
using Nethermind.Specs.Forks;
using NUnit.Framework;

namespace Nethermind.Evm.Test;
Expand All @@ -31,7 +30,7 @@ public void Test()
for (int i = 0; i < inputs.Length; i++)
{
IPrecompile precompile = Bn254MulPrecompile.Instance;
_ = precompile.Run(inputs[i], MuirGlacier.Instance);
_ = precompile.Run(inputs[i], TestPrecompileContext.Instance);
}
}
}
3 changes: 1 addition & 2 deletions src/Nethermind/Nethermind.Evm.Test/BnPairPrecompileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Nethermind.Core.Extensions;
using Nethermind.Evm.Precompiles;
using Nethermind.Evm.Precompiles.Snarks;
using Nethermind.Specs.Forks;
using NUnit.Framework;

namespace Nethermind.Evm.Test;
Expand Down Expand Up @@ -62,7 +61,7 @@ public void Test()
{
byte[] cloned = inputs[i].Clone() as byte[];
IPrecompile precompile = Bn254PairingPrecompile.Instance;
_ = precompile.Run(cloned, MuirGlacier.Instance);
_ = precompile.Run(cloned, TestPrecompileContext.Instance);
}
}
}
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.Evm.Test/Eip2565Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Simple_routine([Random(int.MinValue, int.MaxValue, 100)] int seed)

Prepare input = Prepare.EvmCode.FromCode(randomInput);

(ReadOnlyMemory<byte>, bool) gmpPair = ModExpPrecompile.Instance.Run(input.Done.ToArray(), Berlin.Instance);
(ReadOnlyMemory<byte>, bool) gmpPair = ModExpPrecompile.Instance.Run(input.Done.ToArray(), TestPrecompileContext.Instance);
#pragma warning disable 618
(ReadOnlyMemory<byte>, bool) bigIntPair = ModExpPrecompile.OldRun(input.Done.ToArray());
#pragma warning restore 618
Expand All @@ -47,7 +47,7 @@ public void Overflow_gas_cost()
public void ModExp_run_should_not_throw_exception(string inputStr)
{
Prepare input = Prepare.EvmCode.FromCode(inputStr);
Assert.DoesNotThrow(() => ModExpPrecompile.Instance.Run(input.Done.ToArray(), London.Instance));
Assert.DoesNotThrow(() => ModExpPrecompile.Instance.Run(input.Done.ToArray(), TestPrecompileContext.Instance));
long gas = ModExpPrecompile.Instance.DataGasCost(input.Done, London.Instance);
gas.Should().Be(200);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class PointEvaluationPrecompileTests
[TestCaseSource(nameof(OutputTests))]
public bool Test_PointEvaluationPrecompile_Produces_Correct_Outputs(byte[] input)
{
(ReadOnlyMemory<byte> output, bool success) = PointEvaluationPrecompile.Instance.Run(input, Cancun.Instance);
(ReadOnlyMemory<byte> output, bool success) = PointEvaluationPrecompile.Instance.Run(input, TestPrecompileContext.Instance);
output.ToArray().Should().BeEquivalentTo(success ? _predefinedSuccessAnswer : _predefinedFailureAnswer);
return success;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using FluentAssertions;
using Nethermind.Core.Extensions;
using Nethermind.Evm.Precompiles;
using Nethermind.Specs.Forks;
using NUnit.Framework;

namespace Nethermind.Evm.Test
Expand Down Expand Up @@ -61,7 +60,7 @@ public class Secp256r1PrecompilePrecompileTests : VirtualMachineTestsBase
public void Produces_Correct_Outputs(string input, bool isValid)
{
var bytes = Bytes.FromHexString(input);
(ReadOnlyMemory<byte> output, bool success) = Secp256r1Precompile.Instance.Run(bytes, Prague.Instance);
(ReadOnlyMemory<byte> output, bool success) = Secp256r1Precompile.Instance.Run(bytes, TestPrecompileContext.Instance);
success.Should().BeTrue();
output.ToArray().Should().BeEquivalentTo(isValid ? ValidAnswer : []);
}
Expand All @@ -79,7 +78,7 @@ public void Produces_Correct_Outputs(string input, bool isValid)
public void Produces_Empty_Output_On_Invalid_Input(string input)
{
var bytes = Bytes.FromHexString(input);
(ReadOnlyMemory<byte> output, bool success) = Secp256r1Precompile.Instance.Run(bytes, Prague.Instance);
(ReadOnlyMemory<byte> output, bool success) = Secp256r1Precompile.Instance.Run(bytes, TestPrecompileContext.Instance);
success.Should().BeTrue();
output.Should().Be(ReadOnlyMemory<byte>.Empty);
}
Expand Down
Loading
Loading