Skip to content

Latest commit

 

History

History
57 lines (35 loc) · 5.69 KB

factor-difficulty.md

File metadata and controls

57 lines (35 loc) · 5.69 KB

Difficulty adjustment

FACTOR difficulty is the bit length of the integer to factor. The checkout contains historical retarget algorithms and a deployment-gated ASERT-inspired algorithm in modeled compute space.

Reviewed source: e224c5277, version fields 6.0.43; documentation review December 2, 2026. This is a descriptive engineering reference. The applicable implementation and validated chain state determine active behavior; release publication alone does not prove activation.

Selection and activation

GetNextWorkRequired first honors fPowNoRetargeting (default regtest), then chooses ASERT if DEPLOYMENT_ASERT is active after the parent. Otherwise it selects the time-limited interim DAA or the older interval DAA. deploymentstatus.h distinguishes buried heights, BIP9 state and time-limited active duration.

Mainnet configuration in chainparams.cpp:

Parameter Value
Target spacing 1,800 seconds
Original period 672 blocks; target timespan 1,209,600 seconds
Hard-difficulty removal Buried height 168,672
Interim DAA Bit 25; 42-block voting period, threshold 40; at most 1,344 active blocks
Interim signaling window Median-time start 2026-01-01, timeout 2026-07-20
ASERT Bit 24; 672-block voting period, threshold 639
ASERT signaling window Median-time start 2026-03-01, timeout 2027-03-01
ASERT half-life and bounds 172,800 seconds; even difficulty 32 through 1,022

These are configuration facts, not observed mainnet activation dates. Check getblockchaininfo on a synchronized node of a known revision; this HEAD adds ASERT to its reported deployments after v6.0.43. Testnet uses a 300-second target and 3,600-second half-life; testnet/signet configure ASERT always active. Regtest parameters and test overrides must not be exported as mainnet rules.

Interval algorithms

Original CalculateDifficultyDelta changes by -1 if actual/target timespan exceeds 1.0333f, +1 if below 0.90f, otherwise zero. After hard-difficulty removal it aims for an even result: slow periods move down by 2 from even or 1 from odd difficulty, with 2 more subtracted above 2.0f; fast periods move up by 2 from even or 1 from odd, with 2 more added below 0.5f. A neutral odd value is lowered by 1.

Interim adjustment uses a 42-block boundary and (42-1)*targetSpacing for elapsed-time comparison. It first subtracts 1 for odd input, then adds +6/+4/+2 below 0.5f/0.6667f/0.9f, or -6/-4/-2 above 2.0f/1.5f/1.0333f; the comparisons are strict and ordered. The source float constants and conversion semantics govern exact boundary behavior. These paths do not acquire ASERT bounds merely because those bounds exist in the same parameter structure.

Before ASERT, configured test networks may allow a minimum-difficulty block after twice target spacing; the ASERT wrapper intentionally does not apply that escape hatch.

ASERT model and arithmetic

asert_table.h contains 511 committed Q32.32 values, indexed by i=d/2-1 for even d=2..1022. Its documented model is:

log2(C(d)) = 0.0301*log2(3.8)*d + 2*log2(d)
log2(C_target) = log2(C(anchor)) + (h*T-t)/H

Here h and t are the parent height and timestamp differences from the anchor itself, T is spacing and H half-life. There is no extra +1 or anchor-parent time in this implementation. At exact schedule the modeled cost stays at the anchor cost; one half-life behind subtracts 1 from log2 cost, halving modeled compute before quantization, rather than halving nBits.

The anchor is the last block of LOCKED_IN for real BIP9 activation; always-active networks use block 1. The wrapper floors an odd anchor to even and clamps it to the allowed range. It caches an anchor only while it remains on the examined ancestry.

CalculateFACTORASERT computes signed time_error=h*T-t, splits division into integer and remainder terms, scales by 2^32 through unsigned shifts, and divides the remainder with C++ truncation toward zero. It adds that fixed-point exponent to the committed anchor table value. Binary search chooses the nearest table entry, ties toward the lower/easier difficulty. It clamps low; if the target is strictly greater than the maximum table entry, the wrapper returns nBits=1024, which proof checking rejects. This protective circuit breaker deliberately halts acceptance under those conditions; recovery would require an agreed protocol change. Equality with the maximum is allowed.

Reproducibility

Use the committed table and exact integer arithmetic rather than regenerating it with platform libm. The checked-in table generator uses 60-digit Decimal arithmetic and round-half-even conversion to Q32.32. Its modern Python features require a newer interpreter than the inherited general test minimum. ASERT unit tests cover steady state, half-life behavior, exhaustive sweeps, clamps and large intervals. PoW tests cover chain/anchor integration; versionbits tests cover deployments; interim functional tests cover activation, adjustment and reversion. Test-vector utilities are supporting evidence, not activation evidence.

Further reading

Consensus knowledge · Consensus reference

Documentation index · Release history · Repository knowledge index