+ All Categories
Home > Documents > Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message...

Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message...

Date post: 12-Mar-2020
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
61
Cryptocurrency Engineering and Design MAS.S62 2/7/2018 Lecture 1 1
Transcript
Page 1: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Cryptocurrency Engineering and Design MAS.S62

2/7/2018 Lecture 1

1

Page 2: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Introduction • Who we are

– Neha Narula – Tadge Dryja – James Lovejoy (TA)

• Digital Currency Initiative • Course

– Lectures (20%) – Labs (40%) – Final project (40%)

2

Page 3: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Cryptocurrency Engineering and Design

• What is a cryptocurrency? • How is it different than a regular currency? • What does it mean to build one?

3

Page 4: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

What we are not going to do • How to ICO • Trading advice • Permissioned blockchains

4

Page 5: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Origins of Money

Images of sheep, grains, various ancient and modern currencies © unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see https://ocw.mit.edu/fairuse.

5

Page 6: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Traditional payments Alice: $10

Bob: $0

“I, Alice, would like to send Bob $5”

Alice Bob Various clip art images in this document © unknown. All rights reserved. This content is excluded from our Creative Commons license. For more information, see https://ocw.mit.edu/fairuse.

6

Page 7: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Traditional payments Alice: $5

Bob: $5

Bob, I sent you $5! Alice Bob

7

Page 8: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Traditional payments Alice: $5

Bob: $5

Alice Bob 8

Page 9: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Traditional payments

Alice Bob

Alice: $5

Bob: $5

9

Page 10: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Pros/cons of banks Pros • Digital payments

Cons • Not peer-to-peer (bank must be online during every

transaction) • Bank can fail • Bank can delay or censor transactions • Privacy

10

Page 11: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

The bank can fail Alice: $10

Bob: $0

Alice Bob 11

Page 12: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

The bank can delay or censor Alice: $10

Bob: $0

“I, Alice, would like to send Bob $5”

No!

Alice Bob 12

Page 13: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

E-cash

“I, Alice, would like a coin”

Alice Bob 13

Page 14: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

E-cash SN

Alice Bob 14

Page 15: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

E-cash

Alice Bob

SN

15

Page 16: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

E-cash

Alice Bob

SN

16

Page 17: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

E-cash SNSN

Alice Bob 17

Page 18: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

E-cash SN

Alice Bob 18

Page 19: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Pros/cons of simple e-cash Pros • Digital payments • Peer-to-peer

Cons • Bank needs to be online to verify • Bank can fail • Bank can delay or censor transactions • Privacy

19

Page 20: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Chaumian e-cash • Alice can choose SN • Alice “blinds” her message to the bank so

bank can’t see SN • When Bob redeems, bank doesn’t know

payment came from Alice

20

Page 21: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Chaumian e-cash

“I, Alice, would like a coin b(SN)”

Alice Bob 21

Page 22: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Chaumian e-cash

Alice Bob

Sig(b(SN))

Sig(SN), SN 22

Page 23: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Chaumian e-cash

Alice Bob Sig(SN), SN

23

Page 24: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Chaumian e-cash

Alice Bob 24

Page 25: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Chaumian e-cash

Sig(SN), SN

SN

Alice Bob 25

Page 26: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Double spend detection

Alice Bob

uAlice, vAlice

Charlie

26

Page 27: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Pros/cons of Chaumian e-cash Pros • Digital payments • Peer-to-peer • Privacy • Offline double-spend detection

Cons • Bank can censor withdrawals and deposits

27

Page 28: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Alice Bob

How to build decentralized digital token transfer?

1MHepPtrqAxZ

28

Page 29: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

mas.s62 lecture 1

2018-02-07 Neha Narula & Tadge Dryja

29

Page 30: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Primitives for making a cryptocurrency

Hash functions

Signatures

30

Page 31: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Hash functions Simple, right? But powerful.

hash(data) -> output

data can be any size; output is fixed size

31

Page 32: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Hash functions Important. You can do everything* with just hash functions.

*can’t do some fun stuff with keys

(Key exchange, signature aggregation, etc)

32

Page 33: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Hash functions Any size input, fixed output… output is “random” looking

What’s that mean? Deterministic, no randomness

But the outputs look like noise; half the bits are 1s, half are 0s

33

Page 34: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Hash functions Somewhat more well defined -

“Avalanche effect”: change 1 bit of the input, about half the output bits should change

34

Page 35: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Hash functions Well defined: what it shouldn’t do

preimage resistance

(2nd preimage resistance)

