Blockchains
Technical foundations
@stadolf
#elmariachi#8789
stadolf.eth
transactional
ledgers
From Value To
Alice $100 Bob
Bob Banana Alice
Bob $100 Charly
Charly Apple Bob
Ledger: ordered transaction list
What’s Alice’s current balance?
accounts
Alice Bob Charly
100$
From Value To
Alice Bob Charlie
100$ Banana Apple
Alice Bob Charly
100$
From Value To
Alice $100 Bob
Alice Bob Charlie
100$ Banana Apple
Banana, 100$ Apple
Alice Bob Charly
From Value To
Alice $100 Bob
Bob Banana Alice
Alice Bob Charlie
100$ Banana Apple
Banana, 100$ Apple
Banana 100$ Apple
100$
Alice Bob Charly
From Value To
Alice $100 Bob
Bob Banana Alice
Bob $100 Charly
Alice Bob Charlie
100$ Banana Apple
Banana, 100$ Apple
Banana 100$ Apple
Banana Apple, 100$
100$
Alice Bob Charly
From Value To
Alice $100 Bob
Bob Banana Alice
Bob $100 Charly
Charly Apple Bob
Alice Bob Charlie
100$ Banana Apple
Banana, 100$ Apple
Banana 100$ Apple
Banana 100$
Banana Apple 100$
100$
From Value To
Alice $100 Bob
Bob $100 Charly
Bob Banana Alice
Charly Apple Bob
Alice Bob Charlie
100$ Banana Apple
Banana, 100$ Apple
Banana Apple, 100$
Banana Apple, 100$
Banana Apple 100$
100$ 100$
Alice Bob Charly
From Value To
Charly Apple Bob
Bob Banana Alice
Alice 100$ Bob
Bob 100$ Charly
Alice Bob Charlie
100$ Banana Apple
Banana, 100$ Apple
Banana, 100$ Apple
Banana Apple, 100$
Banana Apple 100$
100$ 100$
Alice Bob Charly
100$
?
Alice Bob Charly
How many $ are in this diagram, vs how many fruits?
centralized answers
Problem: track history + state
When did things happen?
Who decides about the final ordering?
What’s Alice’s current account balance?
How can you prove this is true?
Can anyone have a different truth?
How can you guarantee effects?
Adds number to each transaction
Orders transactions when they arrive
Keeps an account book
Don’t believe us? Sue us!
We’re wearing suits and ties!
We know our customers!
We simply remove bad actors if we find them
Decentralized state is super hard.
Let’s count to 20.
When you hear a number, multiply it with 17.
Call the next number after the one you heard
regardless of the ones you heard in the meanwhile
Close your eyes, please.
Let’s count to 20.
Decentralized ledgers
ingredients
0. “Money” / Value
Each chain has a “native” currency baked in
ETH in Ethereum, SOL in Solana, BTC in Bitcoin
Splittable to much smaller units (1,000,000,000,000,000,000 wei = 1Eth)
- It’s just a numeric value, upon chain start it’s worth $0.
- Used to pay for network fees / rewards
- It’s minted upon network rules / intrinsically scarce
- It follows natural economic rules (supply / demand) .
1. The users’ side
Accounts, transactions & proofs are based on
cryptographic primitives
Users keep their private keys inside their wallet
Keys are derived by one secret random value (seed)
Users use their private keys to sign transactions
transaction + signature = public key
Accounts are addressed by a hash over their public key
Many blockchain nodes around the world
sync a copy of ledger and account state
Users submit (signed) transactions to
a node they know
User transactions are distributed to
a world wide memory pool
No one sees the same pool
2. The network’s side
3. Block building
Block producers pick transactions
that yield the highest fees
They check each transaction for validity
according to the account state they know
They order them in a valid ordering
no apple stays behind
They submit blocks to validators
E.g themselves, in case of PoW
4. Consensus & Finality
Proof of Work (“Mining”)
Every miner tries to find a value (“nonce”) that - combined with
the block’s data - leads to a hash that starts with a lot of zeros.
This is extremely hardTM
.
- Once found, the miner adds his block to its own chain copy
and tells his peers about it.
- Peers check the block’s validity and its nonce. This is super easy.
- The longest valid blockchain that you see, is your current truth
- Once behind 6 blocks, it’s impossibleTM
to change a block’s content.
- Each valid block contains an implicit reward for the miner.
4. Consensus & Finality
Proof of Stake (“Validating”)
Validators must stake 32 Eth before they can participate.
Block producers are randomly selected to propose a block for a slot.
Their blocks are checked by other random nodes (committee).
If a block is invalid, the proposer loses some of his stake.
All validators vote on checkpoint blocks after an epoch (32 slots)
If ⅔ of all validators agree on a checkpoint, it’s justified, the previous
checkpoint (the epoch of 32 blocks) is finalized.
See it in action.
5. Smart Contracts
executable code on chain
have a public address (but no private key)
have a balance
have a (complex) state
- Everyone can send transactions to contracts
- Contract code is executed by block producers
- State changes are stored by each node
- Release funds upon provable logic rules
→ no apple can stay behind
Common kinds of smart contracts
Fungible Tokens (“ERC-20”)
An account book of numeric balances
Non Fungible Tokens (“ERC-721”)
An account book of unique items (numbers)
Can contain metadata to give each item a context / meaning
Semi-fungible Tokens (“ERC-1155”)
An account book of items with limited copies
ENS Associates metadata (e.g. a “name”) with an account
Multisig Wallets Control funds on behalf of several users
Exchanges Keep several kinds of tokens and
swap them against each other
Dealing with congestion: Gas fees
We can’t all write at the same time
Each operation / byte changed implies a gas cost (e.g Eth transfer = 21.000gas)
Users multiply the gas costs with a gas fee and add a tip
All execution fees are burnt
Block producers prefer transactions with highest gas fees and tips
Block gas limit
Contracts can’t be arbitrarily complex / run forever
Transaction parameters can’t be arbitrarily complex
Examples
The nomad bridge attack
https://etherscan.io/txs?block=15259101&p=4
Bored Ape Yacht Club NFT
https://etherscan.io/address/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d
Vitalik’s private account
https://etherscan.io/address/0xab5801a7d398351b8be11c439e05c5b3259aec9b
Blockchains, in a nutshell
Decentralized, unstoppable, trustless & permissionless networks
Transaction ledgers
Account books (“provable state”)
Bundle Changesets into blocks
All blocks depend on a common history
Global Consensus is incentivized
fees / mining rewards / stake returns
ask me anything.
@stadolf
#elmariachi#8789
stadolf.eth

