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

Signature verification failed: when account number is 0 #217

Closed
angelorc opened this issue Dec 10, 2021 · 2 comments
Closed

Signature verification failed: when account number is 0 #217

angelorc opened this issue Dec 10, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@angelorc
Copy link

Summary of Bug

When an account number 0 tries to sign any transaction always gets the following error:

Broadcasting transaction failed with code 4 (codespace: sdk). Log: signature verification failed; please verify account number (0) and chain-id (localnet): unauthorized.

Versions

  • CosmJS - v0.26.5
  • Cosmos-SDK - v0.42.10

Step to Reproduce

  1. Start a new chain v0.42.10
  2. Add 2 accounts
  3. Import the first (account 0) and the second (account 1) to Keplr
  4. Connect keplr with your application window.getOfflineSigner(chainId)
  5. Send tokens from the account 0
     {
     	"typeUrl": "/cosmos.bank.v1beta1.MsgSend",
     	"value": {
     		"fromAddress": "bitsong1vgpsha4f8grmsqr6krfdxwpcf3x20h0q3ztaj2",
     		"toAddress": "bitsong1vgpsha4f8grmsqr6krfdxwpcf3x20h0q3ztaj2",
     		"amount": [
     			{
     				"amount": "1000000",
     				"denom": "ubtsg"
     			}
     		]
     	}
     }
    
    • The transaction receive an error
      Broadcasting transaction failed with code 4 (codespace: sdk). Log: signature verification failed; please verify account number (0) and chain-id (localnet): unauthorized.
      
  6. Send tokens from the account 1
     {
     	"typeUrl": "/cosmos.bank.v1beta1.MsgSend",
     	"value": {
     		"fromAddress": "bitsong1zm6wlhr622yr9d7hh4t70acdfg6c32kcv34duw",
     		"toAddress": "bitsong1zm6wlhr622yr9d7hh4t70acdfg6c32kcv34duw",
     		"amount": [
     			{
     				"amount": "1000000",
     				"denom": "ubtsg"
     			}
     		]
     	}
     }
    
    • The transaction will pass Successful Send

Side note

If instead we try to perform the same operation via command line (bitsongd tx send.....) no errors are found.
The bug isn't related to cosmjs cosmos/cosmjs#961

@Thunnini
Copy link
Member

At a glance, it should be skipped when the account number is 0, but it seems to be a problem because it is encoded as 0. Let me explore some more about protobufjs.
https://github.com/chainapsis/keplr-extension/blob/master/packages/cosmos/src/stargate/proto/generated/codecimpl.js#L2982

@Thunnini
Copy link
Member

Looking at cosmjs, it seems that cosmjs uses https://github.com/stephenh/ts-proto. The protobufjs currently used by keplr includes the default value on encoding, and there seems to be no way to prevent it.
First of all, since I have never used ts-proto, this issue is unlikely to be resolved in the next version.

Either use ts-proto or manually modify the output from the compiled protobufjs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants
@angelorc @Thunnini and others