mirror of
https://github.com/vacp2p/status-linea-besu.git
synced 2026-01-09 13:58:02 -05:00
Exclude empty requests from requests hash (#8036)
* exclude empty requests from requests hash Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net> * Exclude empty requests and prepend request type byte in engine_getPayloadV4 Fixes https://github.com/ethereum/execution-apis/pull/599 change to EIP-7685 Signed-off-by: Simon Dudley <simon.dudley@consensys.net> * fix test Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net> * fix prague tests: change request hash, reorder json elements Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net> * fix extracting of request for new payload Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net> * fix test by fixing request object creation Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net> * spotless Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net> * set request type to only one byte, fixed creation of request list in T8nExecutor Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net> * fix expected json output to exclude empty requests Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net> --------- Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net> Signed-off-by: Simon Dudley <simon.dudley@consensys.net> Co-authored-by: Simon Dudley <simon.dudley@consensys.net>
This commit is contained in:
@@ -140,8 +140,8 @@ public class CodeDelegationTransactionAcceptanceTest extends AcceptanceTestBase
|
||||
*/
|
||||
@Test
|
||||
public void shouldCheckNonceAfterNonceIncreaseOfSender() throws IOException {
|
||||
final long GAS_LIMIT = 1000000L;
|
||||
cluster.verify(authorizer.balanceEquals(Amount.ether(90000)));
|
||||
final long GAS_LIMIT = 1_000_000L;
|
||||
cluster.verify(authorizer.balanceEquals(Amount.ether(90_000)));
|
||||
|
||||
final CodeDelegation authorization =
|
||||
org.hyperledger.besu.ethereum.core.CodeDelegation.builder()
|
||||
@@ -159,7 +159,7 @@ public class CodeDelegationTransactionAcceptanceTest extends AcceptanceTestBase
|
||||
.type(TransactionType.DELEGATE_CODE)
|
||||
.chainId(BigInteger.valueOf(20211))
|
||||
.nonce(0)
|
||||
.maxPriorityFeePerGas(Wei.of(1000000000))
|
||||
.maxPriorityFeePerGas(Wei.of(1_000_000_000))
|
||||
.maxFeePerGas(Wei.fromHexString("0x02540BE400"))
|
||||
.gasLimit(GAS_LIMIT)
|
||||
.to(Address.fromHexStringStrict(authorizer.getAddress()))
|
||||
@@ -209,7 +209,7 @@ public class CodeDelegationTransactionAcceptanceTest extends AcceptanceTestBase
|
||||
.nonce(2)
|
||||
.maxPriorityFeePerGas(Wei.of(10))
|
||||
.maxFeePerGas(Wei.of(100))
|
||||
.gasLimit(21000)
|
||||
.gasLimit(21_000)
|
||||
.to(Address.fromHexStringStrict(otherAccount.getAddress()))
|
||||
.value(Wei.ONE)
|
||||
.payload(Bytes.EMPTY)
|
||||
|
||||
@@ -98,6 +98,10 @@ public class PragueAcceptanceTestHelper {
|
||||
executionPayload.toString(), parentBeaconBlockRoot, executionRequests.toString()));
|
||||
try (final Response newPayloadResponse = newPayloadRequest.execute()) {
|
||||
assertThat(newPayloadResponse.code()).isEqualTo(200);
|
||||
|
||||
final String responseStatus =
|
||||
mapper.readTree(newPayloadResponse.body().string()).get("result").get("status").asText();
|
||||
assertThat(responseStatus).isEqualTo("VALID");
|
||||
}
|
||||
|
||||
final Call moveChainAheadRequest = createEngineCall(createForkChoiceRequest(newBlockHash));
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -31,7 +31,6 @@ public class HashTest {
|
||||
public void shouldGetExpectedValueForEmptyRequestsHash() {
|
||||
assertThat(Hash.EMPTY_REQUESTS_HASH)
|
||||
.isEqualTo(
|
||||
Hash.fromHexString(
|
||||
"0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f"));
|
||||
Hash.fromHexString("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.json.Json;
|
||||
@@ -596,8 +595,12 @@ public abstract class AbstractEngineNewPayload extends ExecutionEngineJsonRpcMet
|
||||
|
||||
return maybeRequestsParam.map(
|
||||
requests ->
|
||||
IntStream.range(0, requests.size())
|
||||
.mapToObj(i -> new Request(RequestType.of(i), Bytes.fromHexString(requests.get(i))))
|
||||
requests.stream()
|
||||
.map(
|
||||
s -> {
|
||||
final Bytes request = Bytes.fromHexString(s);
|
||||
return new Request(RequestType.of(request.get(0)), request.slice(1));
|
||||
})
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
|
||||
@@ -167,7 +167,9 @@ public class BlockResultFactory {
|
||||
rqs ->
|
||||
rqs.stream()
|
||||
.sorted(Comparator.comparing(Request::getType))
|
||||
.map(r -> r.getData().toHexString())
|
||||
.filter(r -> !r.getData().isEmpty())
|
||||
.map(Request::getEncodedRequest)
|
||||
.map(Bytes::toHexString)
|
||||
.toList());
|
||||
|
||||
final BlobsBundleV1 blobsBundleV1 =
|
||||
|
||||
@@ -147,7 +147,8 @@ public class EngineGetPayloadV4Test extends AbstractEngineGetPayloadTest {
|
||||
final List<String> requestsWithoutRequestId =
|
||||
requests.stream()
|
||||
.sorted(Comparator.comparing(Request::getType))
|
||||
.map(r -> r.getData().toHexString())
|
||||
.map(Request::getEncodedRequest)
|
||||
.map(Bytes::toHexString)
|
||||
.toList();
|
||||
Optional.of(resp)
|
||||
.map(JsonRpcSuccessResponse.class::cast)
|
||||
@@ -172,6 +173,53 @@ public class EngineGetPayloadV4Test extends AbstractEngineGetPayloadTest {
|
||||
verify(engineCallListener, times(1)).executionEngineCalled();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExcludeEmptyRequestsInRequestsList() {
|
||||
|
||||
BlockHeader header =
|
||||
new BlockHeaderTestFixture().timestamp(pragueHardfork.milestone() + 1).buildHeader();
|
||||
PayloadIdentifier payloadIdentifier =
|
||||
PayloadIdentifier.forPayloadParams(
|
||||
Hash.ZERO,
|
||||
pragueHardfork.milestone(),
|
||||
Bytes32.random(),
|
||||
Address.fromHexString("0x42"),
|
||||
Optional.empty(),
|
||||
Optional.empty());
|
||||
|
||||
BlockWithReceipts block =
|
||||
new BlockWithReceipts(
|
||||
new Block(header, new BlockBody(emptyList(), emptyList(), Optional.of(emptyList()))),
|
||||
emptyList());
|
||||
final List<Request> unorderedRequests =
|
||||
List.of(
|
||||
new Request(RequestType.CONSOLIDATION, Bytes.of(1)),
|
||||
new Request(RequestType.DEPOSIT, Bytes.of(1)),
|
||||
new Request(RequestType.WITHDRAWAL, Bytes.EMPTY));
|
||||
PayloadWrapper payload =
|
||||
new PayloadWrapper(payloadIdentifier, block, Optional.of(unorderedRequests));
|
||||
|
||||
when(mergeContext.retrievePayloadById(payloadIdentifier)).thenReturn(Optional.of(payload));
|
||||
|
||||
final var resp = resp(RpcMethod.ENGINE_GET_PAYLOAD_V4.getMethodName(), payloadIdentifier);
|
||||
assertThat(resp).isInstanceOf(JsonRpcSuccessResponse.class);
|
||||
|
||||
final List<String> expectedRequests =
|
||||
List.of(
|
||||
Bytes.concatenate(Bytes.of(RequestType.DEPOSIT.getSerializedType()), Bytes.of(1))
|
||||
.toHexString(),
|
||||
Bytes.concatenate(Bytes.of(RequestType.CONSOLIDATION.getSerializedType()), Bytes.of(1))
|
||||
.toHexString());
|
||||
Optional.of(resp)
|
||||
.map(JsonRpcSuccessResponse.class::cast)
|
||||
.ifPresent(
|
||||
r -> {
|
||||
assertThat(r.getResult()).isInstanceOf(EngineGetPayloadResultV4.class);
|
||||
final EngineGetPayloadResultV4 res = (EngineGetPayloadResultV4) r.getResult();
|
||||
assertThat(res.getExecutionRequests()).isEqualTo(expectedRequests);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnUnsupportedFork() {
|
||||
final var resp = resp(RpcMethod.ENGINE_GET_PAYLOAD_V4.getMethodName(), mockPid);
|
||||
|
||||
@@ -170,7 +170,10 @@ public class EngineNewPayloadV4Test extends EngineNewPayloadV3Test {
|
||||
final List<String> requestsWithoutRequestId =
|
||||
VALID_REQUESTS.stream()
|
||||
.sorted(Comparator.comparing(Request::getType))
|
||||
.map(r -> r.getData().toHexString())
|
||||
.map(
|
||||
r ->
|
||||
Bytes.concatenate(Bytes.of(r.getType().getSerializedType()), r.getData())
|
||||
.toHexString())
|
||||
.toList();
|
||||
Object[] params =
|
||||
maybeParentBeaconBlockRoot
|
||||
|
||||
@@ -29,4 +29,13 @@ public record Request(RequestType type, Bytes data)
|
||||
public Bytes getData() {
|
||||
return data();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the serialized form of the concatenated type and data.
|
||||
*
|
||||
* @return the serialized request as a byte.
|
||||
*/
|
||||
public Bytes getEncodedRequest() {
|
||||
return Bytes.concatenate(Bytes.of(getType().ordinal()), getData());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,19 +92,17 @@ public final class BodyValidation {
|
||||
/**
|
||||
* 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) {
|
||||
List<Bytes> requestHashes = new ArrayList<>();
|
||||
IntStream.range(0, requests.size())
|
||||
.forEach(
|
||||
i -> {
|
||||
final Request request = requests.get(i);
|
||||
final Bytes requestBytes =
|
||||
Bytes.concatenate(
|
||||
Bytes.of(request.getType().getSerializedType()), request.getData());
|
||||
requestHashes.add(sha256(requestBytes));
|
||||
requests.forEach(
|
||||
request -> {
|
||||
// empty requests are excluded from the hash
|
||||
if (!request.getData().isEmpty()) {
|
||||
requestHashes.add(sha256(request.getEncodedRequest()));
|
||||
}
|
||||
});
|
||||
|
||||
return Hash.wrap(sha256(Bytes.wrap(requestHashes)));
|
||||
|
||||
@@ -290,7 +290,7 @@ final class GenesisStateTest {
|
||||
assertThat(header.getHash())
|
||||
.isEqualTo(
|
||||
Hash.fromHexString(
|
||||
"0x554807b22674e6d335f734485993857bbad7a9543affb0663a10c14d78135ec7"));
|
||||
"0x5d2d02fce02d1b7ca635ec91a4fe6f7aa36f9b3997ec4304e8c68d8f6f15d266"));
|
||||
assertThat(header.getGasLimit()).isEqualTo(0x2fefd8);
|
||||
assertThat(header.getGasUsed()).isZero();
|
||||
assertThat(header.getNumber()).isZero();
|
||||
@@ -330,7 +330,7 @@ final class GenesisStateTest {
|
||||
assertThat(header.getRequestsHash().get())
|
||||
.isEqualTo(
|
||||
Hash.fromHexString(
|
||||
"0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f"));
|
||||
"0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -546,7 +546,12 @@ public class T8nExecutor {
|
||||
ArrayNode requests = resultObject.putArray("requests");
|
||||
maybeRequests
|
||||
.orElseGet(List::of)
|
||||
.forEach(request -> requests.add(request.getData().toHexString()));
|
||||
.forEach(
|
||||
request -> {
|
||||
if (!request.data().isEmpty()) {
|
||||
requests.add(request.getEncodedRequest().toHexString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
worldState.persist(blockHeader);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -189,14 +189,6 @@
|
||||
"balance": "0x0",
|
||||
"nonce": "0x1"
|
||||
},
|
||||
"0x0f792be4b0c0cb4dae440ef133e90c0ecd48cccc":{
|
||||
"code":"0x3373fffffffffffffffffffffffffffffffffffffffe14604657602036036042575f35600143038111604257611fff81430311604257611fff9006545f5260205ff35b5f5ffd5b5f35611fff60014303065500",
|
||||
"storage":{
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000":"0x10715cfbefdb8a0cb2f7d7ca5ee6d1ea65515ecb41cff0a22d1e11716a9d27fb"
|
||||
},
|
||||
"balance":"0x0",
|
||||
"nonce":"0x1"
|
||||
},
|
||||
"0x0c15f14308530b7cdb8460094bbb9cc28b9aaaaa": {
|
||||
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe1460cb5760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f457600182026001905f5b5f82111560685781019083028483029004916001019190604d565b909390049250505036603814608857366101f457346101f4575f5260205ff35b34106101f457600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160df575060105b5f5b8181146101835782810160030260040181604c02815460601b8152601401816001015481526020019060020154807fffffffffffffffffffffffffffffffff00000000000000000000000000000000168252906010019060401c908160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160e1565b910180921461019557906002556101a0565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101cd57505f5b6001546002828201116101e25750505f6101e8565b01600290035b5f555f600155604c025ff35b5f5ffd",
|
||||
"storage": {
|
||||
@@ -206,6 +198,14 @@
|
||||
"balance": "0x1",
|
||||
"nonce": "0x1"
|
||||
},
|
||||
"0x0f792be4b0c0cb4dae440ef133e90c0ecd48cccc": {
|
||||
"code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604657602036036042575f35600143038111604257611fff81430311604257611fff9006545f5260205ff35b5f5ffd5b5f35611fff60014303065500",
|
||||
"storage": {
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x10715cfbefdb8a0cb2f7d7ca5ee6d1ea65515ecb41cff0a22d1e11716a9d27fb"
|
||||
},
|
||||
"balance": "0x0",
|
||||
"nonce": "0x1"
|
||||
},
|
||||
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
|
||||
"balance": "0xad78ebc5ac61f2b034",
|
||||
"nonce": "0x1"
|
||||
@@ -213,11 +213,9 @@
|
||||
},
|
||||
"body": "0xf89bf8998007830f424094000000000000000000000000000000000000100080b838000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000026a0d050db98a60dbe4bbbc6ce154c607f28f1cf803a8882f369b28a5eb4ef1a600fa07512ca5133bcb887a41f6136cd645839c1bcf0f300325948387a70f3ad9ced1c",
|
||||
"result": {
|
||||
"requestsHash": "0xab205d558af6253557180e19e89356ed4c7d4b13615ee9560840af3df75ddb12",
|
||||
"requestsHash": "0x16a372318fd60f169dd3e1e2e528d1fb17edc62e741feebcb0896f950018769a",
|
||||
"requests": [
|
||||
"0x",
|
||||
"0x00000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000",
|
||||
"0x"
|
||||
"0x0100000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000"
|
||||
],
|
||||
"stateRoot": "0xc7b49e4aef4229962b94ec0a7c83a6fc0b4015f2573b9a85446ed434c823164e",
|
||||
"txRoot": "0x0d36638e52999b7beafa00eb94f7ca23139774cd14229c011d0edc1fc66125c9",
|
||||
|
||||
Reference in New Issue
Block a user