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

[WIP]Add Eip6110 implementation #6849

Draft
wants to merge 38 commits into
base: master
Choose a base branch
from
Draft

[WIP]Add Eip6110 implementation #6849

wants to merge 38 commits into from

Conversation

Demuirgos
Copy link
Contributor

Fixes Closes Resolves #6274

Please choose one of the keywords above to refer to the issue this PR solves followed by the issue number (e.g. Fixes #000). If no issue number, remove the line. Also, remove everything marked optional that is not applicable. Remove this note after reading.

Changes

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Notes on testing

Optional. Remove if not applicable.

Documentation

Requires documentation update

  • Yes
  • No

If yes, link the PR to the docs update or the issue with the details labeled docs. Remove if not applicable.

Requires explanation in Release Notes

  • Yes
  • No

If yes, fill in the details here. Remove if not applicable.

Remarks

Optional. Remove if not applicable.

{
foreach (var log in receipts[i].Logs)
{
if (log.LoggersAddress == spec.Eip6110ContractAddress)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please find the address for various networks (holesky, sepolia, mainnet, chiado, gnosis) and hardcode them in ChainSpecBasedSpecProviderTests

{
var depositDecoder = new DepositDecoder();
Deposit? deposit = depositDecoder.Decode(new RlpStream(log.Data));
depositList[depositCount++] = deposit;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will throw exception if processedBlock has more deposits than suggested block

I am afriad that such exception won't be handled (perhaps, it should) and will destroy BlockProcessingQueue.

It means that you would be able to break Nethermind nodes by posting invalid block

@@ -24,15 +24,16 @@ public Block(BlockHeader header, BlockBody body)
BlockHeader header,
IEnumerable<Transaction> transactions,
IEnumerable<BlockHeader> uncles,
IEnumerable<Withdrawal>? withdrawals = null)
IEnumerable<Withdrawal>? withdrawals = null,
IEnumerable<Deposit>? deposits = null)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check where this constructor is being used and you will find a few obvious bugs

/// </summary>
public class Deposit
{
public byte[]? PublicKey { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there Engine API spec for this EIP? Names of fields matter for json serialization, here: https://eips.ethereum.org/EIPS/eip-6110 PubKey was used, but the correct names should come from Engine API

src/Nethermind/Nethermind.Core/Deposit.cs Show resolved Hide resolved
@@ -252,6 +252,9 @@ private static ReleaseSpec CreateReleaseSpec(ChainSpec chainSpec, long releaseSt
releaseSpec.IsEip4788Enabled = (chainSpec.Parameters.Eip4788TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp;
releaseSpec.Eip4788ContractAddress = chainSpec.Parameters.Eip4788ContractAddress;

releaseSpec.IsEip6110Enabled = (chainSpec.Parameters.Eip6110TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp;
releaseSpec.Eip6110ContractAddress = chainSpec.Parameters.Eip6110ContractAddress;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should we do if this EIP is specified in config, but no addres? should we stop application with info?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose so, as both inputs are required for correct config

src/Nethermind/Nethermind.Specs/Forks/17_Prague.cs Outdated Show resolved Hide resolved
Copy link
Contributor

@MarekM25 MarekM25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra things that requires thoughts/changes:

  • GenesisLoader - how deposits should be loaded by defaulf from chainspec if we start from Prague in genesis, I guess it should be empty deposit
    -EngineModuleTests - we need a few tests
  • BlockForRpc? with question mark not sure
  • exchangeCapabilitesHandler

Copy link
Contributor

@MarekM25 MarekM25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I see one more potential red flag:
I don't see changes in BlockProcessor. For example, for withdrawals which are very similar we have them here: https://github.com/NethermindEth/nethermind/blob/master/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs#L250

For EIP 7002 we have it here:
https://github.com/NethermindEth/nethermind/blob/feature/eip-7002/src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs#L256

Additionally, check how withdrawals handled root creation for block production, check those two classes:
WithdrawalProcessor
BlockProductionWithdrawalProcessor

It seems that 7002 started with different approach, we have to think about and make it consistent for withdrawals/6110/7002

@MarekM25 MarekM25 mentioned this pull request Apr 3, 2024
16 tasks
rjnrohit and others added 4 commits April 10, 2024 14:22
- moving code from BlockValidator to BlockProcessor
- fixing error discards
@Demuirgos Demuirgos requested review from ak88 and MarekM25 April 11, 2024 07:11
_logger = logManager.GetClassLogger();
}

public void ProcessDeposits(Block block, TxReceipt[] receipts, IReleaseSpec spec)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving IReleaseSpec to ctor instead, or alternatively remove it and make the if check before consumers call ProcessDeposits.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is not possible, you could pass specProvider only. To me this is okay

Demuirgos and others added 3 commits April 15, 2024 09:48
Co-authored-by: ak88 <anders.holmbjerg@hotmail.com>
Co-authored-by: ak88 <anders.holmbjerg@hotmail.com>
Co-authored-by: ak88 <anders.holmbjerg@hotmail.com>
Copy link
Contributor

@MarekM25 MarekM25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI is still red

@@ -116,4 +117,7 @@ public static class BlockErrorMessages

public const string NegativeGasUsed =
"NegativeGasUsed: Cannot be negative.";
public static string MissingDeposits => "MissingDeposits: Deposits cannot be null in block when EIP-6110 activated.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have such messages for deposits in BlockErrorMessages but we don't for withdrawals and 7002?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have MissingWithdrawals Error, I am not sure abt Eip7002 tho

@@ -19,7 +19,7 @@ internal static class BlockExtensions
public static Block CreateCopy(this Block block, BlockHeader header) =>
block is BlockToProduce blockToProduce
? new BlockToProduce(header, blockToProduce.Transactions, blockToProduce.Uncles, blockToProduce.Withdrawals)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Demuirgos @rjnrohit check this line carefully:
? new BlockToProduce(header, blockToProduce.Transactions, blockToProduce.Uncles, blockToProduce.Withdrawals)

analyze all usages of BlockToProduce constructor

@@ -355,6 +355,7 @@ async Task<(MergeTestBlockchain blockchain, IEngineRpcModule engineRpcModule)> M
Substitute.For<IAsyncHandler<byte[], ExecutionPayload?>>(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find EngineModuleTests.V4

if (log.LoggersAddress == spec.Eip6110ContractAddress)
{
var depositDecoder = new DepositDecoder();
Deposit? deposit = depositDecoder.Decode(new RlpStream(log.Data));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open question, probably to other teams as well: is it possible to get incorrect data here?

CalculateDepositsRoot(block, depositList, spec);
}

private void CalculateDepositsRoot(Block block, IEnumerable<Deposit> deposits, IReleaseSpec spec)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cosmetic a bit, but worth considering: Withdrawals only calculates root during the block production while exits and deposits always calculate the root.
cc: @rjnrohit @Demuirgos

@@ -252,6 +252,9 @@ private static ReleaseSpec CreateReleaseSpec(ChainSpec chainSpec, long releaseSt
releaseSpec.IsEip4788Enabled = (chainSpec.Parameters.Eip4788TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp;
releaseSpec.Eip4788ContractAddress = chainSpec.Parameters.Eip4788ContractAddress;

releaseSpec.IsEip6110Enabled = (chainSpec.Parameters.Eip6110TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp;
releaseSpec.Eip6110ContractAddress = chainSpec.Parameters.Eip6110ContractAddress;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Cosmetic) I think it would be nice to rename it to DepositContractAddress. This address could be used in the future in other places

private readonly IAsyncHandler<byte[], GetPayloadV4Result?> _getPayloadHandlerV4;

public Task<ResultWrapper<ForkchoiceUpdatedV1Result>> engine_forkchoiceUpdatedV4(ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes = null)
=> ForkchoiceUpdated(forkchoiceState, payloadAttributes, EngineApiVersions.Cancun);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change from EngineApiVersions.Cancun to EngineApiVersions.Prague

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prototype & implement EIP 6110
4 participants