Skip to content

Commit 109c1a9

Browse files
author
Christian Knöpke
committed
Update 2.0.0.3 Security Update
1 parent f0783c0 commit 109c1a9

25 files changed

+222
-75
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ AC_PREREQ([2.60])
33
define(_CLIENT_VERSION_MAJOR, 2)
44
define(_CLIENT_VERSION_MINOR, 0)
55
define(_CLIENT_VERSION_REVISION, 0)
6-
define(_CLIENT_VERSION_BUILD, 1)
6+
define(_CLIENT_VERSION_BUILD, 3)
77
define(_CLIENT_VERSION_IS_RELEASE, true)
88
define(_COPYRIGHT_YEAR, 2017)
99
AC_INIT([Diamond Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[http://bit.bitclouds],[bitcloud])

src/amount.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ typedef int64_t CAmount;
1616
static const CAmount COIN = 100000000;
1717
static const CAmount CENT = 1000000;
1818

19-
/** No amount larger than this (in satoshi) is valid */
20-
static const CAmount MAX_MONEY = 43199500 * COIN;
21-
inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
22-
2319
/** Type-safe wrapper class to for fee rates
2420
* (how much to pay based on transaction size)
2521
*/

src/chainparams.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2010 Satoshi Nakamoto
22
// Copyright (c) 2009-2014 The Bitcoin developers
33
// Copyright (c) 2014-2015 The Dash developers
4-
// Copyright (c) 2015-2017 The PIVX developers
4+
// Copyright (c) 2015-2017 The PIVX developers
55
// Copyright (c) 2015-2017 The BTDX developers
66
// Distributed under the MIT software license, see the accompanying
77
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -61,7 +61,7 @@ static Checkpoints::MapCheckpoints mapCheckpoints =
6161
*/
6262
static Checkpoints::MapCheckpoints mapCheckpoints =
6363
boost::assign::map_list_of(0, uint256("0x001"));
64-
64+
6565
static const Checkpoints::CCheckpointData data = {
6666
&mapCheckpoints,
6767
1493667067, // * UNIX timestamp of last checkpoint block
@@ -118,6 +118,7 @@ class CMainParams : public CChainParams
118118
nMasternodeCountDrift = 20;
119119
nMasternodeColleteralLimxDev = 10000; //Params().MasternodeColleteralLimxDev()
120120
nModifierUpdateBlock = 1; // we use the version 2 for dmd
121+
nMaxMoneyOut = 21000000 * COIN;
121122
/*
122123
printf("Searching for genesis block...\n");
123124
assert(hashGenesisBlock == uint256("0x00008412c3a4bbf7133c9cfbb8f9041fdd39bc98d1e1527612d10d95ed9b06d1"));
@@ -144,10 +145,10 @@ while (true)
144145
printf("genesis.nTime = %u \n", genesis.nTime);
145146
printf("genesis.nNonce = %u \n", genesis.nNonce);
146147
printf("genesis.nVersion = %u \n", genesis.nVersion);
147-
printf("genesis.GetHash = %s\n", genesis.GetHash().ToString().c_str());
148-
printf("genesis.hashMerkleRoot = %s \n", genesis.hashMerkleRoot.ToString().c_str());
148+
printf("genesis.GetHash = %s\n", genesis.GetHash().ToString().c_str());
149+
printf("genesis.hashMerkleRoot = %s \n", genesis.hashMerkleRoot.ToString().c_str());
149150
*/
150-
151+
151152
/**
152153
* Build the genesis block. Note that the output of the genesis coinbase cannot
153154
* be spent as it did not originally exist in the database.
@@ -214,14 +215,14 @@ genesis hash: 000002d56463941c20eae5cb474cc805b646515d18bc7dc222a0885b206eadb0
214215
fSkipProofOfWorkCheck = false;
215216
fTestnetToBeDeprecatedFieldRPC = false;
216217
fHeadersFirstSyncingActive = false;
217-
218+
218219
/*
219220
fRequireRPCPassword = true;
220221
fMiningRequiresPeers = true;
221222
fAllowMinDifficultyBlocks = true;
222223
fDefaultConsistencyChecks = false;
223224
fRequireStandard = false;
224-
fMineBlocksOnDemand = false;
225+
fMineBlocksOnDemand = false;
225226
fTestnetToBeDeprecatedFieldRPC = true;
226227
*/
227228

@@ -263,11 +264,13 @@ class CTestNetParams : public CMainParams
263264
nLastPOWBlock = 200;
264265
nMaturity = 15;
265266
nModifierUpdateBlock = 51197; //approx Mon, 17 Apr 2017 04:00:00 GMT
267+
nMaxMoneyOut = 43199500 * COIN;
268+
266269

267270
//! Modify the testnet genesis block so the timestamp is valid for a later start.
268271
genesis.nTime = 1502817296;
269272
genesis.nNonce = 934213;
270-
273+
271274

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

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

293-
296+
294297
fRequireRPCPassword = true;
295298
fMiningRequiresPeers = true;
296299
fAllowMinDifficultyBlocks = true;
297300
fDefaultConsistencyChecks = false;
298301
fRequireStandard = false;
299-
fMineBlocksOnDemand = false;
302+
fMineBlocksOnDemand = false;
300303
fTestnetToBeDeprecatedFieldRPC = true;
301-
304+
302305

303306

304307
nPoolMaxTransactions = 2;

src/chainparams.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class CChainParams
7676
int LAST_POW_BLOCK() const { return nLastPOWBlock; }
7777
int COINBASE_MATURITY() const { return nMaturity; }
7878
int ModifierUpgradeBlock() const { return nModifierUpdateBlock; }
79+
CAmount MaxMoneyOut() const { return nMaxMoneyOut; }
7980
/** The masternode count that we will allow the see-saw reward payments to be off by */
8081
int MasternodeCountDrift() const { return nMasternodeCountDrift; }
8182
int MasternodeColleteralLimxDev() const { return nMasternodeColleteralLimxDev; }
@@ -117,6 +118,7 @@ class CChainParams
117118
int nMaturity;
118119
int nMaturityMAX;
119120
int nModifierUpdateBlock;
121+
CAmount nMaxMoneyOut;
120122
int nMinerThreads;
121123
std::vector<CDNSSeedData> vSeeds;
122124
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];

src/clientversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define CLIENT_VERSION_MAJOR 2
1818
#define CLIENT_VERSION_MINOR 0
1919
#define CLIENT_VERSION_REVISION 0
20-
#define CLIENT_VERSION_BUILD 1
20+
#define CLIENT_VERSION_BUILD 3
2121
//bitcoingui.cpp L116
2222
//! Set to true for release, false for prerelease or test build
2323
#define CLIENT_VERSION_IS_RELEASE true

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ bool AppInit2(boost::thread_group& threadGroup)
880880
fAlerts = GetBoolArg("-alerts", DEFAULT_ALERTS);
881881

882882

883-
if (GetBoolArg("-peerbloomfilters", false))
883+
if (GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS))
884884
nLocalServices |= NODE_BLOOM;
885885

886886
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log

src/main.cpp

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,11 @@ bool GetCoinAge(const CTransaction& tx, const unsigned int nTxTime, uint64_t& nC
964964
return true;
965965
}
966966

967+
bool MoneyRange(CAmount nValueOut)
968+
{
969+
return nValueOut >= 0 && nValueOut <= Params().MaxMoneyOut();
970+
}
971+
967972
bool CheckTransaction(const CTransaction& tx, CValidationState& state)
968973
{
969974
// Basic checks that don't depend on any context
@@ -987,7 +992,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState& state)
987992
if (txout.nValue < 0)
988993
return state.DoS(100, error("CheckTransaction() : txout.nValue negative"),
989994
REJECT_INVALID, "bad-txns-vout-negative");
990-
if (txout.nValue > MAX_MONEY)
995+
if (txout.nValue > Params().MaxMoneyOut())
991996
return state.DoS(100, error("CheckTransaction() : txout.nValue too high"),
992997
REJECT_INVALID, "bad-txns-vout-toolarge");
993998
nValueOut += txout.nValue;
@@ -1074,7 +1079,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF
10741079
}
10751080

10761081
if (!MoneyRange(nMinFee))
1077-
nMinFee = MAX_MONEY;
1082+
nMinFee = Params().MaxMoneyOut();
10781083
return nMinFee;
10791084
}
10801085

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

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

2155-
if (!tx.IsCoinBase()) {
2160+
if (tx.IsCoinBase())
2161+
{
2162+
nValueOut += tx.GetValueOut();
2163+
}
2164+
else
2165+
{
21562166
if (!view.HaveInputs(tx))
21572167
return state.DoS(100, error("ConnectBlock() : inputs missing/spent"),
21582168
REJECT_INVALID, "bad-txns-inputs-missingorspent");
@@ -2167,15 +2177,19 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
21672177
REJECT_INVALID, "bad-blk-sigops");
21682178
}
21692179

2170-
nFees += view.GetValueIn(tx) - tx.GetValueOut();
2171-
nValueIn += view.GetValueIn(tx);
2180+
2181+
CAmount nTxValueIn = view.GetValueIn(tx);
2182+
CAmount nTxValueOut = tx.GetValueOut();
2183+
nValueIn += nTxValueIn;
2184+
nValueOut += nTxValueOut;
2185+
if (!tx.IsCoinStake())
2186+
nFees += nTxValueIn - nTxValueOut;
21722187

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

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

2190-
// ppcoin: track money supply and mint amount info
2204+
CAmount nMoneySupplyPrev = pindex->pprev ? pindex->pprev->nMoneySupply : 0;
21912205
pindex->nMint = nValueOut - nValueIn + nFees;
2192-
pindex->nMoneySupply = (pindex->pprev ? pindex->pprev->nMoneySupply : 0) + nValueOut - nValueIn;
2206+
pindex->nMoneySupply = nMoneySupplyPrev + nValueOut - nValueIn;
2207+
2208+
CAmount nExpectedMint = GetBlockValue(pindex->pprev->nHeight);
2209+
if (pindex->pprev->nHeight > 4200 && !IsBlockValueValid(block, nExpectedMint, pindex->nMint)) {
2210+
return state.DoS(100,
2211+
error("ConnectBlock() : reward pays too much (actual=%s vs limit=%s)",
2212+
FormatMoney(pindex->nMint), FormatMoney(nExpectedMint)),
2213+
REJECT_INVALID, "bad-cb-amount");
2214+
}
21932215

