Lecture.1
Lecture.1
BLOCKCHAIN TECHNOLOGIES
Prolegomena
Σωκράτης:
λέγει που Ἡράκλειτος ὅτι ‘πάντα χωρεῖ καὶ οὐδὲν μένει,’ καὶ ποταμοῦ ῥοῇ
ἀπεικάζων τὰ ὄντα λέγει ὡς ‘δὶς ἐς τὸναὐτὸν ποταμὸν οὐκ ἂν ἐμβαίης.’
Ἑρμογένης:
ἔστι ταῦτα.
—Plato, Cratylus, 402a
• “A distributed system is one in which the failure of a computer you didn't even know existed can
render your own computer unusable.”—Leslie Lamport (cf. Byzantine General’s Problem)
• “In terms of cryptocurrencies, generally, I can say with almost certainty that they will come to a bad
ending”—Warren Buffet
• “Scares the hell out of me...”—Conversation with an anonymous bank director, Ritz Bar, 2017
• “Bitcoin is evil.”—Paul Krugman, New York Times editorial, December 28, 2013
About this course
• What are we going to do?
• Foundations:
• Cryptography (Introduction, Hash Functions and Pointers)
• Algorithms (SHA256, RIPEMD-160, Base58Check, Elliptical Curves, Balanced Binary Trees, Merkle Trees)
• Graph Theory
• Game Theory
• Blockchain predecessors, history and fundamentals
• Bitcoin Transactions and Cryptocurrencies, with a focus on bitcoin-core
and supporting APIs
• Other stuff if we have time
• What are you going to do?
• Some labs exercising the above stuff in a language of your choice***
• Write and mine your own simplified distributed peer-to-peer blockchain with
supporting algorithms (SHA-256, Base58Check, Merkle Chains, etc.)
• Work on a team with classmates and build a blockchain solution of your
choice
What this course is not...
• This is not a course in economics, although we will talk a little about money and value
• This is not a course in finance, although we will talk a little about banking as well
• This is not a course in trading cryptocurrencies, or arbitraging cryptocurrencies across
exchanges
• This is not a course on the legal ramifications of cryptocurrency, although we will
mention a few uncertainties
• What we will do is focus on blockchain architecture by using Bitcoin as a reference
model
• Syllabus Review
Circles: Bitcoin is Hard
• There’s lots to talk about...
• We’re going to talk about all of these
concepts and more
• Bitcoin is like an onion...hard to talk
about one thing without presupposing
knowledge of another thing
• We’ll peel the onion strategically,
introducing concepts early and then
diving in to details later, when we peel
another layer of the onion
• And sometimes you may cry when
peeling the bitcoin onion...
What is Bitcoin? A Starter Definition...
• Bitcoin is “a virtual currency system that eschewed a central authority for issuing
currency, transferring ownership, and confirming transactions.”—Marco Iansiti and
Karim R. Lakhani, “The Truth About Blockchain,” Harvard Business Review, Jan-Feb,
2017
• How’s that for starters?
A Starter Definition...
• Bitcoin is “a virtual currency system that eschewed a central authority for issuing
currency, transferring ownership, and confirming transactions.”—Marco Iansiti and
Karim R. Lakhani, “The Truth About Blockchain,” Harvard Business Review, Jan-Feb,
2017
• That’s like defining an Automobile as:
• An automobile is “a physical gasoline-fueled propulsion system that eschewed sitting
idle but rather leverages a human being for initiation and direction-handling.”
A Starter Definition...
• Which is better:
• Bitcoin is “a virtual currency system that eschewed a central authority for issuing currency, transferring
ownership, and confirming transactions.”—Marco Iansiti and Karim R. Lakhani, “The Truth About
Blockchain,” Harvard Business Review, Jan-Feb, 2017
• Or:
• “Satoshi Nakamoto’s ingenious solution lay in a mix of carrot-and-stick incentives that encouraged
those who were validating transactions to do so honestly...If we view the bitcoin currency from this
angle—and not merely as it is popularly portrayed, as a strange new digital unit of value that some geeky
guys think is a good alternative to dollars, euros, or yen—we can build a conceptual framework for
understanding the wider implications of Satoshi’s invention. The currency, bitcoin (lowercase ‘b’) is
first and foremost a store of value that rewards people for securing Bitcoin (uppercase ‘B’), the system
[sc. Blockchain]. That, and not the hope that it will become an everyday medium of exchange, is its
primary purpose. Without its existence as an incentive for computer owners to honestly validate
exchanges of valuable information, Satoshi’s censorship-resistant distributed ledger simply wouldn’t
work.”—Casey and Vigna, The Truth Machine, 2018
Bitcoin and Blockchain at 35,000 feet
• Blockchain is a Distributed Ledger Technology that incorporates a network of mostly
redundant public data stores that interoperate securely, without being controlled and
administered by a central authority, that is known and trusted by all participants, through
the provisioning of incentives to ensure that trust.
• Bitcoin, at the highest level, consists of:
• A decentralized peer-to-peer network (aka the
Bitcoin Protocol)
• A public transaction ledger (the Blockchain)
• A set of rules for independent transaction validation
(Consensus rules)
• A set of rules for money supply (Mining)
• A mechanism for reaching global decentralized
consensus on the Blockchain (Proof-of-Work)
BITCOIN AT 30,000 FEET
“Bitcoin...it’s best understood as a Truth Machine”—Casey and Vigna, The Truth Machine
Bitcoin’s Peer-to-Peer Communication – High-Level View
• Nodes are connected to a small set of “neighboring” peers
• If Alice wants to send a message to Bob, she starts by sending it to those nodes she
knows about, Carmen and Dave
• Carmen and Dave then forward the message to their immediate peers, and so on until
the message reaches Bob
Bitcoin and Blockchain at 20,000 feet
• Bitcoin, at the highest level, has the following characteristics:
• Two parties can transact directly without the need for a “trusted” third party intermediary
• Transactions cannot be reversed, you can’t step into the same river twice
• Double-spending is extraordinarily unlikely (and has empirically proven to be so)
• Anyone can join the Bitcoin network
• Users create wallets to interact with the Bitcoin network
• A wallet has unique addresses (bitcoin addresses) that identify it in the network
• The address comes with a pair of cryptographic keys for signing and verifying transactions,
which are sent and received with reference to wallet addresses
• Each (full) node keeps a full history of all transactions (the blockchain), currently ∼613 Gig
• Although transactions in the ledger are not encrypted, user pseudo-anonymity is preserved
because only the wallet bitcoin addresses of users are publicly exposed
• Mining nodes verify transactions and each work on solving a “mathematically difficult puzzle”
• The winning puzzle-solving miner is rewarded with bitcoins and adds the winning block with
its transactions to the blockchain and is validated and replicated by nodes
Bitcoin Timeline: The $338 Million Dollar Pizza
January 3, 2009
Satoshi
November 9, Nakamoto mines
2008, the Genesis Block, October 12, 2009
Bitcoin project is November 29,
the first 50 New Liberty sells
registered on 2013 December 17, 2017
bitcoins 5,050 BTC for July 18, 2010
BTC surpasses BTC reaches current
SourceForge $5.02 BTC surpasses $1,000 for first
$.01 (one penny) all-time high of
time, propelled by By 2018 there are
for first time $19,783
Chinese investors
over 5,000 ATMS for
January 12, 2009
bitcoin world-wide
August 15, 2008 First Transaction,
February 6, 2010 February 9, 2011 April 1, 2012 Further price volatility,
King et. al. sale, Block 170
The Bitcoin Market BTC surpasses $1 BTC surpasses
Encryption patent SatoshióHal
$100 for first time,
1BTC = $1,000-$5,000
filed Finney currency exchange for first time
established Silk Road opens then to $200 less
than a week later
2018-
2008 2009 2010 2011 2012 2013 2014 2015 2016 2017
2025
JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
Full Node
Bitcoin-cli &
others…
The Bitcoin
Peer-2-Peer
Network
Bitcoin Environments
• Bitcoin may be run in a variety of incarnations:
• Mainnet: The real Bitcoin blockchain, launched by Satoshi Nakamoto, the one on which you can
become a millionaire or lose all your private keys...
• Testnet: A full-featured live peer-to-peer network, replete with wallets, bitcoins, and other users
(testers), with one exception, you’re playing with monopoly money
• You get free play money from faucets...
• Mining difficulty is low (so you can play around)
• Despite pleas from developers, some morons insist on launching ASICs at
Testnet, so every once in a while it needs to be scrapped and restarted, TESTNET
we are currently on Testnet3 (but things are looking good...)
• Allows testing of segregated witness
• Regtest: Your own personal bitcoin blockchain
• “In the Raw”
• Starts in a virgin state
• Yours to play with as you wish
Testnet
• The default Bitcoin network protocol listening port is 18333 (instead of 8333 on main)
• The default RPC connection port is 18332 (instead of 8332 on main)
• Bootstrapping uses different DNS seeds
• A different value of the ADDRESSVERSION field ensures no Testnet Bitcoin addresses
will work on the production network. (0x6F rather than 0x00 for Mainnet)
• The protocol message header bytes are 0x0B110907 (instead of 0xF9BEB4D9 on main)
• Testnet mining difficulty is much less than on Mainnet.
• If no block has been found in 20 minutes, the difficulty automatically resets back to the
minimum for a single block, after which it increases.
• A new genesis block 0
• The IsStandard() check is disabled so that non-standard transactions can be
experimented with.
• Testnet receives fewer transactions than the main block chain and is typically much
smaller in size. As of January 1, 2025, the size of the data on disk is about 192 Gigs,
containing data for about 13 years of Testnet (version 3) activity.
Bitcoin SDLC
What You’re 2018-06-13 16:49:09 Binding RPC on address 0.0.0.0 port 18332 failed.
2018-06-13 16:49:09 HTTP: creating work queue of depth 16
...
Horror Stories
Libertarians are Idealists Too...
“It’s very easy to lose crypto...What people need to understand is this technology was
born out of the cipher-punk movement, using cryptography for people’s individual
freedom and privacy for protection against the state...It was never designed to be user-
friendly, but obviously now people are investing hundreds of billions of dollars into
these systems that are still nascent with respect to the usability and design of the
applications.”—Martin Davidson, co-founder of Blockchain Centre
Horror Stories
• On December 6, 2017, hackers stole 4,700 Bitcoins (∼ $460 million today) in a spear
phishing attack by breaking into Slovenian-based virtual currency marketplace NiceHash
• According to Chainanalysis and Coindesk, a virtual currency exchange, anywhere from
17% up to 33% of the Bitcoins thus-far released and mined have been lost forever
• The reason for disappearance can be anything from losing private keys to hardware
failure.
• The Coindesk study, reported by Fortune, concluded that between 2.78 million and 3.79
million bitcoins—15 to 20 per cent of existing supply—have been lost
• Despite this, there has never been a successful hack of the Bitcoin blockchain itself.
Horror Stories
• Perhaps one of the most infamous stories is that of British IT worker James Howells
who had amassed 7,500 Bitcoins between 2009 and 2010 (worth about £1000 at the
time).
• He kind of forgot about them, and disposed of an old computer which, tragically,
housed an old hard drive which contained his private keys.
• In 2013 after the price of bitcoin had soared from $.01 to over $100 a coin (worth about
£750,000), he remembered his keys…the keys were on that old hard drive...
• As of January 1, 2025, those 7,500 Bitcoins would be worth £591,644,497, or
US$735,000,000
• Rumor has it that the hard drive lies somewhere under tons of landfill in South Wales,
UK.
Horror Stories
• Alex (a pseudonym) is an Australian husband (still we think) who
decided to dabble in bitcoin mining early on.
• In late 2009, when bitcoin was still in its infancy and a single PC
could “mine” a few coins in a day, Alex “got into it just for fun.”
• He managed to mine over 1,000 coins between 2009-2010, storing
his private keys on a USB stick, a smart move.
• Around the end of 2013, after the price peaked to just under $980, he, too, suddenly
remembered his wallet on that USB stick with 1,000 bitcoins.
• The USB stick he’d used to back his keys up on didn’t work...no worries...he had
written down his keys on a sticky note...“Honey, do you remember seeing a yellow piece
of paper about four years ago…I left it on my desk...?”
• Today, his 1,000 bitcoins would be worth roughly US$98,000,000. “Don’t tell my
wife.”
Horror Stories
• In February of 2019, Quadriga, Canada’s largest cryptocurrency exchange, reported it
was unable to gain access to $145 million of bitcoin after its 30-year old CEO and co-
founder, Gerald Cotten, suddenly died of complications arising from Crohn’s Disease
while traveling in India
• Cotten’s widow said that the laptop that her husband had used to run the currency
exchange was encrypted
• Many of the digital currencies held by Quadriga were stored offline in “cold wallets,” as
a way of protecting them from hackers. Cotten was the only person with access to the
wallets, the contents of which were also encrypted
• “I do not know the password...I have not been able to find them written down
anywhere. ”
• Cotten’s death has plunged the exchange into crisis and left it struggling to figure out
how to refund more than 100,000 users
Horror Stories: Mount Gox
• By the first decade of the new millennium, Jed McCaleb, a lover of Japanese culture and
resident of Japan, was running an online trading site that traded playing cards from a game
called “Magic: The Gathering”
• McCaleb called his exchange site Magic The Gathering Online eXchange, or MT GOX
• On July 17, 2010, McCaleb transformed his playing card trading site and released the Mt.
Gox Bitcoin currency exchange, later selling it in March 2011 to Frenchman “MagicalTux,”
Mark Karpelès, who was into Japanese manga and cosplay pastimes
• Karpelès moved Mt. Gox to Tokyo and was at the time about the only place to trade
bitcoins
• The company rode the first meteoric rise of bitcoin in 2010-2011, when around June 13,
2011, investors began to notice that their bitcoins were missing...
Horror Stories: Mount Gox
• Karpelès said the company had lost around 1,000 bitcoins, but when the dust settled, some
850,000 bitcoin private keys (∼US$32 billion) had disappeared and were likely stolen
through multiple siphoning hacks
• Karpelès was arrested in August 2015 in a Japanese police raid while the world reacted with
calls for greater regulation of bitcoin and its exchanges.
• Karpelès was found guilty of the improper use of electronic funds and personally embezzling
a total of $2.7 million of customer funds.
• Although the company later “found” 200,000 bitcoins in a backup, the net loss wound up
being 650,000 coins.
• Last I heard, Karpelès is on bail and cannot leave Japan
Horror Stories: Silk Road
• Ross Ulbricht (aka “Dread Pirate Roberts”) was the pseudonymous proprietor of the
website known as Silk Road, which used Bitcoin for illegal transactions in drugs and arms.
• Between 2011 and 2013, Silk Road became a favorite online marketplace—initially
anonymous to law enforcement agencies—for all sorts of things, including drug mafias,
and a headache for authorities...
• People sold drugs worth millions on the website, and all transactions were done
anonymously using Bitcoin.
• Within months, the website became a leader of the
“darknet”, with over 900,000 users and the annual turnover
of $1 billion—it basically became the Amazon of illicit drugs
• Ulbricht was arrested in October 2013 in a San Francisco
public library by the FBI, and the site was shut down.
• Ulbricht is now serving a life sentence for drug trafficking,
criminal enterprise, aiding and abetting distribution of drugs,
murder-for-hire and money laundering.
Black Eyes: BitInstant
• Charlie Shrem, the 27-year-old CEO of the Bitcoin exchange BitInstant, founded in 2011, was a
young and ambitious entrepreneur who became fascinated with the idea of having a currency no
central authority could control
• After he had bought a couple of bitcoins for a few cents on the dollar at the time, he started the
BitInstant exchange from his home
• He soon caught the attention of young investors like the Winklevoss brothers who invested over
$1.3 million in his company. It began a Boom Time.
• Soon other investors came calling, giants like Walmart, Walgreens, and Duane Reade
• Revenue began to reach over US$1 million a month
• Shrem partnered with a former plumber, “BTCKing” Robert Faiella, whose customers (drug mafias)
were using Silk Road to sell drugs, and both Shrem and Faiella were swept up in the FBI’s Silk Road
dragnet along with the Dread Pirate Roberts, accused of the sale of Bitcoins worth $1 million to Silk
Road.
• Shrem was sentenced to two years in jail and Faiella to four years
• This incident sent shockwaves in the Bitcoin world, as companies like Walgreens and Duane Reade
received a black eye, and world-wide, people started associating bitcoin with money laundering
More Black Eyes: WannaCry?
• The WannaCry ransomware attacked Windows computers in May of 2017 in a
worldwide ransomware cyberattack delivering a cryptoworm
• The virus hit computers of major corporations in over 150 countries throughout the
world.
• Panic spread across the world as message saying “Ooops, your files have been
encrypted!” popped up on the compromised computers.
• The hackers sought $300 ransom in Bitcoin from every compromised computer, giving
people a three-day window to pay the ransom, failing which the hackers threatened to
delete the encrypted files.
• This was yet another black eye on the bitcoin cryptocurrency that was just beginning to
get over its legacy of drugs and black markets
A Recent Horror Story: NiceHash
• NiceHash is a Slovenian cryptocurrency cloud mining marketplace founded in 2014 that
connects sellers of hashing power (miners) with buyers of hashing power, in the form of
pools.
• NiceHash reported on Wednesday, December 6, 2017, that hackers stole nearly around
4,700 Bitcoin private keys worth some $460 million at current prices
• Although NiceHash (nice name after Silk Road...) continues to operate, on December
21, 2017, Marko Kobal resigned as the CEO
• On February 17, 2021 a North Korean hacker group was indicted for the 2017
NiceHash hack
THE DAO FIASCO
“Architecture matters...How a system is designed will affect the freedoms and control
the system enables. And how the internet was designed intimately affected the
freedoms and controls that it has enabled. The code of cyberspace—its architecture
and the software and hardware that implement that architecture—regulates life in
cyberspace generally. Its code is its law.”—Lawrence Lessig, The Future of Ideas, 2001
Libertarians Are Idealists Too
• The DAO (The Decentralized Autonomous Organization) was an investment fund
established on April 30, 2016, at 01:42:58 AM on Ethereum Block 1428757 by Slock.it,
a smart contracts development group founded by one of the partners of Ethereum,
Stephan Tual
• The DAO was to be entirely managed by software, taking Lawrence Lessig’s “code is
law” idea literally in an orgy of libertarian idealism
• Investors could vote online about how to allocate the fund’s money, from a set of
proposed projects
• The DAO was crowdfunded via an Initial Coin Offering (ICO) token sale in May 2016
• The ICO raised more than $34 million by mid-May 2016, and five days later it had
raised over $100 million, with no single investor owning more than 5% of the fund
• The fund’s Ether value as of May 21, 2016, was more than $150 million, and the fund
had more than 11,000 investors
The Warnings
• In May 2016 a paper was published noting several potential security
vulnerabilities associated with The DAO’s code
• Further, an Ethereum developer had pointed out a flaw relating to "recursive calls" in
early June that was picked up and blogged by Peter Vessenes, founder of the Blockchain
Foundation on June 9, 2016
• These warnings were taken seriously and by June 14th fixes had been proposed and were
awaiting approval by members of The DAO (committees move slower than the speed of
the network)
• Further complicating things, on June 13-16 further attention was called to recursive call
vulnerabilities by bloggers affiliated with the The Initiative for CryptoCurrencies &
Contracts
The Sting
• In the early hours of Friday, June 17, 2016, The DAO was subjected to an attack that exploited a
combination of vulnerabilities, siphoning off funds to an impersonator DAO that the hacker(s)
controlled
• By the time they woke up, the hackers had siphoned off almost $55 million worth of ether
• The funds were put into an account subject to a 28-day holding period under the terms of the
DAO contract, so they were not actually gone
• Members of The DAO and the Ethereum community debated what to do next, with some
calling the attack an unethical, but nonetheless, valid “job well done”, saying that when the code
is “its own documentation...this is what happens in the brave new world of programmatic
money flows”
• Others simply called for The DAO to be shut down and remaining funds distributed
• Eventually, the Ethereum network was hard forked to move the funds in The DAO to a recovery
address where they could be exchanged back to Ethereum by their original owners
• However, objectors to the hard fork continued to use the original Ethereum blockchain, now
called Ethereum Classic.
Interest in Blockchain is Skyrocketing
• Get rich mania has continued with new blockchain-based crowdfunding Initial Coin
Offerings (ICOs), wherein most of these new offerings tout a host of new decentralized
applications threatening to disrupt everything from online advertising to medical
research
• The current leader in amounts raised in an ICO is EOS, which quadrupled the previous
winner Telegram whose encrypted-messaging service running over it’s Telegram Open
Network (TON) which allows million of users to pay for services on the TON
blockchain, using the cryptocurrency Gram.
• Telegram raised 1.7 billion dollars in its pre-sale ICO, whereas EOS raised 4.1 Billion in
beginning in June 2018 for its EOS token
Measured in Grams...
• Nonetheless, current fundraising comes at a time when the SEC has grown
increasingly wary of ICOs
• The Wall Street Journal reported in late February 2018, that the SEC had begun issuing
dozens of subpoenas to cryptocurrency-related firms
• In June 2017 Switzerland-based Bancor raised $153 million in just three hours. Within
two years, it plummeted as hackers stole $13.5 million worth of tokens from Bancor’s
decentralized exchange (DEX) and then, in 2019, the platform barred US-based users
due to regulatory uncertainty.
• ICOs are today raising billions of dollars, and steemit.com has issued a tongue-in-cheek
instruction manual for creating your own ICO scam:
https://steemit.com/scam/@moonjelly/how-to-create-an-ico-scam-in-5-simple-steps