Skip to content

Commit

Permalink
rhp4: validate sector indices
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Oct 21, 2024
1 parent f0d4bda commit fd212fd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion rhp/v4/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ func (req *RPCWriteSectorStreamingRequest) Validate(pk types.PublicKey, maxDurat
}

// Validate validates a modify sectors request. Signatures are not validated.
func (req *RPCRemoveSectorsRequest) Validate(pk types.PublicKey, maxActions uint64) error {
func (req *RPCRemoveSectorsRequest) Validate(pk types.PublicKey, fc types.V2FileContract, maxActions uint64) error {
if err := req.Prices.Validate(pk); err != nil {
return fmt.Errorf("prices are invalid: %w", err)
} else if uint64(len(req.Indices)) > maxActions {
return fmt.Errorf("removing to many sectors at once: %d > %d", len(req.Indices), maxActions)
}
sectors := fc.Filesize / SectorSize
for _, index := range req.Indices {
if index >= sectors {
return fmt.Errorf("sector index %d exceeds contract sectors %d", index, sectors)
}
}
return nil
}

Expand Down

0 comments on commit fd212fd

Please sign in to comment.