SlideShare une entreprise Scribd logo
1  sur  82
• Wrote my first BASIC program at the age of 9.
Who am I?
Wasn’t able to replicate the success ever since.
… and sold my first Bitcoins in 2013
leonid@orbs.network
leonid@kik.com
leonid@cointree.capital
PGP Key:
D749 1F09 3721 0A31 72B5
DBF3 7F35 EBC3 E4B2 44B4
• Bought my first Bitcoins in 2012!
• Very enthusiastic about the “crypto revolution” and dedicating it most of my time.
Today:
Engineering and Security a Kik
Engineering and Security at ORBS
Advisory at CoinTree Capital
We’re hiring!
leonid@orbs.network
leonid@kik.com
leonid@cointree.capital
PGP Key:
D749 1F09 3721 0A31 72B5
DBF3 7F35 EBC3 E4B2 44B4
Where am I today?
In the past:
VP R&D at Visualead (acquired)
CTO at Jammer.fm (acquired)
Principal Engineer at Safend (acquired)
Matzov (IDF)
Technion, Computer Science
We’re Hiring!
➢ Backend Developers
➢ Blockchain/Crypto Experts
➢ Devops Engineers
jobs@orbs.network
Blockchain AcademyLeonid Beder Dec 26, 2017
➢ Crypto Security Expert
➢ Web Developers
➢ iOS Developers
natasha@kik.com
Agenda
1. Motivation
2. Introduction to Blockchain(s)
3. Coding the Blockchain
4. Surprise!
5. Q & A
Motivation
Leonid Beder Blockchain Academy
• You’ll understand some of the primitives and architecture
concepts of blockchain technologies.
• You’ll be able to run (and extend) your own, alas wee limited,
Blockchain.
● We’ll deal with the misconception that Blockchain
Engineering == Solidity
● To pique your curiosity; You’ll want to learn more, especially
by reading “Mastering Bitcoin” by Andreas M. Antonopoulos:
https://github.com/bitcoinbook/bitcoinbook
What we want to achive
● How to get filthy rich from x10,000 investments in altcoins and other magical investment
strategies and/or speculative mumbo jumbo.
● ”Other” consensus algorithms. We’ll implement a Bitcoin-like PoW (Internet-scale distributed
Byzantine Fault Tolerant consensus), but it’s important to know that there is a plethora of
other algorithms, such as:
○ Paxos
○ Raft
○ Practical Byzantine Fault Tolerance
○ Proof of Stake (PoS)
○ Delegated Proof of Stake (DPoS)
○ Proof of Importance (PoI)
○ Proof of Authority (PoA)
○ Proof of Elapsed-time (PoEL)
○ Casper the Friendly Ghost (CTFG)
○ Casper the Friendly Finality Gadget (CFFG)
○ Algorand
○ HashGraph
○ Tenderinmt
○ Honeybadger
○ Ouroboros
○ Tezos
○ Tangle (e.g., IOTA)
○ Zilliqa
○ SPECTRE
○ ORBS
What we won’t talk about
● Scaling challenges (throughput, latency, storage requirements, processing requirements,
liveness requirements, etc.).
● Incentive Models and Cryptoeconomics.
● Finality (e.g., probabilistic, theoretic, convergence, etc.).
● Smart Contracts and VM concepts.
● Privacy (ZK proofs, stealth addresses, ZK-SNARKs, etc.).
● Security (algorithms and assumption, implementation, system, etc.).
● Politics and Governance.
● Compliance and Regulation.
● Non-”chain-like” blockchains (e.g., DAG, HashGraph, Tangle, etc.).
● Off-chain protocols, atomic swaps, state/payment channels.
● Hard forks / “airdrops” (a.k.a. “quarterly dividends”).
What we won’t talk about
Introduction: Blockchain
Leonid Beder Blockchain Academy
You have probably heard something
like this already…
What is Blockchain
• Is it kind of a database?
• Is it kind of a protocol?
• Is it only good to store value?
• Is it decentralized?
• Is it public?
• Is it democratic?
• Is it immutable?
• Should there be only “one”? Should it “talk” with other blockchains?
It’s pretty much a theological debate...
What is Blockchain
● From https://en.wikipedia.org/wiki/Blockchain:
○ “A blockchain … is a continuously growing list of records, called
blocks, which are linked and secured using cryptography.”
What is Blockchain
Satoshi Nakomoto, main.h (Bitcoin v0.01 alpha), ‫עממי‬
What is Blockchain
Chain of blocks with transactions!
… let’s work from here
Blockchains are good at:
• Ensuring that the application state is valid (i.e., it got to what it is now through some
process that follows the rules).
• Transparency of process (i.e., we can know how it got there).
• Irreversibility.
Vitalik Buterin, Blockchains and Privacy through Strong Cryptography, ETHWaterloo 2017
For example:
Smart Contracts
What is it good for?
Leonid Beder Blockchain Academy
Let’s build!
Without loss of generality, we’d use:
• Mac OSX or UNIX-like environment (should work on Windows as well, but you know…).
• TypeScript 2.6.2: high-level and popular programming language.
• Node v9.2.1.
• express 4.6 for a minimalistic web server.
• Shell scripts and Postman to interact with the API.
The code is available at:
https://github.com/blockchain-academy/how-build-your-own-blockchain
Setup
We’ll define an initial class with the following interfaces:
1. We’d store all the blocks in the blockchain.
2. We’d store the pool of all the transactions waiting to be processed at
the moment.
3. We’ll differentiate the current instance from other instances (we’d use it
later).
4. Method for creation of new blocks.
5. Method for submission of new transactions to the pool.
Starting from scratch
What should our blocks contain?
1. Block number/height: an incremental counter/id for each block.
2. Transactions (duh!).
3. Timestamp: block creation time.
4. Nonce: an arbitrary number that can only be used once (similar in spirit
to a nonce word).
5. Pointer to the next block way to chain the blocks together.
5. The hash of the previous block: by including a hash of the previous
block, we will make the blockchain immutable.
Blocks
What should our transactions contain?
1. The public address of the sender.
2. The public address of the recipient.
3. The value of the transaction.
Transactions
New transactions will be first submitted to the in-memory transactions
pool (also referred to as the “mempool”):
Submitting new transactions
• A method to achieve trustless consensus.
• It was invented by Cynthia Dwork and Moni Naor in Crypto’92 (as a measure to
combat spam).
• A key feature of PoW is its asymmetry: the work must be hard (but feasible) on the
requester side, but easy to check for the service provider.
Proof of Work (PoW)
An example for such problem (Hashcash):
Block 34
Previous block:
c216c8c6821a...
Transaction
9c9b7
Transaction
855f4
Transaction
a5c50
?
Proof of Work (PoW)
SHA256(block,?)< target
SHA256(block34,12345)= 0xbbd91c3c87061c412543780597b077ebd578d3423c6a914269fa67659bfda5f8
Block 34
Previous block:
0016c8c6821a...
Transaction
9c9b7
Transaction
855f4
Transaction
a5c50
Nonce
99998
Block 35
Previous block:
005d1650c1f4...
Transaction
8effd
Transaction
12345
Transaction
dadff
Nonce
7897372211162
Block 36
Previous block:
002c4a7d215c...
Transaction
3a367
Transaction
7bba2
Transaction
678aa
Nonce
Block 37
Previous block:
00914269fa67...
Transaction
91bcd
Transaction
10a4e
Transaction
55678
Nonce
5252525
SHA256(block34,99998)= 0x005d1650c1f447b8d7f7e5278282093c5d154d12c4a7d215c144bcf563bb14a9
SHA256(block34,33333)= 0xdbece6823de26dcd8ca4ab3c0ffca91be0b20038fb1b28d8b383bcecc25428af
Proof of Work (PoW)
For example: target = 2256-difficulty
, difficulty = 8
target = 2248
= 0x0100000000000000000000000000000000000000000000000000000000000000
So, how does it help us to achieve a trustless consensus?
• Everyone can mine a block. “One CPU - one vote” (is it?).
• We can easily detect cheaters and invalidate/ignore their blocks, which means:
• Strong incentives not to cheat!
Proof of Work (PoW)
?
?
Satoshi: We’ll always choose the longest chain, which is the chain with the most
invested computation.
Longest Chain
There are also quite a few of disadvantages to a PoW scheme:
1. Specialized hardware (ASIC, GPU) usually has an advantage (one CPU - one
vote, right?!).
2. Mining pool centralization (e.g., the top 5 Bitcoin mining pools own close to 70%
of the total computational power).
3. Energy waste: Bitcoin’s current estimated annual electricity consumption stands
at 29.05TWh, which represents 0.13% of total global electricity consumption.
Proof of Work (PoW)
Let’s add the difficulties and target for the PoW hash (cost) function,
the “genesis” block and some utility functions:
Mining and Validation
Now we can add a method to mine a given set of transactions into a
single block:
Mining and Validation
Once we can mine/create new blocks, new block creation is pretty
straightforward:
1. Fetch transactions from the mempool. We’ll assume that blocks are limitless
(which is of course not the case).
2. Keep mining a block with these transactions until a valid PoW is found.
3. Append the new block to the blockchain.
4. Remove the mined transactions from the mempool. We will assume that
there are no race conditions needed to be taken care of.
Creating new blocks
In order for the blockchain to be more robust, we will add support for writing and
reading the blockchain from the storage.
❑ What if someone modifies the data on the disk?
✓ We can verify that the blocks were appended correctly, starting from the genesis
block.
❑ What if someone modifies the genesis block?
✓ We’ll hardcode it directly in the protocol.
❑ What if we were offline for a very long time?
✓ We’ll bootstrap from other miners (not in this talk…).
Storing the blockchain
Let’s implement saving and loading the blockchain to the disk (it won’t be
very efficient, but it’ll do for now):
Storing the blockchain
Let’s implement the validation of the loaded blockchain:
Storing the blockchain
Leonid Beder
Let’s make it
public!
Running a blockchain only on our own machine isn’t very useful (is it?), so let’s
add some web API to our implementation. Specifically:
1. API to list the blockchain.
2. API to list and submit transactions.
3. API to mine/create blocks (just for the demo; it could’ve been a cron-like job.
Setting up a web server
Let’s add an API to submit transactions. For the sake of the demo, we won’t
validate senders of the transaction of their balances.
Submitting transactions
Let’s add an API to block mining.
❑ But wait… why should our node mine blocks?!
✓ Let’s bribe the node with add a mining reward!
Mining blocks
In order to make our blockchain more decentralized, we’d want to:
1. Support multiple nodes (avoid single point of failure, faulty nodes,
improve liveliness of the system, etc.).
2. Don’t blindly trust the output of the other nodes – validate everything
yourself!
3. Reach a consensus about the state of the blockchain among the nodes.
Decentralizing the blockchain
• Let’s add an API for every node to be aware of other nodes.
• Since we’re developing a permissionless blockchain – everyone is
free to join.
Node discovery
• Now, when we have a (naïve) way for the nodes to be aware of each
others – they can communicate together.
• In order to reach a consensus on the “true” state of the blockchain, every
node will:
1. Get the whole blockchain from every other node.
2. If the other blockchain is both longer and valid – use it instead.
Reaching a consensus
Leonid Beder
Surprise!
Award winning contest
• Do you have an idea for an interesting feature?
• Can you make it more secure (in of the bazillion possible ways)?
• Can you make it more performant? More efficient? Easier to govern?
You have 3 weeks to submit an interesting PR (according to the Terms of
Service in the repo). The top 3 submissions will win:
2nd place: New iPhone X 64GB or Samsung Note 8.
3rd place: New Ledger Nano S Hardware Wallet.
1st place: New MacBook Pro 13”, i5, 256 SSD with a Touch Bar.
Blockchain AcademyLeonid Beder December 26th, 2017
Thank You!
Next Events
JAN 25th - How To Become A Smart Contract Engineer
FEB 27th - How to Not Destroy Millions in Smart Contracts

Contenu connexe

Tendances

Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)
Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)
Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)
Svetlin Nakov
 

