aboutsummaryrefslogtreecommitdiff
path: root/src/pow.cpp
diff options
context:
space:
mode:
authorcoblee <[email protected]>2011-10-09 20:46:21 -1000
committerRoss Nicoll <[email protected]>2018-09-19 19:21:49 +0100
commit8279f81b44eaf1a4fc9f2c6a4871d853b5f3fc7e (patch)
treeb6391f84786d3563cbd53ad45a68a2f77dcb2a04 /src/pow.cpp
parentLitecoin: Scrypt n=1024 Pow hash based upon Colin Percival's Tarnsnap (2009) ... (diff)
downloaddiscoin-8279f81b44eaf1a4fc9f2c6a4871d853b5f3fc7e.tar.xz
discoin-8279f81b44eaf1a4fc9f2c6a4871d853b5f3fc7e.zip
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.
Diffstat (limited to 'src/pow.cpp')
-rw-r--r--src/pow.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/pow.cpp b/src/pow.cpp
index 52c826d72..c629ee4a4 100644
--- a/src/pow.cpp
+++ b/src/pow.cpp
@@ -41,8 +41,14 @@ 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.DifficultyAdjustmentInterval()-1;
+ if ((pindexLast->nHeight+1) != params.DifficultyAdjustmentInterval())
+ blockstogoback = params.DifficultyAdjustmentInterval();
+
// Go back by what we want to be 14 days worth of blocks
- int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1);
+ int nHeightFirst = pindexLast->nHeight - blockstogoback;
assert(nHeightFirst >= 0);
const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst);
assert(pindexFirst);