ethereum / remix-project

Remix is a browser-based compiler and IDE that enables users to build Ethereum contracts with Solidity language and to debug transactions.
https://remix-ide.readthedocs.io
MIT License
2.36k stars 888 forks source link

hash message signed by remix is different from eip191? #3141

Open DessertHeart opened 1 year ago

DessertHeart commented 1 year ago

Hi. I have some doubts regarding hash computation in remix IDE. For signing a message in Ethereum, first, the hash of the message is computed. on the hash, signing is done. This is fine.

What I really don't understand is that, how does remix ide compute the message hash? After going through some resources, I found that remix computes the hash value of the message's by prepending a string and then the message.. and that is \x19Ethereum Signed Message:\n32and followed by the keccak256 hash of the message. That is what I have understood.

Say I want to sign a message "hello". So first the hash will be created in this way .. First> x <-- keccak256("hello"); then second hash <-- keccak256("\x19Ethereum Signed Message:\n32"||x);This is the final hash value on which signing will be done. unfortunately, the computed hash value in this way does not match what Remix gives at the run section(in Remix VM mode signing from some account), But! the signature is correct, it can pass the ethereum errecover(), so why plz help.

image image

and i know that hash is computed by ethereum.util.hashPersonalMessage(), if so, it should be same......

image
Qlinak commented 1 month ago

find the solution after hours