Cryptographic Hash Functions
Cryptographic hash function:
- Preimage resistance
- Given H(X), it is computationally difficult to determine X
- Second preimage resistance
- Given X, it is computationally difficult to find some value X' such that H(X) == H(X')
- Collision resistance
- It is computationally difficult to find X and Y such that H(X) == H(Y)
Avalanche effect: a small change in the input produces a pseudorandom change in the output
- Often a significant difference from the first output
- Prevents "hot or cold" game with inputs to produce or predict outputs
SHA-256: A cryptographic hash function designed by the NSA
Bitcoin uses SHA-256^2 ("SHA-256 squared"), meaning that H(x) actually means SHA256(SHA256(x))
A Tamper-Evident Database
BLOCK
BLOCK HEADER (The metadata necessary for understanding the components of the block) |
BLOCK SIZE (How large the block is) |
TRANSACTION COUNTER (How many transactions are within the block) |
TRANSACTIONS (The actual transaction data) |
BLOCK HEADER
PREV BLOCK HASH (The chaining) |
MERCKLE ROOT (A summary of transactions) |
NONCE (The proof-of-work) |
TIMESTAMP | TARGET | VERSION |
The block header is simply the hash of all these filds concatenated.
Bitcoin's partial preimage hash puzzle: A problem with a requirement to find a nonce that satisfies the following inequality:
H(blockHeader) < target
- Used to implement Proof-of-Work in Bitcoin (and every other PoW cryptocurrency)
Hash puzzles need to be:
- Computationally difficult.
- Parameterizable.
- Easily verifiable.
- Mining is like throwing darts at a target whild blindfolded:
- Equal likelihood of hitting any part of the target
- Faster throwers => more hits / second
- Miners look for a hash below an algorithmically decided target
H(blockHeader) < target
Difficulty: A representation of the expected number of computations required to find a block
- Implemented as requirement of leading number of 0s
- Adjusts with global hashrate
- difficulty *= two_weeks / time_to_mine_prev_2016_blocks
- Technically every 2015 blocks
(비트코인 네트워크에서는 새로운 블록이 10분마다 발생하도록 2016 블록마다 블록을 풀어내는 난이도를 조절함. 10분 * 2016 = 2주)
이 글은 edX의 Bitcoin and Cryptocurrencies 강의 자료를 참고하여 정리한 글입니다.