Study notesWeek 5: Decentralized Storage And Content Addressing
Week 5

Decentralized Storage And Content Addressing

Outcomes

What You Can Do By The End

The problem

Dead Links And Location Addressing

The idea

Content Addressing

Tool

Hash Functions In Practice

0143287430573128160256512MD5SHA-1SHA-256SHA-512
import hashlib
for text in [b'hello', b'hello!']:
    print(hashlib.sha256(text).hexdigest())
Code

Content-Addressed Store

import hashlib
store = {}
def put(data):
    key = hashlib.sha256(data).hexdigest()
    store[key] = data
    return key
def get(key):
    data = store[key]
    assert hashlib.sha256(data).hexdigest() == key
    return data
k = put(b'Hello')
Ralph Merkle

Merkle Trees

        root
       /    \
    h(AB)   h(CD)
    /  \    /  \
  h(A) h(B) h(C) h(D)
Code

Merkle Root In Python

import hashlib
h = lambda b: hashlib.sha256(b).digest()

def root(blocks):
    layer = [h(b) for b in blocks]
    while len(layer) > 1:
        if len(layer) % 2: layer.append(layer[-1])
        layer = [h(layer[i] + layer[i+1])
                 for i in range(0, len(layer), 2)]
    return layer[0].hex()

print(root([b'A', b'B', b'C', b'D']))
Compact evidence

Merkle Proofs

Familiar example

Git Is A Merkle DAG

commit 9f2c...
  tree   a41b...
    blob 7d3e... README.md
    blob c0aa... main.py
  parent 5be1...
Juan Benet, 2014

IPFS

Honest limits

What IPFS Does Not Promise

Rented persistence

Filecoin: A Market For Storage

SystemWho paysPromise
IPFSPinnersFind by hash
FilecoinRenterDeals with proofs
ArweavePay onceEndowment funded
Permanence as the goal

Arweave: Pay Once

Common pattern

Combining Chains And Storage

chain:    { document_cid: bafy... }
storage:  bafy... -> 4 MB PDF
Summary

Recap

Week 6

Next Week

Your turn

Questions And Exercise