-
Notifications
You must be signed in to change notification settings - Fork 492
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 <[email protected]> Co-authored-by: MarekM25 <[email protected]>
- Loading branch information
1 parent
9fa73bf
commit c56ef8a
Showing
65 changed files
with
860 additions
and
241 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
70 changes: 44 additions & 26 deletions
70
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,39 +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 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 ?? Eip4788Constants.BeaconRootsAddress; | ||
|
||
if (!stateProvider.AccountExists(eip4788Account)) | ||
return; | ||
|
||
UInt256 timestamp = (UInt256)block.Timestamp; | ||
Hash256 parentBeaconBlockRoot = block.ParentBeaconBlockRoot; | ||
|
||
UInt256.Mod(timestamp, Eip4788Constants.HistoryBufferLength, out UInt256 timestampReduced); | ||
UInt256 rootIndex = timestampReduced + Eip4788Constants.HistoryBufferLength; | ||
|
||
StorageCell tsStorageCell = new(eip4788Account, timestampReduced); | ||
StorageCell brStorageCell = new(eip4788Account, rootIndex); | ||
|
||
stateProvider.Set(tsStorageCell, Bytes.WithoutLeadingZeros(timestamp.ToBigEndian()).ToArray()); | ||
stateProvider.Set(brStorageCell, Bytes.WithoutLeadingZeros(parentBeaconBlockRoot.Bytes).ToArray()); | ||
header.IsGenesis || | ||
header.ParentBeaconBlockRoot is null) return; | ||
|
||
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(); | ||
|
||
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.