-
Notifications
You must be signed in to change notification settings - Fork 388
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
refactor: delegate keypair encoding to cosmrs #2887
refactor: delegate keypair encoding to cosmrs #2887
Conversation
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.
A few spots that I think may cause issues, if we don't have e2e maybe you could stand up a testnet relayer locally and send a message on testnet or something? Or even mainnet
(_, Ok(v)) => ism_type_to_module_type(v.typ), | ||
_ => ModuleType::Null, | ||
}) | ||
let module_type_response = |
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.
😎
let account_id = AccountId::from_str(&addr)?; | ||
|
||
// although `from_slice` can panic if the slice is not 32 bytes long, | ||
// we know that we're passing in a value that is 32 bytes long because it was decoded from |
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.
I believe bech32 is named that because it's the encoding is done in base 32 and not because it's 32 bytes long. I think the pattern in Cosmos is that EOA addresses are 20 bytes and smart contracts are 32 bytes. So we should probably be more defensive here
Looks like account IDs can get up to 255 bytes https://docs.rs/cosmrs/latest/cosmrs/struct.AccountId.html#associatedconstant.MAX_LENGTH
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.
unit tests broke this, good point
/// Wrapper around the cosmrs AccountId type that abstracts keypair conversions and | ||
/// bech32 encoding | ||
#[derive(new)] | ||
pub struct CosmosAddress { |
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.
may be a good place to have some quick unit tests if we're uncertain about the encoding / decoding like iiuc you flag in the PR description
@@ -1,28 +0,0 @@ | |||
use hyperlane_core::{H160, H256, H512}; |
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.
🔥
@@ -1,132 +0,0 @@ | |||
use std::cmp; |
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.
🪦
@@ -78,7 +77,7 @@ impl MultisigIsm for CosmosMultisigIsm { | |||
let validators: ChainResult<Vec<H256>> = response | |||
.validators | |||
.iter() | |||
.map(|v| H160::from_str(v).map(h160_to_h256).map_err(Into::into)) | |||
.map(|v| H256::from_str(v).map_err(Into::into)) |
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.
I believe H256::from_str panics if the input length isn't 32 bytes, so we'll probably need to keep doing H160::from_str(v) and then .into() to H256
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.
great point
Fixed the address generation, just need to add a couple more unit tests |
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.
lgtm! nice job
@@ -1,3 +1,7 @@ | |||
// TODO: this file can be removed if `CosmosAddress` can be imported from `hyperlane-cosmos`. |
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.
I assume this is what you're currently looking into?
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.
actually no but I'll look into this as well
2a7d6d6
into
trevor/new-featv3-cosmos-oct-28
Removes cosmos signer unwraps by making the signer optional. Depends on #2887
Description
Delegates bech32 encoding, decoding, and cosmos address building from a private key to cosmrs/tendermint upstream crates. The only place where this wasn't doable was the tests, because of a cyclic dependency - left a TODO comment there.
As part of this, renamed
rust/chains/hyperlane-cosmos/src/libs/verify.rs
->rust/chains/hyperlane-cosmos/src/libs/address.rs
Warning: We should re-enable e2e and make sure everything still works locally, since the actualencode
/decode
functions that end up being called are differentTesting
Tested manually EVM <> Duality (both ways)