mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 21:12:48 +01:00
452d182739
0c62e3aa73839e97e65a3155e06a98d84b700a1e New regression testing for CVE-2018-17144, CVE-2012-2459, and CVE-2010-5137. (lucash-dev) 38bfca6bb2ad68719415e9c54a981441052da072 Added comments referencing multiple CVEs in tests and production code. (lucash-dev) Pull request description: This functional test includes two scenarios that test for regressions of vulnerabilities, but they are only briefly described. There are freely available documents explaining in detail the issues, but without explicit mentions, the developer trying to maintain the code needs an additional step of digging in commit history and PR conversations to figure it out. Added comments to explicitly mention CVE-2018-17144 and CVE-2012-2459, for more complete documentation. This improves developer experience by making understanding the tests easier. ACKs for top commit: laanwj: ACK 0c62e3aa73839e97e65a3155e06a98d84b700a1e, checked the CVE numbers, thanks for adding documentation Tree-SHA512: 3ee05351745193b8b959e4a25d50f25a693b2d24b0732ed53cf7d5882df40b5dd0f1877bd5c69cffb921d4a7acf9deb3cc1160b96dc730d9b5984151ad06b7c9
66 lines
2.5 KiB
C++
66 lines
2.5 KiB
C++
// Copyright (c) 2017-2018 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <version.h>
|
|
|
|
#include <consensus/consensus.h>
|
|
#include <consensus/tx_check.h>
|
|
|
|
#include <primitives/transaction.h>
|
|
#include <consensus/validation.h>
|
|
|
|
bool CheckTransaction(const CTransaction& tx, CValidationState& state)
|
|
{
|
|
bool allowEmptyTxInOut = false;
|
|
if (tx.nType == TRANSACTION_QUORUM_COMMITMENT) {
|
|
allowEmptyTxInOut = true;
|
|
}
|
|
|
|
// Basic checks that don't depend on any context
|
|
if (!allowEmptyTxInOut && tx.vin.empty())
|
|
return state.DoS(10, false, REJECT_INVALID, "bad-txns-vin-empty");
|
|
if (!allowEmptyTxInOut && tx.vout.empty())
|
|
return state.DoS(10, false, REJECT_INVALID, "bad-txns-vout-empty");
|
|
// Size limits
|
|
if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) > MAX_LEGACY_BLOCK_SIZE)
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-txns-oversize");
|
|
if (tx.vExtraPayload.size() > MAX_TX_EXTRA_PAYLOAD)
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-txns-payload-oversize");
|
|
|
|
// Check for negative or overflow output values (see CVE-2010-5139)
|
|
CAmount nValueOut = 0;
|
|
for (const auto& txout : tx.vout) {
|
|
if (txout.nValue < 0)
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-txns-vout-negative");
|
|
if (txout.nValue > MAX_MONEY)
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-txns-vout-toolarge");
|
|
nValueOut += txout.nValue;
|
|
if (!MoneyRange(nValueOut))
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-txns-txouttotal-toolarge");
|
|
}
|
|
|
|
// Check for duplicate inputs
|
|
std::set<COutPoint> vInOutPoints;
|
|
for (const auto& txin : tx.vin) {
|
|
if (!vInOutPoints.insert(txin.prevout).second)
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-duplicate");
|
|
}
|
|
|
|
if (tx.IsCoinBase()) {
|
|
size_t minCbSize = 2;
|
|
if (tx.nType == TRANSACTION_COINBASE) {
|
|
// With the introduction of CbTx, coinbase scripts are not required anymore to hold a valid block height
|
|
minCbSize = 1;
|
|
}
|
|
if (tx.vin[0].scriptSig.size() < minCbSize || tx.vin[0].scriptSig.size() > 100)
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-cb-length");
|
|
} else {
|
|
for (const auto& txin : tx.vin)
|
|
if (txin.prevout.IsNull())
|
|
return state.DoS(10, false, REJECT_INVALID, "bad-txns-prevout-null");
|
|
}
|
|
|
|
return true;
|
|
}
|