Background: I want to implement sign message feature in Trezor.

Is there a standard for signing text messages?

So far I found out that etherscan.io signs messages without the prefix, i.e. it signs keccak(msg), but also accepts signatures "with Geth prefix" of keccak("\x19Ethereum Signed Message\n32"+keccak(msg)). Signed messages of the form keccak("\x19Ethereum Signed Message\n"+strlen(msg)+msg) are not accepted.

MyEtherWallet only accepts messages signed without any prefix.

Without the prefix one can misuse the sign message feature to sign a transaction, though. Is this intentional?

4 Answers 4


There's no official standard (at the time of this writing) and has been debated for a while in this EIP thread EIP #683

According to issue #3731:

Geth prepends the string \x19Ethereum Signed Message:\n<length of message> to all data before signing it (https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign). If you want to verify such a signature from Solidity, you'll have to prepend the same string in solidity before doing the ecrecovery.


  • Is <length of message> ascii-hex, or ascii-dec or something else? (e.g. 0xff or 255)?
    – Lee
    Commented Jul 25, 2020 at 8:47
  • @atomh33ls it's an integer (e.g. 32) Commented Jul 25, 2020 at 8:57

I think it's not save to always use the same prefix when signing. For example if you have deployed the smart-contract multiple times, signatures can be replayed on each instance. You should always use a custom prefix and also add the contracts address to the hashing before you sign something. For javascript you could use eth-crypto to sign signs with a custom prefix, like described in the tutorial.

  • 1
    No, you should not use a custom prefix, as whatever signatures you end up creating would be unverifiable by every other dapp out there. Also this wouldn't solve your replay attack problem because the way to solve that is to use monotonically increasing nonces who's reuse is forbidden by the contract code. Maybe you are confused as to the purpose of this prefix. Please check out issue #3731 linked above, and this comment: github.com/ethereum/go-ethereum/issues/…
    – almel
    Commented Jun 1, 2020 at 18:15

Yes, you should use the "\x19Ethereum Signed Message" prefix.

Trezor One adds the prefix itself: https://github.com/trezor/trezor-firmware/blob/be76dcc96a09cdbb807e6a1df531912a5be20aee/legacy/firmware/ethereum.c#L631



However Trezor adds the prefix auto, but wherever its required you to manually enter it for strlen(msg),it should be "32" (in string) or better to use "\x19Ethereum Signed Message:\n32" + keccak256(msg)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.