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

fix: blob sidecar validation to ensure KZG commitment count matches #14752

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
### Fixed

- Added check to prevent nil pointer deference or out of bounds array access when validating the BLSToExecutionChange on an impossibly nil validator.
* [Beacon Chain] Fixed blob sidecar validation to ensure the number of available sidecars matches KZG commitment count

### Security

Expand Down
20 changes: 20 additions & 0 deletions beacon-chain/sync/rpc_blob_sidecars_by_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ func (s *Service) streamBlobBatch(ctx context.Context, batch blockBatch, wQuota
s.writeErrorResponseToStream(responseCodeServerError, p2ptypes.ErrGeneric.Error(), stream)
return wQuota, errors.Wrapf(err, "could not retrieve sidecars for block root %#x", root)
}

// Get the number of KZG commitments in the block
kzgCommitments := len(b.Block().Body().BlobKzgCommitments())

// Count available blob sidecars
availableSidecars := 0
for _, hasIndex := range idxs {
if hasIndex {
availableSidecars++
}
}

// Check if we have all required blob sidecars
if kzgCommitments > 0 && availableSidecars < kzgCommitments {
s.writeErrorResponseToStream(responseCodeServerError, errMissingBlobsForBlockCommitments.Error(), stream)
return wQuota, errors.Wrapf(errMissingBlobsForBlockCommitments,
"block root %#x has %d KZG commitments but only %d available sidecars",
root, kzgCommitments, availableSidecars)
}

for i, l := uint64(0), uint64(len(idxs)); i < l; i++ {
// index not available, skip
if !idxs[i] {
Expand Down
18 changes: 18 additions & 0 deletions beacon-chain/sync/rpc_blob_sidecars_by_range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,24 @@ func TestBlobByRangeOK(t *testing.T) {
},
total: func() *int { x := int(params.BeaconConfig().MaxRequestBlobSidecars); return &x }(),
},
{
name: "missing blob sidecars for block with KZG commitments",
nblocks: 1,
requestFromSidecars: func(scs []blocks.ROBlob) interface{} {
return &ethpb.BlobSidecarsByRangeRequest{
StartSlot: scs[0].Slot(),
Count: 1,
}
},
defineExpected: func(t *testing.T, scs []blocks.ROBlob, req interface{}) []*expectedBlobChunk {
return []*expectedBlobChunk{
{
code: responseCodeServerError,
message: errMissingBlobsForBlockCommitments.Error(),
},
}
},
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
Expand Down