コード例 #1
0
        //
        // Check transaction inputs, and make sure any
        // pay-to-script-hash transactions are evaluating IsStandard scripts
        //
        // 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
        //
        public static bool AreInputsStandard(Transaction tx, TxOutRepository mapInputs)
        {
            if(tx.IsCoinBase)
                return true; // Coinbases don't use vin normally

            for(int i = 0 ; i < tx.Inputs.Count ; i++)
            {
                TxOut prev = mapInputs.GetOutputFor(tx.Inputs[i]);
                if(prev == null)
                    return false;
                if(!IsStandardScriptSig(tx.Inputs[i].ScriptSig, prev.ScriptPubKey))
                    return false;
            }

            return true;
        }
コード例 #2
0
        //
        // Check transaction inputs, and make sure any
        // pay-to-script-hash transactions are evaluating IsStandard scripts
        //
        // 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
        //
        public static bool AreInputsStandard(Transaction tx, TxOutRepository mapInputs)
        {
            if (tx.IsCoinBase)
            {
                return(true);                // Coinbases don't use vin normally
            }
            for (int i = 0; i < tx.Inputs.Count; i++)
            {
                TxOut prev = mapInputs.GetOutputFor(tx.Inputs[i]);
                if (prev == null)
                {
                    return(false);
                }
                if (!IsStandardScriptSig(tx.Inputs[i].ScriptSig, prev.ScriptPubKey))
                {
                    return(false);
                }
            }

            return(true);
        }