2. History - how Ethereum come about....
● Started in October 2013, Vitalik Buterin visited Mastercoin team in Israel. He
suggested a few features, to make their protocol more generalized and support
more types of contracts. But Mastercoin has their own vision to move forward.
● December 2013, Vitalik published his first Ethereum protocol. Subsequently,
Gavin Wood joined to further refine the protocol and build the C++
implementation. At the same time, Jeffrey Wilcke lead to build the Go client.
● Source: https://vitalik.ca/general/2017/09/14/prehistory.html
● ...the scripting systems of Bitcoin, and even proto-cryptocurrency 2.0 alternatives like Ripple
and Mastercoin, are far too limited to allow the kind of arbitrarily complex computation
that "decentralized autonomous corporations"s require...take cryptocurrency 2.0, and
generalize it - create a fully-fledged, Turing-complete (but heavily fee-regulated)
cryptographic ledger that allows participants to encode arbitrarily complex contracts,
autonomous agents and relationships that will be mediated entirely by the
blockchain….become trivial to implement….
4. Bitcoin vs ethereum
Bitcoin Blockchain Ethereum Blockchain
Both powered by the principle of distributed ledgers and cryptography
Initial Distribution Mining ICO
Function as a cryptocurrency - transfer currency transfer currency and general program
application (decenrtalized smart contract)
Consensus Proof of Work, energy waste for security Proof of Work with later transition to Proof of
Stake, Casper Friendly Finality Gadget
Mining Hash Secure Hash Algorithm (SHA-256) ETHASH - require more memory to mine hence
harder to be mined with ASICs
Fee Fee based on transaction size Gas based on operation and usage of storage
Finality 6 block confirmations, average 60 mins. 12(25) block confirmations, average 3(6) min.
Extensibility hard, simple scripting language Turing Complete Language - smart contract
Scalability 3 Tx/s, Plan: payment channels (Lightning) 15 Tx/s, Plan: payment channels (Plasma),
sharding
5. Basic of ethereum
● has a built-in Turing-complete programming language used to create
"contracts"
● Similar to Bitcoin, Ethereum uses Blockchain as a globally shared transaction
database.
● Ethereum store these in the Blockchain
○ User accounts state (Eth balance)
○ Smart contract code
○ Smart contract state
● Transaction is the only thing that can trigger a change of states in Blockchain.
● Mining process is used to group and validate transactions in Block.
● Miner who can solve a mathematical puzzle quickest can propagate the block
to the network and claim mining reward.
6. Basic of ethereum - Account #1
Accounts
● Global state of Ethereum comprises of many ‘accounts’
● Two kinds of accounts:
○ Externally owned accounts(EOAs) - owned and controlled by users and have no code
associated with it. Owner has private key to access funds or contracts on the account.
○ Contract accounts - controlled by the associated contract code. The contract code is
executed through transactions sent by EOA’s or messages send by other contracts.
● Each account has a 20-byte address and a state associated with it.
● An EOA
○ can send messages to other EOA (ether transfer)
○ can send messages to other contract accounts (code invocation)
7. Basic of ethereum - Account #2
Source: https://www.coindesk.com/information/how-ethereum-works/
UTXO vs Account basedAccount object has 4 pieces of data:
• Nonce (replay protection)
• Balance
• Code hash (empty for EOA)
• Storage trie root
Source:https://medium.com/@darthrevan344/blockchain-ethereum-iot-poc-
machine-maintenance-part-i-272524c16edf
8. Basic of Ethereum - Transaction
Transaction
• Transactions are signed messages originated by an EOA.
• Transactions to an EOA is value transfer.
• Transactions to a contract resulted the code to be executed and the payload is
the input data.
• Transaction has the following data:
• nonce (replay attack protection)
• to (destination address)
• value (ETH amount to send)
• data (contract code)
• gas price (amount eth/unit gas)
• startgas (maximum gas consumable)
• v, r, s (ECDSA signature values)
9. Basic of Ethereum - Ether
Ether
• Native currency of the Ethereum blockchain.
• It is used as payment for using the network.
Unit Wei
Wei 1
Kwei 1,000
Mwei 1,000,000
Unit Wei
Gwei 1,000,000,000
Szabo 1,000,000,000,000
Ether
1,000,000,000,000,000,
000
10. Basic of ethereum - Gas #1
● Due to Turing-complete of Ethereum, Gas is used as a workaround for Halting
Problem.
● A unit of measurement of the computation work of running transactions in the
Ethereum network.
● This is similar to the using of kilowatts to measure electricity.
● Used to decouple the ETH and the unit of computational measurement. Thus,
avoiding the situation in which an increase in the price of ETH resulting changes
to all gas prices.
● Different kinds of transaction require a different amount of gas. For example:
○ Sending Ether between accounts typically cost 21,000 Gas
○ Using store OPS code in smart contract is more than 20,000 Gas
11. Basic of ethereum - Gas #2
● How much does it cost?
● Each transaction sender define price of
Gas Price (Gwei) and Gas Limit.
● Miner then execute transactions with the
highest gas price first. Thus low price gas
might end up taking longer time to
process (e.g. during CryptoKitties)
● How much to pay?
● Refer to statistics on average Gas price
e.g. GasStation/Etherscan.
Source: etherscan.com
Source: ethgasstation.info
15. Source: https://medium.com/@micheledaliessi/how-does-ethereum-work-8244b6f55297
• DApps definition (https://en.wikipedia.org/wiki/Decentralized_application):
“is an application that is run by many users on a decentralized network with trustless
protocols. They are designed to avoid any single point of failure. They typically have
tokens to reward users for providing computing power.”
Layers of Ethereum Platform
16. State of Decentralized Application
Source:https://www.stateofthedapps.com/stats
(Jul2018)
17. Programming languages for smart contracts
● A few programming languages for smart contracts:
○ Solidity: a high-level language. JavaScript like syntax and is the flagship language for
programming Smart Contract in Ethereum due to good documentation and support.
○ Serpent: One of the earliest smart contract programming language. Based on Python.
○ Lisp-Like-Language, LLL: a lower-level language than Solidity (i.e. direct access to
memory and storage, direct usage of EVM opcodes. Based on Lisp.
○ Vyper: an experimental programming language. Based on Python. Currently it is
under development.
18. Tools for Development of Smart Contract
• User Interface
• Metamask
• Mist
• Remix
• MyEtherWallet
• Any Javascript Framework + Web3JS
• Development Environment
• Truffle
• Remix
• Embark
• Blockchain Environment
• Testnet (Ropsten, Rinkeby, Kovan)
• Private Ethereum Blockchain
• Ganache
• Remix (Javascript VM)
• Library
• OpenZeppelin
19. Solidity
Write and Deploy contract
● Write smart contract in Solidity
● Compile Solidity using Solidity Compiler(Solc) into EVM bytecode (bin)
and interface (abi).
● Deploy compiled contract to Ethereum network i.e. blockchain.
Deployment require payment in ether.
● Once contract has successfully been included in blockchain, the
contract address will be returned.
Source: https://blockgeeks.com/guides/smart-contract-development/
20. Smart Contract - Development to Deployment
Source: http://pospi.spadgos.com/2016/10/01/solidity-smart-contracts-primer/
22. Solidity
Invocation of deployed contract - transactions vs calls
Calls
● A local invocation of a contract function. It does not yield publication on
blockchain. It is read-only operation and free of Ether to run.
● Return value of the contract function returned immediately.
● Create an instance of the contract object using deployed contract address and
ABI.
● Use web3js.API web3.eth.call or JSON-RPC eth_call.
Transactions
● A transaction is a call on contract function that will be published on blockchain. It is
a write-operation that will affect state of the blockchain and consume Ether.
● Use web3js.API web3.eth.sendTransaction or JSON-RPC eth_transaction.
26. Remix
Remix is a suite of tools to interact with the Ethereum blockchain in order to debug
transactions. Remix IDE is an IDE for Solidity dApp developers. Online version is available at
https://remix.ethereum.org. Source: https://blockgeeks.com/guides/smart-contract-development/
29. Future - Proof of Stake (Casper)
● Instead of miner uses validator to create and validate
blocks.
● How it works?
○ Interested validators will stake their Ethereum for
eligibility to validate.
○ Validator discover block and place a bet on it. If block
gets appended, validators get a reward proportionate
to their bets.
○ If validator acts maliciously, stake is being slashed.
● 2 versions of Casper in research and development
○ Casper Friendly Finality Gadget (FFG)
■ Hybrid of PoW and PoS
○ Casper Friendly GHOST Correct-by-Construction (CBC)
■ Fully PoS
■ Instead of fully specifying the protocol, provides
ability to specify properties and work backward to
derive the protocol.
Source: https://blockgeeks.com/guides/ethereum-mining-
proof-stake
Notes de l'éditeur
The halting problem is to never be sure if a transaction will complete without actually running it, so it is very important for the protocol to provide runtime workarounds.
Gas limit — that’s the maximum amount of Gas that user commits to the transaction. If transaction will need more Gas than it was defined in Gas limit, transaction will fail with “out of Gas” status
Gas used by transaction — that’s actual amount of Gas that was used during execution.
Gas price — that’s the Gas price in ETH that sender defined at transaction creation
Actual Tx Cost — gas used by transaction * gas price (in ETH)
Cumulative gas used — The total amount of gas used when this transaction was executed in the block (gas used by previous transactions and this one together)
an ABI tells us the specifications that are needed to interact with the smart contract. It tells us of the various ways in which this contract can be called from an external source (like web3 in our case)
Nothing at Stake issue with PoS - in which as no physical resources to waste (as in compare to POW the CPU), when there is a fork, a validator would stake at each of the fork so not to lose out (so regardless of the final outcome the validator will win).
Advantage of PoS
. more environmentally friendly - as no energy consumption
. stronger alignment of incentives - PoW interest of miners may not align with coin holders, e.g. miner sell coin they mine as they only care about short term. Another issue is the ability to lease hashrate, with the lesee having no economic interest in the long term prospect of the system.
. Mining centralisation and ASICs - improving decentralisation. ASIC are expensive hence only mid-size and above company can operate, many aspects of mining cn have economies of scale, such as maintenance costs and energy cost.