collision resistance

35

Page 36: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

preimage resistance given y, you can’t find any x such that hash(x) == y

(you can find it eventually, but that will take 2256 operations (1078))

36

Page 37: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

2nd preimage resistance given x, y, such that hash(x) == y, you can’t find x’ where

x’ != x

and hash(x’) == y

(this one is a bit of a mess so lets leave it at that) 37

Page 38: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

collision resistance nobody can find any x, z such that

x != z

hash(x) == hash(z)

(again, you can find them eventually. And in this case, not 2256) 38

Page 39: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

resistances Practically speaking, collision resistance is “harder”;

collision resistance is broken while preimage resistance remains

Examples: sha-1, md5

39

Page 40: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

usages hashes are names

hashes are references

hashes are pointers

hashes are commitments

40

Page 41: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Commit reveal Commit to something secret by publishing a hash

Reveal the preimage later.

Example: a1c089bf65e852cf2ba2010d2ba84e2025ec937b5f8b9dac682c35dcf498aef4

41

Page 42: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Commit reveal a1c089bf65e852cf2ba2010d2ba84e2025ec937b5f8b9dac682c35dcf498aef4

Reveal:

I think it won't snow Wednesday! d79fe819

$ echo "I think it won't snow Wednesday! d79fe819" | sha256sum

a1c089bf65e852cf2ba2010d2ba84e2025ec937b5f8b9dac682c35dcf498aef4 -

42

Page 43: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Commit reveal $ echo "I think it won't snow Wednesday! d79fe819" | sha256sum

a1c089bf65e852cf2ba2010d2ba84e2025ec937b5f8b9dac682c35dcf498aef4 -

Add randomness so people can’t guess my preimage; HMAC

This is a kind of proto-signature

43

Page 44: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Linked list with hashes

We could call this a “hash-chain”

Also, it’s basically git

44

Page 45: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Binary tree with hashes

How can 2 inputs go to 1 output? Not a collision. Concatenate then hash: h(a,b) 45

Page 46: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

What’s a signature? Signatures are useful! Messages from someone. 3 functions needed:

GenerateKeys()

Sign(secretKey, message)

Verify(publicKey, message, signature) 46

Page 47: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

3 functions GenerateKeys()

Returns a privateKey, publicKey pair

Takes in only randomness

47

Page 48: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

3 functions Sign(secretKey, message)

Signs a message given a secretKey.

Returns a signature.

48

Page 49: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

3 functions Verify(publicKey, message, signature)

Verify a signature on a message from a public key. Returns a boolean whether it worked or not.

49

Page 50: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Signatures from hashes It’s doable! In fact, you’ll do it!

First pset is to implement a signature system using only hashes.

This is called “Lamport Signatures”

50

Page 51: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Lamport Sigs: Generate key

Make up 256*2 random 256 bit numbers

… (256)

… (256)

0

1

51

Page 52: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Lamport Sigs: Generate key

Get hashes for each

… (256)

… (256)

0

1

52

Page 53: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Lamport Sigs: Generate key

= Secret key = public key

… (256)

… (256)

0

1

53

Page 54: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Lamport Sigs: Sign

Hash string to sign. “Hi” = 8f434346648f6b96df89dda901c5176b10a6d83961dd3c1ac88b59b2dc327aa4

Pick private key blocks to reveal based on bits of message to sign

54

Page 55: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Lamport Sigs: Sign

Hash string to sign. Pick private key blocks to reveal based on bits of message to sign 01101110

55

Page 56: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Lamport Sigs: Verify

Hash each block of the signature Verify that it turns into the block of the public key

56

Page 57: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Lamport Sigs: Signing again

Signing more than once reveals more pieces of the private key

57

Page 58: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Lamport Sigs: Signing again

Signing more than once reveals more pieces of the private key

58

Page 59: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

Lamport Sigs: Signing again

1 sig: can’t forge anything 2 sigs: ~½ bits constrained 3 sigs: ~¼ bits constrained

59

Page 60: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

pset01: Lamport signatures

In golang On github Most of the signing code is written Tests implemented Also public key with 4 signatures; try to forge another! Office hours / messages on slack

60

Page 61: Lecture 1: Signatures, Hashing, Hash Chains, e-cash, and ... · • Alice “blinds” her message to the bank so bank can’t see SN • When Bob redeems, bank doesn’t know payment

MIT OpenCourseWare https://ocw.mit.edu/

MAS.S62 Cryptocurrency Engineering and Design Spring 2018

For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms.


Recommended