Blockchain Technology and Smart Contract Development Workshop

Day 1

Nchinda Nchinda

@Firescar96

Researcher - MIT Media Lab

Ethereum Application Developer

Bitcoin User

Trapdoor Functions

Hashing

Public Key Cryptography

Diffie-Hellman

Signing

Encryption

Merkle Trees

Stag Rabbit
Stag A:3 B:3 A:3 B:0
Rabbit A:0 B:3 A:2 B:2

Alice

Bob

A Hunting Game

On Distributed Communication Networks - Paul Baran

Bitcoin and the Blockchain

Outline

  • Why you should care, today
  • Bitcoin Origins and History
  • What is mining?
  • What is the blockchain?
  • Consensus
  • Pseudonymity
  • Bitcoin and the Blockchain

Bitcoin vs bitcoin

Why you should care, today.

1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2

Strengths

  • it works. today. right now.
  • global reach
  • objective inference
  • inexpensive and swift
  • irreversible transactions
  • consensus and security
  • psuedonymous

Weaknesses

  • ¯\_(ツ)_/¯

A cypherpunk is an activist who uses software, protocol, and most importantly cryptography to invoke social and political change. 

Bitcoin Origins

https://bitcoin.org/bitcoin.pdf

10000 BTC = 2 pizzas

Then 2013 Happened

  • it works. today. right now.
  • global reach
  • objective inference
  • inexpensive and swift
  • irreversible transactions
  • consensus and security
  • psuedonymous

What's the Blockchain

  • it works. today. right now.
  • global reach
  • objective inference
  • inexpensive and swift
  • irreversible transactions
  • consensus and security
  • psuedonymous

What is mining?

It's like Sudoku

  • No central banks

  • No physical form

  • No government backing

  • Anyone can participate

  • No formal identification

Why hasn't Bitcoin collapsed?

Hard to Solve, Easy to Verify

Winning has a Financial Reward

Bitcoin Mining is like Sudoku

Hash Functions

Arbitrary Text

fixed size number

Hash Functions

Mary had a little lamb, little lamb,

little lamb, Mary had a little lamb

whose fleece was white as snow.

And everywhere that Mary went

Mary went, Mary went, everywhere

that Mary went

The lamb was sure to go.

 

He followed her to school one day,

school one day, school one day,

He followed her to school one day,

Which was against the rules,

It made the children laugh and play,

laugh and play, laugh and play,

It made the children laugh and play,

To see a lamb at school.

 

2,474,925,876

Hash Functions

Alice had a little lamb, little lamb,

little lamb, Mary had a little lamb

whose fleece was white as snow.

And everywhere that Mary went

Mary went, Mary went, everywhere

that Mary went

The lamb was sure to go.

 

He followed her to school one day,

school one day, school one day,

He followed her to school one day,

Which was against the rules,

It made the children laugh and play,

laugh and play, laugh and play,

It made the children laugh and play,

To see a lamb at school.

 

184,000,478,453

Hash Functions

Elice had a little lamb, little lamb,

little lamb, Mary had a little lamb

whose fleece was white as snow.

And everywhere that Mary went

Mary went, Mary went, everywhere

that Mary went

The lamb was sure to go.

 

He followed her to school one day,

school one day, school one day,

He followed her to school one day,

Which was against the rules,

It made the children laugh and play,

laugh and play, laugh and play,

It made the children laugh and play,

To see a lamb at school.

 

82,944,583,940

Hash Functions

We're no strangers to love

You know the rules and so do I

A full commitment's what I'm thinking of

You wouldn't get this from any other guy

 

I just want to tell you how I'm feeling

Gotta make you understand

 

Never gonna give you up, never gonna let you down

Never gonna run around and desert you

Never gonna make you cry, never gonna say goodbye

Never gonna tell a lie and hurt you

 

28,486,668,569

Hard to Solve, Easy to Verify

How hard can it be?

  • Current Bitcoin Difficulty (1011 different possibilities)

  • The number of bits on a computer hard disk (typically about 1013, 500-1000 GB)

  • The number of cells in the human body (more than 1014)

  • The number of neuronal connections in the human brain (estimated at 1014)

  • Maximum Bitcoin Difficulty (1077 different possibilities)

  • The estimated number of atoms in the observable Universe (1080)

  • The lower bound on the game-tree complexity of chess (estimated at around 10120)

What is mining?

It's like Sudoku

  • it works. today. right now.
  • global reach
  • objective inference
  • inexpensive and swift
  • irreversible transactions
  • consensus and security
  • psuedonymous

But...what is the blockchain?

header

body

header

body

header

body

time

header

body

header

body

header

 Alice -> Bob; 1 BTC; .0001 fee

 Alice -> Charlie; 1 BTC; .0001 fee

 Dan -> Alice; 1 BTC; .0004 fee

Reward: 12.5BTC

header

 Alice -> Bob; 1 BTC; .0001 fee

 Alice -> Charlie; 1 BTC; .0001 fee

 Dan -> Alice; 1 BTC; .0004 fee

Reward: 12.5BTC

header

 Alice -> Bob; 1 BTC; .0001 fee

 Alice -> Charlie; 1 BTC; .0001 fee

 Dan -> Alice; 1 BTC; .0004 fee

Reward: 12.5BTC

time

header

...

...

...

Reward: 12.5BTC

header

...

...

...

Reward: 12.5BTC

