-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
createdkg: validate inputs #2136
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,22 +79,31 @@ func runCreateDKG(ctx context.Context, conf createDKGConfig) (err error) { | |
} | ||
}() | ||
|
||
// Map prater to goerli to ensure backwards compatibility with older cluster definitions. | ||
// TODO(xenowits): Remove the mapping later. | ||
if conf.Network == eth2util.Prater { | ||
conf.Network = eth2util.Goerli.Name | ||
} | ||
|
||
if err = validateConfig(conf.Threshold, len(conf.OperatorENRs), conf.Network); err != nil { | ||
return err | ||
} | ||
|
||
conf.FeeRecipientAddrs, conf.WithdrawalAddrs, err = validateAddresses(conf.NumValidators, conf.FeeRecipientAddrs, conf.WithdrawalAddrs) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err = validateWithdrawalAddrs(conf.WithdrawalAddrs, conf.Network); err != nil { | ||
return err | ||
} | ||
|
||
version.LogInfo(ctx, "Charon create DKG starting") | ||
|
||
if _, err := os.Stat(path.Join(conf.OutputDir, "cluster-definition.json")); err == nil { | ||
return errors.New("existing cluster-definition.json found. Try again after deleting it") | ||
} | ||
|
||
// Don't allow cluster size to be less than 4. | ||
if len(conf.OperatorENRs) < minNodes { | ||
return errors.New("insufficient operator ENRs (min = 4)") | ||
} | ||
|
||
var operators []cluster.Operator | ||
for i, opENR := range conf.OperatorENRs { | ||
_, err := enr.Parse(opENR) | ||
|
@@ -113,20 +122,6 @@ func runCreateDKG(ctx context.Context, conf createDKGConfig) (err error) { | |
log.Warn(ctx, "Non standard `--threshold` flag provided, this will affect cluster safety", nil, z.Int("threshold", conf.Threshold), z.Int("safe_threshold", safeThreshold)) | ||
} | ||
|
||
// Map prater to goerli to ensure backwards compatibility with older cluster definitions. | ||
// TODO(xenowits): Remove the mapping later. | ||
if conf.Network == eth2util.Prater { | ||
conf.Network = eth2util.Goerli.Name | ||
} | ||
|
||
if !eth2util.ValidNetwork(conf.Network) { | ||
return errors.New("unsupported network", z.Str("network", conf.Network)) | ||
} | ||
|
||
if err := validateWithdrawalAddrs(conf.WithdrawalAddrs, conf.Network); err != nil { | ||
return err | ||
} | ||
|
||
forkVersion, err := eth2util.NetworkToForkVersion(conf.Network) | ||
if err != nil { | ||
return err | ||
|
@@ -166,22 +161,45 @@ func runCreateDKG(ctx context.Context, conf createDKGConfig) (err error) { | |
return nil | ||
} | ||
|
||
// validateWithdrawalAddrs returns an error if any of the provided withdrawal addresses is invalid. | ||
func validateWithdrawalAddrs(addrs []string, network string) error { | ||
for _, addr := range addrs { | ||
if _, err := eth2util.ChecksumAddress(addr); err != nil { | ||
checksumAddr, err := eth2util.ChecksumAddress(addr) | ||
if err != nil { | ||
return errors.Wrap(err, "invalid withdrawal address", z.Str("addr", addr)) | ||
} else if checksumAddr != addr { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix for #2094 |
||
return errors.New("invalid checksummed address", z.Str("addr", addr)) | ||
} | ||
|
||
// We cannot allow a zero withdrawal address on mainnet or gnosis. | ||
if isMainNetwork(network) && addr == zeroAddress { | ||
if isMainOrGnosis(network) && addr == zeroAddress { | ||
return errors.New("zero address forbidden on this network", z.Str("network", network)) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// isMainNetwork returns true if the network is either mainnet or gnosis. | ||
func isMainNetwork(network string) bool { | ||
// validateConfig returns an error if any of the provided config parameter is invalid. | ||
func validateConfig(threshold, numOperators int, network string) error { | ||
if threshold > numOperators { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix for #2093 |
||
return errors.New("threshold cannot be greater than length of operators", | ||
z.Int("threshold", threshold), z.Int("operators", numOperators)) | ||
} | ||
|
||
// Don't allow cluster size to be less than 4. | ||
if numOperators < minNodes { | ||
return errors.New("insufficient operator ENRs (min = 4)") | ||
} | ||
|
||
if !eth2util.ValidNetwork(network) { | ||
return errors.New("unsupported network", z.Str("network", network)) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// isMainOrGnosis returns true if the network is either mainnet or gnosis. | ||
func isMainOrGnosis(network string) bool { | ||
return network == eth2util.Mainnet.Name || network == eth2util.Gnosis.Name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.