Skip to content

Commit

Permalink
Unsigned timestamps and blob gas used (hyperledger#6046)
Browse files Browse the repository at this point in the history
* lots of places an unsigned timestamp is a problem
* adds unchecked annotations to OptionalUnsignedLong rpc parameter type

---------

Signed-off-by: Justin Florentine <[email protected]>
(cherry picked from commit a90ea05)
Signed-off-by: Justin Florentine <[email protected]>
  • Loading branch information
jflo committed Nov 10, 2023
1 parent 17741fb commit f4036d8
Showing 1 changed file with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
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 @@ -28,27 +27,22 @@
public interface ParentBeaconBlockRootHelper {

// Modulus to use for the timestamp to store the root
long HISTORY_BUFFER_LENGTH = 8191;
Address BEACON_ROOTS_ADDRESS =
public static final long HISTORY_BUFFER_LENGTH = 8191;
public static final 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 f4036d8

Please sign in to comment.