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

Apply new blobSidecar gossip rule validating index #7605

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ public SafeFuture<InternalValidationResult> validate(final SignedBlobSidecar sig
tech.pegasys.teku.networking.eth2.gossip.BlobSidecarGossipManager.TopicSubnetIdAwareOperationProcessor
*/

/*
[REJECT] The sidecar's index is consistent with `MAX_BLOBS_PER_BLOCK` -- i.e. `sidecar.index < MAX_BLOBS_PER_BLOCK`
*/
final Optional<Integer> maxBlobsPerBlockAtSlot =
spec.getMaxBlobsPerBlock(blobSidecar.getSlot());
if (maxBlobsPerBlockAtSlot.isEmpty()) {
return completedFuture(reject("BlobSidecar's slot is pre deneb"));
}
if (blobSidecar.getIndex().isGreaterThanOrEqualTo(maxBlobsPerBlockAtSlot.get())) {
return completedFuture(reject("BlobSidecar index is greater than MAX_BLOBS_PER_BLOCK"));
}

/*
[REJECT] The sidecar's block's parent (defined by sidecar.block_parent_root) passes validation.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import tech.pegasys.teku.infrastructure.async.SafeFutureAssert;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.Spec;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.spec.TestSpecContext;
import tech.pegasys.teku.spec.TestSpecInvocationContextProvider.SpecContext;
Expand Down Expand Up @@ -101,6 +102,36 @@ void shouldAccept() {
.isCompletedWithValueMatching(InternalValidationResult::isAccept);
}

@TestTemplate
void shouldRejectWhenIndexIsTooBig(final SpecContext specContext) {

signedBlobSidecar =
specContext
.getDataStructureUtil()
.createRandomBlobSidecarBuilder()
.slot(slot)
.index(UInt64.valueOf(specContext.getSpec().getMaxBlobsPerBlock().orElseThrow()))
.proposerIndex(proposerIndex)
.blockRoot(blockRoot)
.blockParentRoot(blockParentRoot)
.buildSigned();

SafeFutureAssert.assertThatSafeFuture(blobSidecarValidator.validate(signedBlobSidecar))
.isCompletedWithValueMatching(InternalValidationResult::isReject);
}

@TestTemplate
void shouldRejectWhenSlotIsNotDeneb() {
final Spec mockedSpec = mock(Spec.class);
when(mockedSpec.getMaxBlobsPerBlock(slot)).thenReturn(Optional.empty());

blobSidecarValidator =
BlobSidecarValidator.create(mockedSpec, invalidBlocks, gossipValidationHelper);

SafeFutureAssert.assertThatSafeFuture(blobSidecarValidator.validate(signedBlobSidecar))
.isCompletedWithValueMatching(InternalValidationResult::isReject);
}

@TestTemplate
void shouldRejectWhenParentBlockInvalid() {
invalidBlocks.put(blockParentRoot, BlockImportResult.FAILED_INVALID_ANCESTRY);
Expand Down
Loading