Hash Function
- Think of it like a fingerprint of any given input data.
- Input can be any size, output is always the same size (64 hex chars).
- Deterministic, you will always get the same hash for a specific input.
- One directional, given a hash it is impossible to guess the seed.
Key Pair
- Consists of a public key derived from a private key.
- Your address where you send value is derived from your public key.
- Can be used to sign a message and anyone can recover the signer's address.
- Anyone can generate an Ethereum account by just generating a random private key.
Look Ahead: Transactions
- Users can sign messages that go on-chain to send and receive value.
- No decimals! Amounts are integers, in Wei. 1 ETH is 10^18 Wei.
- You can generate accounts by just randomly generating private keys.
Side Quest: Encryption
- Asymmetric encryption with Ethereum key pairs.
- A small amount of data can be encrypted with a public key.
- The private key is used to decrypt the data.
- Not the best way to encrypt data!
Distributed Ledger
- Once we have key pairs and we can sign messages, our messages can be objects with to, from, value, etc.
- A ledger keeps track of everyone's balance and new transactions are added to it.
- Everyone keeps a copy of the same ledger.
- Need a 'nonce' to prevent replay attacks.
- Problems with network topology and consensus...
Byzantine Generals
- Coordination problem arises without a centralized authority.
- Network (communication) is public and untrusted.
- Generals prove their ability to wage war to other generals in messages.
- Proof of work!
Blockchain
- Proof of work is brute forcing a one-way hash function.
- Miners with special hardware work to secure blocks of transactions.
- Each block references the previous block to make a chain.
- Longest chain wins and your weird uncle shows up to help with security.
Transactions
- Send value by signing an object with the details like 'to', 'value', 'data'.
- 'From' address is cryptographically recovered from the signature.
- No decimals! Amounts are integers, in Wei. 1 ETH is 10^18 Wei.
- Miners are incentivized with a fee to package transactions into blocks.
- This fee is called the gas price and you 'bid' to get mined.
Smart Contracts
- Send 'machine code' as data in a transaction without a 'to' address.
- Deployed code has an address just like an "externally owned account" with a private key.
- Reading data is cheap and can come from any node on the network.
- Storage and execution are relatively expensive. All nodes have to run and store everything.
- Call a function on a contract by sending it a transaction with the function args in the data.