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

web3.eth.accounts.hashMessage() does not accept arbitrary hex input #2300

Closed
lukmaz opened this issue Feb 3, 2019 · 3 comments
Closed

web3.eth.accounts.hashMessage() does not accept arbitrary hex input #2300

lukmaz opened this issue Feb 3, 2019 · 3 comments
Labels
Bug Addressing a bug

Comments

@lukmaz
Copy link

lukmaz commented Feb 3, 2019

Expected behavior

If I run:

web3.eth.accounts.hashMessage("0xbf")

I expect to treat "0xbf" as a string and hash it as a string.

Actual behavior

Invalid UTF-8 detected.

Steps to reproduce the behavior

web3.eth.accounts.hashMessage("0xbf")

Error Logs

Invalid UTF-8 detected

Versions

Remix v0.7.5, Web3.js v1.0.0, Chrome, MacOS

Comment:

When the argument to web3.eth.accounts.hashMessage() starts from 0x, the function assumes that it was generated by hex-encoding from UTF-8 and it tries to decode it back to UTF-8. If it's a different hex number, the function fails. Is it really a desired behavior? What if we want to hash a different hex message? For example what if we want to hash a message which itself is a hash?

It is quite a headache if you have a message (which is some hash value, starting from 0x) and you want to sign it in web3.js and then verify the signature in Solidity. To have the same numbers on both sides you need to either:

  • accept hex values to be signed in web3.js (which is impossible because of this hashMessage issue),

or

  • manually modify the hex string to not start with 0x (which is inconvenient in Solidity).
@nivida
Copy link
Contributor

nivida commented Feb 3, 2019

Could you please use the issue template? Otherwise, I will close this issue in the next minutes.

@nivida nivida closed this as completed Feb 3, 2019
@lukmaz
Copy link
Author

lukmaz commented Feb 3, 2019

I've edited the issue to match the template. Is it ok now?

@lukmaz
Copy link
Author

lukmaz commented Feb 4, 2019

Hi @nivida , can you please reopen the issue? The issue didn't disappear and now I think I used the correct template. If something is wrong with this issue, please let me know.

@nivida nivida reopened this Feb 6, 2019
@nivida nivida added Bug Addressing a bug Needs Clarification Requires additional input labels Feb 7, 2019
@nivida nivida removed the Needs Clarification Requires additional input label Feb 27, 2019
@nivida nivida closed this as completed Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

No branches or pull requests

3 participants
@nivida @lukmaz and others