This is part 1 out of a 2 part thread series dedicated to Signatures in Ethereum.
It was inevitable that sooner or later, we would need to talk about this.
But bear with us, as we're going to make this as digestible as possible!
First stop, Public Key Cryptography ๐๐ฉโ๐ซ
๐
There are two main purposes of cryptography
- prove knowledge of a secret without revealing the secret
- prove authenticity of data (digital signature)
Cryptography is used extensively within Ethereum, and one place that users meet with cryptography is via Ethereum accounts.๐ฉโ๐ป
Proof of ownership of Externally Owned Accounts (EOAs) is established through private keys and digital signatures.
The private keys are used almost everywhere within Ethereum during user interactions, and the Ethereum address of an EOA is derived from the private key.
In other words, the Ethereum address is the last 20 bytes of the hash of the public key controlling the account!
To prove you are the owner of an EOA, you need to sign a message with the corresponding private key๐
This means only you have access to the funds on your account.
Imagine making a transaction sending 1 Ether to a contract to mint a new NFT.
Ethereum verified the digital signature you created (using the private key) against the corresponding account's public key hash (the address).
Neat, right? But why does it work? ๐ง
Public key cryptography is based on mathematical functions that allow for unique public/private key pairs ๐งฎ
Those pairs of keys have special properties, like ease of creation, but it's extremely hard (nearly impossible) to create a private key from its public key.
Having a private key makes it easy to create a public key, but just from knowing a public key, we cannot know which private key was used to create that public key.
That's why proper security of the crypto wallets is necessary ๐ฆพ
With signatures in Ethereum, there may be an issue if a valid signature might be used several times in other places where itโs not intended to be used.
This types of security issues are called Replay Attacks. โฎ๐คบ
More about them ๐
Imagine a scenario where we have a function that transfers funds, but only when a valid signature is provided.