mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-08 17:21:47 +00:00
core/types: fix CellProofsAt method (#32198)
This commit is contained in:
parent
5bce990891
commit
fe0ae06c77
2 changed files with 19 additions and 12 deletions
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -75,17 +74,19 @@ 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.
|
||||||
func (sc *BlobTxSidecar) CellProofsAt(idx int) []kzg4844.Proof {
|
// This method is only valid for sidecars with version 1.
|
||||||
var cellProofs []kzg4844.Proof
|
func (sc *BlobTxSidecar) CellProofsAt(idx int) ([]kzg4844.Proof, error) {
|
||||||
for i := range kzg4844.CellProofsPerBlob {
|
if sc.Version != 1 {
|
||||||
index := idx*kzg4844.CellProofsPerBlob + i
|
return nil, fmt.Errorf("cell proof unsupported, version: %d", sc.Version)
|
||||||
if index > len(sc.Proofs) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
proof := sc.Proofs[index]
|
|
||||||
cellProofs = append(cellProofs, proof)
|
|
||||||
}
|
}
|
||||||
return cellProofs
|
if idx < 0 || idx >= len(sc.Blobs) {
|
||||||
|
return nil, fmt.Errorf("cell proof out of bounds, index: %d, blobs: %d", idx, len(sc.Blobs))
|
||||||
|
}
|
||||||
|
index := idx * kzg4844.CellProofsPerBlob
|
||||||
|
if len(sc.Proofs) < index+kzg4844.CellProofsPerBlob {
|
||||||
|
return nil, fmt.Errorf("cell proof is corrupted, index: %d, proofs: %d", idx, len(sc.Proofs))
|
||||||
|
}
|
||||||
|
return sc.Proofs[index : index+kzg4844.CellProofsPerBlob], 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
|
||||||
|
|
@ -217,6 +218,7 @@ func (tx *BlobTx) copy() TxData {
|
||||||
}
|
}
|
||||||
if tx.Sidecar != nil {
|
if tx.Sidecar != nil {
|
||||||
cpy.Sidecar = &BlobTxSidecar{
|
cpy.Sidecar = &BlobTxSidecar{
|
||||||
|
Version: tx.Sidecar.Version,
|
||||||
Blobs: slices.Clone(tx.Sidecar.Blobs),
|
Blobs: slices.Clone(tx.Sidecar.Blobs),
|
||||||
Commitments: slices.Clone(tx.Sidecar.Commitments),
|
Commitments: slices.Clone(tx.Sidecar.Commitments),
|
||||||
Proofs: slices.Clone(tx.Sidecar.Proofs),
|
Proofs: slices.Clone(tx.Sidecar.Proofs),
|
||||||
|
|
|
||||||
|
|
@ -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[:])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue