Skip to content

Commit

Permalink
Update 2.0.0.3 Security Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Knöpke committed Sep 23, 2017
1 parent f0783c0 commit 109c1a9
Show file tree
Hide file tree
Showing 25 changed files with 222 additions and 75 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 2)
define(_CLIENT_VERSION_MINOR, 0)
define(_CLIENT_VERSION_REVISION, 0)
define(_CLIENT_VERSION_BUILD, 1)
define(_CLIENT_VERSION_BUILD, 3)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2017)
AC_INIT([Diamond Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[http://bit.bitclouds],[bitcloud])
Expand Down
4 changes: 0 additions & 4 deletions src/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ typedef int64_t CAmount;
static const CAmount COIN = 100000000;
static const CAmount CENT = 1000000;

/** No amount larger than this (in satoshi) is valid */
static const CAmount MAX_MONEY = 43199500 * COIN;
inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }

/** Type-safe wrapper class to for fee rates
* (how much to pay based on transaction size)
*/
Expand Down
25 changes: 14 additions & 11 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin developers
// Copyright (c) 2014-2015 The Dash developers
// Copyright (c) 2015-2017 The PIVX developers
// Copyright (c) 2015-2017 The PIVX developers
// Copyright (c) 2015-2017 The BTDX developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
Expand Down Expand Up @@ -61,7 +61,7 @@ static Checkpoints::MapCheckpoints mapCheckpoints =
*/
static Checkpoints::MapCheckpoints mapCheckpoints =
boost::assign::map_list_of(0, uint256("0x001"));

static const Checkpoints::CCheckpointData data = {
&mapCheckpoints,
1493667067, // * UNIX timestamp of last checkpoint block
Expand Down Expand Up @@ -118,6 +118,7 @@ class CMainParams : public CChainParams
nMasternodeCountDrift = 20;
nMasternodeColleteralLimxDev = 10000; //Params().MasternodeColleteralLimxDev()
nModifierUpdateBlock = 1; // we use the version 2 for dmd
nMaxMoneyOut = 21000000 * COIN;
/*
printf("Searching for genesis block...\n");
assert(hashGenesisBlock == uint256("0x00008412c3a4bbf7133c9cfbb8f9041fdd39bc98d1e1527612d10d95ed9b06d1"));
Expand All @@ -144,10 +145,10 @@ while (true)
printf("genesis.nTime = %u \n", genesis.nTime);
printf("genesis.nNonce = %u \n", genesis.nNonce);
printf("genesis.nVersion = %u \n", genesis.nVersion);
printf("genesis.GetHash = %s\n", genesis.GetHash().ToString().c_str());
printf("genesis.hashMerkleRoot = %s \n", genesis.hashMerkleRoot.ToString().c_str());
printf("genesis.GetHash = %s\n", genesis.GetHash().ToString().c_str());
printf("genesis.hashMerkleRoot = %s \n", genesis.hashMerkleRoot.ToString().c_str());
*/

/**
* Build the genesis block. Note that the output of the genesis coinbase cannot
* be spent as it did not originally exist in the database.
Expand Down Expand Up @@ -214,14 +215,14 @@ genesis hash: 000002d56463941c20eae5cb474cc805b646515d18bc7dc222a0885b206eadb0
fSkipProofOfWorkCheck = false;
fTestnetToBeDeprecatedFieldRPC = false;
fHeadersFirstSyncingActive = false;

/*
fRequireRPCPassword = true;
fMiningRequiresPeers = true;
fAllowMinDifficultyBlocks = true;
fDefaultConsistencyChecks = false;
fRequireStandard = false;
fMineBlocksOnDemand = false;
fMineBlocksOnDemand = false;
fTestnetToBeDeprecatedFieldRPC = true;
*/

Expand Down Expand Up @@ -263,11 +264,13 @@ class CTestNetParams : public CMainParams
nLastPOWBlock = 200;
nMaturity = 15;
nModifierUpdateBlock = 51197; //approx Mon, 17 Apr 2017 04:00:00 GMT
nMaxMoneyOut = 43199500 * COIN;


//! Modify the testnet genesis block so the timestamp is valid for a later start.
genesis.nTime = 1502817296;
genesis.nNonce = 934213;


hashGenesisBlock = genesis.GetHash();
assert(hashGenesisBlock == uint256("0x000002d56463941c20eae5cb474cc805b646515d18bc7dc222a0885b206eadb0"));
Expand All @@ -290,15 +293,15 @@ class CTestNetParams : public CMainParams

convertSeed6(vFixedSeeds, pnSeed6_test, ARRAYLEN(pnSeed6_test));


fRequireRPCPassword = true;
fMiningRequiresPeers = true;
fAllowMinDifficultyBlocks = true;
fDefaultConsistencyChecks = false;
fRequireStandard = false;
fMineBlocksOnDemand = false;
fMineBlocksOnDemand = false;
fTestnetToBeDeprecatedFieldRPC = true;



nPoolMaxTransactions = 2;
Expand Down
2 changes: 2 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class CChainParams
int LAST_POW_BLOCK() const { return nLastPOWBlock; }
int COINBASE_MATURITY() const { return nMaturity; }
int ModifierUpgradeBlock() const { return nModifierUpdateBlock; }
CAmount MaxMoneyOut() const { return nMaxMoneyOut; }
/** The masternode count that we will allow the see-saw reward payments to be off by */
int MasternodeCountDrift() const { return nMasternodeCountDrift; }
int MasternodeColleteralLimxDev() const { return nMasternodeColleteralLimxDev; }
Expand Down Expand Up @@ -117,6 +118,7 @@ class CChainParams
int nMaturity;
int nMaturityMAX;
int nModifierUpdateBlock;
CAmount nMaxMoneyOut;
int nMinerThreads;
std::vector<CDNSSeedData> vSeeds;
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define CLIENT_VERSION_MAJOR 2
#define CLIENT_VERSION_MINOR 0
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_BUILD 1
#define CLIENT_VERSION_BUILD 3
//bitcoingui.cpp L116
//! Set to true for release, false for prerelease or test build
#define CLIENT_VERSION_IS_RELEASE true
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ bool AppInit2(boost::thread_group& threadGroup)
fAlerts = GetBoolArg("-alerts", DEFAULT_ALERTS);


if (GetBoolArg("-peerbloomfilters", false))
if (GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS))
nLocalServices |= NODE_BLOOM;

// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
Expand Down
81 changes: 57 additions & 24 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,11 @@ bool GetCoinAge(const CTransaction& tx, const unsigned int nTxTime, uint64_t& nC
return true;
}

bool MoneyRange(CAmount nValueOut)
{
return nValueOut >= 0 && nValueOut <= Params().MaxMoneyOut();
}

bool CheckTransaction(const CTransaction& tx, CValidationState& state)
{
// Basic checks that don't depend on any context
Expand All @@ -987,7 +992,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState& state)
if (txout.nValue < 0)
return state.DoS(100, error("CheckTransaction() : txout.nValue negative"),
REJECT_INVALID, "bad-txns-vout-negative");
if (txout.nValue > MAX_MONEY)
if (txout.nValue > Params().MaxMoneyOut())
return state.DoS(100, error("CheckTransaction() : txout.nValue too high"),
REJECT_INVALID, "bad-txns-vout-toolarge");
nValueOut += txout.nValue;
Expand Down Expand Up @@ -1074,7 +1079,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF
}

if (!MoneyRange(nMinFee))
nMinFee = MAX_MONEY;
nMinFee = Params().MaxMoneyOut();
return nMinFee;
}

Expand Down Expand Up @@ -2141,8 +2146,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
std::vector<std::pair<uint256, CDiskTxPos> > vPos;
vPos.reserve(block.vtx.size());
blockundo.vtxundo.reserve(block.vtx.size() - 1);
int64_t nValueOut = 0;
int64_t nValueIn = 0;
CAmount nValueOut = 0;
CAmount nValueIn = 0;
for (unsigned int i = 0; i < block.vtx.size(); i++) {
const CTransaction& tx = block.vtx[i];

Expand All @@ -2152,7 +2157,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
return state.DoS(100, error("ConnectBlock() : too many sigops"),
REJECT_INVALID, "bad-blk-sigops");

if (!tx.IsCoinBase()) {
if (tx.IsCoinBase())
{
nValueOut += tx.GetValueOut();
}
else
{
if (!view.HaveInputs(tx))
return state.DoS(100, error("ConnectBlock() : inputs missing/spent"),
REJECT_INVALID, "bad-txns-inputs-missingorspent");
Expand All @@ -2167,15 +2177,19 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
REJECT_INVALID, "bad-blk-sigops");
}

nFees += view.GetValueIn(tx) - tx.GetValueOut();
nValueIn += view.GetValueIn(tx);

CAmount nTxValueIn = view.GetValueIn(tx);
CAmount nTxValueOut = tx.GetValueOut();
nValueIn += nTxValueIn;
nValueOut += nTxValueOut;
if (!tx.IsCoinStake())
nFees += nTxValueIn - nTxValueOut;

std::vector<CScriptCheck> vChecks;
if (!CheckInputs(tx, state, view, fScriptChecks, flags, false, nScriptCheckThreads ? &vChecks : NULL))
return false;
control.Add(vChecks);
}
nValueOut += tx.GetValueOut();

