Skip to content

Commit

Permalink
Hardening threshold parameter checks
Browse files Browse the repository at this point in the history
  • Loading branch information
aadomn committed Aug 28, 2024
1 parent 616d302 commit 14a5726
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/createcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,15 @@ func validateCreateConfig(ctx context.Context, conf clusterConfig) error {
return errors.New("missing --nodes flag")
}

// check for threshold parameter
if conf.Threshold < 2 {
return errors.New("threshold cannot be smaller than 2", z.Int("threshold", conf.Threshold))
}
if conf.Threshold > conf.NumNodes {
return errors.New("threshold cannot be greater than number of operators",
z.Int("threshold", conf.Threshold), z.Int("operators", conf.NumNodes))
}

// Check for valid network configuration.
if err := validateNetworkConfig(conf); err != nil {
return errors.Wrap(err, "get network config")
Expand Down
4 changes: 4 additions & 0 deletions cmd/createdkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ func validateWithdrawalAddrs(addrs []string, network string) error {

// validateDKGConfig returns an error if any of the provided config parameter is invalid.
func validateDKGConfig(threshold, numOperators int, network string, depositAmounts []int) error {
if threshold < 2 {
return errors.New("threshold cannot be smaller than 2", z.Int("threshold", threshold))
}

if threshold > numOperators {
return errors.New("threshold cannot be greater than length of operators",
z.Int("threshold", threshold), z.Int("operators", numOperators))
Expand Down

0 comments on commit 14a5726

Please sign in to comment.