Difficulty Algorithm at Fork-choice Rules

Tumpak na walk-through sa kasaysayan ng difficulty adjustment ng Parallax — BTC-style DAA mula sa genesis, ang ASERT upgrade sa block 17,560 (PIP-0002), at ang Nakamoto fork-choice rule based sa cumulative work.

Consensus Parameters
ParameterSymbolValueNotes
Target block interval
τ
600 s
Bitcoin-like target
Future time drift bound
300 s
5 minutes
MTP sample size
11 blocks
Median ng huling 11 timestamps
Difficulty algorithm history
BTC-style DAA → ASERT
BTC-style 2016-block windows mula genesis–17,559; ASERT (aserti3-2d) para sa blocks ≥ 17,560 (PIP-0002).
Overview
Tina-target ng Parallax ang 10-minutong blocks gamit ang XHash Proof of Work at per-block ASERT difficulty algorithm, pagkatapos ng initial BTC-style DAA phase.
  • Mula genesis hanggang block 17,559, gumamit ang Parallax ng Bitcoin-style 2016-block difficulty adjustment window (BTC-style DAA).
  • Inactivate ng PIP-0002 (Migration mula sa BTC-Style Difficulty Adjustment Algorithm papunta sa ASERT) ang ASERT sa block 17,560.
  • Ang ASERT (aserti3-2d, na ginagamit ng Bitcoin Cash) ay nag-a-adjust ng difficulty kada block relative sa fixed anchor, na nag-co-converge nang maayos papunta sa 600 s target sa ilalim ng hashrate shocks.
  • Pinapangalagaan ng Median-Time-Past (MTP, median ng huling 11) ang timestamp validity; tinatanggihan ng nodes ang headers na higit sa +300s sa hinaharap at vine-verify ang PoW gamit ang target = ⌊(2^256−1)/D⌋.
Target ↔ Difficulty
Work threshold mapping na ginagamit ng XHash verification (common sa parehong BTC-DAA at ASERT eras).
  • Hayaan ang TWO256M1 = 2^256 − 1. Valid ang header kung XHash(header) ≤ target, kung saan target = ⌊TWO256M1 / D⌋.
  • Mas mataas na difficulty D ⇒ mas maliit na target ⇒ mas mahirap na block.
  • Dapat katumbas ng Header.MixDigest ang computed digest mula sa hashimoto (light/full paths).
  • Dapat strictly positive ang difficulty; invalid ang zero/negative.
Target calculation (conceptual)
pseudocode
// Given difficulty D (big integer)
TWO256M1 = (1n << 256n) - 1n
target   = TWO256M1 / D
valid    = BigIntFromBytes(result) <= target
Difficulty Adjustment: BTC-Style DAA → ASERT
Historical 2016-block windows, modern per-block ASERT relative sa anchor.
  • Genesis → block 17,559: nagpapatupad ang CalcNakamotoDifficulty() ng Bitcoin-style 2016-block window gamit ang epoch anchors.
  • Block 17,560 at higit pa: nagpapatupad ang CalcAsertDifficulty() ng aserti3-2d gamit ang fixed anchor {anchorHeight, anchorParentTime, anchorTarget}.
  • Gumagamit ang ASERT ng height offset Δh at elapsed time Δt relative sa anchor para itulak ang difficulty papunta sa 600 s target na may 2-day half-life.
  • Pinapanatili ng historical blocks ang kanilang orihinal na BTC-style DAA difficulty at vine-validate pa rin sa ilalim ng mga rule na iyon; entirely ASERT-based ang forward-looking adjustment.
Height-dependent difficulty selection (conceptual)
pseudocode
// Difficulty selection by era
CalcDifficulty(config, anchor, parent, header):
  if height(header) < 17560:
    // BTC-style DAA: 2016-block window with epoch anchors
    return CalcNakamotoDifficulty(config, parent)
  else:
    // ASERT: per-block retarget relative to fixed anchor
    return CalcAsertDifficulty(config, anchor, parent, header)

