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

EIP 7742 implementation #7518

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
de19765
Get target_blob_count, max_blob_count from Engine Api
yerke26 Sep 30, 2024
eca6690
fix HeaderDecoder, restore Eip4844 changes, Add Eip7742
yerke26 Oct 1, 2024
7ac90df
Merge branch 'master' into feature/eip-7742
yerke26 Oct 1, 2024
9be8a53
fix HeaderDecoder
yerke26 Oct 1, 2024
c592412
move new params from ExecutionPayload to ExecutionPayloadV4
yerke26 Oct 1, 2024
f6ae01c
revert minor changes
yerke26 Oct 1, 2024
f803097
added new params to PayloadAttributes
yerke26 Oct 1, 2024
7043124
fix tests
yerke26 Oct 1, 2024
fef9cb2
fix whitespaces
yerke26 Oct 1, 2024
cc02ce5
add tests
yerke26 Oct 2, 2024
206d514
Merge branch 'master' into feature/eip-7742
yerke26 Oct 2, 2024
9fbb9c1
add missing fields
yerke26 Oct 4, 2024
8ada4e2
fix PayloadAttributes
yerke26 Oct 7, 2024
3ae0fed
add engine_forkchoiceUpdatedV4 to EngineRpcModule.Prague
yerke26 Oct 7, 2024
372868a
change to engine_forkchoiceUpdatedV4
yerke26 Oct 7, 2024
0bd75c6
Merge branch 'master' into feature/eip-7742
yerke26 Oct 7, 2024
4b5fbfc
add new fields to EngineModuleTests.V4
yerke26 Oct 7, 2024
5078b76
added new engine_forkchoiceUpdatedV4 to EngineRpcCapabilitiesProvider
yerke26 Oct 7, 2024
a92cdde
fix test cases
yerke26 Oct 8, 2024
c032480
Merge branch 'master' into feature/eip-7742
yerke26 Oct 8, 2024
4ab5fda
fix whitespace
yerke26 Oct 8, 2024
0ba2006
fix EngineRpcCapabilitiesProvider, revert ChainSpecBasedSpecProviderT…
yerke26 Oct 8, 2024
911d232
remove unnecessary comment
yerke26 Oct 8, 2024
f806f22
remove comments
yerke26 Oct 8, 2024
8dc3d6a
Merge branch 'master' into feature/eip-7742
yerke26 Oct 15, 2024
a993d59
Merge branch 'master' into feature/eip-7742
yerke26 Oct 30, 2024
ba1a3de
Merge branch 'master' into feature/eip-7742
yerke26 Nov 4, 2024
87e721a
add eip7742 logic to TryCalculateFeePerBlobGas
yerke26 Nov 4, 2024
e52fc98
remove MaxBlobCount, pass Spec to BlobGasCalculator
yerke26 Nov 4, 2024
49424d9
Merge branch 'master' into feature/eip-7742
yerke26 Nov 4, 2024
2162240
resolve merge conflicts
yerke26 Nov 4, 2024
9d4ec74
add MaxBlobCount in PayloadAttributes, refactoring, resolve comments
yerke26 Nov 5, 2024
d8e088c
fix tests
yerke26 Nov 5, 2024
793d085
Merge branch 'master' into feature/eip-7742
yerke26 Nov 5, 2024
a4fd1ef
fix Evm tool
yerke26 Nov 5, 2024
d022c4f
fix Evm tool
yerke26 Nov 5, 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
4 changes: 2 additions & 2 deletions src/Nethermind/Ethereum.Test.Base/GeneralTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ protected EthereumTestResult RunTest(GeneralStateTest test, ITxTracer txTracer)
BlobGasUsed = (ulong)test.ParentBlobGasUsed,
ExcessBlobGas = (ulong)test.ParentExcessBlobGas,
};
header.ExcessBlobGas = BlobGasCalculator.CalculateExcessBlobGas(parent, spec);
header.ExcessBlobGas = BlobGasCalculator.CalculateExcessBlobGas(parent, spec, header);
}

ValidationResult txIsValid = _txValidator.IsWellFormed(test.Transaction, spec);

if (txIsValid)
{
transactionProcessor.Execute(test.Transaction, new BlockExecutionContext(header), txTracer);
transactionProcessor.Execute(test.Transaction, new BlockExecutionContext(header, spec), txTracer);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ protected override BlockProcessor CreateBlockProcessor()
blockGasLimitContractTransition.Key,
new ReadOnlyTxProcessingEnv(
WorldStateManager,
BlockTree.AsReadOnly(), SpecProvider, LimboLogs.Instance));
BlockTree.AsReadOnly(), SpecProvider, LimboLogs.Instance),
SpecProvider);

