-
Notifications
You must be signed in to change notification settings - Fork 438
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
Changes from 26 commits
962de19
ec00aec
30f15e0
17a58e2
927c006
28edbd4
b900af3
a4e316f
c911bd6
73f9d08
0b6c02d
4c8c401
46108e8
ae7c4fd
6297784
768c1ef
b286950
27bb1ff
fc7ed2d
61c949f
13d3c1d
b2a1456
8d45da3
dcf7998
011687d
5c2da2f
cac566f
ce1cb7c
8b411d5
c2d1876
2a822bb
3d975ef
467d74c
06d9491
2e3c632
763d032
c4c4b12
1447648
3a5379a
7ed2ab4
a9a7e36
f8c8b9b
895669d
ddb0262
1edb452
4877dd6
4da6ccd
dc1b94e
1a718f3
706c8dc
26ddb49
e0f109a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Nethermind.Core.Specs; | ||
using Nethermind.Core; | ||
using Nethermind.Evm.Precompiles.Stateful; | ||
using Nethermind.Int256; | ||
using Nethermind.State; | ||
using static Nethermind.Evm.Precompiles.Stateful.BeaconBlockRootPrecompile; | ||
|
||
|
||
namespace Nethermind.Consensus.BeaconBlockRoot; | ||
public class BeaconBlockRootHandler : IBeaconBlockRootHandler | ||
{ | ||
public void HandleBeaconBlockRoot(Block block, IReleaseSpec spec, IWorldState stateProvider) | ||
{ | ||
if (!spec.IsBeaconBlockRootAvailable) return; | ||
|
||
var timestamp = (UInt256)block.Timestamp; | ||
var parentBeaconBlockRoot = block.ParentBeaconBlockRoot; | ||
|
||
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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Nethermind.Core.Specs; | ||
using Nethermind.Core; | ||
using Nethermind.State; | ||
|
||
namespace Nethermind.Consensus.BeaconBlockRoot; | ||
public interface IBeaconBlockRootHandler | ||
{ | ||
void HandleBeaconBlockRoot(Block block, IReleaseSpec spec, IWorldState state); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Nethermind.Consensus.BeaconBlockRoot; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Specs; | ||
using Nethermind.State; | ||
|
||
namespace Nethermind.Consensus.AuRa.BeaconBlockRoot; | ||
internal class NullBeaconBlockRootHandler : IBeaconBlockRootHandler | ||
{ | ||
public void HandleBeaconBlockRoot(Block block, IReleaseSpec spec, IWorldState state) | ||
{ | ||
} | ||
|
||
public static IBeaconBlockRootHandler Instance { get; } = new NullBeaconBlockRootHandler(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets:
There was a problem hiding this comment.
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)