Skip to content

Commit fe0ae06

Browse files
authored
core/types: fix CellProofsAt method (ethereum#32198)
1 parent 5bce990 commit fe0ae06

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

core/types/tx_blob.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"errors"
2323
"fmt"
2424
"math/big"
25-
2625
"slices"
2726

2827
"github.com/ethereum/go-ethereum/common"
@@ -75,17 +74,19 @@ func (sc *BlobTxSidecar) BlobHashes() []common.Hash {
7574
}
7675

7776
// CellProofsAt returns the cell proofs for blob with index idx.
78-
func (sc *BlobTxSidecar) CellProofsAt(idx int) []kzg4844.Proof {
79-
var cellProofs []kzg4844.Proof
80-
for i := range kzg4844.CellProofsPerBlob {
81-
index := idx*kzg4844.CellProofsPerBlob + i
82-
if index > len(sc.Proofs) {
83-
return nil
84-
}
85-
proof := sc.Proofs[index]
86-
cellProofs = append(cellProofs, proof)
77+
// This method is only valid for sidecars with version 1.
78+
func (sc *BlobTxSidecar) CellProofsAt(idx int) ([]kzg4844.Proof, error) {
79+
if sc.Version != 1 {
80+
return nil, fmt.Errorf("cell proof unsupported, version: %d", sc.Version)
81+
}
82+
if idx < 0 || idx >= len(sc.Blobs) {
83+
return nil, fmt.Errorf("cell proof out of bounds, index: %d, blobs: %d", idx, len(sc.Blobs))
8784
}
88-
return cellProofs
85+
index := idx * kzg4844.CellProofsPerBlob
86+
if len(sc.Proofs) < index+kzg4844.CellProofsPerBlob {
87+
return nil, fmt.Errorf("cell proof is corrupted, index: %d, proofs: %d", idx, len(sc.Proofs))
88+
}
89+
return sc.Proofs[index : index+kzg4844.CellProofsPerBlob], nil
8990
}
9091

9192
// encodedSize computes the RLP size of the sidecar elements. This does NOT return the
@@ -217,6 +218,7 @@ func (tx *BlobTx) copy() TxData {
217218
}
218219
if tx.Sidecar != nil {
219220
cpy.Sidecar = &BlobTxSidecar{
221+
Version: tx.Sidecar.Version,
220222
Blobs: slices.Clone(tx.Sidecar.Blobs),
221223
Commitments: slices.Clone(tx.Sidecar.Commitments),
222224
Proofs: slices.Clone(tx.Sidecar.Proofs),

eth/catalyst/api.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,12 @@ func (api *ConsensusAPI) GetBlobsV2(hashes []common.Hash) ([]*engine.BlobAndProo
564564
blobHashes := sidecar.BlobHashes()
565565
for bIdx, hash := range blobHashes {
566566
if idxes, ok := index[hash]; ok {
567-
proofs := sidecar.CellProofsAt(bIdx)
567+
proofs, err := sidecar.CellProofsAt(bIdx)
568+
if err != nil {
569+
// TODO @rjl @marius we should return an error
570+
log.Info("Failed to get cell proof", "err", err)
571+
return nil, nil
572+
}
568573
var cellProofs []hexutil.Bytes
569574
for _, proof := range proofs {
570575
cellProofs = append(cellProofs, proof[:])

0 commit comments

Comments
 (0)