GasLimitOverrideCache = new AuRaContractGasLimitOverride.Cache();
GasLimitCalculator = new AuRaContractGasLimitOverride(new[] { gasLimitContract }, GasLimitOverrideCache, false, new FollowOtherMiners(SpecProvider), LimboLogs.Instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Nethermind.Consensus.AuRa.Contracts;
using Nethermind.Core;
using Nethermind.Core.Extensions;
using Nethermind.Specs;
using NSubstitute;
using NUnit.Framework;

Expand All @@ -17,15 +18,15 @@ public class ReportingValidatorContractTests
[Test]
public void Should_generate_malicious_transaction()
{
ReportingValidatorContract contract = new(AbiEncoder.Instance, new Address("0x1000000000000000000000000000000000000001"), Substitute.For<ISigner>());
ReportingValidatorContract contract = new(AbiEncoder.Instance, new Address("0x1000000000000000000000000000000000000001"), Substitute.For<ISigner>(), TestSpecProvider.Instance);
Transaction transaction = contract.ReportMalicious(new Address("0x75df42383afe6bf5194aa8fa0e9b3d5f9e869441"), 10, new byte[0]);
transaction.Data.AsArray().ToHexString().Should().Be("c476dd4000000000000000000000000075df42383afe6bf5194aa8fa0e9b3d5f9e869441000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000");
}

[Test]
public void Should_generate_benign_transaction()
{
ReportingValidatorContract contract = new(AbiEncoder.Instance, new Address("0x1000000000000000000000000000000000000001"), Substitute.For<ISigner>());
ReportingValidatorContract contract = new(AbiEncoder.Instance, new Address("0x1000000000000000000000000000000000000001"), Substitute.For<ISigner>(), TestSpecProvider.Instance);
Transaction transaction = contract.ReportBenign(new Address("0x75df42383afe6bf5194aa8fa0e9b3d5f9e869441"), 10);
transaction.Data.AsArray().ToHexString().Should().Be("d69f13bb00000000000000000000000075df42383afe6bf5194aa8fa0e9b3d5f9e869441000000000000000000000000000000000000000000000000000000000000000a");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ protected override TxPoolTxSource CreateTxPoolTxSource()
TxPoolTxSource txPoolTxSource = base.CreateTxPoolTxSource();

TxPriorityContract = new TxPriorityContract(AbiEncoder.Instance, TestItem.AddressA,
new ReadOnlyTxProcessingEnv(WorldStateManager, BlockTree.AsReadOnly(), SpecProvider, LimboLogs.Instance));
new ReadOnlyTxProcessingEnv(WorldStateManager, BlockTree.AsReadOnly(), SpecProvider, LimboLogs.Instance), SpecProvider);

Priorities = new DictionaryContractDataStore<TxPriorityContract.Destination>(
new TxPriorityContract.DestinationSortedListContractDataStoreCollection(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Nethermind.Evm.Tracing;
using Nethermind.Evm.TransactionProcessing;
using Nethermind.Logging;
using Nethermind.Specs;
using Nethermind.State;
using NSubstitute;
using NUnit.Framework;
Expand Down Expand Up @@ -52,7 +53,8 @@ public void constructor_throws_ArgumentNullException_on_null_contractAddress()
null,
_stateProvider,
_readOnlyTxProcessorSource,
new Signer(0, TestItem.PrivateKeyD, LimboLogs.Instance));
new Signer(0, TestItem.PrivateKeyD, LimboLogs.Instance),
TestSpecProvider.Instance);
action.Should().Throw<ArgumentNullException>();
}

Expand All @@ -78,7 +80,8 @@ public void finalize_change_should_call_correct_transaction()
_contractAddress,
_stateProvider,
_readOnlyTxProcessorSource,
new Signer(0, TestItem.PrivateKeyD, LimboLogs.Instance));
new Signer(0, TestItem.PrivateKeyD, LimboLogs.Instance),
TestSpecProvider.Instance);

contract.FinalizeChange(_block.Header);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using NSubstitute;
using NUnit.Framework;
using Nethermind.Evm;
using Nethermind.Specs;

