Skip to content

Commit

Permalink
Merge pull request #11 from sxcer/master
Browse files Browse the repository at this point in the history
Fix KGW Timewarp vulnerability
  • Loading branch information
sxcer committed May 5, 2014
2 parents 0dea2e1 + cb616c1 commit 4b29d28
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sexcoin-qt.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = app
TARGET =
VERSION = 0.6.4.5
VERSION = 0.6.4.6
INCLUDEPATH += src src/json src/qt
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE USE_IPV6 __NO_SYSTEM_INCLUDES
CONFIG += no_include_pwd
Expand Down
2 changes: 1 addition & 1 deletion sexcoin-qt.pro.unix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = app
TARGET =
VERSION = 0.6.4.5
VERSION = 0.6.4.6
INCLUDEPATH += src src/json src/qt
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE USE_IPV6
CONFIG += no_include_pwd
Expand Down
2 changes: 1 addition & 1 deletion sexcoin-qt.pro.windows
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEMPLATE = app
TARGET =
VERSION = 0.6.4.5
VERSION = 0.6.4.6
INCLUDEPATH += src src/json src/qt
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE USE_IPV6
CONFIG += no_include_pwd
Expand Down
15 changes: 13 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin developers
// Copyright (c) 2012-2013 Sexcoin Developers.
// Copyright (c) 2013 Megacoin Developers. (KGW Algo)
// Copyright (c) 2014 Auroracoin Developers. (KGW Time Warp Fix)
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand Down Expand Up @@ -952,6 +954,7 @@ unsigned int static KimotoGravityWell(const CBlockIndex* pindexLast, const CBloc

if (BlockLastSolved == NULL || BlockLastSolved->nHeight == 0 || (uint64)BlockLastSolved->nHeight < PastBlocksMin) { return bnProofOfWorkLimit.GetCompact(); }

int64 LatestBlockTime = BlockLastSolved->GetBlockTime();
for (unsigned int i = 1; BlockReading && BlockReading->nHeight > 0; i++) {
if (PastBlocksMax > 0 && i > PastBlocksMax) { break; }
PastBlocksMass++;
Expand All @@ -960,10 +963,18 @@ unsigned int static KimotoGravityWell(const CBlockIndex* pindexLast, const CBloc
else { PastDifficultyAverage = ((CBigNum().SetCompact(BlockReading->nBits) - PastDifficultyAveragePrev) / i) + PastDifficultyAveragePrev; }
PastDifficultyAveragePrev = PastDifficultyAverage;

PastRateActualSeconds = BlockLastSolved->GetBlockTime() - BlockReading->GetBlockTime();
if (LatestBlockTime < BlockReading->GetBlockTime()) {
if (BlockReading->nHeight > FIX_KGW_TIMEWARP_HEIGHT)
LatestBlockTime = BlockReading->GetBlockTime();
}
PastRateActualSeconds = LatestBlockTime - BlockReading->GetBlockTime();
PastRateTargetSeconds = TargetBlocksSpacingSeconds * PastBlocksMass;
PastRateAdjustmentRatio = double(1);
if (PastRateActualSeconds < 0) { PastRateActualSeconds = 0; }
if (BlockReading->nHeight > FIX_KGW_TIMEWARP_HEIGHT) {
if (PastRateActualSeconds < 1) { PastRateActualSeconds = 1; }
} else {
if (PastRateActualSeconds < 0) { PastRateActualSeconds = 0; }
}
if (PastRateActualSeconds != 0 && PastRateTargetSeconds != 0) {
PastRateAdjustmentRatio = double(PastRateTargetSeconds) / double(PastRateActualSeconds);
}
Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static const unsigned int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100;
static const int MAGIC_NUM_SWITCH_HEIGHT = 680000;
static const int FIX_RETARGET_HEIGHT = 155000; // Don't fuck with this.
static const int FIX_SECOND_RETARGET_HEIGHT = 572000;
static const int FIX_KGW_TIMEWARP_HEIGHT = 643808; // Projected to be Fri May 4 2014 12PM GMT
static const int64 MIN_TX_FEE = 10000000;
static const int64 MIN_RELAY_TX_FEE = MIN_TX_FEE;
static const int64 MAX_MONEY = 250000000 * COIN; // Sexcoin: maximum of 250000000 coins
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 6
#define CLIENT_VERSION_REVISION 4
#define CLIENT_VERSION_BUILD 5
#define CLIENT_VERSION_BUILD 6

static const int CLIENT_VERSION =
1000000 * CLIENT_VERSION_MAJOR
Expand Down

0 comments on commit 4b29d28

Please sign in to comment.