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 4788/beacon parent block root in evm #5476

Closed
wants to merge 52 commits into from

Conversation

Demuirgos
Copy link
Contributor

@Demuirgos Demuirgos commented Mar 21, 2023

Changes

  • Implements Eip4788
  • Adds BeaconStateRoot stateful precompile
  • Modifies BlockProcessor
  • Refactor access modifier of Precompile.Instance.Address field

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

@Demuirgos Demuirgos requested a review from MarekM25 March 30, 2023 14:14
@Demuirgos Demuirgos force-pushed the EIP-4788/BeaconStateRoot-in-EVM branch from aa05d72 to 68c4fce Compare May 4, 2023 12:43
@Demuirgos Demuirgos self-assigned this May 18, 2023
@Demuirgos Demuirgos force-pushed the EIP-4788/BeaconStateRoot-in-EVM branch from 9d4aadf to 7c35693 Compare June 13, 2023 16:30
@Demuirgos Demuirgos marked this pull request as ready for review June 13, 2023 19:15
Copy link
Contributor

@smartprogrammer93 smartprogrammer93 left a comment

Choose a reason for hiding this comment

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

Would advice to keep refactoring changes in separate PR.

Copy link
Contributor

@smartprogrammer93 smartprogrammer93 left a comment

Choose a reason for hiding this comment

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

Great, Still would put the refactoring changes in a separate PR <3

@Demuirgos Demuirgos added the eip label Jun 22, 2023
@Demuirgos Demuirgos force-pushed the EIP-4788/BeaconStateRoot-in-EVM branch from af267e2 to d95d388 Compare June 23, 2023 11:37
@Demuirgos Demuirgos requested review from a team and rubo as code owners June 23, 2023 11:37
@Demuirgos Demuirgos requested review from benaadams and removed request for rubo July 4, 2023 13:51
Span<byte> inputDataSpan = stackalloc byte[32];
inputData.PrepareEthInput(inputDataSpan);

UInt256 timestamp = new UInt256(inputDataSpan, true);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can avoid it with Unsafe? @benaadams

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.

wrong naming (BeaconStateRoot -> ParentBeaconBlockRoot)?

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.

Added a few comments.
Do you know about any hive tets/execution spec tests for this EIP?

@@ -38,6 +38,16 @@ public async Task ExccessDataGas_should_present_in_cancun_only((IReleaseSpec Spe
Is.EqualTo(input.IsExcessDataGasSet));
}

[TestCaseSource(nameof(BeacondStateRootGetPayloadV3ForDifferentSpecTestSource))]
Copy link
Contributor

Choose a reason for hiding this comment

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

no tests that verify if we can produce blocks with ParentBeaconBlockRoot and send them later through engine API?

no tests that we can't pass null ParentBeaconBlockRoot to payload attributes

src/Nethermind/Nethermind.Evm/Metrics.cs Outdated Show resolved Hide resolved
@Demuirgos Demuirgos force-pushed the EIP-4788/BeaconStateRoot-in-EVM branch 2 times, most recently from 9aabf7c to 224a831 Compare July 14, 2023 12:39
Comment on lines 27 to 36
stateProvider.CreateAccountIfNotExists(BeaconBlockRootPrecompile.Address, 1);

UInt256.Mod(timestamp, HISTORICAL_ROOTS_LENGTH, out UInt256 timestampReduced);
UInt256 rootIndex = timestampReduced + HISTORICAL_ROOTS_LENGTH;

StorageCell tsStorageCell = new(BeaconBlockRootPrecompile.Address, timestampReduced);
StorageCell brStorageCell = new(BeaconBlockRootPrecompile.Address, rootIndex);

stateProvider.Set(tsStorageCell, timestamp.ToBigEndian());
stateProvider.Set(brStorageCell, parentBeaconBlockRoot.Bytes.ToArray());
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be better if this code would live in some static method in BeaconBlockRootPrecompile?
You are touching its address, you are duplicating the logic of calculating indexes, doesn't make sense to be anywhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

funnily tho it was in a static method on IBeaconBlockRootPrecompile, but I dont think it's worth modifying now cause chances are it will be yeeeted out completely one the v2 comes arround

{
public void HandleBeaconBlockRoot(Block block, IReleaseSpec spec, IWorldState stateProvider)
{
if (!spec.IsBeaconBlockRootAvailable) return;
Copy link
Member

@LukaszRozmej LukaszRozmej Aug 7, 2023

Choose a reason for hiding this comment

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

Lets:

  1. Rename it to InitStatefulPrecompiles (Handler?)
  2. Create it in the BlockProcessor instead of injecting it, contrary to withdrawals which are consensus specific, this is directly controlled by spec, so doesn't make sense to inject different implementations - sorry if I confused you earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

perfect ig (it was painful to make it injectable xD)

@flcl42 flcl42 force-pushed the EIP-4788/BeaconStateRoot-in-EVM branch from aea2755 to 3d975ef Compare August 7, 2023 13:53
@Demuirgos Demuirgos force-pushed the EIP-4788/BeaconStateRoot-in-EVM branch from 81eeece to 895669d Compare August 9, 2023 12:48
@Demuirgos Demuirgos changed the base branch from master to cancun August 17, 2023 09:06
@Demuirgos Demuirgos changed the base branch from cancun to master August 17, 2023 09:28
@Demuirgos Demuirgos force-pushed the EIP-4788/BeaconStateRoot-in-EVM branch from 3142e87 to 26ddb49 Compare August 17, 2023 09:54
@Demuirgos Demuirgos closed this Aug 17, 2023
@rubo rubo deleted the EIP-4788/BeaconStateRoot-in-EVM branch December 20, 2023 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants