Permalink
Browse files

Fix zeitgeist2 attack thanks to Lolcust and ArtForz.

  • Loading branch information...
1 parent 1a4faf7 commit b1be77210970a6ceb3680412cc3d2f0dd4ca8fb9 @coblee committed Oct 10, 2011
Showing with 7 additions and 1 deletion.
  1. +7 −1 src/main.cpp
View
@@ -661,9 +661,15 @@ unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast)
if ((pindexLast->nHeight+1) % nInterval != 0)
return pindexLast->nBits;
+ // Litecoin: 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);

0 comments on commit b1be772

Please sign in to comment.