Tendances (20)

Dappsmedia smartcontract _write_smartcontracts_on_console_ethereum
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereumDappsmedia smartcontract _write_smartcontracts_on_console_ethereum
Dappsmedia smartcontract _write_smartcontracts_on_console_ethereum
 
A research-oriented introduction to the cryptographic currencies (starting wi...
A research-oriented introduction to the cryptographic currencies (starting wi...A research-oriented introduction to the cryptographic currencies (starting wi...
A research-oriented introduction to the cryptographic currencies (starting wi...
 
Introduction to Ethereum
Introduction to EthereumIntroduction to Ethereum
Introduction to Ethereum
 
Explaining Ethereum
Explaining EthereumExplaining Ethereum
Explaining Ethereum
 
Smart contracts and applications part II
Smart contracts and applications   part IISmart contracts and applications   part II
Smart contracts and applications part II
 
Eclipsecon Europe: Blockchain, Ethereum and Business Applications
Eclipsecon Europe: Blockchain, Ethereum and Business ApplicationsEclipsecon Europe: Blockchain, Ethereum and Business Applications
Eclipsecon Europe: Blockchain, Ethereum and Business Applications
 
Tmc mastering bitcoins ppt
Tmc mastering bitcoins pptTmc mastering bitcoins ppt
Tmc mastering bitcoins ppt
 
Blockchain for Developers
Blockchain for DevelopersBlockchain for Developers
Blockchain for Developers
 
OWASP Poland Day 2018 - Damian Rusinek - Outsmarting smart contracts
OWASP Poland Day 2018 - Damian Rusinek - Outsmarting smart contractsOWASP Poland Day 2018 - Damian Rusinek - Outsmarting smart contracts
OWASP Poland Day 2018 - Damian Rusinek - Outsmarting smart contracts
 
Learning Solidity
Learning SolidityLearning Solidity
Learning Solidity
 
Blockchain and smart contracts, what they are and why you should really care ...
Blockchain and smart contracts, what they are and why you should really care ...Blockchain and smart contracts, what they are and why you should really care ...
Blockchain and smart contracts, what they are and why you should really care ...
 
Bitcoins Math
Bitcoins MathBitcoins Math
Bitcoins Math
 
Blockchain Programming
Blockchain ProgrammingBlockchain Programming
Blockchain Programming
 
Kriptovaluták, hashbányászat és okoscicák
Kriptovaluták, hashbányászat és okoscicákKriptovaluták, hashbányászat és okoscicák
Kriptovaluták, hashbányászat és okoscicák
 
Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)
Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)
Crypto Wallets: A Technical Perspective (Nakov at OpenFest 2018)
 
EDCON 2017 sharing @Taipei Ethereum Meetup
EDCON 2017 sharing @Taipei Ethereum Meetup EDCON 2017 sharing @Taipei Ethereum Meetup
EDCON 2017 sharing @Taipei Ethereum Meetup
 
The Ethereum Geth Client
The Ethereum Geth ClientThe Ethereum Geth Client
The Ethereum Geth Client
 
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
以比特幣為例的區塊鏈技術介紹 ( Intro to Blockchain using Bitcoin as an example)
 
Bitcoin Blockchain - Under the Hood
Bitcoin Blockchain - Under the HoodBitcoin Blockchain - Under the Hood
Bitcoin Blockchain - Under the Hood
 
How to be a smart contract engineer
How to be a smart contract engineerHow to be a smart contract engineer
How to be a smart contract engineer
 

Similaire à How to Build Your Own Blockchain

Similaire à How to Build Your Own Blockchain (20)

A Quick Start To Blockchain by Seval Capraz
A Quick Start To Blockchain by Seval CaprazA Quick Start To Blockchain by Seval Capraz
A Quick Start To Blockchain by Seval Capraz
 
Blockchain, cryptography and tokens — NYC Bar presentation
Blockchain, cryptography and tokens — NYC Bar presentationBlockchain, cryptography and tokens — NYC Bar presentation
Blockchain, cryptography and tokens — NYC Bar presentation
 
Crypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies IntroCrypto & Crpyocurrencies Intro
Crypto & Crpyocurrencies Intro
 
Introduction to Blockchain with an Ethereuem Hands-on
Introduction to Blockchain with an Ethereuem Hands-onIntroduction to Blockchain with an Ethereuem Hands-on
Introduction to Blockchain with an Ethereuem Hands-on
 
Node.js Blockchain Implementation
Node.js Blockchain ImplementationNode.js Blockchain Implementation
Node.js Blockchain Implementation
 
Blockchain Fundamentals
Blockchain FundamentalsBlockchain Fundamentals
Blockchain Fundamentals
 
BlockchainConf.tech - Build a private blockchain workshop
BlockchainConf.tech - Build a private blockchain workshopBlockchainConf.tech - Build a private blockchain workshop
BlockchainConf.tech - Build a private blockchain workshop
 
New Business Models enabled by Blockchain
New Business Models enabled by BlockchainNew Business Models enabled by Blockchain
New Business Models enabled by Blockchain
 
Blockchain for scala lovers
Blockchain for scala loversBlockchain for scala lovers
Blockchain for scala lovers
 
Best practices to build secure smart contracts
Best practices to build secure smart contractsBest practices to build secure smart contracts
Best practices to build secure smart contracts
 
Basics of Block Chain
Basics of Block ChainBasics of Block Chain
Basics of Block Chain
 
Blockchain 101 - public, tokenized blockchains
Blockchain 101 - public, tokenized blockchainsBlockchain 101 - public, tokenized blockchains
Blockchain 101 - public, tokenized blockchains
 
4-ZeroLab_consensus-1908.pptx
4-ZeroLab_consensus-1908.pptx4-ZeroLab_consensus-1908.pptx
4-ZeroLab_consensus-1908.pptx
 
Ivy Block - technicals.pdf
Ivy Block - technicals.pdfIvy Block - technicals.pdf
Ivy Block - technicals.pdf
 
Blockchain
BlockchainBlockchain
Blockchain
 
Bruno Lowagie (iText) #cfoconferenz
Bruno Lowagie (iText) #cfoconferenzBruno Lowagie (iText) #cfoconferenz
Bruno Lowagie (iText) #cfoconferenz
 
Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018
Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018
Simone Bronzini - Weaknesses of blockchain applications - Codemotion Milan 2018
 
On Private Blockchains, Technically
On Private Blockchains, TechnicallyOn Private Blockchains, Technically
On Private Blockchains, Technically
 
“A bitcoin mining rig”
“A bitcoin mining rig”“A bitcoin mining rig”
“A bitcoin mining rig”
 
DEF CON 27 - WENXIANG QIAN and YUXIANG LI HUIYU - breaking google home exploi...
DEF CON 27 - WENXIANG QIAN and YUXIANG LI HUIYU - breaking google home exploi...DEF CON 27 - WENXIANG QIAN and YUXIANG LI HUIYU - breaking google home exploi...
DEF CON 27 - WENXIANG QIAN and YUXIANG LI HUIYU - breaking google home exploi...
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

How to Build Your Own Blockchain

  • 1.
  • 2. • Wrote my first BASIC program at the age of 9. Who am I? Wasn’t able to replicate the success ever since. … and sold my first Bitcoins in 2013 leonid@orbs.network leonid@kik.com leonid@cointree.capital PGP Key: D749 1F09 3721 0A31 72B5 DBF3 7F35 EBC3 E4B2 44B4 • Bought my first Bitcoins in 2012! • Very enthusiastic about the “crypto revolution” and dedicating it most of my time.
  • 3. Today: Engineering and Security a Kik Engineering and Security at ORBS Advisory at CoinTree Capital We’re hiring! leonid@orbs.network leonid@kik.com leonid@cointree.capital PGP Key: D749 1F09 3721 0A31 72B5 DBF3 7F35 EBC3 E4B2 44B4 Where am I today? In the past: VP R&D at Visualead (acquired) CTO at Jammer.fm (acquired) Principal Engineer at Safend (acquired) Matzov (IDF) Technion, Computer Science
  • 4. We’re Hiring! ➢ Backend Developers ➢ Blockchain/Crypto Experts ➢ Devops Engineers jobs@orbs.network Blockchain AcademyLeonid Beder Dec 26, 2017 ➢ Crypto Security Expert ➢ Web Developers ➢ iOS Developers natasha@kik.com
  • 5. Agenda 1. Motivation 2. Introduction to Blockchain(s) 3. Coding the Blockchain 4. Surprise! 5. Q & A
  • 7. • You’ll understand some of the primitives and architecture concepts of blockchain technologies. • You’ll be able to run (and extend) your own, alas wee limited, Blockchain. ● We’ll deal with the misconception that Blockchain Engineering == Solidity ● To pique your curiosity; You’ll want to learn more, especially by reading “Mastering Bitcoin” by Andreas M. Antonopoulos: https://github.com/bitcoinbook/bitcoinbook What we want to achive
  • 8. ● How to get filthy rich from x10,000 investments in altcoins and other magical investment strategies and/or speculative mumbo jumbo. ● ”Other” consensus algorithms. We’ll implement a Bitcoin-like PoW (Internet-scale distributed Byzantine Fault Tolerant consensus), but it’s important to know that there is a plethora of other algorithms, such as: ○ Paxos ○ Raft ○ Practical Byzantine Fault Tolerance ○ Proof of Stake (PoS) ○ Delegated Proof of Stake (DPoS) ○ Proof of Importance (PoI) ○ Proof of Authority (PoA) ○ Proof of Elapsed-time (PoEL) ○ Casper the Friendly Ghost (CTFG) ○ Casper the Friendly Finality Gadget (CFFG) ○ Algorand ○ HashGraph ○ Tenderinmt ○ Honeybadger ○ Ouroboros ○ Tezos ○ Tangle (e.g., IOTA) ○ Zilliqa ○ SPECTRE ○ ORBS What we won’t talk about
  • 9. ● Scaling challenges (throughput, latency, storage requirements, processing requirements, liveness requirements, etc.). ● Incentive Models and Cryptoeconomics. ● Finality (e.g., probabilistic, theoretic, convergence, etc.). ● Smart Contracts and VM concepts. ● Privacy (ZK proofs, stealth addresses, ZK-SNARKs, etc.). ● Security (algorithms and assumption, implementation, system, etc.). ● Politics and Governance. ● Compliance and Regulation. ● Non-”chain-like” blockchains (e.g., DAG, HashGraph, Tangle, etc.). ● Off-chain protocols, atomic swaps, state/payment channels. ● Hard forks / “airdrops” (a.k.a. “quarterly dividends”). What we won’t talk about
  • 11. You have probably heard something like this already… What is Blockchain
  • 12.
  • 13. • Is it kind of a database? • Is it kind of a protocol? • Is it only good to store value? • Is it decentralized? • Is it public? • Is it democratic? • Is it immutable? • Should there be only “one”? Should it “talk” with other blockchains? It’s pretty much a theological debate... What is Blockchain
  • 14. ● From https://en.wikipedia.org/wiki/Blockchain: ○ “A blockchain … is a continuously growing list of records, called blocks, which are linked and secured using cryptography.” What is Blockchain
  • 15. Satoshi Nakomoto, main.h (Bitcoin v0.01 alpha), ‫עממי‬
  • 16. What is Blockchain Chain of blocks with transactions! … let’s work from here
  • 17. Blockchains are good at: • Ensuring that the application state is valid (i.e., it got to what it is now through some process that follows the rules). • Transparency of process (i.e., we can know how it got there). • Irreversibility. Vitalik Buterin, Blockchains and Privacy through Strong Cryptography, ETHWaterloo 2017 For example: Smart Contracts What is it good for?
  • 18. Leonid Beder Blockchain Academy Let’s build!
  • 19. Without loss of generality, we’d use: • Mac OSX or UNIX-like environment (should work on Windows as well, but you know…). • TypeScript 2.6.2: high-level and popular programming language. • Node v9.2.1. • express 4.6 for a minimalistic web server. • Shell scripts and Postman to interact with the API. The code is available at: https://github.com/blockchain-academy/how-build-your-own-blockchain Setup
  • 20. We’ll define an initial class with the following interfaces: 1. We’d store all the blocks in the blockchain. 2. We’d store the pool of all the transactions waiting to be processed at the moment. 3. We’ll differentiate the current instance from other instances (we’d use it later). 4. Method for creation of new blocks. 5. Method for submission of new transactions to the pool. Starting from scratch
  • 21.
  • 22. What should our blocks contain? 1. Block number/height: an incremental counter/id for each block. 2. Transactions (duh!). 3. Timestamp: block creation time. 4. Nonce: an arbitrary number that can only be used once (similar in spirit to a nonce word). 5. Pointer to the next block way to chain the blocks together. 5. The hash of the previous block: by including a hash of the previous block, we will make the blockchain immutable. Blocks
  • 23.
  • 24. What should our transactions contain? 1. The public address of the sender. 2. The public address of the recipient. 3. The value of the transaction. Transactions
  • 25.
  • 26. New transactions will be first submitted to the in-memory transactions pool (also referred to as the “mempool”): Submitting new transactions
  • 27.
  • 28.
  • 29. • A method to achieve trustless consensus. • It was invented by Cynthia Dwork and Moni Naor in Crypto’92 (as a measure to combat spam). • A key feature of PoW is its asymmetry: the work must be hard (but feasible) on the requester side, but easy to check for the service provider. Proof of Work (PoW)
  • 30. An example for such problem (Hashcash): Block 34 Previous block: c216c8c6821a... Transaction 9c9b7 Transaction 855f4 Transaction a5c50 ? Proof of Work (PoW) SHA256(block,?)< target
  • 31. SHA256(block34,12345)= 0xbbd91c3c87061c412543780597b077ebd578d3423c6a914269fa67659bfda5f8 Block 34 Previous block: 0016c8c6821a... Transaction 9c9b7 Transaction 855f4 Transaction a5c50 Nonce 99998 Block 35 Previous block: 005d1650c1f4... Transaction 8effd Transaction 12345 Transaction dadff Nonce 7897372211162 Block 36 Previous block: 002c4a7d215c... Transaction 3a367 Transaction 7bba2 Transaction 678aa Nonce Block 37 Previous block: 00914269fa67... Transaction 91bcd Transaction 10a4e Transaction 55678 Nonce 5252525 SHA256(block34,99998)= 0x005d1650c1f447b8d7f7e5278282093c5d154d12c4a7d215c144bcf563bb14a9 SHA256(block34,33333)= 0xdbece6823de26dcd8ca4ab3c0ffca91be0b20038fb1b28d8b383bcecc25428af Proof of Work (PoW) For example: target = 2256-difficulty , difficulty = 8 target = 2248 = 0x0100000000000000000000000000000000000000000000000000000000000000
  • 32. So, how does it help us to achieve a trustless consensus? • Everyone can mine a block. “One CPU - one vote” (is it?). • We can easily detect cheaters and invalidate/ignore their blocks, which means: • Strong incentives not to cheat! Proof of Work (PoW)
  • 33. ? ? Satoshi: We’ll always choose the longest chain, which is the chain with the most invested computation. Longest Chain
  • 34. There are also quite a few of disadvantages to a PoW scheme: 1. Specialized hardware (ASIC, GPU) usually has an advantage (one CPU - one vote, right?!). 2. Mining pool centralization (e.g., the top 5 Bitcoin mining pools own close to 70% of the total computational power). 3. Energy waste: Bitcoin’s current estimated annual electricity consumption stands at 29.05TWh, which represents 0.13% of total global electricity consumption. Proof of Work (PoW)
  • 35. Let’s add the difficulties and target for the PoW hash (cost) function, the “genesis” block and some utility functions: Mining and Validation
  • 36.
  • 37.
  • 38.
  • 39. Now we can add a method to mine a given set of transactions into a single block: Mining and Validation
  • 40.
  • 41.
  • 42. Once we can mine/create new blocks, new block creation is pretty straightforward: 1. Fetch transactions from the mempool. We’ll assume that blocks are limitless (which is of course not the case). 2. Keep mining a block with these transactions until a valid PoW is found. 3. Append the new block to the blockchain. 4. Remove the mined transactions from the mempool. We will assume that there are no race conditions needed to be taken care of. Creating new blocks
  • 43.
  • 44. In order for the blockchain to be more robust, we will add support for writing and reading the blockchain from the storage. ❑ What if someone modifies the data on the disk? ✓ We can verify that the blocks were appended correctly, starting from the genesis block. ❑ What if someone modifies the genesis block? ✓ We’ll hardcode it directly in the protocol. ❑ What if we were offline for a very long time? ✓ We’ll bootstrap from other miners (not in this talk…). Storing the blockchain
  • 45. Let’s implement saving and loading the blockchain to the disk (it won’t be very efficient, but it’ll do for now): Storing the blockchain
  • 46.
  • 47.
  • 48.
  • 49. Let’s implement the validation of the loaded blockchain: Storing the blockchain
  • 50.
  • 51.
  • 52.
  • 54. Running a blockchain only on our own machine isn’t very useful (is it?), so let’s add some web API to our implementation. Specifically: 1. API to list the blockchain. 2. API to list and submit transactions. 3. API to mine/create blocks (just for the demo; it could’ve been a cron-like job. Setting up a web server
  • 55.
  • 56.
  • 57. Let’s add an API to submit transactions. For the sake of the demo, we won’t validate senders of the transaction of their balances. Submitting transactions
  • 58.
  • 59. Let’s add an API to block mining. ❑ But wait… why should our node mine blocks?! ✓ Let’s bribe the node with add a mining reward! Mining blocks
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65. In order to make our blockchain more decentralized, we’d want to: 1. Support multiple nodes (avoid single point of failure, faulty nodes, improve liveliness of the system, etc.). 2. Don’t blindly trust the output of the other nodes – validate everything yourself! 3. Reach a consensus about the state of the blockchain among the nodes. Decentralizing the blockchain
  • 66. • Let’s add an API for every node to be aware of other nodes. • Since we’re developing a permissionless blockchain – everyone is free to join. Node discovery
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72. • Now, when we have a (naïve) way for the nodes to be aware of each others – they can communicate together. • In order to reach a consensus on the “true” state of the blockchain, every node will: 1. Get the whole blockchain from every other node. 2. If the other blockchain is both longer and valid – use it instead. Reaching a consensus
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 81. Award winning contest • Do you have an idea for an interesting feature? • Can you make it more secure (in of the bazillion possible ways)? • Can you make it more performant? More efficient? Easier to govern? You have 3 weeks to submit an interesting PR (according to the Terms of Service in the repo). The top 3 submissions will win: 2nd place: New iPhone X 64GB or Samsung Note 8. 3rd place: New Ledger Nano S Hardware Wallet. 1st place: New MacBook Pro 13”, i5, 256 SSD with a Touch Bar.
  • 82. Blockchain AcademyLeonid Beder December 26th, 2017 Thank You! Next Events JAN 25th - How To Become A Smart Contract Engineer FEB 27th - How to Not Destroy Millions in Smart Contracts