21942216
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex)))
21952217
return error("Connect() : WriteBlockIndex for pindex failed");
@@ -2198,13 +2220,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
21982220
nTimeConnect += nTime1 - nTimeStart;
21992221
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);
22002222

2201-
if (!IsInitialBlockDownload() && !IsBlockValueValid(block, GetBlockValue(pindex->pprev->nHeight))) {
2202-
return state.DoS(100,
2203-
error("ConnectBlock() : reward pays too much (actual=%d vs limit=%d)",
2204-
block.vtx[0].GetValueOut(), GetBlockValue(pindex->pprev->nHeight)),
2205-
REJECT_INVALID, "bad-cb-amount");
2206-
}
2207-
22082223
if (!control.Wait())
22092224
return state.DoS(100, false);
22102225
int64_t nTime2 = GetTimeMicros();
@@ -4590,14 +4605,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
45904605
CAddress addrFrom;
45914606
uint64_t nNonce = 1;
45924607
vRecv >> pfrom->nVersion >> pfrom->nServices >> nTime >> addrMe;
4593-
if (pfrom->nVersion < ActiveProtocol()) {
4594-
// disconnect from peers older than this proto version
4595-
LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion);
4596-
pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE,
4597-
strprintf("Version must be %d or greater", ActiveProtocol()));
4598-
pfrom->fDisconnect = true;
4608+
if (pfrom->DisconnectOldProtocol(ActiveProtocol(), strCommand))
45994609
return false;
4600-
}
46014610

46024611
if (pfrom->nVersion == 10300)
46034612
pfrom->nVersion = 300;
@@ -5094,6 +5103,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
50945103
std::string strError = "invalid header received " + header.GetHash().ToString();
50955104
return error(strError.c_str());
50965105
}
5106+
5107+
//disconnect this node if its old protocol version
5108+
pfrom->DisconnectOldProtocol(ActiveProtocol(), strCommand);
50975109
}
50985110
}
50995111

@@ -5143,6 +5155,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
51435155
TRY_LOCK(cs_main, lockMain);
51445156
if (lockMain) Misbehaving(pfrom->GetId(), nDoS);
51455157
}
5158+
5159+
//disconnect this node if its old protocol version
5160+
pfrom->DisconnectOldProtocol(ActiveProtocol(), strCommand);
51465161
}
51475162
}
51485163

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

5394+
// Note: whenever a protocol update is needed toggle between both implementations (comment out the formerly active one)
5395+
// so we can leave the existing clients untouched (old SPORK will stay on so they don't see even older clients).
5396+
// Those old clients won't react to the changes of the other (new) SPORK because at the time of their implementation
5397+
// it was the one which was commented out
53795398
int ActiveProtocol()
53805399
{
5400+
5401+
// SPORK_14 was used for 70710. Leave it 'ON' so they don't see < 70710 nodes. They won't react to SPORK_15
5402+
// messages because it's not in their code
5403+
/*
53815404
if (IsSporkActive(SPORK_14_NEW_PROTOCOL_ENFORCEMENT)) {
53825405
if (chainActive.Tip()->nHeight >= Params().ModifierUpgradeBlock())
53835406
return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;
53845407
}
53855408
5409+
return MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT;
5410+
*/
5411+
5412+
5413+
// SPORK_15 is used for 70910. Nodes < 70910 don't see it and still get their protocol version via SPORK_14 and their
5414+
// own ModifierUpgradeBlock()
5415+
5416+
if (IsSporkActive(SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2))
5417+
return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT;
5418+
53865419
return MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT;
53875420
}
53885421

src/main.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ static const unsigned int DATABASE_WRITE_INTERVAL = 3600;
103103
/** Maximum length of reject messages. */
104104
static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
105105

106+
/** Enable bloom filter */
107+
static const bool DEFAULT_PEERBLOOMFILTERS = true;
108+
106109
/** "reject" message codes */
107110
static const unsigned char REJECT_MALFORMED = 0x01;
108111
static const unsigned char REJECT_INVALID = 0x10;
@@ -293,6 +296,7 @@ struct CDiskTxPos : public CDiskBlockPos {
293296

294297

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

297301
/**
298302
* Check transaction inputs, and make sure any

0 commit comments

Comments
 (0)