src/policy/policy.cpp
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
{
    if (tx.IsCoinBase())
        return true; // Coinbases don't use vin normally

    for (unsigned int i = 0; i < tx.vin.size(); i++)
    {
        const CTxOut& prev = mapInputs.AccessCoin(tx.vin[i].prevout).out;

        std::vector<std::vector<unsigned char> > vSolutions;
        txnouttype whichType = Solver(prev.scriptPubKey, vSolutions);
        if (whichType == TX_NONSTANDARD || whichType == TX_WITNESS_UNKNOWN) {
            // WITNESS_UNKNOWN failures are typically also caught with a policy
            // flag in the script interpreter, but it can be helpful to catch
            // this type of NONSTANDARD transaction earlier in transaction
            // validation.
            return false;
        } else if (whichType == TX_SCRIPTHASH) {
            std::vector<std::vector<unsigned char> > stack;
            // convert the scriptSig into a stack, so we can inspect the redeemScript
            if (!EvalScript(stack, tx.vin[i].scriptSig, SCRIPT_VERIFY_NONE, BaseSignatureChecker(), SigVersion::BASE))
                return false;
            if (stack.empty())
                return false;
            CScript subscript(stack.back().begin(), stack.back().end());
            if (subscript.GetSigOpCount(true) > MAX_P2SH_SIGOPS) {
                return false;
            }
        }
    }

    return true;
}
/**
 * Check transaction inputs to mitigate two
 * potential denial-of-service attacks:
 *
 * 1. scriptSigs with extra data stuffed into them,
 *    not consumed by scriptPubKey (or P2SH script)
 * 2. P2SH scripts with a crazy number of expensive
 *    CHECKSIG/CHECKMULTISIG operations
 *
 * Why bother? To avoid denial-of-service attacks; an attacker
 * can submit a standard HASH... OP_EQUAL transaction,
 * which will get accepted into blocks. The redemption
 * script can be anything; an attacker could use a very
 * expensive-to-check-upon-redemption script like:
 *   DUP CHECKSIG DROP ... repeated 100 times... OP_1
 *
 * Note that only the non-witness portion of the transaction is checked here.
 */
Check transaction inputs to mitigate two
potential denial-of-service attacks.

1. scriptSigs with extra data stuffed into them,
not consumed by scriptPubKey (or P2SH script)
2. P2SH scripts with a crazy number of expensive
CHECKSIG/CHECKMULTISIG operations



Note that only the non-witness portion of the transaction is checked here.
Check transaction inputs to mitigate two potential denial - of - service attacks . 1 . scriptSigs with extra data stuffed into them not consumed by scriptPubKey ( or P2SH script ) 2 . P2SH scripts with a crazy number of expensive CHECKSIG / CHECKMULTISIG operations Note that only the non - witness portion of the transaction is checked here .
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
{
    if (tx.IsCoinBase())
        return true; 
    for (unsigned int i = 0; i < tx.vin.size(); i++)
    {
        const CTxOut& prev = mapInputs.AccessCoin(tx.vin[i].prevout).out;
        std::vector<std::vector<unsigned char> > vSolutions;
        txnouttype whichType = Solver(prev.scriptPubKey, vSolutions);
        if (whichType == TX_NONSTANDARD || whichType == TX_WITNESS_UNKNOWN) {
            return false;
        } else if (whichType == TX_SCRIPTHASH) {
            std::vector<std::vector<unsigned char> > stack;
            if (!EvalScript(stack, tx.vin[i].scriptSig, SCRIPT_VERIFY_NONE, BaseSignatureChecker(), SigVersion::BASE))
                return false;
            if (stack.empty())
                return false;
            CScript subscript(stack.back().begin(), stack.back().end());
            if (subscript.GetSigOpCount(true) > MAX_P2SH_SIGOPS) {
                return false;
            }
        }
    }
    return true;
}
bool AreInputsStandard ( const CTransaction & tx , const CCoinsViewCache & mapInputs ) { if ( tx . IsCoinBase ( ) ) return true ; for ( unsigned int i = 0 ; i < tx . vin . size ( ) ; i ++ ) { const CTxOut & prev = mapInputs . AccessCoin ( tx . vin [ i ] . prevout ) . out ; std :: vector < std :: vector < unsigned char > > vSolutions ; txnouttype whichType = Solver ( prev . scriptPubKey , vSolutions ) ; if ( whichType == TX_NONSTANDARD || whichType == TX_WITNESS_UNKNOWN ) { return false ; } else if ( whichType == TX_SCRIPTHASH ) { std :: vector < std :: vector < unsigned char > > stack ; if ( ! EvalScript ( stack , tx . vin [ i ] . scriptSig , SCRIPT_VERIFY_NONE , BaseSignatureChecker ( ) , SigVersion :: BASE ) ) return false ; if ( stack . empty ( ) ) return false ; CScript subscript ( stack . back ( ) . begin ( ) , stack . back ( ) . end ( ) ) ; if ( subscript . GetSigOpCount ( true ) > MAX_P2SH_SIGOPS ) { return false ; } } } return true ; }
Check transaction inputs to mitigate two
 potential denial-of-service attacks:
Check transaction inputs to mitigate two potential denial - of - service attacks :
// Coinbases don't use vin normally // WITNESS_UNKNOWN failures are typically also caught with a policy // flag in the script interpreter, but it can be helpful to catch // this type of NONSTANDARD transaction earlier in transaction // validation. // convert the scriptSig into a stack, so we can inspect the redeemScript