diff --git a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRangeListenerValidatingProxyTest.java b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRangeListenerValidatingProxyTest.java index 7ac8775afcd..bcbe3297723 100644 --- a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRangeListenerValidatingProxyTest.java +++ b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRangeListenerValidatingProxyTest.java @@ -22,8 +22,8 @@ import static tech.pegasys.teku.infrastructure.async.SafeFutureAssert.safeJoin; import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ONE; import static tech.pegasys.teku.infrastructure.unsigned.UInt64.ZERO; +import static tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BlobSidecarsByRootValidatorTest.breakInclusionProof; -import java.util.stream.IntStream; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import tech.pegasys.teku.infrastructure.async.SafeFuture; @@ -35,7 +35,6 @@ import tech.pegasys.teku.spec.TestSpecFactory; import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; -import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb; import tech.pegasys.teku.spec.util.DataStructureUtil; @SuppressWarnings("JavaCase") @@ -91,29 +90,7 @@ void blobSidecarFailsInclusionProofVerification() { final BlobSidecar blobSidecar1_0 = dataStructureUtil.randomBlobSidecarWithValidInclusionProofForBlock( dataStructureUtil.randomSignedBeaconBlock(ONE), 0); - final BlobSidecar blobSidecar1_0_modified = - SchemaDefinitionsDeneb.required(spec.getGenesisSchemaDefinitions()) - .getBlobSidecarSchema() - .create( - blobSidecar1_0.getIndex(), - blobSidecar1_0.getBlob(), - blobSidecar1_0.getKZGCommitment(), - blobSidecar1_0.getKZGProof(), - blobSidecar1_0.getSignedBeaconBlockHeader(), - IntStream.range(0, blobSidecar1_0.getKzgCommitmentInclusionProof().size()) - .mapToObj( - index -> { - if (index == 0) { - return blobSidecar1_0 - .getKzgCommitmentInclusionProof() - .get(index) - .get() - .not(); - } else { - return blobSidecar1_0.getKzgCommitmentInclusionProof().get(index).get(); - } - }) - .toList()); + final BlobSidecar blobSidecar1_0_modified = breakInclusionProof(spec, blobSidecar1_0); final SafeFuture result = listenerWrapper.onResponse(blobSidecar1_0_modified); assertThat(result).isCompletedExceptionally(); diff --git a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootListenerValidatingProxyTest.java b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootListenerValidatingProxyTest.java index 679cb76387c..cfabe5c4a3a 100644 --- a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootListenerValidatingProxyTest.java +++ b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootListenerValidatingProxyTest.java @@ -19,6 +19,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static tech.pegasys.teku.networking.eth2.rpc.beaconchain.methods.BlobSidecarsByRootValidatorTest.breakInclusionProof; import java.util.List; import org.junit.jupiter.api.BeforeEach; @@ -69,11 +70,16 @@ void blobSidecarsAreCorrect() { listenerWrapper = new BlobSidecarsByRootListenerValidatingProxy(peer, spec, listener, kzg, blobIdentifiers); - final BlobSidecar blobSidecar1_0 = dataStructureUtil.randomBlobSidecarForBlock(block1, 0); - final BlobSidecar blobSidecar1_1 = dataStructureUtil.randomBlobSidecarForBlock(block1, 1); - final BlobSidecar blobSidecar2_0 = dataStructureUtil.randomBlobSidecarForBlock(block2, 0); - final BlobSidecar blobSidecar3_0 = dataStructureUtil.randomBlobSidecarForBlock(block3, 0); - final BlobSidecar blobSidecar4_0 = dataStructureUtil.randomBlobSidecarForBlock(block4, 0); + final BlobSidecar blobSidecar1_0 = + dataStructureUtil.randomBlobSidecarWithValidInclusionProofForBlock(block1, 0); + final BlobSidecar blobSidecar1_1 = + dataStructureUtil.randomBlobSidecarWithValidInclusionProofForBlock(block1, 1); + final BlobSidecar blobSidecar2_0 = + dataStructureUtil.randomBlobSidecarWithValidInclusionProofForBlock(block2, 0); + final BlobSidecar blobSidecar3_0 = + dataStructureUtil.randomBlobSidecarWithValidInclusionProofForBlock(block3, 0); + final BlobSidecar blobSidecar4_0 = + dataStructureUtil.randomBlobSidecarWithValidInclusionProofForBlock(block4, 0); assertDoesNotThrow(() -> listenerWrapper.onResponse(blobSidecar1_0).join()); assertDoesNotThrow(() -> listenerWrapper.onResponse(blobSidecar1_1).join()); @@ -93,9 +99,12 @@ void blobSidecarIdentifierNotRequested() { listenerWrapper = new BlobSidecarsByRootListenerValidatingProxy(peer, spec, listener, kzg, blobIdentifiers); - final BlobSidecar blobSidecar1_0 = dataStructureUtil.randomBlobSidecarForBlock(block1, 0); - final BlobSidecar blobSidecar1_1 = dataStructureUtil.randomBlobSidecarForBlock(block1, 1); - final BlobSidecar blobSidecar2_0 = dataStructureUtil.randomBlobSidecarForBlock(block2, 0); + final BlobSidecar blobSidecar1_0 = + dataStructureUtil.randomBlobSidecarWithValidInclusionProofForBlock(block1, 0); + final BlobSidecar blobSidecar1_1 = + dataStructureUtil.randomBlobSidecarWithValidInclusionProofForBlock(block1, 1); + final BlobSidecar blobSidecar2_0 = + dataStructureUtil.randomBlobSidecarWithValidInclusionProofForBlock(block2, 0); assertDoesNotThrow(() -> listenerWrapper.onResponse(blobSidecar1_0).join()); assertDoesNotThrow(() -> listenerWrapper.onResponse(blobSidecar1_1).join()); @@ -119,7 +128,8 @@ void blobSidecarFailsKzgVerification() { new BlobSidecarsByRootListenerValidatingProxy( peer, spec, listener, kzg, List.of(blobIdentifier)); - final BlobSidecar blobSidecar1_0 = dataStructureUtil.randomBlobSidecarForBlock(block1, 0); + final BlobSidecar blobSidecar1_0 = + dataStructureUtil.randomBlobSidecarWithValidInclusionProofForBlock(block1, 0); final SafeFuture result = listenerWrapper.onResponse(blobSidecar1_0); assertThat(result).isCompletedExceptionally(); @@ -131,4 +141,27 @@ void blobSidecarFailsKzgVerification() { .BLOB_SIDECAR_KZG_VERIFICATION_FAILED .describe()); } + + @Test + void blobSidecarFailsInclusionProofVerification() { + final SignedBeaconBlock block1 = dataStructureUtil.randomSignedBeaconBlock(UInt64.ONE); + final BlobIdentifier blobIdentifier = new BlobIdentifier(block1.getRoot(), UInt64.ZERO); + listenerWrapper = + new BlobSidecarsByRootListenerValidatingProxy( + peer, spec, listener, kzg, List.of(blobIdentifier)); + + final BlobSidecar blobSidecar1_0 = + dataStructureUtil.randomBlobSidecarWithValidInclusionProofForBlock(block1, 0); + final BlobSidecar blobSidecar1_0_modified = breakInclusionProof(spec, blobSidecar1_0); + + final SafeFuture result = listenerWrapper.onResponse(blobSidecar1_0_modified); + assertThat(result).isCompletedExceptionally(); + assertThatThrownBy(result::get) + .hasCauseExactlyInstanceOf(BlobSidecarsResponseInvalidResponseException.class); + assertThatThrownBy(result::get) + .hasMessageContaining( + BlobSidecarsResponseInvalidResponseException.InvalidResponseType + .BLOB_SIDECAR_INCLUSION_PROOF_VERIFICATION_FAILED + .describe()); + } } diff --git a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootValidatorTest.java b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootValidatorTest.java index d8621cd1473..01548f8f016 100644 --- a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootValidatorTest.java +++ b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/rpc/beaconchain/methods/BlobSidecarsByRootValidatorTest.java @@ -47,6 +47,33 @@ void setUp() { when(kzg.verifyBlobKzgProof(any(), any(), any())).thenReturn(true); } + public static BlobSidecar breakInclusionProof(final Spec spec, final BlobSidecar blobSidecar) { + final BlobSidecar blobSidecarModified = + SchemaDefinitionsDeneb.required(spec.getGenesisSchemaDefinitions()) + .getBlobSidecarSchema() + .create( + blobSidecar.getIndex(), + blobSidecar.getBlob(), + blobSidecar.getKZGCommitment(), + blobSidecar.getKZGProof(), + blobSidecar.getSignedBeaconBlockHeader(), + IntStream.range(0, blobSidecar.getKzgCommitmentInclusionProof().size()) + .mapToObj( + index -> { + if (index == 0) { + return blobSidecar + .getKzgCommitmentInclusionProof() + .get(index) + .get() + .not(); + } else { + return blobSidecar.getKzgCommitmentInclusionProof().get(index).get(); + } + }) + .toList()); + return blobSidecarModified; + } + @Test void blobSidecarIsCorrect() { final SignedBeaconBlock block1 = dataStructureUtil.randomSignedBeaconBlock(UInt64.ONE); @@ -98,29 +125,7 @@ void blobSidecarFailsInclusionProofVerification() { final BlobIdentifier blobIdentifier1_0 = new BlobIdentifier(block1.getRoot(), UInt64.ZERO); final BlobSidecar blobSidecar1_0 = dataStructureUtil.randomBlobSidecarWithValidInclusionProofForBlock(block1, 0); - final BlobSidecar blobSidecar1_0_modified = - SchemaDefinitionsDeneb.required(spec.getGenesisSchemaDefinitions()) - .getBlobSidecarSchema() - .create( - blobSidecar1_0.getIndex(), - blobSidecar1_0.getBlob(), - blobSidecar1_0.getKZGCommitment(), - blobSidecar1_0.getKZGProof(), - blobSidecar1_0.getSignedBeaconBlockHeader(), - IntStream.range(0, blobSidecar1_0.getKzgCommitmentInclusionProof().size()) - .mapToObj( - index -> { - if (index == 0) { - return blobSidecar1_0 - .getKzgCommitmentInclusionProof() - .get(index) - .get() - .not(); - } else { - return blobSidecar1_0.getKzgCommitmentInclusionProof().get(index).get(); - } - }) - .toList()); + final BlobSidecar blobSidecar1_0_modified = breakInclusionProof(spec, blobSidecar1_0); validator = new BlobSidecarsByRootValidator(peer, spec, kzg, List.of(blobIdentifier1_0)); assertThatThrownBy(() -> validator.validate(blobSidecar1_0_modified))