Bitcoin and Blockchain

Séminaire ECO/Escape
Victor Poupet
\( \newcommand{\TR}{\operatorname{TR}} \renewcommand{\epsilon}{\varepsilon} \newcommand{\ZZ}{\mathbb{Z}} \newcommand{\NN}{\mathbb{N}} \newcommand{\QQ}{\mathbb{Q}} \newcommand{\RR}{\mathbb{R}} \newcommand{\ACA}{\mathcal{A}} \newcommand{\ACQ}{\mathcal{Q}} \)

Introduction

What is Bitcoin?


Cryptographic Tools

Hash function

Digital Signature

\( \newcommand{\sig}{\operatorname{sig}} \)

Transaction Ledger

  1. Alice pays Bob 50 BTC
  2. Bob pays Charlie 20 BTC
  3. Bob pays Alice 40 BTC
  4. ...
  1. Alice gets 100 BTC
  2. Alice pays Bob 50 BTC
  3. Bob pays Charlie 20 BTC
  4. Bob pays Alice 40 BTC
  5. ...
  1. Alice gets 100 BTC
  2. Alice pays Bob 50 BTC (\(\sig_A\))
  3. Bob pays Charlie 20 BTC (\(\sig_B\))
  4. ...
  1. Alice gets 100 BTC
  2. Alice pays Bob 50 BTC (\(\sig_A\))
  3. Bob pays Charlie 20 BTC (\(\sig_B\))
  4. ...

Problems


Note: no need to store account balance

Distributed Ledger

To avoid central authority, ledger is distributed to all users

→ Problem with conflicting updates (double spending)

Proof of Work

Idea (Proof of Work)
In case of several conflicting series of transactions, keep the one that has the most computational work put into.

The Blockchain

The Blockchain

Transactions are gathered in blocks

Blocks contain

Proof of Work

Example: Block 712897


Note: The target is adjusted every 2016 blocks so that it takes ~10 minutes to validate a block.

Immutability

Transactions

Transactions are made of

Example

Coinbase Transaction

User who validates a block can add a special coinbase transaction with no input and fixed value (block reward)

Overview

  1. Users broadcast new transactions to all nodes
  2. Nodes gather new transactions into blocks
  3. Nodes work to find suitable hash for block (proof of work)
  4. When proof of work is found, block is broadcast to all nodes
  5. Nodes check validity of block
    • Transactions are valid
    • Transactions inputs are not spent
    • Block structure and hash are correct
  6. If valid, all nodes start working on next block

Note: possible ties are solved by working on block that arrived first (for each node) and switching to first solved

Note 2: The system is fundamentally a distributed consensus protocol but the block reward and transaction fees are required to make it work

Merkle Trees

Simple verification

Its possible to verify a transaction with only block headers and a query of the Merkle branch for the transaction


Image from Bitcoin white paper

Scripting


see list of opcodes

Example: send to an account (hash of public key)


scriptSig

<sig>
<pubKey>

scriptPubKey

OP_DUP
OP_HASH160
<pubKeyHash>
OP_EQUALVERIFY
OP_CHECKSIG

Example: reverse a given hash


scriptSig

<data>

scriptPubKey

OP_HASH256
<hash>
OP_EQUAL

Example: find a hash collision


scriptSig

<data1>
<data2>

scriptPubKey

OP_2DUP
OP_EQUAL
OP_NOT
OP_VERIFY
OP_SHA1
OP_SWAP
OP_SHA1
OP_EQUAL

Calculations

Probability of an attacker branch successfully catching up from a deficit of \(z\) blocks:

\[ q_z = \left\{\begin{array}{ll}1 & \textrm{if } p \leq q \\ (q/p)^z & \textrm{if } p > q\\ \end{array}\right. \]

\(p\): prob. honest node finds next block

\(q\): prob. attacker finds next block

With q = 0.1

z=0 P=1.0000000
z=1 P=0.2045873
z=2 P=0.0509779
z=3 P=0.0131722
z=4 P=0.0034552
z=5 P=0.0009137
z=6 P=0.0002428
z=7 P=0.0000647
z=8 P=0.0000173
z=9 P=0.0000046
z=10 P=0.0000012

With q = 0.3

z=0 P=1.0000000
z=5 P=0.1773523
z=10 P=0.0416605
z=15 P=0.0101008
z=20 P=0.0024804
z=25 P=0.0006132
z=30 P=0.0001522
z=35 P=0.0000379
z=40 P=0.0000095
z=45 P=0.0000024
z=50 P=0.0000006

For P < 0.001

q=0.10 z=5
q=0.15 z=8
q=0.20 z=11
q=0.25 z=15
q=0.30 z=24
q=0.35 z=41
q=0.40 z=89
q=0.45 z=340

References