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

Can we make AccAddressFromHex safer? #11881

Closed
ebuchman opened this issue May 5, 2022 · 4 comments · Fixed by #11888
Closed

Can we make AccAddressFromHex safer? #11881

ebuchman opened this issue May 5, 2022 · 4 comments · Fixed by #11888

Comments

@ebuchman
Copy link
Member

ebuchman commented May 5, 2022

Juno seems to have sent funds to a tx hash: https://www.coindesk.com/tech/2022/05/05/typo-moves-36m-in-seized-juno-tokens-to-wrong-wallet/

It looks like they converted a 64-byte tx hash to an address: https://github.com/CosmosContracts/juno/blob/v4.0.0/app/upgrade/upgrade_handler.go#L17-L21

Addresses are 20 bytes, while this thing is 32 bytes. Can we get AccAddressFromHex to panic if the address is not the right length?

I know there is some work to allow longer addresses, but maybe it can still be configured somehow to prevent errors like this ?

@webmaster128
Copy link
Member

webmaster128 commented May 5, 2022

32 byte addresses are perfectly valid these days. Yes, this is the same length as tx hashes. But 32 is common for a lot of things.

Isn't the issue more there source of the data? I'm not familiar with what junod keys parse juno1nz96hjc926e6a74gyvkwvtt0qhu22wx049c6ph6f4q8kp3ffm9xq5938mr does, but it does not seem to be bech32 decoding.

Using CosmJS to decode the input, you get a different 32 byte data:

$ npx @cosmjs/cli@0.28.0 --code 'import { fromBech32, toHex } from "@cosmjs/encoding"; const { prefix, data } = fromBech32("juno1nz96hjc926e6a74gyvkwvtt0qhu22wx049c6ph6f4q8kp3ffm9xq5938mr"); console.log(toHex(data))'
>> 988babcb0556b3aefaa8232ce62d6f05f8a538cfa971a0df49a80f60c529d94c

Same result in the Go code:

$ ~/go/bin/wasmd keys parse juno1nz96hjc926e6a74gyvkwvtt0qhu22wx049c6ph6f4q8kp3ffm9xq5938mr
human: juno
bytes: 988BABCB0556B3AEFAA8232CE62D6F05F8A538CFA971A0DF49A80F60C529D94C

@ebuchman
Copy link
Member Author

ebuchman commented May 5, 2022

Right thanks, good to know.

What if we just get rid of AccAddressFromHex? Or at least call it Unsafe or something? Seems like it's hardly used.

@webmaster128
Copy link
Member

webmaster128 commented May 5, 2022

Yeah. Not sure why AccAddressFromBech32 was not used. Maybe the global config causes issues in some contexts? In this case it would be good to have an bech32 to bytes converter that ignores the prefix.

@giansalex
Copy link
Contributor

Yeah. Not sure why AccAddressFromBech32 was not used. Maybe the global config causes issues in some contexts? In this case it would be good to have an bech32 to bytes converter that ignores the prefix.

bech32 could be used perfectly, there was no need to use hex address

@mergify mergify bot closed this as completed in #11888 May 6, 2022
mergify bot pushed a commit that referenced this issue May 6, 2022
## Description

Closes: #11881



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this issue May 22, 2023
## Description

Closes: cosmos#11881



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants