-
Notifications
You must be signed in to change notification settings - Fork 334
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
cosmwasm-std instantiate2 implementation not accounting for chain contract address length #2155
Comments
This is out of scope as Instantiate2 always uses the ADR for module accounts that always results in 32 byte addresses. All implementations of instantiate2 create 32 byte addresses. |
Actually I wonder why we even have |
Yes it's done by forking wasmd, see e.g. https://github.com/InjectiveLabs/wasmd/blob/f/v0.40.2-inj-1/x/wasm/types/types.go#L21 |
Okay, then I think we should remove that part and always make it 32 byte addresses. The whole algorithm does not have a address length input. It's based on the "Basic Address" Hash from https://github.com/cosmos/cosmos-sdk/blob/v0.45.8/docs/architecture/adr-028-public-key-addresses.md which is all about moving from 20 byte to 32 byte addresses. |
We cannot use 32 byte addresses at Injective for various reasons and have also deemed the risks of having 20 byte addresses as acceptable. Other chains may choose non-32 byte addresses as well and |
I will ask around if we adapt the spec at some point in the future, but for now Instantate2 are fixed length 32 bytes outputs. You can have a custom solution by just wrapping it in a custom manner like this: pub fn my_address(
checksum: &[u8],
creator: &CanonicalAddr,
salt: &[u8],
) -> Result<CanonicalAddr, Instantiate2AddressError> {
Ok(instantiate2_address(checksum, creator, salt)?[..20].into())
} |
Ok, that's how to fix it for predicting instantiate2 address, but what about WasmMsg::Instantiate2? Does it also shorten and result to same address with length of 20? |
@taitruong The chain side is already truncating it accordingly: https://github.com/CosmWasm/wasmd/blob/5ec0c5ed3f93ab5eb8a3e1d3e923a6db28a27160/x/wasm/keeper/addresses.go#L71 |
Ty, ser! I've tested it on testnet for ics721 (public-awesome/cw-ics721#97) and it works like a charm! |
Any update on this? As @gorgos mentioned
Ran into this issue today. |
For now, I'll be using this solution, but it took me quite some time to figure out what went wrong and to find this post. It should just work, and that will make future (injective) developers happy. |
This is on our radar and we will take a look at this for the 2.3 release. I think it would also make sense to make the wasmd const a var to allow chains to change it without having to fork. |
The
instantiate2_address
helper inside cosmwasm-std is not accounting for the length of chain's contract addresses. Something like this would work:The text was updated successfully, but these errors were encountered: