Bitcoin Forum
February 07, 2026, 09:59:25 PM *
News: Community awards 2025
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Satoshi's target recalculation off-by-one bug?  (Read 117 times)
nullama (OP)
Legendary
*
Offline Offline

Activity: 1554
Merit: 1021



View Profile
January 27, 2026, 11:09:04 AM
 #1

I was reading Karpathy's implementation of Bitcoin from scratch in Python, and he commented:

            # recalculate the target at every epoch (2016 blocks), approx 2 week period
            # note that Satoshi had an off-by-one bug in this calculation because we are
            # looking at timestamp difference between first and last block in an epoch,
            # so these are only 2015 blocks apart instead of 2016 blocks apart ¯\_(ツ)_/¯

I think he is actually correct. That number should be 2015, and not 2016, right?

Or is there something I'm not considering?
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4634
Merit: 10374



View Profile WWW
January 27, 2026, 04:47:01 PM
Merited by vapourminer (1), ABCbits (1)
 #2

It was probably actually an off by one bug, OTOH, dividing by one off there is the minimum variance unbiased estimator for that process (it's scaled by (n-1)/n), so in that sense it's the correct measure (perhaps accidentally).
j2002ba2
Full Member
***
Online Online

Activity: 216
Merit: 473


View Profile
January 27, 2026, 07:36:39 PM
 #3

I think it's not off by one bug. It seems, that the genesis block took several days to mine - mined with much higher difficulty - so it was omitted from the difficulty calculation.
BattleDog
Full Member
***
Offline Offline

Activity: 168
Merit: 176



View Profile WWW
January 29, 2026, 06:19:15 PM
 #4

Gotta love that we're still reverse-engineering decade-old code trying to figure out if the creator was playing 4D chess or just shipping fast and breaking things before that was a Silicon Valley mantra.

Karpathy's Python implementation is solid homework if anyone wants to actually trace through this themselves instead of armchair theorizing.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!