Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude empty requests from requests hash #8036

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions datatypes/src/main/java/org/hyperledger/besu/datatypes/Hash.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,9 @@ public class Hash extends DelegatingBytes32 {
public static final Hash EMPTY = hash(Bytes.EMPTY);

/**
* Hash of empty requests or "0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f"
* Hash of empty requests or "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
*/
public static final Hash EMPTY_REQUESTS_HASH =
Hash.wrap(
sha256(
Bytes.concatenate(
sha256(Bytes.of(RequestType.DEPOSIT.getSerializedType())),
sha256(Bytes.of(RequestType.WITHDRAWAL.getSerializedType())),
sha256(Bytes.of(RequestType.CONSOLIDATION.getSerializedType())))));
public static final Hash EMPTY_REQUESTS_HASH = Hash.wrap(sha256(Bytes.EMPTY));

/**
* Instantiates a new Hash.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public void shouldGetExpectedValueForEmptyHash() {
public void shouldGetExpectedValueForEmptyRequestsHash() {
assertThat(Hash.EMPTY_REQUESTS_HASH)
.isEqualTo(
Hash.fromHexString(
"0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f"));
Hash.fromHexString("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static Hash withdrawalsRoot(final List<Withdrawal> withdrawals) {
/**
* Generates the requests hash for a list of requests
*
* @param requests list of request
* @param requests list of request (must be sorted by request type ascending)
* @return the requests hash
*/
public static Hash requestsHash(final List<Request> requests) {
Expand All @@ -101,10 +101,14 @@ public static Hash requestsHash(final List<Request> requests) {
.forEach(
i -> {
final Request request = requests.get(i);
final Bytes requestBytes =
Bytes.concatenate(
Bytes.of(request.getType().getSerializedType()), request.getData());
requestHashes.add(sha256(requestBytes));

// empty requests are excluded from the hash
if (!request.getData().isEmpty()) {
final Bytes requestBytes =
Bytes.concatenate(
Bytes.of(request.getType().getSerializedType()), request.getData());
requestHashes.add(sha256(requestBytes));
}
});

return Hash.wrap(sha256(Bytes.wrap(requestHashes)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,14 @@ void genesisFromPrague(final DataStorageConfiguration dataStorageConfiguration)
assertThat(header.getRequestsHash().get())
.isEqualTo(
Hash.fromHexString(
"0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f"));
"0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
assertThat(header.getTargetBlobsPerBlock().isPresent()).isTrue();
assertThat(header.getTargetBlobsPerBlock().get()).isEqualTo(UInt64.ONE);

assertThat(header.getHash())
.isEqualTo(
Hash.fromHexString(
"0xdbc64edecb3a432e48cbd270b4a248ffc611b5f3dd666c8a10d546672cae17bd"));
"0xdb3cb6f894b434d55c66cf6aeb3d12ab9acc276f130dad82d5791eef8b048f2e"));
}

@Test
Expand Down
Loading