Blockchains - Technical foundations

  • 1.
  • 2.
  • 3.
    From Value To Alice$100 Bob Bob Banana Alice Bob $100 Charly Charly Apple Bob Ledger: ordered transaction list What’s Alice’s current balance?
  • 4.
  • 5.
    Alice Bob Charly 100$ FromValue To Alice Bob Charlie 100$ Banana Apple
  • 6.
    Alice Bob Charly 100$ FromValue To Alice $100 Bob Alice Bob Charlie 100$ Banana Apple Banana, 100$ Apple
  • 7.
    Alice Bob Charly FromValue To Alice $100 Bob Bob Banana Alice Alice Bob Charlie 100$ Banana Apple Banana, 100$ Apple Banana 100$ Apple 100$
  • 8.
    Alice Bob Charly FromValue To Alice $100 Bob Bob Banana Alice Bob $100 Charly Alice Bob Charlie 100$ Banana Apple Banana, 100$ Apple Banana 100$ Apple Banana Apple, 100$ 100$
  • 9.
    Alice Bob Charly FromValue To Alice $100 Bob Bob Banana Alice Bob $100 Charly Charly Apple Bob Alice Bob Charlie 100$ Banana Apple Banana, 100$ Apple Banana 100$ Apple Banana 100$ Banana Apple 100$ 100$
  • 10.
    From Value To Alice$100 Bob Bob $100 Charly Bob Banana Alice Charly Apple Bob Alice Bob Charlie 100$ Banana Apple Banana, 100$ Apple Banana Apple, 100$ Banana Apple, 100$ Banana Apple 100$ 100$ 100$ Alice Bob Charly
  • 11.
    From Value To CharlyApple Bob Bob Banana Alice Alice 100$ Bob Bob 100$ Charly Alice Bob Charlie 100$ Banana Apple Banana, 100$ Apple Banana, 100$ Apple Banana Apple, 100$ Banana Apple 100$ 100$ 100$ Alice Bob Charly
  • 12.
    100$ ? Alice Bob Charly Howmany $ are in this diagram, vs how many fruits?
  • 13.
    centralized answers Problem: trackhistory + state When did things happen? Who decides about the final ordering? What’s Alice’s current account balance? How can you prove this is true? Can anyone have a different truth? How can you guarantee effects? Adds number to each transaction Orders transactions when they arrive Keeps an account book Don’t believe us? Sue us! We’re wearing suits and ties! We know our customers! We simply remove bad actors if we find them
  • 14.
    Decentralized state issuper hard. Let’s count to 20. When you hear a number, multiply it with 17. Call the next number after the one you heard regardless of the ones you heard in the meanwhile
  • 15.
    Close your eyes,please. Let’s count to 20.
  • 16.
  • 17.
    0. “Money” /Value Each chain has a “native” currency baked in ETH in Ethereum, SOL in Solana, BTC in Bitcoin Splittable to much smaller units (1,000,000,000,000,000,000 wei = 1Eth) - It’s just a numeric value, upon chain start it’s worth $0. - Used to pay for network fees / rewards - It’s minted upon network rules / intrinsically scarce - It follows natural economic rules (supply / demand) .
  • 18.
    1. The users’side Accounts, transactions & proofs are based on cryptographic primitives Users keep their private keys inside their wallet Keys are derived by one secret random value (seed) Users use their private keys to sign transactions transaction + signature = public key Accounts are addressed by a hash over their public key
  • 19.
    Many blockchain nodesaround the world sync a copy of ledger and account state Users submit (signed) transactions to a node they know User transactions are distributed to a world wide memory pool No one sees the same pool 2. The network’s side
  • 20.
    3. Block building Blockproducers pick transactions that yield the highest fees They check each transaction for validity according to the account state they know They order them in a valid ordering no apple stays behind They submit blocks to validators E.g themselves, in case of PoW
  • 21.
    4. Consensus &Finality Proof of Work (“Mining”) Every miner tries to find a value (“nonce”) that - combined with the block’s data - leads to a hash that starts with a lot of zeros. This is extremely hardTM . - Once found, the miner adds his block to its own chain copy and tells his peers about it. - Peers check the block’s validity and its nonce. This is super easy. - The longest valid blockchain that you see, is your current truth - Once behind 6 blocks, it’s impossibleTM to change a block’s content. - Each valid block contains an implicit reward for the miner.
  • 22.
    4. Consensus &Finality Proof of Stake (“Validating”) Validators must stake 32 Eth before they can participate. Block producers are randomly selected to propose a block for a slot. Their blocks are checked by other random nodes (committee). If a block is invalid, the proposer loses some of his stake. All validators vote on checkpoint blocks after an epoch (32 slots) If ⅔ of all validators agree on a checkpoint, it’s justified, the previous checkpoint (the epoch of 32 blocks) is finalized.
  • 23.
    See it inaction.
  • 24.
    5. Smart Contracts executablecode on chain have a public address (but no private key) have a balance have a (complex) state - Everyone can send transactions to contracts - Contract code is executed by block producers - State changes are stored by each node - Release funds upon provable logic rules → no apple can stay behind
  • 25.
    Common kinds ofsmart contracts Fungible Tokens (“ERC-20”) An account book of numeric balances Non Fungible Tokens (“ERC-721”) An account book of unique items (numbers) Can contain metadata to give each item a context / meaning Semi-fungible Tokens (“ERC-1155”) An account book of items with limited copies ENS Associates metadata (e.g. a “name”) with an account Multisig Wallets Control funds on behalf of several users Exchanges Keep several kinds of tokens and swap them against each other
  • 26.
    Dealing with congestion:Gas fees We can’t all write at the same time Each operation / byte changed implies a gas cost (e.g Eth transfer = 21.000gas) Users multiply the gas costs with a gas fee and add a tip All execution fees are burnt Block producers prefer transactions with highest gas fees and tips Block gas limit Contracts can’t be arbitrarily complex / run forever Transaction parameters can’t be arbitrarily complex
  • 27.
    Examples The nomad bridgeattack https://etherscan.io/txs?block=15259101&p=4 Bored Ape Yacht Club NFT https://etherscan.io/address/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d Vitalik’s private account https://etherscan.io/address/0xab5801a7d398351b8be11c439e05c5b3259aec9b
  • 28.
    Blockchains, in anutshell Decentralized, unstoppable, trustless & permissionless networks Transaction ledgers Account books (“provable state”) Bundle Changesets into blocks All blocks depend on a common history Global Consensus is incentivized fees / mining rewards / stake returns
  • 29.