Skip to content

Commit

Permalink
fix(blockchain): remove reachable panic in blobsidecar processing (#2244
Browse files Browse the repository at this point in the history
)
  • Loading branch information
shotes authored Dec 11, 2024
1 parent 357fee0 commit 36f1a04
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions consensus-types/types/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ func (b *BeaconBlockBody) Empty(forkVersion uint32) *BeaconBlockBody {
func BlockBodyKZGOffset(
slot math.Slot,
cs common.ChainSpec,
) uint64 {
) (uint64, error) {
switch cs.ActiveForkVersionForSlot(slot) {
case version.Deneb:
return KZGMerkleIndexDeneb * cs.MaxBlobCommitmentsPerBlock()
return KZGMerkleIndexDeneb * cs.MaxBlobCommitmentsPerBlock(), nil
default:
panic(ErrForkVersionNotSupported)
return 0, ErrForkVersionNotSupported
}
}

Expand Down
18 changes: 10 additions & 8 deletions da/blob/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Processor[
verifier *verifier[BeaconBlockHeaderT, BlobSidecarT, BlobSidecarsT]
// blockBodyOffsetFn is a function that calculates the block body offset
// based on the slot and chain specifications.
blockBodyOffsetFn func(math.Slot, common.ChainSpec) uint64
blockBodyOffsetFn func(math.Slot, common.ChainSpec) (uint64, error)
// metrics is used to collect and report processor metrics.
metrics *processorMetrics
}
Expand All @@ -68,7 +68,7 @@ func NewProcessor[
logger log.Logger,
chainSpec common.ChainSpec,
proofVerifier kzg.BlobProofVerifier,
blockBodyOffsetFn func(math.Slot, common.ChainSpec) uint64,
blockBodyOffsetFn func(math.Slot, common.ChainSpec) (uint64, error),
telemetrySink TelemetrySink,
) *Processor[
AvailabilityStoreT, BeaconBlockBodyT, BeaconBlockHeaderT,
Expand Down Expand Up @@ -110,14 +110,16 @@ func (sp *Processor[
return nil
}

kzgOffset, err := sp.blockBodyOffsetFn(
blkHeader.GetSlot(), sp.chainSpec,
)
if err != nil {
return err
}

// Verify the blobs and ensure they match the local state.
return sp.verifier.verifySidecars(
sidecars,
sp.blockBodyOffsetFn(
sidecars.Get(0).GetBeaconBlockHeader().GetSlot(),
sp.chainSpec,
),
blkHeader,
sidecars, kzgOffset, blkHeader,
)
}

Expand Down

0 comments on commit 36f1a04

Please sign in to comment.