Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Proof of work

Proof-of-work (PoW) is a cryptographic puzzle system where miners expend computational effort (hashing) to find a nonce making a block header hash below a target; PoW secures blockchains by making block creation costly and probabilistic.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Proof-of-work (PoW) is the core security mechanism used by many blockchains (for example Bitcoin) to decide which block becomes canonical. An engineer uses PoW to design or analyse miner behaviour, calculate expected mining times, set or explain difficulty adjustments, and reason about attack probabilities such as double-spend and 51% attacks.

Key ideas

Start from first principles and simple definitions.

  • Proof-of-work (PoW): a protocol where a prover must solve a computational puzzle (perform expensive work) and a verifier can cheaply check the solution. In blockchains, the prover is a miner and the verifier is the whole network.

  • Cryptographic hash function: a deterministic function H that maps inputs of arbitrary length to a fixed-size bit string. Properties used in PoW: pre-image resistance (hard to find input for a given output) and pseudorandomness (output looks random). For many blockchains H is SHA-256 or similar.

  • Nonce: an extra field (a number) the miner varies to change the hash of the block header. The miner tries many nonces until a hash satisfying the target is found.

  • Target: a numeric threshold T. A candidate block header hash h is valid if h < T (treating hash as an integer). Lower T means harder puzzle. Note: Some protocols (e.g., Bitcoin) use h ≤ T; our formulas assume h < T. For h ≤ T, the exact success probability is (T + 1)/2^n, which differs negligibly for large n.

  • Hash output size: if H outputs n bits (e.g. n = 256 for SHA-256), then possible hash values are uniformly distributed in [0, 2^n - 1] under the random-oracle assumption.

  • Success probability per hash: If hashes are uniform, the probability p that one random hash is < T is p = T / 2^n. Independence between attempts is assumed when analyzing repeated trials, not for this single-trial probability.

  • Hash rate: the miner’s or network’s hashing power H (hashes per second, unit hashes/s). The expected success rate (blocks found per second) is H·p.

  • Expected number of hashes (work) to find solution: geometric distribution with success probability p implies expected trials = 1/p. Expected time = (1/p) / H.

  • Difficulty: a convenience number inversely proportional to the target. One way to define it for n-bit hash output is D := 2^n / T, so higher D means harder. Some blockchains (Bitcoin) define difficulty relative to a fixed reference target; the idea is the same: difficulty ∝ 1/T.

  • Network objective and difficulty adjustment: blockchains typically choose a target (hence difficulty) so the network, with its total hash rate H_net, finds blocks at a target mean interval (for Bitcoin ~10 minutes). A difficulty adjustment periodically changes T so expected time per block equals the protocol target. The adjustment assumes miners’ hash rate is approximately constant during the adjustment window.

  • Security model and assumptions: the PoW security argument assumes (1) hash outputs are unpredictable and behave like random samples, (2) no miner controls >>50% of total hash rate (if some miner has majority, they can out-mine the honest chain), and (3) network propagation times are short relative to block interval so forks are rare.

  • Attacker model: an attacker with fraction q of total hash power tries to build an alternative chain. If q < 0.5, the probability of catching up declines exponentially with the number z of confirmations (blocks deep). A common approximation used in exam answers: attack success probability ≈ (q/(1 - q))^z (this is an approximation; the exact Poisson-based formula is in Nakamoto’s paper). State clearly when you use approximations.

Diagrams to draw for an exam answer:

  • Draw a timeline showing honest chain blocks at times t0, t1, … and attacker private chain diverging at time t0; label depth z (number of confirmations).
  • Draw block header breakdown to label fields: version, previous-block-hash, merkle-root, timestamp, target (or difficulty bits), nonce. Indicate that the hash is computed over the whole header and compared to target.

Formulas

Each formula on its own line. After each line: symbols, units and when it applies.

p = T / 2^n

  • p: probability a single hash is valid (dimensionless). T: integer target (0 < T ≤ 2^n - 1) (dimensionless). n: output bits of hash function (unit: bits). Applies when hash outputs are uniformly random across 0..2^n-1. Exact for condition h < T; for h ≤ T, use (T + 1)/2^n.

E[trials] = 1 / p

  • E[trials]: expected number of hash attempts to find valid nonce (dimensionless). p as above. Holds for geometric distribution of independent trials.

E[time] = (1 / p) / H

  • E[time]: expected wall-clock time to find a valid block (seconds). H: hash rate (hashes per second, hashes/s). Use when H is steady and attempts are independent.

rate = H * p

  • rate: expected valid blocks per second produced by entity with hash rate H.

