Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mooselumph committed Oct 23, 2024
1 parent a26dd1e commit 72bc6e0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
1 change: 0 additions & 1 deletion core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ func RoundUpDivideBig(a, b *big.Int) *big.Int {
num := new(big.Int).Sub(new(big.Int).Add(a, b), one) // a + b - 1
res := new(big.Int).Div(num, b) // (a + b - 1) / b
return res

}

func RoundUpDivide[T constraints.Integer](a, b T) T {
Expand Down
2 changes: 2 additions & 0 deletions core/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
)

var (
// TODO(mooselumph): Put these parameters on chain and add on-chain checks to ensure that the number of operators does not
// conflict with the existing on-chain limits
ParametersMap = map[uint8]BlobVersionParameters{
0: {CodingRate: 8, ReconstructionThreshold: 0.22, NumChunks: 8192},
}
Expand Down
2 changes: 1 addition & 1 deletion disperser/batcher/encoding_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (e *EncodingStreamer) RequestEncodingForBlob(ctx context.Context, metadata

params := encoding.ParamsFromMins(chunkLength, info.TotalChunks)

err = encoding.ValidateEncodingParams(params, int(blobLength), e.SRSOrder)
err = encoding.ValidateEncodingParamsAndBlobLength(params, uint64(blobLength), uint64(e.SRSOrder))
if err != nil {
e.logger.Error("invalid encoding params", "err", err)
// Cancel the blob
Expand Down
11 changes: 2 additions & 9 deletions encoding/kzg/prover/prover_cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package prover

import (
"fmt"
"log"
"math"

Expand All @@ -21,14 +20,8 @@ import (

func (g *Prover) newProver(params encoding.EncodingParams) (*ParametrizedProver, error) {

// Check that the parameters are valid with respect to the SRS. The precomputed terms of the amortized KZG
// prover use up to order params.ChunkLen*params.NumChunks-1 for the SRS, so we must have
// params.ChunkLen*params.NumChunks-1 <= g.SRSOrder. The condition below could technically
// be relaxed to params.ChunkLen*params.NumChunks > g.SRSOrder+1, but because all of the paramters are
// powers of 2, the stricter condition is equivalent.

if params.ChunkLength*params.NumChunks > g.SRSOrder {
return nil, fmt.Errorf("the supplied encoding parameters are not valid with respect to the SRS. ChunkLength: %d, NumChunks: %d, SRSOrder: %d", params.ChunkLength, params.NumChunks, g.SRSOrder)
if err := encoding.ValidateEncodingParams(params, g.SRSOrder); err != nil {
return nil, err
}

encoder, err := rs.NewEncoder(params, g.Verbose)
Expand Down
24 changes: 20 additions & 4 deletions encoding/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,29 @@ func GetNumSys(dataSize uint64, chunkLen uint64) uint64 {
}

// ValidateEncodingParams takes in the encoding parameters and returns an error if they are invalid.
func ValidateEncodingParams(params EncodingParams, blobLength, SRSOrder int) error {

if int(params.ChunkLength*params.NumChunks) >= SRSOrder {
func ValidateEncodingParams(params EncodingParams, SRSOrder uint64) error {

// Check that the parameters are valid with respect to the SRS. The precomputed terms of the amortized KZG
// prover use up to order params.ChunkLen*params.NumChunks-1 for the SRS, so we must have
// params.ChunkLen*params.NumChunks-1 <= g.SRSOrder. The condition below could technically
// be relaxed to params.ChunkLen*params.NumChunks > g.SRSOrder+1, but because all of the paramters are
// powers of 2, the stricter condition is equivalent.
if params.ChunkLength*params.NumChunks > SRSOrder {
return fmt.Errorf("the supplied encoding parameters are not valid with respect to the SRS. ChunkLength: %d, NumChunks: %d, SRSOrder: %d", params.ChunkLength, params.NumChunks, SRSOrder)
}

if int(params.ChunkLength*params.NumChunks) < blobLength {
return nil

}

// ValidateEncodingParamsAndBlobLength takes in the encoding parameters and blob length and returns an error if they are collectively invalid.
func ValidateEncodingParamsAndBlobLength(params EncodingParams, blobLength, SRSOrder uint64) error {

if err := ValidateEncodingParams(params, SRSOrder); err != nil {
return err
}

if params.ChunkLength*params.NumChunks < blobLength {
return errors.New("the supplied encoding parameters are not sufficient for the size of the data input")
}

Expand Down

0 comments on commit 72bc6e0

Please sign in to comment.