Skip to content

Commit 770ee68

Browse files
committed
exclude empty requests from requests hash
Signed-off-by: Daniel Lehrner <[email protected]>
1 parent 6c952a3 commit 770ee68

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

datatypes/src/main/java/org/hyperledger/besu/datatypes/Hash.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,9 @@ public class Hash extends DelegatingBytes32 {
5252
public static final Hash EMPTY = hash(Bytes.EMPTY);
5353

5454
/**
55-
* Hash of empty requests or "0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f"
55+
* Hash of empty requests or "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
5656
*/
57-
public static final Hash EMPTY_REQUESTS_HASH =
58-
Hash.wrap(
59-
sha256(
60-
Bytes.concatenate(
61-
sha256(Bytes.of(RequestType.DEPOSIT.getSerializedType())),
62-
sha256(Bytes.of(RequestType.WITHDRAWAL.getSerializedType())),
63-
sha256(Bytes.of(RequestType.CONSOLIDATION.getSerializedType())))));
57+
public static final Hash EMPTY_REQUESTS_HASH = Hash.wrap(sha256(Bytes.EMPTY));
6458

6559
/**
6660
* Instantiates a new Hash.

datatypes/src/test/java/org/hyperledger/besu/datatypes/HashTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public void shouldGetExpectedValueForEmptyHash() {
3131
public void shouldGetExpectedValueForEmptyRequestsHash() {
3232
assertThat(Hash.EMPTY_REQUESTS_HASH)
3333
.isEqualTo(
34-
Hash.fromHexString(
35-
"0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f"));
34+
Hash.fromHexString("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
3635
}
3736
}

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidation.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static Hash withdrawalsRoot(final List<Withdrawal> withdrawals) {
9292
/**
9393
* Generates the requests hash for a list of requests
9494
*
95-
* @param requests list of request
95+
* @param requests list of request (must be sorted by request type ascending)
9696
* @return the requests hash
9797
*/
9898
public static Hash requestsHash(final List<Request> requests) {
@@ -101,10 +101,14 @@ public static Hash requestsHash(final List<Request> requests) {
101101
.forEach(
102102
i -> {
103103
final Request request = requests.get(i);
104-
final Bytes requestBytes =
105-
Bytes.concatenate(
106-
Bytes.of(request.getType().getSerializedType()), request.getData());
107-
requestHashes.add(sha256(requestBytes));
104+
105+
// empty requests are excluded from the hash
106+
if (!request.getData().isEmpty()) {
107+
final Bytes requestBytes =
108+
Bytes.concatenate(
109+
Bytes.of(request.getType().getSerializedType()), request.getData());
110+
requestHashes.add(sha256(requestBytes));
111+
}
108112
});
109113

110114
return Hash.wrap(sha256(Bytes.wrap(requestHashes)));

ethereum/core/src/test/java/org/hyperledger/besu/ethereum/chain/GenesisStateTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,14 @@ void genesisFromPrague(final DataStorageConfiguration dataStorageConfiguration)
327327
assertThat(header.getRequestsHash().get())
328328
.isEqualTo(
329329
Hash.fromHexString(
330-
"0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f"));
330+
"0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
331331
assertThat(header.getTargetBlobsPerBlock().isPresent()).isTrue();
332332
assertThat(header.getTargetBlobsPerBlock().get()).isEqualTo(UInt64.ONE);
333333

334334
assertThat(header.getHash())
335335
.isEqualTo(
336336
Hash.fromHexString(
337-
"0xdbc64edecb3a432e48cbd270b4a248ffc611b5f3dd666c8a10d546672cae17bd"));
337+
"0xdb3cb6f894b434d55c66cf6aeb3d12ab9acc276f130dad82d5791eef8b048f2e"));
338338
}
339339

340340
@Test

0 commit comments

Comments
 (0)