Skip to content

Commit

Permalink
Fix Art Forz's time-traveller attack, where a 51% attack can change d…
Browse files Browse the repository at this point in the history
…ifficulty at will.
  • Loading branch information
Mark Friedenbach committed Dec 31, 2013
1 parent e57bd72 commit 013a0d9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,9 +1637,16 @@ unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast, const CBl
else if ( dAdjustmentFactor < kLimiterDown )
dAdjustmentFactor = kLimiterDown;
} else {
// This fixes an issue where a 51% attack can change difficulty at will.
// Go back the full period unless it's the first retarget after genesis.
// Code courtesy of Art Forz
int blockstogoback = nInterval-1;
if ((pindexLast->nHeight+1) != nInterval)
blockstogoback = nInterval;

// Go back by what we want to be 14 days worth of blocks
const CBlockIndex* pindexFirst = pindexLast;
for (int i = 0; pindexFirst && i < nInterval-1; i++)
for (int i = 0; pindexFirst && i < blockstogoback; i++)
pindexFirst = pindexFirst->pprev;
assert(pindexFirst);

Expand Down

0 comments on commit 013a0d9

Please sign in to comment.