Skip to content

Commit

Permalink
Dencun corner cases (hyperledger#6060)
Browse files Browse the repository at this point in the history
* cherry pick changes from https://github.com/hyperledger/besu/pull/6054/files\#diff-22b78733e37a697fa8d1d8a02d2a87fe5ccea9cf67c34ce5e6311f024c14abd6L643-R738

Signed-off-by: Sally MacFarlane <[email protected]>

* cherry pick changes from https://github.com/hyperledger/besu/pull/6054/files\#diff-61db834b59eae5ce5c438462505de1add8fa244deda830742060d15f668a9806R39-R44

Signed-off-by: Sally MacFarlane <[email protected]>

* formatting

Signed-off-by: Sally MacFarlane <[email protected]>

* update the EIP-6110 acceptance tests

Signed-off-by: Danno Ferrin <[email protected]>

---------

Signed-off-by: Sally MacFarlane <[email protected]>
Signed-off-by: Danno Ferrin <[email protected]>
Co-authored-by: Danno Ferrin <[email protected]>
(cherry picked from commit 9d9fe8c)
Signed-off-by: Justin Florentine <[email protected]>
  • Loading branch information
2 people authored and jflo committed Nov 10, 2023
1 parent fd7d69e commit 956d1ab
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.hyperledger.besu.ethereum.mainnet;

import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.evm.account.MutableAccount;
import org.hyperledger.besu.evm.worldstate.WorldUpdater;

Expand All @@ -27,22 +28,27 @@
public interface ParentBeaconBlockRootHelper {

// Modulus to use for the timestamp to store the root
public static final long HISTORY_BUFFER_LENGTH = 8191;
public static final Address BEACON_ROOTS_ADDRESS =
long HISTORY_BUFFER_LENGTH = 8191;
Address BEACON_ROOTS_ADDRESS =
Address.fromHexString("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02");

static void storeParentBeaconBlockRoot(
final WorldUpdater worldUpdater, final long timestamp, final Bytes32 root) {
/*
see EIP-4788: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4788.md
*/
// If code is not deployed don't do anything
final MutableAccount account = worldUpdater.getOrCreate(BEACON_ROOTS_ADDRESS);
if (Hash.EMPTY.equals(account.getCodeHash())) {
return;
}

final long timestampReduced = Long.remainderUnsigned(timestamp, HISTORY_BUFFER_LENGTH);
final long timestampExtended = timestampReduced + HISTORY_BUFFER_LENGTH;

final UInt256 timestampIndex = UInt256.valueOf(timestampReduced);
final UInt256 rootIndex = UInt256.valueOf(timestampExtended);

final MutableAccount account = worldUpdater.getOrCreate(BEACON_ROOTS_ADDRESS);
account.setStorageValue(
timestampIndex, UInt256.fromBytes(Bytes.of(Longs.toByteArray(timestamp))));
account.setStorageValue(rootIndex, UInt256.fromBytes(root));
Expand Down

0 comments on commit 956d1ab

Please sign in to comment.