-
Notifications
You must be signed in to change notification settings - Fork 41
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
feat: CUDOS extra config verification #414
Merged
MissingNO57
merged 3 commits into
release/v0.14.x
from
improvement/cudos_config_verification
Oct 25, 2024
Merged
Changes from 1 commit
Commits
Show all changes
3 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"encoding/json" | ||
"fmt" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/bech32" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
@@ -549,3 +550,131 @@ func (c *ProdDevContract) GetContracts(contracts []string) []string { | |
|
||
return contracts | ||
} | ||
|
||
func verifyAddress(address string, expectedPrefix *string) error { | ||
prefix, decodedAddrData, err := bech32.DecodeAndConvert(address) | ||
if err != nil { | ||
return err | ||
} | ||
if expectedPrefix != nil && prefix != *expectedPrefix { | ||
return fmt.Errorf("expected address prefix %s, got %s", *expectedPrefix, prefix) | ||
} | ||
|
||
reconstructedAddr, err := bech32.ConvertAndEncode(prefix, decodedAddrData) | ||
if err != nil { | ||
return err | ||
} | ||
if address != reconstructedAddr { | ||
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. This effectively ensures, that the original |
||
return fmt.Errorf("Invalid address '%s'", address) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func VerifyConfig(cudosCfg *CudosMergeConfig, sourceAddrPrefix string, DestAddrPrefix string) error { | ||
expectedSourceValoperPrefix := sourceAddrPrefix + ValAddressPrefix | ||
expectedDestValoperPrefix := DestAddrPrefix + ValAddressPrefix | ||
|
||
for i := range cudosCfg.ValidatorsMap.Iterate() { | ||
srcValidator, DestValidator := i.Key, i.Value | ||
err := verifyAddress(srcValidator, &expectedSourceValoperPrefix) | ||
if err != nil { | ||
return err | ||
} | ||
err = verifyAddress(DestValidator, &expectedDestValoperPrefix) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
for _, notDelegatedAccount := range cudosCfg.NotDelegatedAccounts.Keys() { | ||
err := verifyAddress(notDelegatedAccount, &sourceAddrPrefix) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
for _, notVestedAccount := range cudosCfg.NotVestedAccounts.Keys() { | ||
err := verifyAddress(notVestedAccount, &sourceAddrPrefix) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
for _, movement := range cudosCfg.Config.MovedAccounts { | ||
err := verifyAddress(movement.SourceAddress, &sourceAddrPrefix) | ||
if err != nil { | ||
return err | ||
} | ||
err = verifyAddress(movement.DestinationAddress, &sourceAddrPrefix) | ||
if err != nil { | ||
return err | ||
} | ||
if movement.Amount != nil && movement.Amount.IsNegative() { | ||
return fmt.Errorf("negative amount %s for movement from account %s to %s", movement.Amount, movement.SourceAddress, movement.DestinationAddress) | ||
} | ||
} | ||
|
||
err := verifyAddress(cudosCfg.Config.IbcTargetAddr, &sourceAddrPrefix) | ||
if err != nil { | ||
return fmt.Errorf("ibc targer address error: %v", err) | ||
} | ||
|
||
err = verifyAddress(cudosCfg.Config.RemainingStakingBalanceAddr, &sourceAddrPrefix) | ||
if err != nil { | ||
return fmt.Errorf("remaining staking balance address error: %v", err) | ||
} | ||
|
||
err = verifyAddress(cudosCfg.Config.RemainingGravityBalanceAddr, &sourceAddrPrefix) | ||
if err != nil { | ||
return fmt.Errorf("remaining gravity balance address error: %v", err) | ||
} | ||
|
||
err = verifyAddress(cudosCfg.Config.RemainingDistributionBalanceAddr, &sourceAddrPrefix) | ||
if err != nil { | ||
return fmt.Errorf("remaining distribution balance address error: %v", err) | ||
} | ||
|
||
err = verifyAddress(cudosCfg.Config.ContractDestinationFallbackAddr, &sourceAddrPrefix) | ||
if err != nil { | ||
return fmt.Errorf("contract destination fallback address error: %v", err) | ||
} | ||
|
||
err = verifyAddress(cudosCfg.Config.GenericModuleRemainingBalance, &sourceAddrPrefix) | ||
if err != nil { | ||
return fmt.Errorf("remaining general module balance address error: %v", err) | ||
} | ||
|
||
// Community pool address is optional | ||
if cudosCfg.Config.CommunityPoolBalanceDestAddr != "" { | ||
err = verifyAddress(cudosCfg.Config.CommunityPoolBalanceDestAddr, &sourceAddrPrefix) | ||
if err != nil { | ||
return fmt.Errorf("community pool balance destination address error: %v", err) | ||
} | ||
} | ||
|
||
err = verifyAddress(cudosCfg.Config.CommissionFetchAddr, &DestAddrPrefix) | ||
if err != nil { | ||
return fmt.Errorf("comission address error: %v", err) | ||
} | ||
|
||
err = verifyAddress(cudosCfg.Config.ExtraSupplyFetchAddr, &DestAddrPrefix) | ||
if err != nil { | ||
return fmt.Errorf("extra supply address error: %v", err) | ||
} | ||
|
||
err = verifyAddress(cudosCfg.Config.VestingCollisionDestAddr, &sourceAddrPrefix) | ||
if err != nil { | ||
return fmt.Errorf("vesting collision destination address error: %v", err) | ||
} | ||
|
||
if len(cudosCfg.Config.BalanceConversionConstants) == 0 { | ||
return fmt.Errorf("list of conversion constants is empty") | ||
} | ||
|
||
if len(cudosCfg.Config.BackupValidators) == 0 { | ||
return fmt.Errorf("list of backup validators is empty") | ||
} | ||
|
||
return nil | ||
} |
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.
This ensures exclusivity of the
pair.Key
in the input list = that input list do NOT contain more then single pair with the samepair.Key
value.