Skip to content

Commit 44c7beb

Browse files
committed
check multiplication overflow
1 parent 9fe61b5 commit 44c7beb

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

encoding/params.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ var (
1111
ErrInvalidParams = errors.New("invalid encoding params")
1212
)
1313

14+
const maxUint64 = ^uint64(0)
15+
1416
type EncodingParams struct {
1517
ChunkLength uint64 // ChunkSize is the length of the chunk in symbols
1618
NumChunks uint64
@@ -61,6 +63,9 @@ func GetNumSys(dataSize uint64, chunkLen uint64) uint64 {
6163

6264
// ValidateEncodingParams takes in the encoding parameters and returns an error if they are invalid.
6365
func ValidateEncodingParams(params EncodingParams, SRSOrder uint64) error {
66+
if params.ChunkLength != 0 && params.NumChunks > maxUint64/params.ChunkLength {
67+
return fmt.Errorf("multiplication overflow: ChunkLength: %d, NumChunks: %d", params.ChunkLength, params.NumChunks)
68+
}
6469

6570
// Check that the parameters are valid with respect to the SRS. The precomputed terms of the amortized KZG
6671
// prover use up to order params.ChunkLen*params.NumChunks-1 for the SRS, so we must have

0 commit comments

Comments
 (0)