add validation for the idx parameter

This commit is contained in:
maskpp 2025-07-14 22:33:12 +08:00
parent ba4a57043d
commit caa8e5aa0f

View file

@ -77,6 +77,10 @@ func (sc *BlobTxSidecar) BlobHashes() []common.Hash {
// CellProofsAt returns the cell proofs for blob with index idx.
// This method is only valid for sidecars with version 1.
func (sc *BlobTxSidecar) CellProofsAt(idx int) []kzg4844.Proof {
if idx < 0 || idx >= len(sc.Blobs) {
log.Error("cellProofsAt called with out of bounds index", "index", idx, "blobs", len(sc.Blobs))
return nil
}
if sc.Version == 1 {
index := idx * kzg4844.CellProofsPerBlob
return sc.Proofs[index : index+kzg4844.CellProofsPerBlob]