Cosmos-sdk: SignBytes calculation differs per msg type

Created on 21 Jan 2019  Â·  4Comments  Â·  Source: cosmos/cosmos-sdk

Summary of Bug

Serializing bank.MsgSend and staking.Delegation differs. In bank.MsgSend the msg is serialized without type and value:

{"account_number":"0","chain_id":"local-testnet","fee":{"amount":[],"gas":"500000"},"memo":"","msgs":[{"inputs":[{"address":"cosmos1sn0f0phpv9rzkf0956uwu5ja88ramcv7u2dx2y","coins":[{"amount":"10","denom":"photino"}]}],"outputs":[{"address":"cosmos1sn0f0phpv9rzkf0956uwu5ja88ramcv7u2dx2y","coins":[{"amount":"10","denom":"photino"}]}]}],"sequence":"4"}

For staking.Delegation we need to leave type and value in:

{"account_number":"0","chain_id":"local-testnet","fee":{"amount":[],"gas":"500000"},"memo":"","msgs":[{"type":"cosmos-sdk/MsgDelegate","value":{"delegation":{"amount":"10","denom":"stake"},"delegator_addr":"cosmos1sn0f0phpv9rzkf0956uwu5ja88ramcv7u2dx2y","validator_addr":"cosmosvaloper1sn0f0phpv9rzkf0956uwu5ja88ramcv7e7enxh"}}],"sequence":"3"}

Steps to Reproduce


For Admin Use

  • [ ] Not duplicate issue
  • [ ] Appropriate labels applied
  • [ ] Appropriate contributors tagged
  • [ ] Contributor assigned/self-assigned
bug security

Most helpful comment

That's a bug, great catch.

type and value should be left in as replay-protection against different modules.

We ought to review this across all of our modules.

All 4 comments

That's a bug, great catch.

type and value should be left in as replay-protection against different modules.

We ought to review this across all of our modules.

$ gaiacli tx send --from=foo --to=cosmos103ee72v6m096y2xq3rrxv5uex7pawh5y6uykt4 --amount=1stake --generate-only 
{"type":"auth/StdTx","value":{"msg":[{"type":"cosmos-sdk/Send","value":{"inputs":[{"address":"cosmos1570v2fq3twt0f0x02vhxpuzc9jc4yl30q2qned","coins":[{"denom":"stake","amount":"1"}]}],"outputs":[{"address":"cosmos103ee72v6m096y2xq3rrxv5uex7pawh5y6uykt4","coins":[{"denom":"stake","amount":"1"}]}]}}],"fee":{"amount":null,"gas":"200000"},"signatures":null,"memo":""}}

send seems to work just fine. Haven't tested delegate quite yet though

It's not about the generate_only it is about the signBytes you need to calculate before creating the signature of those signBytes.

Is it because GetSignBytes for MsgSend uses a custom inline struct not resisted with the codec?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rigelrozanski picture rigelrozanski  Â·  3Comments

fedekunze picture fedekunze  Â·  3Comments

cwgoes picture cwgoes  Â·  3Comments

ValarDragon picture ValarDragon  Â·  3Comments

kevlubkcm picture kevlubkcm  Â·  3Comments