SHA256 Hash
Data:
Bits:
Hex as 0-15:
Hex:
Hash:
64 hex symbols x 4 bits per symbol = 256 bits (32 bytes x 8 bits).
Block
In this demo, a valid block hash must start with 0000.
Block:
Block number is this block's position in the blockchain.
Nonce:
Nonce is the counter miners change to search for a valid hash.
Data:
Hash:
Mined with prefix 0000.
Blockchain
Block:
Nonce:
Data:
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Data:
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Data:
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Data:
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Data:
Prev:
Hash:
Mined with prefix 0000.
Distributed Blockchain
If chain was altered, its tip hash will be different from original chain.
Peer A
Tip hash
Reference chain
0000bb2fb1a5d6d03b4a1fe43bd97f98a037953315b287e07e7269b9e640818f
Peer B
Tip hash
Synced with Peer A
0000bb2fb1a5d6d03b4a1fe43bd97f98a037953315b287e07e7269b9e640818f
Peer C
Tip hash
Different chain
0000859218d50abd9235743a27b72f52c541ebcf3706ee35dc18678c8266a6d4
Peer A
Block:
Nonce:
Data:
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Data:
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Data:
Prev:
Hash:
Mined with prefix 0000.
Peer B
Block:
Nonce:
Data:
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Data:
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Data:
Prev:
Hash:
Mined with prefix 0000.
Peer C
Block:
Nonce:
Data:
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Data:
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Data:
Prev:
Hash:
Mined with prefix 0000.
Tokens
• amount — how much value is being transferred
• from — the sender
• to — the recipient
Balance = total received - total sent.
Anonymity ~ public ids are stored, not real names.
Peer A
Tip hash
Reference chain
00003e5f9d25ae04c9750e8d836142e3e13f744d8ecfd9440046887f56dc931c
Balances
Peer B
Tip hash
Synced with Peer A
00003e5f9d25ae04c9750e8d836142e3e13f744d8ecfd9440046887f56dc931c
Balances
Peer C
Tip hash
Different chain
0000f03fbf335541da26a3fad3ea09e4d139c6c55d8a200348a67804fef3f303
Balances
Peer A
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> |
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> |
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> |
Prev:
Hash:
Mined with prefix 0000.
Peer B
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> |
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> |
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> |
Prev:
Hash:
Mined with prefix 0000.
Peer C
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> |
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> |
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> | ||||
| $ | From: | -> |
Prev:
Hash:
Mined with prefix 0000.
Public / Private Key Pairs
Symmetric encryption demo: Caesar cipher
Data → encrypt with secret key → gibberish.
Gibberish → decrypt with the same secret key → original data.
Data
Secret Key (for Caesar - number by which to shift characters)
Encrypt and decrypt both use the same shared key.
Data
HELLO
Encrypt key
+3
Gibberish
KHOOR
Decrypt key
-3
Original Data
HELLO
Problem - how to share the key with someone?
Meeting in person is not convenient, and sending it is unsafe.
Asymmetric encryption demo
Generate two linked keys and select one of them to be private, and the other to be public.
Linked means you cannot guess one key knowing the other, but anything encrypted with one key can be decrypted with the other.
Data → encrypt with private key → gibberish.
Gibberish → decrypt with the matching public key → original data.
Private Key
Valid secp256k1 private key.
Public Key
Uncompressed format: 04 + X (32 bytes) + Y (32 bytes).
Data
Data
HELLO
Encrypt key
private key (1)
Gibberish
21507 14985 15309 15309 18730
Decrypt key
public key (0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8)
Original Data
HELLO
Me
Private key (I keep it secret from everyone)
1
Public key (shared on email, documents, key server etc.)
0479be667ef9dcbbac55...47d08ffb10d4b8
<-------- We share public keys -------->
Other person
Private key
***************** (their secret)
Public key
0457e66226392a1aa161...ed92121ef6a69e
1) Me encrypt with other person public key
Only they know their private key, so only they can decrypt and read the message.
Data
Me
HELLO
other's public key
0457...a69e
Gibberish
Network / transit
27d6ea8ea1
other's private key
********
Decrypted
Other person - reads the message
HELLO
2) Me encrypt with my private key
Everyone knows my public key, so anyone can decrypt and read the message.
Because only I know my private key - only I can encrypt in such a way that it is decrypted with my public key, so everyone knows that I was the one who sent the message.
Data
Me
HELLO
my private key
1...1
Gibberish
Network / transit
25c134c2f9
my public key
0479...d4b8
Decrypted
Other person - knows message is from me
HELLO
3) Both: Me encrypt with my private key, then encrypt with other person public key
Other person decrypts twice in reverse order to recover the original data.
Because I used my private key - the other person can verify the message came from me.
Because I used the other person's public key - only they can decrypt and read the message.
Data
Me
HELLO
my private key
1...1
gibberish (signed payload)
Me
25c134c2f9
other's public key
0457...a69e
Outer gibberish
Network / transit
5da6c5f3dde1883c4874
other's private key
********
Decrypted signed payload
Other person
25c134c2f9
my public key
0479...d4b8
Final decrypted
Other person
HELLO
Math behind key pairs
Why and how key pairs actually work and encrypt or decrypt data?
Explore the math behind key pairs on a dedicated page:
Signed Transaction
A signed transaction message includes amount, from public key, and to public key.
The sender signs this message with their private key.
From Me
My private key
Valid sender private key.
My public key
To Other Person
Their public key
Message
| $ | From: | -> |
Instead of names - public keys of people.
Message Signature
(not signed yet)
Message Signature Decrypted
(verify to decrypt signature)
Signed Blockchain
A signed block stores token transfers where sender and recipient are public keys.
Each transaction contains four fields:
- amount: how much value is being transferred
- from: sender public key
- to: recipient public key
- sig: sender signature over transaction data
Balance = total received - total sent.
Identity is represented by public keys instead of names.
Peer A
Tip hash
Reference chain
000007d4949a00392b336882262354d1ff86cbc172d8f7594effc9ac1cc49cee
Balances
Peer B
Tip hash
Synced with Peer A
000007d4949a00392b336882262354d1ff86cbc172d8f7594effc9ac1cc49cee
Balances
Peer C
Tip hash
Different chain
00000323bb3e6ac68844f498cde36adbc0ecf503e8fee833d7cad64f5b62b45e
Balances
Peer A
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
Prev:
Hash:
Mined with prefix 0000.
Peer B
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
Prev:
Hash:
Mined with prefix 0000.
Peer C
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
Prev:
Hash:
Mined with prefix 0000.
Block:
Nonce:
Coinbase:
| $ | -> |
Coinbase mints new tokens for the miner and is not debited from another wallet.
Tx:
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
| $ | From: | -> | ||||
| Sig: | ||||||
Prev:
Hash:
Mined with prefix 0000.