From 72bc6e01c2f865e983ced085fb43a059be70e47a Mon Sep 17 00:00:00 2001 From: Robert Raynor <35671663+mooselumph@users.noreply.github.com> Date: Wed, 23 Oct 2024 00:46:33 +0000 Subject: [PATCH] Fixes --- core/utils.go | 1 - core/v2/types.go | 2 ++ disperser/batcher/encoding_streamer.go | 2 +- encoding/kzg/prover/prover_cpu.go | 11 ++--------- encoding/params.go | 24 ++++++++++++++++++++---- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/core/utils.go b/core/utils.go index e2098859d0..479e61a872 100644 --- a/core/utils.go +++ b/core/utils.go @@ -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 { diff --git a/core/v2/types.go b/core/v2/types.go index b01da095d8..f3c9eda15e 100644 --- a/core/v2/types.go +++ b/core/v2/types.go @@ -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}, } diff --git a/disperser/batcher/encoding_streamer.go b/disperser/batcher/encoding_streamer.go index 2a14aa7ff6..eda194f5ef 100644 --- a/disperser/batcher/encoding_streamer.go +++ b/disperser/batcher/encoding_streamer.go @@ -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 diff --git a/encoding/kzg/prover/prover_cpu.go b/encoding/kzg/prover/prover_cpu.go index 3ac9298a25..5a230b51cb 100644 --- a/encoding/kzg/prover/prover_cpu.go +++ b/encoding/kzg/prover/prover_cpu.go @@ -4,7 +4,6 @@ package prover import ( - "fmt" "log" "math" @@ -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) diff --git a/encoding/params.go b/encoding/params.go index e334fb8967..422fa0799c 100644 --- a/encoding/params.go +++ b/encoding/params.go @@ -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") }