namespace Nethermind.AuRa.Test.Reward
{
Expand Down Expand Up @@ -61,21 +62,21 @@ public void SetUp()
[Test]
public void constructor_throws_ArgumentNullException_on_null_auraParameters()
{
Action action = () => new AuRaRewardCalculator(null, _abiEncoder, _transactionProcessor);
Action action = () => new AuRaRewardCalculator(null, _abiEncoder, _transactionProcessor, TestSpecProvider.Instance);
action.Should().Throw<ArgumentNullException>();
}

[Test]
public void constructor_throws_ArgumentNullException_on_null_encoder()
{
Action action = () => new AuRaRewardCalculator(_auraParameters, null, _transactionProcessor);
Action action = () => new AuRaRewardCalculator(_auraParameters, null, _transactionProcessor, TestSpecProvider.Instance);
action.Should().Throw<ArgumentNullException>();
}

[Test]
public void constructor_throws_ArgumentNullException_on_null_transactionProcessor()
{
Action action = () => new AuRaRewardCalculator(_auraParameters, _abiEncoder, null);
Action action = () => new AuRaRewardCalculator(_auraParameters, _abiEncoder, null, TestSpecProvider.Instance);
action.Should().Throw<ArgumentNullException>();
}

Expand All @@ -87,7 +88,7 @@ public void constructor_throws_ArgumentException_on_BlockRewardContractTransitio
{2, Address.FromNumber(2)}
};

Action action = () => new AuRaRewardCalculator(_auraParameters, _abiEncoder, _transactionProcessor);
Action action = () => new AuRaRewardCalculator(_auraParameters, _abiEncoder, _transactionProcessor, TestSpecProvider.Instance);
action.Should().Throw<ArgumentException>();
}

Expand All @@ -97,7 +98,7 @@ public void constructor_throws_ArgumentException_on_BlockRewardContractTransitio
public void calculates_rewards_correctly_before_contract_transition(long blockNumber, ulong expectedReward)
{
_block.Header.Number = blockNumber;
AuRaRewardCalculator calculator = new(_auraParameters, _abiEncoder, _transactionProcessor);
AuRaRewardCalculator calculator = new(_auraParameters, _abiEncoder, _transactionProcessor, TestSpecProvider.Instance);
BlockReward[] result = calculator.CalculateRewards(_block);
result.Should().BeEquivalentTo(new BlockReward(_block.Beneficiary, expectedReward));
}
Expand All @@ -106,7 +107,7 @@ public void calculates_rewards_correctly_before_contract_transition(long blockNu
public void calculates_rewards_correctly_for_genesis()
{
_block.Header.Number = 0;
AuRaRewardCalculator calculator = new(_auraParameters, _abiEncoder, _transactionProcessor);
AuRaRewardCalculator calculator = new(_auraParameters, _abiEncoder, _transactionProcessor, TestSpecProvider.Instance);
BlockReward[] result = calculator.CalculateRewards(_block);
result.Should().BeEmpty();
}
Expand All @@ -118,7 +119,7 @@ public void calculates_rewards_correctly_after_contract_transition(long blockNum
_block.Header.Number = blockNumber;
BlockReward expected = new(_block.Beneficiary, expectedReward, BlockRewardType.External);
SetupBlockRewards(new Dictionary<Address, BlockReward[]>() { { _address10, new[] { expected } } });
AuRaRewardCalculator calculator = new(_auraParameters, _abiEncoder, _transactionProcessor);
AuRaRewardCalculator calculator = new(_auraParameters, _abiEncoder, _transactionProcessor, TestSpecProvider.Instance);
BlockReward[] result = calculator.CalculateRewards(_block);
result.Should().BeEquivalentTo(expected);
}
Expand All @@ -144,7 +145,7 @@ public void calculates_rewards_correctly_after_subsequent_contract_transitions(l
_block.Header.Number = blockNumber;
BlockReward expected = new(_block.Beneficiary, expectedReward, BlockRewardType.External);
SetupBlockRewards(new Dictionary<Address, BlockReward[]>() { { address, new[] { expected } } });
AuRaRewardCalculator calculator = new(_auraParameters, _abiEncoder, _transactionProcessor);
AuRaRewardCalculator calculator = new(_auraParameters, _abiEncoder, _transactionProcessor, TestSpecProvider.Instance);
BlockReward[] result = calculator.CalculateRewards(_block);
result.Should().BeEquivalentTo(expected);
}
Expand All @@ -167,7 +168,7 @@ public void calculates_rewards_correctly_for_uncles(long blockNumber, ulong expe
};

SetupBlockRewards(new Dictionary<Address, BlockReward[]>() { { _address10, expected } });
AuRaRewardCalculator calculator = new(_auraParameters, _abiEncoder, _transactionProcessor);
AuRaRewardCalculator calculator = new(_auraParameters, _abiEncoder, _transactionProcessor, TestSpecProvider.Instance);
BlockReward[] result = calculator.CalculateRewards(_block);
result.Should().BeEquivalentTo(expected);
}
Expand All @@ -190,7 +191,7 @@ public void calculates_rewards_correctly_for_external_addresses()
};

