From b1be77210970a6ceb3680412cc3d2f0dd4ca8fb9 Mon Sep 17 00:00:00 2001 From: coblee Date: Sun, 9 Oct 2011 23:46:21 -0700 Subject: [PATCH] Fix zeitgeist2 attack thanks to Lolcust and ArtForz. --- src/main.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 5b7c6168..5546fc0d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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);