Skip to content

Commit

Permalink
[Encoder][Node] Add nil checks (Layr-Labs#425)
Browse files Browse the repository at this point in the history
Co-authored-by: Siddharth More <Siddhi More>
  • Loading branch information
siddimore authored Apr 3, 2024
1 parent e250ad8 commit cf6cd94
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions disperser/encoder/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ func (s *Server) popRequest() {
func (s *Server) handleEncoding(ctx context.Context, req *pb.EncodeBlobRequest) (*pb.EncodeBlobReply, error) {
begin := time.Now()

if len(req.Data) == 0 {
return nil, errors.New("handleEncoding: missing data")

}

if req.EncodingParams == nil {
return nil, errors.New("handleEncoding: missing encoding parameters")
}

// Convert to core EncodingParams
var encodingParams = encoding.EncodingParams{
ChunkLength: uint64(req.GetEncodingParams().GetChunkLength()),
Expand Down
6 changes: 6 additions & 0 deletions node/grpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ func ValidatePointsFromBlobHeader(h *pb.BlobHeader) error {

// GetBlobHeaderFromProto constructs a core.BlobHeader from a proto of pb.BlobHeader.
func GetBlobHeaderFromProto(h *pb.BlobHeader) (*core.BlobHeader, error) {

if h == nil {
return nil, api.NewInvalidArgError("GetBlobHeaderFromProto: blob header is nil")

}

commitX := new(fp.Element).SetBytes(h.GetCommitment().GetX())
commitY := new(fp.Element).SetBytes(h.GetCommitment().GetY())
commitment := &encoding.G1Commitment{
Expand Down
5 changes: 3 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,11 @@ 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")
return nil, errors.New("ProcessBatch: 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")
return nil, errors.New("number of parsed blobs must be the same as number of blobs from protobuf request")
}

// Measure num batches received and its size in bytes
Expand Down

0 comments on commit cf6cd94

Please sign in to comment.