Distributed Ledgers, Blockchains, and Smart Contracts

19
Distributed Ledgers Blockchains Smart Contracts An introduction into the ideas, technologies, and use cases.

Transcript of Distributed Ledgers, Blockchains, and Smart Contracts

Distributed Ledgers Blockchains Smart ContractsAn introduction into the ideas, technologies, and use cases.

Distributed Ledger Technology

Digital Data that is shared and replicated over multiple locations  Peer-to-Peer Consensus based, no central authority has power to approve or reject changes to the

ledger

Blockchains

An implementation of DLT Most  commonly known Blockchain technologies are cryptocurrencies 

Bitcoin Litecoin Dogecoin

Can be thought of as a ledger of transactions between actors Can exist as a public or private network

Classical Example of how things work in the real world.

Central Authority

Actor 0 Actor 1 Actor 2

• Consider several actors that want to transact some state changes amongst themselves.

• Reads and Writes are managed by a central authority.

• Actors have to trust the central authority.

• Auditability is either nonexistent or nontrivial.

With Blockchains and DLTs

Actor 0

Actor 2Actor 1

• Decentralized, no single authority. • Trustless• Consensus based changes to

state. • P2P, no single failure can bring

down network.• Immediate auditability• Immutability of data written to

the blockchain• Satisfies Byzantine Fault

Tolerance

Consensus, how does it work?It depends on the Blockchain Technology in question. • Proof of Work

• Mining such as in bitcoin• Proof of Stake

• Those who have the biggest stake • Proof of Activity

• Hybrid of the two

Byzantine Fault Tolerance (BFT)

Systems that satisfy BFT tolerate a class of failures known as the Byzantine Generals’ Problem

Byzantine Failures are the most general and difficult class of failures BFT systems are used in areas such as Nuclear Submarines and Fly-By-Wire avionics in

modern Commercial and Fighter Jets.

City

General 0

General 1

General 2

General 3

General 4

• Generals in the Byzantine army each commanding their own portion.

• Generals need to decide if they attack the city or retreat.

• Opinions may differ, but in the end, every general must agree to the course of action.

• Complicated by the fact there may be traitorous generals and they all must communicate by messenger.

• Byzantine Fault Tolerance is achieved if the loyal generals agree unanimously on the strategy.

Summary so far…

Blockchains are an implementation of DLTs. Provide us with security, immutability, fault tolerance, and more… There exist different methods for achieving consensus. Can be public like Bitcoin, or private for special use cases.

Ethereum and Smart Contracts

The generalization of the blockchain beyond cryptocurrency

Ethereum

Blockchain paired up with a decentralized computer Every node runs the Ethereum Virtual Machine Smart Contracts are the applications that run on the

network in a decentralized manner Consensus on the execution of Smart Contracts

What IS a Smart Contract?

“A smart contract is a computerized transaction protocol that executes the terms of a contract.” - Tapscott, Alex (May 2016). The Blockchain Revolution: How the Technology Behind Bitcoin is Changing Money, Business, and the World.

Visible to all users on the blockchain. In the case of Ethereum, Smart Contracts are Turing Complete. Every node calculates the execution of a Smart Contract.

Ether & Gas

The Ethereum blockchain has a currency or form of payment called Ether. Just like in Bitcoin, miners are rewarded with Ether.

The smallest unit of Ether is called Wei. Gas is how the amount of computation required for a particular transaction is

measured. Think of it like an electricity cost to running a computer. If you want a Smart Contract to

preform some work, you need to supply it Gas. The amount of Ether needed to run a transaction is the Gas * GasPrice.

How Gas I Calculated

Operation Name Gas Cost Remark

step 1 default amount per execution cycle

stop 0 freesuicide 0 freesha3 20  

sload 20 get from permanent storage

sstore 100 put into permanent storage

balance 20  create 100 contract creationcall 20 initiating a read-only call

memory 1 every additional word when expanding memory

txdata 5 every byte of data or code for a transaction

transaction 500 base fee transaction

contract creation 53000 changed in homestead from 21000

• Each operation in the EVM consumes a certain amount of gas.

• There is an API that can estimate the cost of a transaction to a reasonable degree.

Dapps

Decentralized Application. Two components, Backend + UI. Backend is the Smart Contract, or collection of Smart Contracts running on a

Blockchain or P2P network. The UI calls out and interfaces with the Smart Contracts. No management of user IDs or accounts needed, that is handled by the Blockchain

technology in question. Storage of data can be handled by technologies like IPFS.

Extras

Private Blockchains? Specialized use cases that don’t want to

be shared on a public ledger. A need for better performance, not

sharing the network bandwidth with the public.

Custom network difficulty, protocols and consensus.

Tooling

Solidity is the language of choice for Smart Contracts.

Truffle Framework – creating, testing, deploying smart contracts and Dapps.

testrpc – ethereum client for dev and testing. Microsoft Azure: Blockchain as a Service Support in most editors and IDEs Web3.js

EXAMPLES IN THE REAL WORLD

• ASX • Slock.it• Land Registries

Form Filled By User DACO

Office DACO Database ICGC API DCC Auth

Services

Form Filled By User DACO

Office DACO Database ICGC API DCC Auth

Services