From b1b31d15cc720a1c186431b21ecc9d1a9062bcb6 Mon Sep 17 00:00:00 2001 From: coblee Date: Sun, 9 Oct 2011 20:46:21 -1000 Subject: [PATCH] Litecoin: Fix zeitgeist2 attack thanks to Lolcust and ArtForz. 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. --- src/pow.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index bdcfa852f..73579b1cd 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -41,9 +41,15 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead 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 = Params().Interval()-1; + if ((pindexLast->nHeight+1) != Params().Interval()) + blockstogoback = Params().Interval(); + // 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);