Wallets do not hold your bitcoin

  • it works. today. right now.
  • global reach
  • objective inference
  • inexpensive and swift
  • irreversible transactions
  • consensus and security
  • psuedonymous

Consensus

The Nash Equilibrium

Stag Rabbit
Stag A:4 B:4 A:2 B:0
Rabbit A:0 B:2 A:1 B:1

Alice

Bob

A Hunting Game

Defend Attack
Defend A:12 B:12 C:∅ A:∅ B:24 C:∅
Attack A:24 B:∅ C:∅ A:∅ B:∅ C:∅

Alice

Bob

Defend Attack
Defend A:8 B:8 C:8 A:∅ B:12 C:12
Attack A:12 B:∅ C:12 A:∅ B:∅ C:24

Alice

Bob

Charlie

Defend

Attack

three players, 24 bitcoin per block

Defend Attack
Defend A:12 B:12 C:∅ A:∅ B:24 C:∅
Attack A:24 B:∅ C:∅ A:∅ B:∅ C:∅

Alice

Bob

Defend Attack
Defend A:8 B:8 C:8 A:∅ B:12 C:12
Attack A:12 B:∅ C:12 A:∅ B:∅ C:24

Alice

Bob

Charlie

Defend

Attack

three players, 24 bitcoin per block

Defend Attack
Defend A:12 B:12 C:∅ A:∅ B:24 C:∅
Attack A:24 B:∅ C:∅ A:∅ B:∅ C:∅

Alice

Bob

Defend Attack
Defend A:8 B:8 C:8 A:∅ B:12 C:12
Attack A:12 B:∅ C:12 A:∅ B:∅ C:24

Alice

Bob

Charlie

Defend

Attack

three players, 24 bitcoin per block

Defend Attack
Defend A:12 B:12 C:∅ A:∅ B:24 C:∅
Attack A:24 B:∅ C:∅ A:∅ B:∅ C:∅

Alice

Bob

Defend Attack
Defend A:8 B:8 C:8 A:∅ B:12 C:12
Attack A:12 B:∅ C:12 A:∅ B:∅ C:24

Alice

Bob

Charlie

Defend

Attack

three players, 24 bitcoin per block

  • it works. today. right now.
  • global reach
  • objective inference
  • inexpensive and swift
  • irreversible transactions
  • consensus and security
  • psuedonymous

Pseudonymity

Almost anonymous

other projects can accomplish this though

  • it works. today. right now.
  • global reach
  • objective inference
  • inexpensive and swift
  • irreversible transactions
  • consensus and security
  • psuedonymous

But Bitcoin is just a distraction from the blockchain...

Nyet.

What if we put code...

on the blockchain?

Lunch

Types

Constructors and Functions

Special Solidity Calls

Types

  • boolean
    • true or false
  • int and uint
    • represent 256 bit signed and unsigned numbers respectively
  • address
    • holds a 20 byte ethereum address
  • bytes1 - bytes32
    • fixed size byte array
  • struct
    • fixed size byte array
  • enum
    • fixed size byte array

Contract Structure

pragma solidity ^0.4.0;

contract SimpleStorage {
    uint storedData;

  function SimpleStorage() {
    // ...
  }

  function bid() payable { // Function
    // ...
    }
  }

}

Special Operations

  • msg.sender
    • the ethereum address that directly called the contract
  • msg.value
    • value of the calling transaction
  • block.number
    • current blocknumber
  • sha256 and sha3
    • hash functions
  • selfdestruct(<address>)
    • kill self and send money to an address
  • wei, finney, szabo, ether
    • currency denominations

Contract walkthrough

Development Time

Tasks:

A) write two contracts that can call each other

B) redo the solidity tutorial videos

C) do some of these challenges

make sure to ask for help

Blockchain Technology and Smart Contract Development Workshop

Day 2

Recap

  • cryptographic primitives
  • history of bitcoin/blockchain
  • setting up an ethereum wallet
  • how to write and deploy smart contracts

Web Dev Intro

Devlopment Time

Tasks:

A) work on your contracts from yesterday
B) start adding a frontend component

C) do some of these challenges

Recap

  • cryptographic primitives
  • history of bitcoin/blockchain
  • setting up an ethereum wallet
  • how to write and deploy smart contracts
  • how to link smart contracts to frontend

Lunch

Testing

Mocha

describe('Array', function() {

  before(function() {
    // runs before all tests in this block
  });  

  describe('#indexOf()', function() {
    it('should not be empty', function() {
      // ...some assertions here
    });
  });
});

Mocha

$ ./node_modules/mocha/bin/mocha

  Array
    #indexOf()
       should not be empty


  1 passing (9ms)

Embark + Mocha

contract('MySimpleContract', function() {

  describe('setting the state', function() {
    // ..some assertions here
  });


  // ...some more contract tests here

});

Chai - expect style

expect(2).to.equal(2);

expect({a: 1, b: 2})
  .to.not.have.any.keys('c', 'd');

expect([1, 2]).to.be.an('array')
 .that.does.not.include(3);

 

expect(false, 'nooo why fail??').to.be.true;

 

Testing Activity

Break

MedRec

More Stuff

Proof of Stake and Authority

Context of Smart Contracts

Race to Empty

 Blockchain Projects

Contact

Free Time

Blockchain Workshop

By Nchinda Nchinda

Blockchain Workshop

This is the 2 day workshop version

  • 745