SetupBlockRewards(new Dictionary<Address, BlockReward[]>() { { _address10, expected } });
AuRaRewardCalculator calculator = new(_auraParameters, _abiEncoder, _transactionProcessor);
AuRaRewardCalculator calculator = new(_auraParameters, _abiEncoder, _transactionProcessor, TestSpecProvider.Instance);
BlockReward[] result = calculator.CalculateRewards(_block);
result.Should().BeEquivalentTo(expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public async Task registry_contract_returns_not_found_when_key_doesnt_exist()
public async Task registry_contract_returns_not_found_when_contract_doesnt_exist()
{
using TestTxPermissionsBlockchain chain = await TestContractBlockchain.ForTest<TestTxPermissionsBlockchain, TxCertifierFilterTests>();
RegisterContract contract = new(AbiEncoder.Instance, Address.FromNumber(1000), chain.ReadOnlyTransactionProcessorSource);
RegisterContract contract = new(AbiEncoder.Instance, Address.FromNumber(1000), chain.ReadOnlyTransactionProcessorSource, _specProvider);
contract.TryGetAddress(chain.BlockTree.Head.Header, CertifierContract.ServiceTransactionContractRegistryName, out Address _).Should().BeFalse();
}

Expand All @@ -141,11 +141,12 @@ protected override BlockProcessor CreateBlockProcessor()
WorldStateManager,
BlockTree.AsReadOnly(), SpecProvider,
LimboLogs.Instance);
RegisterContract = new RegisterContract(abiEncoder, ChainSpec.Parameters.Registrar, ReadOnlyTransactionProcessorSource);
RegisterContract = new RegisterContract(abiEncoder, ChainSpec.Parameters.Registrar, ReadOnlyTransactionProcessorSource, Substitute.For<ISpecProvider>());
CertifierContract = new CertifierContract(
abiEncoder,
RegisterContract,
ReadOnlyTransactionProcessorSource);
ReadOnlyTransactionProcessorSource,
Substitute.For<ISpecProvider>());

return new AuRaBlockProcessor(
SpecProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void SetUp()
.Encode(AbiEncodingStyle.IncludeSignature, Arg.Is<AbiSignature>(s => s.Name == "finalizeChange"), Arg.Any<object[]>())
.Returns(_finalizeChangeData.TransactionData);

_validatorContract = new ValidatorContract(_transactionProcessor, _abiEncoder, _contractAddress, _stateProvider, _readOnlyTxProcessorSource, new Signer(0, TestItem.PrivateKeyD, LimboLogs.Instance));
_validatorContract = new ValidatorContract(_transactionProcessor, _abiEncoder, _contractAddress, _stateProvider, _readOnlyTxProcessorSource, new Signer(0, TestItem.PrivateKeyD, LimboLogs.Instance), TestSpecProvider.Instance);
}

[TearDown]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public TestEip4844Config(ulong? maxBlobGasPerBlock = null)

public ulong GasPerBlob => Eip4844Constants.GasPerBlob;

public int GetMaxBlobsPerBlock() => (int)(MaxBlobGasPerBlock / GasPerBlob);
public ulong GetMaxBlobsPerBlock() => MaxBlobGasPerBlock / GasPerBlob;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Nethermind.Core.Eip2930;
using Nethermind.Core.Specs;
using Nethermind.Crypto;
using Nethermind.Evm;
using Nethermind.Evm.Tracing;
using Nethermind.Evm.TransactionProcessing;
using Nethermind.Int256;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void StoreBeaconRoot(Block block, IReleaseSpec spec, ITxTracer tracer)

transaction.Hash = transaction.CalculateHash();

