-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix: nested multisig signatures using CLI #20438
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
Changes from 7 commits
da2293e
483812c
3d4e5ab
5602a59
9a76694
af33f6d
661eee7
d212cb8
3cab6e8
fb8506f
4ecdd81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -169,6 +169,9 @@ func packPubKeys(pubKeys []cryptotypes.PubKey) ([]*types.Any, error) { | |||||||||
| return nil, err | ||||||||||
| } | ||||||||||
| anyPubKeys[i] = any | ||||||||||
|
|
||||||||||
| // sets the compat.aminoBz value | ||||||||||
| anyPubKeys[i].UnmarshalAmino(pubKeys[i].Bytes()) | ||||||||||
|
Contributor
Author
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 was the necessary fix to allow nested anys
Contributor
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. The error return value of - anyPubKeys[i].UnmarshalAmino(pubKeys[i].Bytes())
+ if err := anyPubKeys[i].UnmarshalAmino(pubKeys[i].Bytes()); err != nil {
+ return nil, err
+ }Committable suggestion
Suggested change
Toolsgolangci-lint
GitHub Check: golangci-lint
|
||||||||||
| } | ||||||||||
| return anyPubKeys, nil | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,10 @@ If the --offline flag is on, the client will not reach out to an external node. | |
| Account number or sequence number lookups are not performed so you must | ||
| set these parameters manually. | ||
|
|
||
| If the --skip-signature-verification flag is on, the command will not verify the | ||
| signatures in the provided signature files. This is useful when the multisig | ||
| account is a signer in a nested multisig scenario. | ||
|
|
||
| The current multisig implementation defaults to amino-json sign mode. | ||
| The SIGN_MODE_DIRECT sign mode is not supported.' | ||
| `, | ||
|
|
@@ -57,6 +61,7 @@ The SIGN_MODE_DIRECT sign mode is not supported.' | |
| Args: cobra.MinimumNArgs(3), | ||
| } | ||
|
|
||
| cmd.Flags().Bool(flagSkipSignatureVerification, false, "Skip signature verification") | ||
|
Contributor
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. can we add this to some docs somewhere? easy to get lost in the immense amount of code
Contributor
Author
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. Added docs and changelog 💪 |
||
| cmd.Flags().Bool(flagSigOnly, false, "Print only the generated signature, then exit") | ||
| cmd.Flags().String(flags.FlagOutputDocument, "", "The document is written to the given file instead of STDOUT") | ||
| flags.AddTxFlagsToCmd(cmd) | ||
|
|
@@ -109,6 +114,10 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { | |
| return err | ||
| } | ||
|
|
||
| // avoid signature verification if the sender of the tx is different than | ||
| // the multisig key (useful for nested multisigs). | ||
| skipSigVerify, _ := cmd.Flags().GetBool(flagSkipSignatureVerification) | ||
|
Contributor
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. We should describe this flag somewhere in the docs.
Contributor
Author
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. done! |
||
|
|
||
| multisigPub := pubKey.(*kmultisig.LegacyAminoPubKey) | ||
| multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) | ||
| if !clientCtx.Offline { | ||
|
|
@@ -153,11 +162,13 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { | |
| } | ||
| txData := adaptableTx.GetSigningTxData() | ||
|
|
||
| err = signing.VerifySignature(cmd.Context(), sig.PubKey, txSignerData, sig.Data, | ||
| txCfg.SignModeHandler(), txData) | ||
| if err != nil { | ||
| addr, _ := sdk.AccAddressFromHexUnsafe(sig.PubKey.Address().String()) | ||
| return fmt.Errorf("couldn't verify signature for address %s", addr) | ||
| if !skipSigVerify { | ||
| err = signing.VerifySignature(cmd.Context(), sig.PubKey, txSignerData, sig.Data, | ||
| txCfg.SignModeHandler(), txData) | ||
| if err != nil { | ||
| addr, _ := sdk.AccAddressFromHexUnsafe(sig.PubKey.Address().String()) | ||
| return fmt.Errorf("couldn't verify signature for address %s %w", addr, err) | ||
| } | ||
| } | ||
|
|
||
| if err := multisig.AddSignatureV2(multisigSig, sig, multisigPub.GetPubKeys()); err != nil { | ||
|
|
||
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.
The test
TestBech32KeysOutputNestedMsigappears comprehensive and correctly tests the output of a nested multisig key. However, consider adding more assertions to verify the structure of the nested multisig key in more detail, such as checking individual public keys within the nested structure.