// ASERT core idea (fixed-point, aserti3-2d)
CalcAsertDifficulty(config, anchor, parent, header):
  Δh = height(header) - anchor.height
  Δt = header.Time - anchor.parentTime   // seconds
  // τ = 600 s target, T_half = 172800 s (2 days)
  e  = ((Δt - Δh * τ) * RADIX) / T_half  // fixed-point exponent
  target = anchor.target * 2^e           // via cubic approximation in integer math
  target = clamp(target, 1, maxTarget)
  return DifficultyFromTarget(target)
Median-Time-Past (MTP)
Timestamp sanity para sa validity at time-warp resistance.
  • MTP(parent) = median ng huling 11 block timestamps na nagtatapos sa parent.
  • Ang validity ay nangangailangan ng header.Time > MTP(parent) (strict inequality).
  • Future-drift bound: header.Time ≤ now + 300s.
  • Sa ilalim ng ASERT, ang elapsed time relative sa anchor ay pinapatakbo ng timestamps na naka-constrain ng MTP, na pumipigil sa classic na long-range time-warp attacks laban sa difficulty algorithm.
MTP computation
pseudocode
MTP(n):
  ts = timestamps(n, upTo=11) // back from n inclusive
  sort(ts)
  return ts[len(ts)//2]
Fork Choice Rule
Heaviest valid chain by cumulative work, independent sa active difficulty era.
  • Mag-maintain ng ChainWork[tip] = ChainWork[parent] + Work(block).
  • Ang Work(block) ay monotone function ng target/difficulty; anumang consistent definition ay nagbibigay ng equivalent ordering.
  • Piliin ang valid tip na may pinakamalaking ChainWork; pwedeng buwagin ang ties lexicographically sa pamamagitan ng tip hash.
  • Tinatanggal ang invalid headers (time, PoW, BTC-DAA/ASERT rules) bago ang fork choice.
Cumulative work (conceptual)
pseudocode
Work(block):
  target = TWO256M1 / Difficulty(block)
  // Use an approximation that preserves ordering; e.g.,
  return TWO256M1 / (target + 1)

SelectBest(tips):
  return argmax(tips, ChainWork[tip])
Reorgs at Probabilistic Finality
Depth-based assurances sa halip na absolute finality.
  • Pinapababa ng confirmation depth k ang reorg probability nang exponential sa k.
  • Pinipili ng Wallets/UIs ang k by value at risk (e.g., 6-conf defaults para sa high-value).
  • Pwedeng mag-implement ang nodes ng practical guards (e.g., max reorg depth) para maiwasan ang DoS mula sa pathological peers.
  • Ang mas maayos na per-block difficulty response ng ASERT ay nagpapababa sa incentive para sa oscillation-driven o opportunistic na mahabang reorgs kumpara sa large-window BTC-style DAA.
Reorg handling (conceptual)
pseudocode
OnNewTip(candidate):
  if ChainWork[candidate] > ChainWork[currentTip]:
    currentTip = candidate
    ReorgTo(candidate)
Attacks at Mitigations
Mga key vector na relevant sa Parallax difficulty design.
  • Time-warp: Strict MTP enforcement plus per-block feedback ng ASERT (walang long static windows) ang nagpapababa sa classic BTC-style 2016-block na time-warp manipulation.
  • Future timestamp skew: tinatanggihan ang headers na higit sa +300s mula sa local time.
  • MixDigest spoofing: dapat tumugma ang header.MixDigest sa hashimoto output (light/full).
Header validity subset
pseudocode
ValidHeader(h, parent):
  require(len(h.Extra) <= MaximumExtraDataSize)
  require(h.Time <= now() + 300)
  require(h.Time > MTP(parent))
  require(h.Difficulty > 0)
  // difficulty rules depend on height:
  //   < 17560: BTC-style DAA epoch invariants
  //   ≥ 17560: ASERT anchor-based invariants
  // PoW: MixDigest match & XHash(h) <= targetFrom(D)
Pipeline

End-to-end selection flow

Sinusuri ang headers para sa Extra size, time (MTP at future drift), era-specific difficulty rules (BTC-style DAA para sa mga unang block, ASERT para sa height ≥ 17,560), gas limits/EIPs, height increment, at PoW seal. Pinapalawak ng valid blocks ang ChainWork, at ang heaviest tip ang canonical.

1
Validate
2
Check Anchor / Era
3
Compute Difficulty (DAA/ASERT)
4
Accumulate Work
5
Select Heaviest