mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-02 03:31:09 +00:00
Compared with previous bans, the following changes are made: * Txn with empty vin/vout or null prevouts move from 10 DoS points to 100. * Loose transactions with a dependency loop now result in a ban instead of 10 DoS points. * Many pre-segwit soft-fork errors now result in a ban. Note: Transactions that violate soft-fork script flags since P2SH do not generally result in a ban. Also, banning behavior for invalid blocks is dependent on whether the node is validating with multiple script check threads, due to a long- standing bug. That inconsistency is still present after this commit. * Proof of work failure moves from 50 DoS points to a ban. * Blocks with timestamps under MTP now result in a ban, blocks too far in the future continue to *not* result in a ban. * Inclusion of non-final transactions in a block now results in a ban instead of 10 DoS points. Co-authored-by: Anthony Towns <aj@erisian.com.au>
58 lines
2.2 KiB
C++
58 lines
2.2 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 <consensus/tx_check.h>
|
|
|
|
#include <primitives/transaction.h>
|
|
#include <consensus/validation.h>
|
|
|
|
bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fCheckDuplicateInputs)
|
|
{
|
|
// Basic checks that don't depend on any context
|
|
if (tx.vin.empty())
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-txns-vin-empty");
|
|
if (tx.vout.empty())
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-txns-vout-empty");
|
|
// Size limits (this doesn't take the witness into account, as that hasn't been checked for malleability)
|
|
if (::GetSerializeSize(tx, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT)
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-txns-oversize");
|
|
|
|
// Check for negative or overflow output values
|
|
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 - note that this check is slow so we skip it in CheckBlock
|
|
if (fCheckDuplicateInputs) {
|
|
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())
|
|
{
|
|
if (tx.vin[0].scriptSig.size() < 2 || 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(100, false, REJECT_INVALID, "bad-txns-prevout-null");
|
|
}
|
|
|
|
return true;
|
|
}
|