-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Demuirgos <ayman.bouchareb@outlook.fr> Co-authored-by: MarekM25 <marekm2504@gmail.com> Co-authored-by: Kamil Chodoła <kamil@nethermind.io>
- Loading branch information
1 parent
a8ccee7
commit b21823f
Showing
63 changed files
with
875 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 42 additions & 23 deletions
65
src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,57 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Core.Specs; | ||
using System; | ||
using Nethermind.Core; | ||
using Nethermind.Int256; | ||
using Nethermind.State; | ||
using Nethermind.Core.Crypto; | ||
using Nethermind.Core.Extensions; | ||
using Nethermind.Core.Specs; | ||
using Nethermind.Crypto; | ||
using Nethermind.Evm.Tracing; | ||
using Nethermind.Evm.TransactionProcessing; | ||
using Nethermind.Int256; | ||
using Nethermind.Logging; | ||
using Nethermind.State; | ||
|
||
namespace Nethermind.Consensus.BeaconBlockRoot; | ||
namespace Nethermind.Blockchain.BeaconBlockRoot; | ||
public class BeaconBlockRootHandler : IBeaconBlockRootHandler | ||
{ | ||
public static UInt256 HISTORICAL_ROOTS_LENGTH = 8191; | ||
private static readonly Address DefaultPbbrContractAddress = new Address("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02"); | ||
|
||
public void ApplyContractStateChanges(Block block, IReleaseSpec spec, IWorldState stateProvider) | ||
private readonly ITransactionProcessor _processor; | ||
private static Address Default4788Address = new Address("0x000f3df6d732807ef1319fb7b8bb8522d0beac02"); | ||
private readonly ILogger _logger; | ||
private const long GasLimit = 30_000_000L; | ||
public BeaconBlockRootHandler( | ||
ITransactionProcessor processor, | ||
ILogManager logManager) | ||
{ | ||
_processor = processor; | ||
_logger = logManager.GetClassLogger(); | ||
} | ||
public void ExecuteSystemCall(Block block, IReleaseSpec spec) | ||
{ | ||
BlockHeader? header = block.Header; | ||
if (!spec.IsBeaconBlockRootAvailable || | ||
block.IsGenesis || | ||
block.Header.ParentBeaconBlockRoot is null) return; | ||
Address? eip4788Account = spec.Eip4788ContractAddress ?? DefaultPbbrContractAddress; | ||
if (!stateProvider.AccountExists(eip4788Account)) | ||
return; | ||
|
||
UInt256 timestamp = (UInt256)block.Timestamp; | ||
Hash256 parentBeaconBlockRoot = block.ParentBeaconBlockRoot; | ||
|
||
UInt256.Mod(timestamp, HISTORICAL_ROOTS_LENGTH, out UInt256 timestampReduced); | ||
UInt256 rootIndex = timestampReduced + HISTORICAL_ROOTS_LENGTH; | ||
header.IsGenesis || | ||
header.ParentBeaconBlockRoot is null) return; | ||
|
||
StorageCell tsStorageCell = new(eip4788Account, timestampReduced); | ||
StorageCell brStorageCell = new(eip4788Account, rootIndex); | ||
Transaction? transaction = new() | ||
{ | ||
Value = UInt256.Zero, | ||
Data = header.ParentBeaconBlockRoot.Bytes.ToArray(), | ||
To = spec.Eip4788ContractAddress ?? Default4788Address, | ||
SenderAddress = Address.SystemUser, | ||
GasLimit = GasLimit, | ||
GasPrice = UInt256.Zero, | ||
}; | ||
transaction.Hash = transaction.CalculateHash(); | ||
|
||
stateProvider.Set(tsStorageCell, Bytes.WithoutLeadingZeros(timestamp.ToBigEndian()).ToArray()); | ||
stateProvider.Set(brStorageCell, Bytes.WithoutLeadingZeros(parentBeaconBlockRoot.Bytes).ToArray()); | ||
try | ||
{ | ||
_processor.Execute(transaction, header, NullTxTracer.Instance); | ||
} | ||
catch (Exception e) | ||
{ | ||
if (_logger.IsError) _logger.Error("Error during calling BeaconBlockRoot contract", e); | ||
} | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Core.Specs; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Specs; | ||
using Nethermind.State; | ||
|
||
namespace Nethermind.Consensus.BeaconBlockRoot; | ||
namespace Nethermind.Blockchain.BeaconBlockRoot; | ||
public interface IBeaconBlockRootHandler | ||
{ | ||
void ApplyContractStateChanges(Block block, IReleaseSpec spec, IWorldState state); | ||
void ExecuteSystemCall(Block block, IReleaseSpec spec); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
src/Nethermind/Nethermind.Consensus.AuRa/BeaconBlockRoot/NullBeaconBlockRootHandler.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.