Skip to content
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

fix: Prevent signing from wrong key in multisig #12446

Merged
merged 9 commits into from
Jul 12, 2022

Conversation

likhita-809
Copy link
Contributor

Description

Closes: #12328


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@codecov
Copy link

codecov bot commented Jul 6, 2022

Codecov Report

Merging #12446 (cbdf185) into main (0559893) will decrease coverage by 0.03%.
The diff coverage is 36.84%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #12446      +/-   ##
==========================================
- Coverage   65.32%   65.28%   -0.04%     
==========================================
  Files         693      693              
  Lines       71823    71869      +46     
==========================================
+ Hits        46919    46921       +2     
- Misses      22265    22308      +43     
- Partials     2639     2640       +1     
Impacted Files Coverage Δ
x/auth/client/cli/tx_sign.go 0.00% <0.00%> (ø)
crypto/keyring/record.go 66.66% <50.00%> (-1.29%) ⬇️
x/auth/client/testutil/suite.go 93.65% <100.00%> (+0.05%) ⬆️
x/distribution/simulation/operations.go 80.85% <0.00%> (-9.58%) ⬇️
x/group/keeper/keeper.go 58.66% <0.00%> (+0.39%) ⬆️
crypto/keys/internal/ecdsa/privkey.go 83.01% <0.00%> (+1.88%) ⬆️

@github-actions github-actions bot added the C:Keys Keybase, KMS and HSMs label Jul 12, 2022
@likhita-809 likhita-809 marked this pull request as ready for review July 12, 2022 11:11
@likhita-809 likhita-809 requested a review from a team as a code owner July 12, 2022 11:11
@alexanderbez alexanderbez merged commit 28f4fb9 into main Jul 12, 2022
@alexanderbez alexanderbez deleted the likhita/fix-multisig-key branch July 12, 2022 13:42
@alexanderbez
Copy link
Contributor

Crap, I forgot to mention a changelog is needed prior to merging this. @likhita-809 can you please create a PR with a chagnelog entry for this please?

Also, should we backport this to v0.46?

Copy link
Contributor

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should have been merged, I have some doubts that this PR introduces regressions, would like to clear that up first.

@alexanderbez for non-trivial PRs like this one, how about let's keep 2 approvals before merge?

@@ -59,6 +60,16 @@ func NewMultiRecord(name string, pk cryptotypes.PubKey) (*Record, error) {
return newRecord(name, pk, recordMultiItem)
}

// GetMultisigPubKey fetches a public key of the multi type record
func (k *Record) GetMultisigPubKey() (*multisig.LegacyAminoPubKey, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good API on Record: there should only be a method to get the PubKey.

Then, in tx_sign.go, we can cast .GetPubKey().(*multisig.LegacyAminoPubKey)

@@ -243,15 +242,44 @@ func makeSignCmd() func(cmd *cobra.Command, args []string) error {
}

overwrite, _ := f.GetBool(flagOverwrite)
if multisig != "" {
multisigAddr, err := sdk.AccAddressFromBech32(multisig)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that this line got deleted. @likhita-809 is this intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, because at the line L251, we are getting both name and address of the multisig irrespective of multisig flag value(be it name or address).

@@ -1057,7 +1072,7 @@ func (s *IntegrationTestSuite) TestSignWithMultisig() {
// as the main point of this test is to test the `--multisig` flag with an address
// that is not in the keyring.
_, err = TxSignExec(val1.ClientCtx, addr1, multiGeneratedTx2File.Name(), "--multisig", multisigAddr.String())
s.Require().Contains(err.Error(), "tx intended signer does not match the given signer")
s.Require().Contains(err.Error(), "error getting account from keybase")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that we changed this test seems a bit suspicious to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this test, we are passing multisig flag value as its address.
As you can see here https://github.com/cosmos/cosmos-sdk/blob/main/x/auth/client/cli/tx_sign.go#L247, since it is an address the error check will be skipped. But if multisig flag is a name, then we'll encounter error getting account from keybase error.

@alexanderbez
Copy link
Contributor

@alexanderbez for non-trivial PRs like this one, how about let's keep 2 approvals before merge?

Sure.

mergify bot pushed a commit that referenced this pull request Jul 12, 2022
@julienrbrt julienrbrt restored the likhita/fix-multisig-key branch July 12, 2022 16:04
@amaury1093 amaury1093 deleted the likhita/fix-multisig-key branch July 13, 2022 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:CLI C:Keys Keybase, KMS and HSMs C:x/auth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent signing from wrong key in multisig
3 participants