From 4c28f5894a99f0e66a65b8e73c10adcac5cbf956 Mon Sep 17 00:00:00 2001 From: Jian Xiao <99709935+jianoaix@users.noreply.github.com> Date: Sat, 30 Mar 2024 21:09:11 -0700 Subject: [PATCH] Fix: index of bounds panics (#417) --- core/aggregation.go | 5 ++++- encoding/kzg/verifier/batch_commit_equivalence.go | 3 +++ encoding/kzg/verifier/multiframe.go | 3 +++ node/node.go | 7 +++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/aggregation.go b/core/aggregation.go index cc067193f2..ebc690e24e 100644 --- a/core/aggregation.go +++ b/core/aggregation.go @@ -78,9 +78,12 @@ func NewStdSignatureAggregator(logger logging.Logger, transactor Transactor) (*S var _ SignatureAggregator = (*StdSignatureAggregator)(nil) func (a *StdSignatureAggregator) AggregateSignatures(ctx context.Context, state *IndexedOperatorState, quorumIDs []QuorumID, message [32]byte, messageChan chan SignerMessage) (*SignatureAggregation, error) { - // TODO: Add logging + if len(quorumIDs) == 0 { + return nil, errors.New("the number of quorums must be greater than zero") + } + // Ensure all quorums are found in state for _, id := range quorumIDs { _, found := state.Operators[id] diff --git a/encoding/kzg/verifier/batch_commit_equivalence.go b/encoding/kzg/verifier/batch_commit_equivalence.go index 7a290e4c12..1019ba8f7b 100644 --- a/encoding/kzg/verifier/batch_commit_equivalence.go +++ b/encoding/kzg/verifier/batch_commit_equivalence.go @@ -30,6 +30,9 @@ func GetRandomFr() (fr.Element, error) { } func CreateRandomnessVector(n int) ([]fr.Element, error) { + if n <= 0 { + return nil, errors.New("the length of vector must be positive") + } r, err := GetRandomFr() if err != nil { return nil, err diff --git a/encoding/kzg/verifier/multiframe.go b/encoding/kzg/verifier/multiframe.go index 8585846cdb..5c27785479 100644 --- a/encoding/kzg/verifier/multiframe.go +++ b/encoding/kzg/verifier/multiframe.go @@ -186,6 +186,9 @@ func (v *Verifier) UniversalVerify(params encoding.EncodingParams, samples []Sam n := len(samples) fmt.Printf("Batch verify %v frames of %v symbols out of %v blobs \n", n, params.ChunkLength, m) + if n == 0 { + return errors.New("the number of samples (i.e. chunks) must not be empty") + } // generate random field elements to aggregate equality check randomsFr, err := CreateRandomnessVector(n) diff --git a/node/node.go b/node/node.go index ddfce30d96..0208adf96d 100644 --- a/node/node.go +++ b/node/node.go @@ -267,6 +267,13 @@ func (n *Node) ProcessBatch(ctx context.Context, header *core.BatchHeader, blobs log.Debug("Processing batch", "num of blobs", len(blobs)) + if len(blobs) == 0 { + return nil, errors.New("the number of blobs must be greater than zero") + } + if len(blobs) != len(rawBlobs) { + return nil, errors.New("the number of parsed blobs must be the same as number of blobs from protobuf request") + } + // Measure num batches received and its size in bytes batchSize := int64(0) for _, blob := range blobs {