From d8406f0d200e03e1e9c3f52ee94eca4180c8a5e3 Mon Sep 17 00:00:00 2001 From: Stefan Pingel <16143240+pinges@users.noreply.github.com> Date: Tue, 5 Sep 2023 18:41:46 +1000 Subject: [PATCH 1/4] add parent beacon block root to payload id calculation (#5843) Signed-off-by: Stefan --- .../merge/blockcreation/MergeCoordinator.java | 7 +- .../blockcreation/PayloadIdentifier.java | 7 +- .../blockcreation/PayloadIdentifierTest.java | 93 +++++++++++++++++-- .../AbstractEngineForkchoiceUpdatedTest.java | 6 +- .../engine/AbstractEngineGetPayloadTest.java | 14 ++- .../engine/EngineGetPayloadV3Test.java | 1 + 6 files changed, 115 insertions(+), 13 deletions(-) diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java index 7b394b5b952..cac3edf952c 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/MergeCoordinator.java @@ -254,7 +254,12 @@ public PayloadIdentifier preparePayload( final PayloadIdentifier payloadIdentifier = PayloadIdentifier.forPayloadParams( - parentHeader.getBlockHash(), timestamp, prevRandao, feeRecipient, withdrawals); + parentHeader.getBlockHash(), + timestamp, + prevRandao, + feeRecipient, + withdrawals, + parentBeaconBlockRoot); if (blockCreationTasks.containsKey(payloadIdentifier)) { LOG.debug( diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/PayloadIdentifier.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/PayloadIdentifier.java index 6c946ba2ee2..ddd3c1b3e4e 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/PayloadIdentifier.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/blockcreation/PayloadIdentifier.java @@ -62,6 +62,7 @@ public PayloadIdentifier(final Long payloadId) { * @param prevRandao the prev randao * @param feeRecipient the fee recipient * @param withdrawals the withdrawals + * @param parentBeaconBlockRoot the parent beacon block root * @return the payload identifier */ public static PayloadIdentifier forPayloadParams( @@ -69,7 +70,8 @@ public static PayloadIdentifier forPayloadParams( final Long timestamp, final Bytes32 prevRandao, final Address feeRecipient, - final Optional> withdrawals) { + final Optional> withdrawals, + final Optional parentBeaconBlockRoot) { return new PayloadIdentifier( timestamp @@ -84,7 +86,8 @@ public static PayloadIdentifier forPayloadParams( .sorted(Comparator.comparing(Withdrawal::getIndex)) .map(Withdrawal::hashCode) .reduce(1, (a, b) -> a ^ (b * 31))) - .orElse(0)); + .orElse(0) + ^ ((long) parentBeaconBlockRoot.hashCode()) << 40); } @Override diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/PayloadIdentifierTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/PayloadIdentifierTest.java index 39597f9aabe..314224cf55d 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/PayloadIdentifierTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/blockcreation/PayloadIdentifierTest.java @@ -48,7 +48,12 @@ public void serializesToEvenHexRepresentation() { public void conversionCoverage() { var idTest = PayloadIdentifier.forPayloadParams( - Hash.ZERO, 1337L, Bytes32.random(), Address.fromHexString("0x42"), Optional.empty()); + Hash.ZERO, + 1337L, + Bytes32.random(), + Address.fromHexString("0x42"), + Optional.empty(), + Optional.empty()); assertThat(new PayloadIdentifier(idTest.getAsBigInteger().longValue())).isEqualTo(idTest); assertThat(new PayloadIdentifier(idTest.getAsBigInteger().longValue())).isEqualTo(idTest); } @@ -82,10 +87,20 @@ public void differentWithdrawalAmountsYieldDifferentHash() { final Bytes32 prevRandao = Bytes32.random(); var idForWithdrawals1 = PayloadIdentifier.forPayloadParams( - Hash.ZERO, 1337L, prevRandao, Address.fromHexString("0x42"), Optional.of(withdrawals1)); + Hash.ZERO, + 1337L, + prevRandao, + Address.fromHexString("0x42"), + Optional.of(withdrawals1), + Optional.empty()); var idForWithdrawals2 = PayloadIdentifier.forPayloadParams( - Hash.ZERO, 1337L, prevRandao, Address.fromHexString("0x42"), Optional.of(withdrawals2)); + Hash.ZERO, + 1337L, + prevRandao, + Address.fromHexString("0x42"), + Optional.of(withdrawals2), + Optional.empty()); assertThat(idForWithdrawals1).isNotEqualTo(idForWithdrawals2); } @@ -118,10 +133,20 @@ public void differentOrderedWithdrawalsYieldSameHash() { final Bytes32 prevRandao = Bytes32.random(); var idForWithdrawals1 = PayloadIdentifier.forPayloadParams( - Hash.ZERO, 1337L, prevRandao, Address.fromHexString("0x42"), Optional.of(withdrawals1)); + Hash.ZERO, + 1337L, + prevRandao, + Address.fromHexString("0x42"), + Optional.of(withdrawals1), + Optional.empty()); var idForWithdrawals2 = PayloadIdentifier.forPayloadParams( - Hash.ZERO, 1337L, prevRandao, Address.fromHexString("0x42"), Optional.of(withdrawals2)); + Hash.ZERO, + 1337L, + prevRandao, + Address.fromHexString("0x42"), + Optional.of(withdrawals2), + Optional.empty()); assertThat(idForWithdrawals1).isEqualTo(idForWithdrawals2); } @@ -130,10 +155,64 @@ public void emptyOptionalAndEmptyListWithdrawalsYieldDifferentHash() { final Bytes32 prevRandao = Bytes32.random(); var idForWithdrawals1 = PayloadIdentifier.forPayloadParams( - Hash.ZERO, 1337L, prevRandao, Address.fromHexString("0x42"), Optional.empty()); + Hash.ZERO, + 1337L, + prevRandao, + Address.fromHexString("0x42"), + Optional.empty(), + Optional.empty()); var idForWithdrawals2 = PayloadIdentifier.forPayloadParams( - Hash.ZERO, 1337L, prevRandao, Address.fromHexString("0x42"), Optional.of(emptyList())); + Hash.ZERO, + 1337L, + prevRandao, + Address.fromHexString("0x42"), + Optional.of(emptyList()), + Optional.empty()); + assertThat(idForWithdrawals1).isNotEqualTo(idForWithdrawals2); + } + + @Test + public void emptyOptionalAndNonEmptyParentBeaconBlockRootYieldDifferentHash() { + final Bytes32 prevRandao = Bytes32.random(); + var idForWithdrawals1 = + PayloadIdentifier.forPayloadParams( + Hash.ZERO, + 1337L, + prevRandao, + Address.fromHexString("0x42"), + Optional.empty(), + Optional.empty()); + var idForWithdrawals2 = + PayloadIdentifier.forPayloadParams( + Hash.ZERO, + 1337L, + prevRandao, + Address.fromHexString("0x42"), + Optional.empty(), + Optional.of(Bytes32.ZERO)); + assertThat(idForWithdrawals1).isNotEqualTo(idForWithdrawals2); + } + + @Test + public void differentParentBeaconBlockRootYieldDifferentHash() { + final Bytes32 prevRandao = Bytes32.random(); + var idForWithdrawals1 = + PayloadIdentifier.forPayloadParams( + Hash.ZERO, + 1337L, + prevRandao, + Address.fromHexString("0x42"), + Optional.empty(), + Optional.of(Bytes32.fromHexStringLenient("0x1"))); + var idForWithdrawals2 = + PayloadIdentifier.forPayloadParams( + Hash.ZERO, + 1337L, + prevRandao, + Address.fromHexString("0x42"), + Optional.empty(), + Optional.of(Bytes32.ZERO)); assertThat(idForWithdrawals1).isNotEqualTo(idForWithdrawals2); } } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java index 32dc15ffc57..63713c4bd0f 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java @@ -242,6 +242,7 @@ public void shouldReturnValidWithoutFinalizedWithPayload() { payloadParams.getTimestamp(), payloadParams.getPrevRandao(), payloadParams.getSuggestedFeeRecipient(), + Optional.empty(), Optional.empty()); when(mergeCoordinator.preparePayload( @@ -518,6 +519,7 @@ public void shouldReturnValidIfWithdrawalsIsNull_WhenWithdrawalsProhibited() { payloadParams.getTimestamp(), payloadParams.getPrevRandao(), payloadParams.getSuggestedFeeRecipient(), + Optional.empty(), Optional.empty()); when(mergeCoordinator.preparePayload( @@ -603,7 +605,8 @@ public void shouldReturnValidIfWithdrawalsIsNotNull_WhenWithdrawalsAllowed() { payloadParams.getTimestamp(), payloadParams.getPrevRandao(), payloadParams.getSuggestedFeeRecipient(), - withdrawals); + withdrawals, + Optional.empty()); when(mergeCoordinator.preparePayload( mockHeader, @@ -645,6 +648,7 @@ public void shouldReturnValidIfProtocolScheduleIsEmpty() { payloadParams.getTimestamp(), payloadParams.getPrevRandao(), payloadParams.getSuggestedFeeRecipient(), + Optional.empty(), Optional.empty()); when(mergeCoordinator.preparePayload( diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayloadTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayloadTest.java index 823cd6712ab..fd2f02ba024 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayloadTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineGetPayloadTest.java @@ -85,7 +85,12 @@ public AbstractEngineGetPayloadTest() { protected static final BlockResultFactory factory = new BlockResultFactory(); protected static final PayloadIdentifier mockPid = PayloadIdentifier.forPayloadParams( - Hash.ZERO, 1337L, Bytes32.random(), Address.fromHexString("0x42"), Optional.empty()); + Hash.ZERO, + 1337L, + Bytes32.random(), + Address.fromHexString("0x42"), + Optional.empty(), + Optional.empty()); protected static final BlockHeader mockHeader = new BlockHeaderTestFixture().prevRandao(Bytes32.random()).buildHeader(); private static final Block mockBlock = @@ -147,7 +152,12 @@ public void shouldFailForUnknownPayloadId() { resp( getMethodName(), PayloadIdentifier.forPayloadParams( - Hash.ZERO, 0L, Bytes32.random(), Address.fromHexString("0x42"), Optional.empty())); + Hash.ZERO, + 0L, + Bytes32.random(), + Address.fromHexString("0x42"), + Optional.empty(), + Optional.empty())); assertThat(resp).isInstanceOf(JsonRpcErrorResponse.class); verify(engineCallListener, times(1)).executionEngineCalled(); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3Test.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3Test.java index 3fc8a6bfd83..1e19bc3fd5d 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3Test.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3Test.java @@ -104,6 +104,7 @@ public void shouldReturnBlockForKnownPayloadId() { cancunHardfork.milestone(), Bytes32.random(), Address.fromHexString("0x42"), + Optional.empty(), Optional.empty()); BlobTestFixture blobTestFixture = new BlobTestFixture(); From a63bf3d8a1f510f84e61356150ed2fe83aadd9fa Mon Sep 17 00:00:00 2001 From: Daniel Lehrner Date: Wed, 6 Sep 2023 10:42:27 +0200 Subject: [PATCH 2/4] bump version to 23.7.3-SNAPSHOT (#5854) Signed-off-by: Daniel Lehrner --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index d8ed3fba79c..32a11f7cc8c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=23.7.2-SNAPSHOT +version=23.7.3-SNAPSHOT org.gradle.welcome=never # Set exports/opens flags required by Google Java Format and ErrorProne plugins. (JEP-396) From cb82010868200b46ea932522aaa8aadc02ff0429 Mon Sep 17 00:00:00 2001 From: Stefan Pingel <16143240+pinges@users.noreply.github.com> Date: Wed, 6 Sep 2023 21:24:27 +1000 Subject: [PATCH 3/4] set the beacon root address to the correct value (#5853) Signed-off-by: Stefan --- .../hyperledger/besu/datatypes/Address.java | 22 ++++++++----------- .../mainnet/ParentBeaconBlockRootHelper.java | 20 ++++------------- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/datatypes/src/main/java/org/hyperledger/besu/datatypes/Address.java b/datatypes/src/main/java/org/hyperledger/besu/datatypes/Address.java index 6fa4de418ef..0897617c834 100644 --- a/datatypes/src/main/java/org/hyperledger/besu/datatypes/Address.java +++ b/datatypes/src/main/java/org/hyperledger/besu/datatypes/Address.java @@ -59,28 +59,24 @@ public class Address extends DelegatingBytes { public static final Address BLAKE2B_F_COMPRESSION = Address.precompiled(0x09); /** The constant KZG_POINT_EVAL aka POINT_EVALUATION_PRECOMPILE_ADDRESS. */ public static final Address KZG_POINT_EVAL = Address.precompiled(0xA); - /** The constant PARENT_BEACON_BLOCK_ROOT_REGISTRY aka HISTORY_STORAGE_ADDRESS. */ - public static final Address PARENT_BEACON_BLOCK_ROOT_REGISTRY = Address.precompiled(0xB); - // TODO: this is not a precompile anymore. The address is correct for testnet 8. Fix after testnet - // 8 when we know what the real address is /** The constant BLS12_G1ADD. */ - public static final Address BLS12_G1ADD = Address.precompiled(0xC); + public static final Address BLS12_G1ADD = Address.precompiled(0xB); /** The constant BLS12_G1MUL. */ - public static final Address BLS12_G1MUL = Address.precompiled(0xD); + public static final Address BLS12_G1MUL = Address.precompiled(0xC); /** The constant BLS12_G1MULTIEXP. */ - public static final Address BLS12_G1MULTIEXP = Address.precompiled(0xE); + public static final Address BLS12_G1MULTIEXP = Address.precompiled(0xD); /** The constant BLS12_G2ADD. */ - public static final Address BLS12_G2ADD = Address.precompiled(0xF); + public static final Address BLS12_G2ADD = Address.precompiled(0xE); /** The constant BLS12_G2MUL. */ - public static final Address BLS12_G2MUL = Address.precompiled(0x10); + public static final Address BLS12_G2MUL = Address.precompiled(0xF); /** The constant BLS12_G2MULTIEXP. */ - public static final Address BLS12_G2MULTIEXP = Address.precompiled(0x11); + public static final Address BLS12_G2MULTIEXP = Address.precompiled(0x10); /** The constant BLS12_PAIRING. */ - public static final Address BLS12_PAIRING = Address.precompiled(0x12); + public static final Address BLS12_PAIRING = Address.precompiled(0x11); /** The constant BLS12_MAP_FP_TO_G1. */ - public static final Address BLS12_MAP_FP_TO_G1 = Address.precompiled(0x13); + public static final Address BLS12_MAP_FP_TO_G1 = Address.precompiled(0x12); /** The constant BLS12_MAP_FP2_TO_G2. */ - public static final Address BLS12_MAP_FP2_TO_G2 = Address.precompiled(0x14); + public static final Address BLS12_MAP_FP2_TO_G2 = Address.precompiled(0x13); /** The constant ZERO. */ public static final Address ZERO = Address.fromHexString("0x0"); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ParentBeaconBlockRootHelper.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ParentBeaconBlockRootHelper.java index 39d5b664fbe..8b9cf256aef 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ParentBeaconBlockRootHelper.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ParentBeaconBlockRootHelper.java @@ -26,24 +26,13 @@ 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 final Address BEACON_ROOTS_ADDRESS = + Address.fromHexString("0xbEac00dDB15f3B6d645C48263dC93862413A222D"); 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) + see EIP-4788: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4788.md */ final long timestampReduced = timestamp % HISTORICAL_ROOTS_MODULUS; final long timestampExtended = timestampReduced + HISTORICAL_ROOTS_MODULUS; @@ -51,8 +40,7 @@ public static void storeParentBeaconBlockRoot( final UInt256 timestampIndex = UInt256.valueOf(timestampReduced); final UInt256 rootIndex = UInt256.valueOf(timestampExtended); - final MutableAccount account = - worldUpdater.getOrCreate(Address.PARENT_BEACON_BLOCK_ROOT_REGISTRY).getMutable(); + final MutableAccount account = worldUpdater.getOrCreate(BEACON_ROOTS_ADDRESS).getMutable(); account.setStorageValue(timestampIndex, UInt256.valueOf(timestamp)); account.setStorageValue(rootIndex, UInt256.fromBytes(root)); worldUpdater.commit(); From b74d39268f66d44e2a6f40f0601e7516aee33347 Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Wed, 6 Sep 2023 17:56:03 -0700 Subject: [PATCH 4/4] docs(readme): fix broken link to installation of binaries page (#5859) Fixes #5858 Signed-off-by: Peter Somogyvari --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 98560c66ed6..38eb3e7725f 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ If you have any questions, queries or comments, [Besu channel on Hyperledger Dis ## Besu Users -To install the Besu binary, follow [these instructions](https://besu.hyperledger.org/HowTo/Get-Started/Install-Binaries/). +To install the Besu binary, follow [these instructions](https://besu.hyperledger.org/public-networks/get-started/install/binary-distribution). ## Besu Developers