mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-12 01:41:36 +00:00
modify cell indices validation
This commit is contained in:
parent
22bcf90bf0
commit
b950503b89
1 changed files with 8 additions and 14 deletions
|
|
@ -20,7 +20,6 @@ package kzg4844
|
|||
import (
|
||||
"embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash"
|
||||
"reflect"
|
||||
"sync/atomic"
|
||||
|
|
@ -214,6 +213,8 @@ func IsValidVersionedHash(h []byte) bool {
|
|||
// For this function, it is sufficient to only provide some of the cells.
|
||||
//
|
||||
// The `cellIndices` specify which of the 128 cells of each blob are given.
|
||||
// Indices must be given in ascending order.
|
||||
//
|
||||
// Note the list of indices is shared among all blobs, i.e. for a given list of indices
|
||||
// [1, 2, 13], the cells slice must contain cells [1, 2, 13] of each blob.
|
||||
// Thus, `len(cells)` must be a multiple of `len(cellIndices)`.
|
||||
|
|
@ -232,6 +233,9 @@ func VerifyCells(cells []Cell, commitments []Commitment, proofs []Proof, cellInd
|
|||
if err := validateCellIndices(cells, cellIndices); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(cells)/len(cellIndices) != len(commitments) {
|
||||
return errors.New("invalid number of cells for blob count")
|
||||
}
|
||||
|
||||
if useCKZG.Load() {
|
||||
return ckzgVerifyCells(cells, commitments, proofs, cellIndices)
|
||||
|
|
@ -265,23 +269,13 @@ func validateCellIndices(cells []Cell, cellIndices []uint64) error {
|
|||
switch {
|
||||
case len(cellIndices) == 0:
|
||||
return errors.New("no cellIndices given")
|
||||
case len(cellIndices) < len(cells):
|
||||
return errors.New("less cellIndices than cells")
|
||||
case len(cellIndices) > len(cells):
|
||||
return errors.New("less cells than cellIndices")
|
||||
case len(cellIndices) > CellsPerBlob:
|
||||
return errors.New("too many cellIndices")
|
||||
case len(cells)%len(cellIndices) != 0:
|
||||
return errors.New("len(cells) must be a multiple of len(cellIndices)")
|
||||
}
|
||||
// check no duplicates
|
||||
var bm [CellsPerBlob / 8]uint64
|
||||
for _, i := range cellIndices {
|
||||
if i >= CellsPerBlob {
|
||||
return fmt.Errorf("invalid cell index %d", i)
|
||||
}
|
||||
if bm[i>>8]&(1<<(i%8)) != 0 {
|
||||
return fmt.Errorf("duplicate cell index %d", i)
|
||||
}
|
||||
bm[i>>8] |= 1 << (i % 8)
|
||||
}
|
||||
// The library checks the canonical ordering of indices, so we don't have to do it here.
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue