core/types, eth/catalyst: return error if cell proof is invalid

This commit is contained in:
Gary Rong 2025-07-15 09:05:00 +08:00
parent caa8e5aa0f
commit d0df9fe6eb
2 changed files with 15 additions and 10 deletions

View file

@ -26,7 +26,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/kzg4844" "github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/holiman/uint256" "github.com/holiman/uint256"
@ -76,17 +75,18 @@ func (sc *BlobTxSidecar) BlobHashes() []common.Hash {
// CellProofsAt returns the cell proofs for blob with index idx. // CellProofsAt returns the cell proofs for blob with index idx.
// This method is only valid for sidecars with version 1. // This method is only valid for sidecars with version 1.
func (sc *BlobTxSidecar) CellProofsAt(idx int) []kzg4844.Proof { func (sc *BlobTxSidecar) CellProofsAt(idx int) ([]kzg4844.Proof, error) {
if sc.Version != 1 {
return nil, fmt.Errorf("cell proof unsupported, version: %d", sc.Version)
}
if idx < 0 || idx >= len(sc.Blobs) { if idx < 0 || idx >= len(sc.Blobs) {
log.Error("cellProofsAt called with out of bounds index", "index", idx, "blobs", len(sc.Blobs)) return nil, fmt.Errorf("cell proof out of bounds, index: %d, blobs: %d", idx, len(sc.Blobs))
return nil
} }
if sc.Version == 1 { index := idx * kzg4844.CellProofsPerBlob
index := idx * kzg4844.CellProofsPerBlob if len(sc.Proofs) < index+kzg4844.CellProofsPerBlob {
return sc.Proofs[index : index+kzg4844.CellProofsPerBlob] return nil, fmt.Errorf("cell proof is corrupted, index: %d, proofs: %d", idx, len(sc.Proofs))
} }
log.Error("cellProofsAt called with unsupported version", "version", sc.Version) return sc.Proofs[index : index+kzg4844.CellProofsPerBlob], nil
return nil
} }
// encodedSize computes the RLP size of the sidecar elements. This does NOT return the // encodedSize computes the RLP size of the sidecar elements. This does NOT return the

View file

@ -564,7 +564,12 @@ func (api *ConsensusAPI) GetBlobsV2(hashes []common.Hash) ([]*engine.BlobAndProo
blobHashes := sidecar.BlobHashes() blobHashes := sidecar.BlobHashes()
for bIdx, hash := range blobHashes { for bIdx, hash := range blobHashes {
if idxes, ok := index[hash]; ok { if idxes, ok := index[hash]; ok {
proofs := sidecar.CellProofsAt(bIdx) proofs, err := sidecar.CellProofsAt(bIdx)
if err != nil {
// TODO @rjl @marius we should return an error
log.Info("Failed to get cell proof", "err", err)
return nil, nil
}
var cellProofs []hexutil.Bytes var cellProofs []hexutil.Bytes
for _, proof := range proofs { for _, proof := range proofs {
cellProofs = append(cellProofs, proof[:]) cellProofs = append(cellProofs, proof[:])