P(success within t) = 1 - exp(-H * p * t)

  • probability that a miner with hash rate H finds at least one valid block in time t (seconds). This is the exact Poisson-process result with rate λ = H·p; equivalently, for discrete attempts, 1 - (1 - p)^{H·t} ≈ 1 - exp(-H·p·t).

D = 2^n / T (definition used here)

  • D: difficulty (dimensionless), n and T as above. Holds if difficulty is defined as inverse-proportional to target.

Approximate bound used in proofs (for q < 0.5): P( attacker catches up from z blocks behind ) ≲ (q / (1 - q))^z

  • q: attacker fraction of total hash power (dimensionless). z: number of confirmations the honest chain is ahead (integer). This is an approximation showing exponential decrease in success probability with z.

Worked examples

  1. Small-bit demonstration (algorithm trace). Purpose: make the idea concrete.
  • Setup: imagine a toy hash that outputs 8-bit integers (n = 8). Target requires hash < 16 (i.e., top 4 bits zero). So T = 16, p = 16 / 256 = 1/16 = 0.0625.
  • Miner enumerates nonce values 0..7 and computes hash(header || nonce) (show made-up hash outputs): 0 -> 0xAB (171) not < 16 1 -> 0x0F (15) valid because 15 < 16
  • Result: miner finds nonce = 1 as proof-of-work after 2 attempts. Verifier recomputes H(header||1) = 15 and checks 15 < 16: accepts.
  • This trace is what exam answers should show: list nonces tried, hash results, and stop when condition satisfied.
  1. Numerical expected time with leading-zero requirement (clear arithmetic and units).
  • Problem: Miner has H = 1 MH/s = 1·10^6 hashes/s. The PoW requires k = 20 leading zero bits in an n = 32-bit hash. Probability per hash p = 2^{-20} ≈ 9.53674316·10^-7.
  • Formula: E[time] = (1 / p) / H.
  • Compute: 1 / p = 2^{20} = 1,048,576 trials. E[time] = 1,048,576 / (1·10^6 s^-1) = 1.048576 s.
  • Answer: Expected time ≈ 1.0486 seconds.
  1. Network difficulty setting (theory + computation).
  • Problem: A protocol target is mean block interval τ = 600 s. Network hash rate is H_net = 1·10^18 hashes/s. What should p be and what is expected number of hashes per block?
  • p = 1 / (H_net * τ) = 1 / (1·10^18 * 600) = 1.6666667·10^-21.
  • Expected hashes per block = 1 / p = H_net * τ = 6·10^20 hashes.
  • Answer: Each block requires on average 6·10^20 hashes at current network power. (This is a conceptual calculation; real blockchains use more precise bit-size and difficulty encodings.)

Common mistakes

  • Applying the simple approximation p = T/2^n but then plugging in decimal difficulty definitions from Bitcoin without conversion—Bitcoin's difficulty uses a specific reference target; be explicit about which definition you use.
  • Using the approximation (q/(1-q))^z as exact rather than an approximation; exam answers must say "approximate" or provide the exact Poisson-based expression if asked.
  • Not stating assumptions (random-oracle behavior of hash, independent trials, steady hash rate) before deriving expected values.

For your exam

Kinds of questions:

  • Definitions: define PoW, nonce, target, difficulty, hash rate.
  • Short notes: explain how PoW provides security and how difficulty adjustment works.
  • Derivations: derive expected time to find a block for a given hash rate and target; derive p = T/2^n and E[time] formula.
  • Numericals: compute expected time, given H and either target, difficulty or required leading-zero bits.
  • Algorithm traces / small examples: show nonce trials on toy hash and explain verification.
  • Theory/long questions: explain how PoW defends against double-spend and 51% attacks; give probability estimates for attacker success.

What a full-marks answer includes:

  • Clear definitions with bolded terms (as above).
  • Explicit assumptions (randomness of hash, independence, steady H, attacker model q).
  • Correct formula derivations from p = T/2^n to E[trials] and E[time], carrying units.
  • For probability or security questions, state whether approximations are being used; draw the fork timeline and explain confirmations z.

Quick check

  1. If hash output is n = 32 bits and target T = 2^20, what is p?
  2. A miner with hash rate H = 10^9 hashes/s faces p = 10^-9. What is expected time to find a block?
  3. Does increasing difficulty D (as defined D = 2^n / T) make mining easier or harder?

Answers: 1) p = 2^20 / 2^32 = 2^-12 = 1/4096 ≈ 2.4414·10^-4. 2) E[time] = (1/p)/H = (1/10^-9)/10^9 = 10^9 / 10^9 = 1 s. 3) Increasing D makes mining harder (difficulty ∝ 1/target).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?