5

I was searching through the internet for the meaning of this prefix. Solidity docs do not have a clear explanation. So what is this and why should I use it?

"\x19Ethereum Signed Message:\n32",

juice
  • 49
  • 2

1 Answers1

3

The prefix was introduced in EIP-191 as a way to distinguish signatures meant for Ethereum smart contracts, and for other cryptographic platforms. By adding the Ethereum-specific prefix, the message (with the prefix) results in a different signature, specific just for Ethereum. But if there were no platform-specific prefixes, the resulting signature would be the same for all platforms, which could potentially lead to signature replay attacks.

Note: Back in 2016, when this standard was introduced, there were no other EVM networks (e.g. Binance Smart Chain and Polygon) - or at least they were not widely used. Nowdays it's common to use the "Ethereum" prefix even if the message is intended for other EVM networks such as Polygon.

This specific byte 0x19 was standardized simply because an already existing implementation (in the Go Ethereum client software) was using it before the standard was finalized.

And the last number (32 in this case) is the byte length of the message (excluding the prefix) that is being signed.

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100