mirror of https://github.com/hyperledger/besu
Eip4788 parentBeaconBlockRoot (#5758)
Implement EIP 4788 Unit tests need to be added Implementation is working for test net 8, address of the contract will probably change EIP 4788 is still not finalized. Some changes might be necessary. Signed-off-by: Stefan <stefan.pingel@consensys.net> Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com> Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>pull/5783/head
parent
c3c7205fe8
commit
47285a48f6
@ -0,0 +1,39 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu Contributors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine; |
||||
|
||||
import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator; |
||||
import org.hyperledger.besu.ethereum.ProtocolContext; |
||||
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; |
||||
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; |
||||
|
||||
import io.vertx.core.Vertx; |
||||
|
||||
public class EngineForkchoiceUpdatedV3 extends AbstractEngineForkchoiceUpdated { |
||||
|
||||
public EngineForkchoiceUpdatedV3( |
||||
final Vertx vertx, |
||||
final ProtocolSchedule protocolSchedule, |
||||
final ProtocolContext protocolContext, |
||||
final MergeMiningCoordinator mergeCoordinator, |
||||
final EngineCallListener engineCallListener) { |
||||
super(vertx, protocolSchedule, protocolContext, mergeCoordinator, engineCallListener); |
||||
} |
||||
|
||||
@Override |
||||
public String getName() { |
||||
return RpcMethod.ENGINE_FORKCHOICE_UPDATED_V3.getMethodName(); |
||||
} |
||||
} |
@ -0,0 +1,60 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu Contributors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.mainnet; |
||||
|
||||
import org.hyperledger.besu.datatypes.Address; |
||||
import org.hyperledger.besu.evm.account.MutableAccount; |
||||
import org.hyperledger.besu.evm.worldstate.WorldUpdater; |
||||
|
||||
import org.apache.tuweni.bytes.Bytes32; |
||||
import org.apache.tuweni.units.bigints.UInt256; |
||||
|
||||
/** A helper class to store the parent beacon block root. */ |
||||
public class ParentBeaconBlockRootHelper { |
||||
|
||||
// Modulus use to for the timestamp to store the root
|
||||
public static final long HISTORICAL_ROOTS_MODULUS = 98304; |
||||
|
||||
// Address of the system user, that is used to call the contract for storing the root
|
||||
// public static final Address SYSTEM_ADDRESS =
|
||||
// Address.fromHexString("0xfffffffffffffffffffffffffffffffffffffffe");
|
||||
|
||||
// The address of the contract that stores the roots
|
||||
// public static final Address BEACON_ROOTS_ADDRESS =
|
||||
// Address.fromHexString("0x89e64Be8700cC37EB34f9209c96466DEEDc0d8a6");
|
||||
|
||||
public static void storeParentBeaconBlockRoot( |
||||
final WorldUpdater worldUpdater, final long timestamp, final Bytes32 root) { |
||||
/* |
||||
pseudo code from EIP 4788: |
||||
timestamp_as_uint256 = to_uint256_be(block_header.timestamp) |
||||
parent_beacon_block_root = block_header.parent_beacon_block_root |
||||
|
||||
sstore(HISTORY_STORAGE_ADDRESS, timestamp_index, timestamp_as_uint256) |
||||
sstore(HISTORY_STORAGE_ADDRESS, root_index, parent_beacon_block_root) |
||||
*/ |
||||
final long timestampReduced = timestamp % HISTORICAL_ROOTS_MODULUS; |
||||
final long timestampExtended = timestampReduced + HISTORICAL_ROOTS_MODULUS; |
||||
|
||||
final UInt256 timestampIndex = UInt256.valueOf(timestampReduced); |
||||
final UInt256 rootIndex = UInt256.valueOf(timestampExtended); |
||||
|
||||
final MutableAccount account = |
||||
worldUpdater.getOrCreate(Address.PARENT_BEACON_BLOCK_ROOT_REGISTRY).getMutable(); |
||||
account.setStorageValue(timestampIndex, UInt256.valueOf(timestamp)); |
||||
account.setStorageValue(rootIndex, UInt256.fromBytes(root)); |
||||
worldUpdater.commit(); |
||||
} |
||||
} |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@ |
||||
<< (9ee7c86c) {"jsonrpc":"2.0","id":12,"result":{"executionPayload":{"parentHash":"0x90c8b9e1e8e51584453f5516036bfe0031ebb595e47c5fd664bd56471ce618d6","feeRecipient":"0x0000000000000000000000000000000000000000","stateRoot":"0xfb58f52e7d31c6d3232b10a33799f7b5b8f7b883a8cbdd0c41cdefb207de4648","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","prevRandao":"0xe7f1a1fb5c08adeb1e62a01f58dda79626f9ab56bce81f8ffa587b3045e007bb","gasLimit":"0x2ffbd8","gasUsed":"0x0","timestamp":"0x1237","extraData":"0x","baseFeePerGas":"0x28482258","excessBlobGas":"0x0","parentBeaconBlockRoot":"0xe19f3a77f925a661b19f84ba74acddd84c121b4813b7470d91df7d3270667511","transactions":[],"withdrawals":[],"blockNumber":"0x3","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","blobGasUsed":"0x0","blockHash":"0x69607c0fc6af60144538ad4c3028d0ac86baa0cd45fbc1c080b2d5f095811c84"},"blockValue":"0x0","blobsBundle":{"commitments":[],"proofs":[],"blobs":[]}}} |
Loading…
Reference in new issue