CTxUndo undoDummy;
if (i > 0) {
Expand All @@ -2187,9 +2201,17 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION);
}

// ppcoin: track money supply and mint amount info
CAmount nMoneySupplyPrev = pindex->pprev ? pindex->pprev->nMoneySupply : 0;
pindex->nMint = nValueOut - nValueIn + nFees;
pindex->nMoneySupply = (pindex->pprev ? pindex->pprev->nMoneySupply : 0) + nValueOut - nValueIn;
pindex->nMoneySupply = nMoneySupplyPrev + nValueOut - nValueIn;

CAmount nExpectedMint = GetBlockValue(pindex->pprev->nHeight);
if (pindex->pprev->nHeight > 4200 && !IsBlockValueValid(block, nExpectedMint, pindex->nMint)) {
return state.DoS(100,
error("ConnectBlock() : reward pays too much (actual=%s vs limit=%s)",
FormatMoney(pindex->nMint), FormatMoney(nExpectedMint)),
REJECT_INVALID, "bad-cb-amount");
}

if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex)))
return error("Connect() : WriteBlockIndex for pindex failed");
Expand All @@ -2198,13 +2220,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
nTimeConnect += nTime1 - nTimeStart;
LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs - 1), nTimeConnect * 0.000001);

if (!IsInitialBlockDownload() && !IsBlockValueValid(block, GetBlockValue(pindex->pprev->nHeight))) {
return state.DoS(100,
error("ConnectBlock() : reward pays too much (actual=%d vs limit=%d)",
block.vtx[0].GetValueOut(), GetBlockValue(pindex->pprev->nHeight)),
REJECT_INVALID, "bad-cb-amount");
}

if (!control.Wait())
return state.DoS(100, false);
int64_t nTime2 = GetTimeMicros();
Expand Down Expand Up @@ -4590,14 +4605,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
CAddress addrFrom;
uint64_t nNonce = 1;
vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe;
if (pfrom->nVersion < ActiveProtocol()) {
// disconnect from peers older than this proto version
LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion);
pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE,
strprintf("Version must be %d or greater", ActiveProtocol()));
pfrom->fDisconnect = true;
if (pfrom->DisconnectOldProtocol(ActiveProtocol(), strCommand))
return false;
}

if (pfrom->nVersion == 10300)
pfrom->nVersion = 300;
Expand Down Expand Up @@ -5094,6 +5103,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
std::string strError = "invalid header received " + header.GetHash().ToString();
return error(strError.c_str());
}

//disconnect this node if its old protocol version
pfrom->DisconnectOldProtocol(ActiveProtocol(), strCommand);
}
}

Expand Down Expand Up @@ -5143,6 +5155,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
TRY_LOCK(cs_main, lockMain);
if (lockMain) Misbehaving(pfrom->GetId(), nDoS);
}

//disconnect this node if its old protocol version
pfrom->DisconnectOldProtocol(ActiveProtocol(), strCommand);
}
}

Expand Down Expand Up @@ -5376,13 +5391,31 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
return true;
}

// Note: whenever a protocol update is needed toggle between both implementations (comment out the formerly active one)
// so we can leave the existing clients untouched (old SPORK will stay on so they don't see even older clients).
// Those old clients won't react to the changes of the other (new) SPORK because at the time of their implementation
// it was the one which was commented out
int ActiveProtocol()
{

// SPORK_14 was used for 70710. Leave it 'ON' so they don't see < 70710 nodes. They won't react to SPORK_15
// messages because it's not in their code
/*
if (IsSporkActive(SPORK_14_NEW_PROTOCOL_ENFORCEMENT)) {
if (chainActive.Tip()->nHeight >= Params().ModifierUpgradeBlock())
return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;
}
return MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT;
*/


// SPORK_15 is used for 70910. Nodes < 70910 don't see it and still get their protocol version via SPORK_14 and their
// own ModifierUpgradeBlock()

if (IsSporkActive(SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2))
return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;

return MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT;
}

Expand Down
4 changes: 4 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ static const unsigned int DATABASE_WRITE_INTERVAL = 3600;
/** Maximum length of reject messages. */
static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;

/** Enable bloom filter */
static const bool DEFAULT_PEERBLOOMFILTERS = true;

/** "reject" message codes */
static const unsigned char REJECT_MALFORMED = 0x01;
static const unsigned char REJECT_INVALID = 0x10;
Expand Down Expand Up @@ -293,6 +296,7 @@ struct CDiskTxPos : public CDiskBlockPos {


CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree);
bool MoneyRange(CAmount nValueOut);

/**
* Check transaction inputs, and make sure any
Expand Down
Loading

0 comments on commit 109c1a9

Please sign in to comment.