Closed penso closed 6 months ago
Seems similar to #1417, but in this case the public key is invalid:
AF390E8EB13DC2C89F91D09EB5BEF64367BD3BD0C3446C270A6277335228E7DF87
It's 33-bytes like we'd expect: SEC1 tag || secp256k1 x-coordinate
, but where a valid SEC1 tag is: 0x00
, 0x02
, 0x03
, 0x04
, this key for whatever reason has 0xAF
, which is not a valid SEC1 tag.
Really this is a CosmRS (and Osmosis) issue as opposed to a tendermint-rs one. CosmRS tries to eagerly parse the public key, and it seems like we just won't be able to rely on chains not to put out garbage public keys. Those garbage public keys likely represent some sort of bug in Osmosis where it failed to validate the key in the first place, but once they wind up in the chain data there's really no way of fixing them.
cosmos-rust
shouldn't try to validate public keys, there is too much garbage out there. Maybe it should be a specific call like public_key.is_valid()
to prevent such issues but looking at the code you can't create an invalid PublicKey
so it should be done differently, like holding the raw bytes for the keys and only call Secp256k1::from_sec1_bytes
when is_valid()
or parse()
is called.Is there a deeper issue if the Osmosis chain accepted invalid public keys as part of a successful transaction?
Possibly. You might open an Osmosis issue about this block and see if they can figure out what happened.
Closing this, will followup if any news.
@penso as a stopgap, you can parse these transactions as e.g. cosmos_sdk_proto::cosmos::tx::v1beta1::Tx
rather than cosmrs::Tx
This is likely coming from the SDK not validating this first byte here: https://github.com/cosmos/cosmos-sdk/blob/main/crypto/keys/secp256k1/secp256k1.go#L203-L211
I opened a Cosmos SDK bug: https://github.com/cosmos/cosmos-sdk/issues/20406
What went wrong?
I get a cryptographic error in this cosmos-rust line coming from this tendermint-rs line when parsing what seems to be a valid transaction. This is the mintscan transaction properly indexed.
Steps to reproduce
This is a code sample showing it fails.
Output:
Definition of "done"
We should be able to parse this public key without error