Certified Blockchain Professional - Module 07: Ethereum
As previously discussed, I'm doing the Certified Blockchain Professional course. It is self-directed learning, so I'm going through it at my own pace. In order to consolidate my learning, and help organise my thoughts, I'm blogging about my reflections on each module.
These are mostly notes to myself - but I hope if you find something interesting (or incorrect) that you'll leave a comment.
Again, a terribly written & edited chapter. I had to revert to the sources on Wikipedia to understand it.
Ethereum is a Turning-complete language for running decentralised apps (dApps) and smart contracts on a blockchain. By contrast, Bitcoin's scripting language can only perform the operations necessary to financial transactions.
A DAO hack forced a hard for into ETC (classic) and ETH (Ether).
ETH is a reward for miners for verifying and validating transactions. It is spent to pay for the execution of contracts on the Ethereum Virtual Machine (EVM).
ETHASH is the PoW. Approx 3x faster than Bitcoin. No limit to the number of ETH.
Public / Private key pairs as standard. Addresses are a 20b code derived from the public key. Addresses represent accounts.
Ethereum is a transaction driven state machine. Transactions between accounts represent state transactions. The function is
- Check validity of syntax, cryptographic signature, and nOnce.
- Calculate the the sending address from the signature.
- Calculate the transaction fee (how?!)
- Sender's account balance is checked and deducted. Return an error if balance is insufficient.
- Increment nOnce
- Provide enough ETH (gas price) to pay for the transaction.
- ETH is charged per byte (!) proportional to the size of the transaction.
- If the destination doesn't exist - create it.
- If the destination is a smart contract - execute the contract.
- The contract will run for as long as there is ETH. This may not be enough to fully execute the contract.
- If there is insufficient balance or gas, The state is rolled back - except for fee payments (of course!)
- The remainder of the ETH (if there is any) is sent back to the sender - and fees paid accordingly.
- The function returns the final state which is stored on the Blockchain.
Ethereum is a project which attempts to build the generalised technology; technology on which all transaction- based state machine concepts may be built.
All stems from Ethereum's Yellow Paper.
Good explainer of the Yellow Paper.
Ethereum Virtual Machine - EVM. Runs bytecode. Simple stack execution model. LIFO queue of 1,024 elements.
Requires gas (money) to run - which makes infinite loops and DDoS expensive and therefore "impossible".
EVM is deterministic and isolated from the network and filesystem.
Smart Contracts
First defined in Szabo's "Formalizing and Securing Relationships on Public Networks"
Smart contracts are self-enforcing as opposed to legally enforceable. This idea might be regarded as a libertarian's dream, but it is entirely possible and is in line with the true spirit of smart contracts.
Ignores the fallibility of programmers!
Solidity
Language for writing Ethereum Smart Contracts. Compiled using solc
to EVM bytecode to be executed on chain.
Remix is a web-based IDE.
Absolutely no discussion of how either the language or IDE works!
Supporting Protocols
Because of how poorly designed Ethereum is, there are a few supporting protocols.
Swarm for file storage. Decentralised - uses hashes to address files.
Whisper for messaging. A communications protocol between dApps. Small message size and not real-time. Untraceable.
ASSIGNMENT
Download the Ethereum yellow paper from http://gavwood.com/paper.pdf (NB - old link)
Read the paper and answer the following questions * What is world state and how it is maintained? * A map of addresses (160 public keys) and states (a data structure). * Merkle-patricia tries - with every node verifying transaction. * What is a block in Ethereum? * A collection of hashes, representing transactions, bundled together with a representation of the end state. * Why is Gas mechanism introduced? * This introduces a cost per computation. This means that infinite loops or Denial of Service attacks are too costly to perform. It also works as a way to reward miners. * What is EVM and how does it work? * A simple state transaction machine with a deliberately limited instruction set. Isolated and secure. It computes until it finishes, or runs out of gas.