diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/versions/electra/ExecutionRequestsDataCodec.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/versions/electra/ExecutionRequestsDataCodec.java index 652b7416a07..a31930f38c7 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/versions/electra/ExecutionRequestsDataCodec.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/versions/electra/ExecutionRequestsDataCodec.java @@ -27,6 +27,10 @@ public class ExecutionRequestsDataCodec { private static final int EXPECTED_REQUEST_DATA_ELEMENTS = 3; + private static final Bytes DEPOSIT_REQUEST_PREFIX = Bytes.of(DepositRequest.REQUEST_TYPE); + private static final Bytes WITHDRAWAL_REQUEST_PREFIX = Bytes.of(WithdrawalRequest.REQUEST_TYPE); + private static final Bytes CONSOLIDATION_REQUEST_PREFIX = + Bytes.of(ConsolidationRequest.REQUEST_TYPE); private final ExecutionRequestsSchema executionRequestsSchema; @@ -75,7 +79,7 @@ public ExecutionRequests decode(final List executionRequestData) { } @VisibleForTesting - List encode(final ExecutionRequests executionRequests) { + List encodeWithTypePrefix(final ExecutionRequests executionRequests) { final SszList depositRequestsSszList = executionRequestsSchema .getDepositRequestsSchema() @@ -90,18 +94,15 @@ List encode(final ExecutionRequests executionRequests) { .createFromElements(executionRequests.getConsolidations()); return List.of( + Bytes.concatenate(DEPOSIT_REQUEST_PREFIX, depositRequestsSszList.sszSerialize()), + Bytes.concatenate(WITHDRAWAL_REQUEST_PREFIX, withdrawalRequestsSszList.sszSerialize()), Bytes.concatenate( - Bytes.of(DepositRequest.REQUEST_TYPE), depositRequestsSszList.sszSerialize()), - Bytes.concatenate( - Bytes.of(WithdrawalRequest.REQUEST_TYPE), withdrawalRequestsSszList.sszSerialize()), - Bytes.concatenate( - Bytes.of(ConsolidationRequest.REQUEST_TYPE), - consolidationRequestsSszList.sszSerialize())); + CONSOLIDATION_REQUEST_PREFIX, consolidationRequestsSszList.sszSerialize())); } public Bytes32 hash(final ExecutionRequests executionRequests) { final Bytes sortedEncodedRequests = - encode(executionRequests).stream() + encodeWithTypePrefix(executionRequests).stream() .map(Hash::sha256) .map(Bytes.class::cast) .reduce(Bytes.EMPTY, Bytes::concatenate); diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/execution/versions/electra/ExecutionRequestsDataCodecTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/execution/versions/electra/ExecutionRequestsDataCodecTest.java index e6752871dfd..520565983b2 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/execution/versions/electra/ExecutionRequestsDataCodecTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/datastructures/execution/versions/electra/ExecutionRequestsDataCodecTest.java @@ -122,7 +122,7 @@ public void decodeExecutionRequestDataWithZeroElements() { } @Test - public void encodeExecutionRequests() { + public void encodeWithTypePrefixExecutionRequests() { final ExecutionRequests executionRequests = new ExecutionRequestsBuilderElectra(executionRequestsSchema) .deposits(List.of(depositRequest1, depositRequest2)) @@ -130,7 +130,7 @@ public void encodeExecutionRequests() { .consolidations(List.of(consolidationRequest1)) .build(); - final List encodedRequests = codec.encode(executionRequests); + final List encodedRequests = codec.encodeWithTypePrefix(executionRequests); assertThat(encodedRequests) .containsExactly( @@ -142,7 +142,7 @@ public void encodeExecutionRequests() { } @Test - public void encodeExecutionRequestsWithOneEmptyRequestList() { + public void encodeWithTypePrefixExecutionRequestsWithOneEmptyRequestList() { final ExecutionRequests executionRequests = new ExecutionRequestsBuilderElectra(executionRequestsSchema) .deposits(List.of(depositRequest1, depositRequest2)) @@ -150,7 +150,7 @@ public void encodeExecutionRequestsWithOneEmptyRequestList() { .consolidations(List.of(consolidationRequest1)) .build(); - final List encodedRequests = codec.encode(executionRequests); + final List encodedRequests = codec.encodeWithTypePrefix(executionRequests); assertThat(encodedRequests) .containsExactly( @@ -161,7 +161,7 @@ public void encodeExecutionRequestsWithOneEmptyRequestList() { } @Test - public void encodeExecutionRequestsWithAllEmptyRequestLists() { + public void encodeWithTypePrefixExecutionRequestsWithAllEmptyRequestLists() { final ExecutionRequests executionRequests = new ExecutionRequestsBuilderElectra(executionRequestsSchema) .deposits(List.of()) @@ -169,7 +169,7 @@ public void encodeExecutionRequestsWithAllEmptyRequestLists() { .consolidations(List.of()) .build(); - final List encodedRequests = codec.encode(executionRequests); + final List encodedRequests = codec.encodeWithTypePrefix(executionRequests); assertThat(encodedRequests) .containsExactly(