processor.Execute(transaction, header, tracer);
processor.Execute(transaction, new BlockExecutionContext(header, spec), tracer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ private void OnHeadChanged(object? sender, BlockReplacementEventArgs e)
BlockGasLimit = e.Block!.GasLimit;
CurrentBaseFee = e.Block.Header.BaseFeePerGas;
CurrentFeePerBlobGas =
BlobGasCalculator.TryCalculateFeePerBlobGas(e.Block.Header, out UInt256 currentFeePerBlobGas)
BlobGasCalculator.TryCalculateFeePerBlobGas(e.Block.Header, out UInt256 currentFeePerBlobGas,
SpecProvider.GetSpec(e.Block.Header))
? currentFeePerBlobGas
: UInt256.Zero;
HeadChanged?.Invoke(sender, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using Nethermind.Abi;
using Nethermind.Core;
using Nethermind.Core.Specs;
using Nethermind.Int256;
using Nethermind.Evm;
using Nethermind.Evm.Tracing;
Expand All @@ -24,7 +25,8 @@ public abstract class CallableContract : Contract
/// <param name="transactionProcessor">Transaction processor on which all <see cref="Call(Nethermind.Core.BlockHeader,Nethermind.Core.Transaction)"/> should be run on.</param>
/// <param name="abiEncoder">Binary interface encoder/decoder.</param>
/// <param name="contractAddress">Address where contract is deployed.</param>
protected CallableContract(ITransactionProcessor transactionProcessor, IAbiEncoder abiEncoder, Address contractAddress) : base(abiEncoder, contractAddress)
/// <param name="specProvider">Address where contract is deployed.</param>
protected CallableContract(ITransactionProcessor transactionProcessor, IAbiEncoder abiEncoder, Address contractAddress, ISpecProvider specProvider) : base(specProvider, abiEncoder, contractAddress)
{
_transactionProcessor = transactionProcessor ?? throw new ArgumentNullException(nameof(transactionProcessor));
}
Expand Down Expand Up @@ -66,7 +68,7 @@ private bool TryCall(BlockHeader header, Transaction transaction, out byte[] res

try
{
_transactionProcessor.Execute(transaction, new BlockExecutionContext(header), tracer);
_transactionProcessor.Execute(transaction, new BlockExecutionContext(header, SpecProvider.GetSpec(header)), tracer);
result = tracer.ReturnValue;
return tracer.StatusCode == StatusCode.Success;
}
Expand All @@ -87,7 +89,7 @@ private bool TryCall(BlockHeader header, Transaction transaction, out byte[] res
/// <param name="arguments">Arguments to the function.</param>
/// <returns>true if function was <see cref="StatusCode.Success"/> otherwise false.</returns>
protected bool TryCall(BlockHeader header, string functionName, Address sender, out object[] result, params object[] arguments) =>
TryCall(header, functionName, sender, DefaultContractGasLimit, out result, arguments);
TryCall(header, functionName, sender, DefaultContractGasLimit, out result);

/// <summary>
/// Same as <see cref="Call(Nethermind.Core.BlockHeader,AbiFunctionDescription,Address,object[])"/> but returns false instead of throwing <see cref="AbiException"/>.
Expand Down
10 changes: 7 additions & 3 deletions src/Nethermind/Nethermind.Blockchain/Contracts/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Nethermind.Blockchain.Contracts.Json;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Specs;
using Nethermind.Crypto;
using Nethermind.Int256;
using Nethermind.Evm;
Expand Down Expand Up @@ -36,18 +37,21 @@ public abstract partial class Contract
protected IAbiEncoder AbiEncoder { get; }
public AbiDefinition AbiDefinition { get; }
public Address? ContractAddress { get; protected set; }
protected ISpecProvider SpecProvider { get; set; }

/// <summary>
/// Creates contract
/// </summary>
/// <param name="specProvider">Binary interface encoder/decoder.</param>
/// <param name="abiEncoder">Binary interface encoder/decoder.</param>
/// <param name="contractAddress">Address where contract is deployed.</param>
/// <param name="abiDefinition">Binary definition of contract.</param>
protected Contract(IAbiEncoder? abiEncoder = null, Address? contractAddress = null, AbiDefinition? abiDefinition = null)
protected Contract(ISpecProvider specProvider, IAbiEncoder? abiEncoder = null, Address? contractAddress = null, AbiDefinition? abiDefinition = null)
{
AbiEncoder = abiEncoder ?? Abi.AbiEncoder.Instance;
ContractAddress = contractAddress;
AbiDefinition = abiDefinition ?? new AbiDefinitionParser().Parse(GetType());
SpecProvider = specProvider;
}

protected virtual Transaction GenerateTransaction<T>(Address? contractAddress, byte[] transactionData, Address sender, long gasLimit = DefaultContractGasLimit, BlockHeader header = null)
Expand Down Expand Up @@ -178,11 +182,11 @@ protected byte[] CallCore(ITransactionProcessor transactionProcessor, BlockHeade
{
if (callAndRestore)
{
transactionProcessor.CallAndRestore(transaction, new BlockExecutionContext(header), tracer);
transactionProcessor.CallAndRestore(transaction, new BlockExecutionContext(header, SpecProvider.GetSpec(header)), tracer);
}
else
{
transactionProcessor.Execute(transaction, new BlockExecutionContext(header), tracer);
transactionProcessor.Execute(transaction, new BlockExecutionContext(header, SpecProvider.GetSpec(header)), tracer);
}

failure = tracer.StatusCode != StatusCode.Success;
Expand Down
Loading
Loading