Bitcoin Mechanics & Optimizations
- crypto hash functions
BTC database
dissected the block
Digital signature
keys
to ensure trust in communication
standardized randomness
- data input > fixedsize output of enciphered text: hash value
- value is psedurandom
- value used to verfiy user
- data info affects hash value
- output = image, input= preimagee
Properties (math fingerprints)
second preimage resistance
- difficult for different input to product same output
- if x' =/= x, h(x)=/=h(x')
- ie not possible to find someone with same finger print as you
Collision resistance
- difficult to find two seperate inputs = same output
- if x=/=y, h(y)=/=h(x)
ie not possible to find two people with same finger print
Preimage resistance
- difficult to derive input from output
ie. not possible to know person from fingerprint
Avalanche effect
- small input change > large output change (pseudorandom)
- not possible to predict
SHA-256^2 /d(Secure hash algorithm)
- used by bitcoin (sha256 twice)
- 2^64
- 1st on original image, 2nd on output of first
- input : 2^64 or less
- output: 256 bit fixed size
click to edit
Components of the block
Block size
transaction counter
Block header
click to edit
can check blockchain explorer
merkle root (summary of transactions)
Nonce (proof of work)
Prevblock hash (prove the chain)
Merkle tree
- binary tree (at most two children per node)
- transactions are summaried and hashed
- two hashed outputs are rehashed
- the two hashes left are hashed to derive the merkle root
Proof of inclusion
- one piece of info from each depth is required to derive the root
tamper evident
if merkle root changed
- blockheader change
- next block prev blockheader change
(prevblockhash= h(prevblockheader)
Partial preimage hash puzzle
parameterizable (difficulty can be adjusted)
easily verifirable
Computationally difficult
Mining
like throwing darts are target
look for hash below alg decided target : h(blockheader) < targetin
target
timestamp
version
Block difficulty
- leading number of zeros on the block hash
- more zeros > more difficult
- adjusted by the global hash rate
- maintain 10 mins
- difficulty should be
- two- weeks/time to mine prev 2016 blocks
- two week = 10
- 1 week = 20
- 4 weeks = 5
Coinbase transactions
- how miners get bitcoin
- has a seperate nonce field
- always the first tx in the merkle tree
- each guess loop. try coinbase nonce first then inner loop for header nonce
ECDSA (Elliptic curve digital signature algorithm)
priv and pub key generation algo
Keys and address
- k > K : elliptic curve multiplication
- K > A: hasing functions
- k= private key
- K= public key
-A = bitcoin address
- user generate private key n
- public key via ECDSA > private key nP
- double hash = RIPEMD160(SHA256(nP)) > address