Skip to content

Commit

Permalink
Hardfork: Fix Art Forz's time-traveller attack, where a 51% attack ca…
Browse files Browse the repository at this point in the history
…n change difficulty at will.
  • Loading branch information
Mark Friedenbach authored and jtimon committed Feb 21, 2015
1 parent e43f25c commit beb2fa5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
return pindexLast->nBits;
}

// 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 < Params().Interval()-1; i++)
for (int i = 0; pindexFirst && i < blockstogoback; i++)
pindexFirst = pindexFirst->pprev;
assert(pindexFirst);

Expand Down

4 comments on commit beb2fa5

@peterzion45
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent call! Weekend away from the charts for me, enjoying a great week of returns. Thanks a lot for the calls and the work you do Chief. 👌

— Leo Halloway (@leohallowaycryp) November 26, 2022
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

@peterzion45
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4db58cd513c8a42284c0d7b7cd40b4f06d45221005df3188e880a90ee9874e9b

@freicoin
Copy link
Collaborator

@freicoin freicoin commented on beb2fa5 Nov 26, 2022 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterzion45
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0a2f6ffff49b1e633b34526597e03da8871c7ff95f87f0c9992e8fa5308c1a33

Please sign in to comment.