Ivan Voras
Ivan Voras is a freelancer and entrepreneur, proud of the breadth of the projects under his belt, and those span from Bitcoin and blockchain technologies, to hardware solutions for Internet of Things devices.
Toptal academy Blockchain lectures #5
2018-03-07
ivan.voras@toptal.com
Source for all this: Ethereum's
"Yellow paper" (technical spec), at
https://ethereum.github.io/yellowpaper/paper.pdf
No UTXO in Ethereum :)
Refresher: in Bitcoin, transactions reference outputs of previous transactions as their input. A transaction I create to spend N coins references 1 or more transactions paid to me,
totalling at at least N coins.
In Ethereum, the account / contract state is maintained externally (off-chain, very similar to bitcoin's chainstate), and that includes its balance.
The result is that Ethereum transactions send money directly from account to account, and the transactions
themselves are irrelevant (do not have to be kept on disk).
Bitcoin:
Private key P signs a transaction referencing previous transactions' outputs X, Y, and Z, all of which are spendable by P. This transaction's output sends N coins to address A, and this output becomes spendable by private key W which "owns" A.
Ethereum:
Private key P signs a transaction transferring N coins to address A. They're spendable by A's private key
W via signature verification.
The "balance" (amount of coins spendable by P and W) is maintained separately.
Each transaction can change the state of an account, which usually means its balance, but can be other data if the account is actually a contract.
The state of all the accounts and contracts is maintained externally from the blockchain. Miners re-calculate the new state of accounts, and include the Merkle root hash of the new state in the block. This state can thus be re-calculated and verified by all other full nodes.
This "Merkle root hash" is actually the root hash of a Merkle-Patricia trie which is a huge structure covering all accounts ever.
This actually makes more sense than how Merkle trees are used in Bitcoin. Here, they speed up computation enormously.
Note: each block contains the
NEW ROOT of the Merkle state trie!
(the state is a moving target)
Account states:
UTXO:
Here's a bright idea: let's put code into the blockchain!
Some "accounts" have code attached to them,
they become "contracts".
The code can:
"Oracles" are external systems which input real-world data into the blockchain.
Example: a gambling system for horse races: an oracle exists which sends data about which horse won into the blockchain.
Smart contracts on Ethereum (currently) can ONLY work with data which is in the blockchain. So external information / triggers must first be wrapped in transactions and inputted into the blockchain.
Who do you trust?
In general, Oracles can either periodically, or when requested (by an event generated from a contract) generate data, and send it in a transaction in a call to a smart contract method.
In addition to Ether, there's a parallel Ethereum currency / concept called "gas".
Gas is a measure of computational work involved in processing a transaction, and this includes the price of execution of a smart contract call (since it's executed on each and every node).
All operations (compiled for the EVM) have a certain price in "gas", and this gas is supplied when the transaction is posted.
Smart contracts can stockpile gas so they can run and/or create new transactions.
Each transaction has two numbers attached:
The process of determining how much a tx's fee will
be goes like this:
I, the creator of this transaction, are willing to let that the transaction will consume at most "gas limit" gas, which is purchased at a price of "gas price". This fee, calculated as
"gas limit" x "gas price"
will be deducted from my account (in Ether).
Note:
In principle similar to Bitcoin mining, with some notable changes:
Homework
Inspect these addresses in a tool like https://etherscan.io/:
Note: you can click "Read smart contract", "Read contract source") or a similar button to interact, read-only, with the contract, without sending new tx (if the address is a smart contract). You can also google for them, some of them are famous.
ivan.voras@toptal.com
Blockchain lecture #5: Ethereum's blockchain
March 2018
By Ivan Voras
Differences between Ethereum and Bitcoin, how are the blockchains structured, how are transactions structures. Introduction into how smart contracts work.
Ivan Voras is a freelancer and entrepreneur, proud of the breadth of the projects under his belt, and those span from Bitcoin and blockchain technologies, to hardware solutions for Internet of Things devices.