Bitcoin Core measures each 2,016-block difficulty period from the timestamp of its own first block to that of its last block, which spans 2,015 block intervals rather than 2,016, so consecutive measurement windows do not overlap. This off-by-one is the property the timewarp attack exploits.
Sources and checks
T1Bitcoin Core src/pow.cpp, GetNextWorkRequiredSource code, says this directly
int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1);
GetNextWorkRequired, choice of first block, read 2026-11-20
T1Great Consensus Cleanup Revival (Delving Bitcoin, post 1)Delving Bitcoin, says this directly
The timewarp vulnerability exploits how difficulty adjustment periods don't overlap.
Post 1, timewarp section, published 2024-03-24, read 2026-11-20
T2Bitcoin Optech Newsletter, 24 April 2024Bitcoin Optech, supports part of it
explains the off-by-one error in Bitcoin’s difficulty retargeting calculation
Selected Q&A from Bitcoin Stack Exchange, Where exactly is the off-by-one difficulty bug?, read 2026-11-20
bitcoin/bitcoin at f498a5a671 contains this text in src/pow.cpp, and still does on the default branch.
Run it yourself
git clone https://github.com/bitcoin/bitcoin && git -C bitcoin show f498a5a6718d9157b6afb85412c3462439117702:src/pow.cpp | grep -nF 'int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1);'Checked at block 976,753, 20 Nov 2026, 16:42 UTC: quotes 3/3, code 1/1
History
Nothing is edited silently; every revision keeps what it replaced.
- 20 Nov 2026, 16:42 UTCblock 976,753
Published Revision 1, run 2026-11-20-seed-proof-of-work