Skip to content

Commit

Permalink
cmd: validate withdrawal address for create dkg command (#599)
Browse files Browse the repository at this point in the history
Adds a validation for withdrawal address for create dkg command.

category: bug
ticket: #582
  • Loading branch information
dB2510 authored May 24, 2022
1 parent f56ceb3 commit a2fd562
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cmd/createdkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"path"

"github.com/ethereum/go-ethereum/common"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

Expand Down Expand Up @@ -74,7 +75,7 @@ func bindCreateDKGFlags(flags *pflag.FlagSet, config *createDKGConfig) {
flags.IntVar(&config.NumValidators, "num-validators", 1, "The number of distributed validators the cluster will manage (32ETH staked for each).")
flags.IntVarP(&config.Threshold, "threshold", "t", 3, "The threshold required for signature reconstruction. Minimum is n-(ceil(n/3)-1).")
flags.StringVar(&config.FeeRecipient, "fee-recipient-address", "", "Optional Ethereum address of the fee recipient")
flags.StringVar(&config.WithdrawalAddress, "withdrawal-address", "", "Withdrawal Ethereum address")
flags.StringVar(&config.WithdrawalAddress, "withdrawal-address", defaultWithdrawalAddr, "Withdrawal Ethereum address")
flags.StringVar(&config.Network, "network", defaultNetwork, "Ethereum network to create validators for. Options: mainnet, prater, kintsugi, kiln, gnosis.")
flags.StringVar(&config.DKGAlgo, "dkg-algorithm", "default", "DKG algorithm to use; default, keycast, frost")
flags.StringSliceVar(&config.OperatorENRs, "operator-enrs", nil, "Comma-separated list of each operator's Charon ENR address")
Expand All @@ -92,6 +93,10 @@ func runCreateDKG(_ context.Context, conf createDKGConfig) error {
return errors.New("unsupported network", z.Str("network", conf.Network))
}

if err := validateWithdrawalAddr(conf.WithdrawalAddress, conf.Network); err != nil {
return err
}

forkVersion := networkToForkVersion[conf.Network]

def := cluster.NewDefinition(conf.Name, conf.NumValidators, conf.Threshold, conf.FeeRecipient, conf.WithdrawalAddress,
Expand All @@ -113,3 +118,17 @@ func runCreateDKG(_ context.Context, conf createDKGConfig) error {

return nil
}

func validateWithdrawalAddr(addr string, network string) error {
if !common.IsHexAddress(addr) {
return errors.New("invalid address")
}

// We cannot allow a zero withdrawal address on mainnet or gnosis.
if (network == "mainnet" || network == "gnosis") &&
addr == defaultWithdrawalAddr {
return errors.New("zero address forbidden on this network", z.Str("network", network))
}

return nil
}

0 comments on commit a2fd562

Please sign in to comment.