Skip to content

Commit

Permalink
add checkpoints
Browse files Browse the repository at this point in the history
help KGW timewarp attack
  • Loading branch information
labuser committed Mar 31, 2014
1 parent ca74f31 commit 0c3e5f2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ namespace Checkpoints
( 80, uint256("0x95746e7a94c06551f218d2ba2bb73adeeda7b21956c64a3d8bd283b75ae6f579") )
( 100, uint256("0x369b92144ce318374dc39363fefabcd99852eaa83ef74504a276da5ebd76bb3f") )
( 120, uint256("0xbd9f08c7aa7540d9226888df85b1b38ef0b5066d5f4579647e9fc6144e1894e5") )
( 1000, uint256("0xbd5a1aa9de103fbcb83e213fe9d99b767ae3cf8486c5ee57868258dfa8b60148") )
( 2000, uint256("0x1b40f18aed39afad18b0fd59027d837bbdd19c8e213e68899651c10a7ec30598") )
( 3000, uint256("0x37d9e5d4411156930ce637073177d4703e8dea14dc89e656999a238cfbdf12be") )
( 4000, uint256("0x4ad2c3655159c450fbebe3f2bdae1bc5fef58a7b5f169e0b19a00f1048fada9c") )
( 4554, uint256("0x5c43372d0058dd8f77ef90d234c0b556be7a9524bef4a644a90edef53e9f5a18") )
;

static const CCheckpointData data = {
Expand Down
12 changes: 12 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2256,6 +2256,18 @@ bool CBlock::AcceptBlock(CValidationState &state, CDiskBlockPos *dbp)
if (GetBlockTime() <= pindexPrev->GetMedianTimePast())
return state.Invalid(error("AcceptBlock() : block's timestamp is too early"));


// Prevent blocks from too far in the future
if (GetBlockTime() > GetAdjustedTime() + 15 * 60) {
return error("AcceptBlock() : block's timestamp too far in the future");
}

// Check timestamp is not too far in the past
if (GetBlockTime() <= pindexPrev->GetBlockTime() - 15 * 60) {
return error("AcceptBlock() : block's timestamp is too early compare to last block");
}


// Check that all transactions are finalized
BOOST_FOREACH(const CTransaction& tx, vtx)
if (!tx.IsFinal(nHeight, GetBlockTime()))
Expand Down
2 changes: 1 addition & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ void AddTimeData(const CNetAddr& ip, int64 nTime)
int64 nMedian = vTimeOffsets.median();
std::vector<int64> vSorted = vTimeOffsets.sorted();
// Only let other nodes change our time by so much
if (abs64(nMedian) < 35 * 60) // PlanetDollar: changed maximum adjust to 35 mins to avoid letting peers change our time too much in case of an attack.
if (abs64(nMedian) < 14 * 60) // PlanetDollar: changed maximum adjust to 35 mins to avoid letting peers change our time too much in case of an attack.
{
nTimeOffset = nMedian;
}
Expand Down

0 comments on commit 0c3e5f2

Please sign in to comment.