Notes: Cryptography
source: Mastering Ethereum, Chapter 3 by Andreas Antonopoulos
cryptography is one of Ethereum’s foundational technologies, however, the Ethereum protocol does not involve encryption. Communication between nodes is unencrypted
- This means that anyone can verify state updates
We use Public Key Cryptography (PKC) to control ownership of funds
Keys and Addresses
private keys are used to derive:
- public keys, which generate account addresses
- digital signatures give you access to funds and enable transactions on the blockchain
contracts have account addresses that are not generated by a private key
Public Key Cryptography
aka asymmetric cryptography - it’s easy to calculate a public key from a private key, but the opposite is difficult
- used to create public-private key pairs in Ethereum
digital signatures - can only be produced with a transaction and a private key. Proves that the person with the private key sent the transaction
- it’s trivial to verify that the transaction is valid with the public key
prime factorization - finding prime factors is difficult with very large numbers
trapdoor functions you can invert some math functions easily if you know some secret information (for example, if you have one of the prime factors)
elliptic curve arithmetic adding points on a curve together
- discrete logarithm problem multiplication modulo of a prime is simple, division is practically impossible - no known trapdoors
elliptic curve cryptography forms the basis of Ethereum’s private keys and digital signatures
Private Keys
a number, picked at random. Used to create signatures (signatures are required to spend ether)
Public Keys
represents a point (x, y) on an elliptic curve
- in Ethereum, the public key is those two numbers joined together
- derived from a private key in a one way function
$K = k*G$, where:
- $k$ is the private key
- $G$ is a generator point (a constant)
- $K$ is the public key
- $*$ is the elliptic curve “multiplication” operator
note: elliptic curve multiplication is not like normal multiplication
- it’s a one-way function
- multiplication is easy, division is currently impossible
Elliptic Curve Cryptography
it’s a type of asymmetric cryptography
- based on the discrete logarithm problem
- expressed by addition and multiplication on the points of an elliptic curve
Cryptographic Hash Functions
Hash function used to map data of arbitrary size to data of a fixed size
- input is called pre-image, message or input data
- output is called the has
Cryptographic hash functions are a one-way hash functions. Used throughout cryptographic systems
- many-to-one many inputs could create the output
hash collision two sets of input data that could create the same output
- effectively impossible in Ethereum
Ethereum uses cryptographic hash functions to:
- transform ethereum public keys into addresses
- create digital finger prints (aid in verification of data)
properties of a hash function
- determinism
- verifiability computing hash is linearly complex
- noncorrelation a small change to the message creates a large change in the output
- irreversibility
- collision protection this is important for Ethereum because it prevents people from forging digital signatures
Keccak-256
Ethereum’s cryptographic has function is called Keccak-256
Ethereum Addresses
unique identifiers - derived from public keys (or contracts)
- we use keccak-256 to caculate the hash
- then we keep the last 20 bytes
address formats
raw hex, no checksum. This can lead to problems if you mistype an address
Inter exchange Client Address Protocol
ICAP - Ethereum address encoding
- partly compatible with the International Bank Account Number (IBAN) encoding
- can encode addresses registered with an ethereum name registry