| 96 | } |
| 97 | |
| 98 | bool IsStandardTx(const CTransaction& tx, bool permit_bare_multisig, const CFeeRate& dust_relay_fee, std::string& reason) |
| 99 | { |
| 100 | if (tx.nVersion > TX_MAX_STANDARD_VERSION || tx.nVersion < 1) { |
| 101 | reason = "version"; |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | // Extremely large transactions with lots of inputs can cost the network |
| 106 | // almost as much to process as they cost the sender in fees, because |
| 107 | // computing signature hashes is O(ninputs*txsize). Limiting transactions |
| 108 | // to MAX_STANDARD_TX_WEIGHT mitigates CPU exhaustion attacks. |
| 109 | unsigned int sz = GetTransactionWeight(tx); |
| 110 | if (sz > MAX_STANDARD_TX_WEIGHT) { |
| 111 | reason = "tx-size"; |
| 112 | return false; |
| 113 | } |
| 114 | |
| 115 | for (const CTxIn& txin : tx.vin) |
| 116 | { |
| 117 | // Biggest 'standard' txin involving only keys is a 15-of-15 P2SH |
| 118 | // multisig with compressed keys (remember the 520 byte limit on |
| 119 | // redeemScript size). That works out to a (15*(33+1))+3=513 byte |
| 120 | // redeemScript, 513+1+15*(73+1)+3=1627 bytes of scriptSig, which |
| 121 | // we round off to 1650(MAX_STANDARD_SCRIPTSIG_SIZE) bytes for |
| 122 | // some minor future-proofing. That's also enough to spend a |
| 123 | // 20-of-20 CHECKMULTISIG scriptPubKey, though such a scriptPubKey |
| 124 | // is not considered standard. |
| 125 | if (txin.scriptSig.size() > MAX_STANDARD_SCRIPTSIG_SIZE) { |
| 126 | reason = "scriptsig-size"; |
| 127 | return false; |
| 128 | } |
| 129 | if (!txin.scriptSig.IsPushOnly()) { |
| 130 | reason = "scriptsig-not-pushonly"; |
| 131 | return false; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | CChainParams params = Params(); |
| 136 | unsigned int nDataOut = 0; |
| 137 | TxoutType whichType; |
| 138 | for (const CTxOut& txout : tx.vout) { |
| 139 | if (!::IsStandard(txout.scriptPubKey, whichType)) { |
| 140 | reason = "scriptpubkey"; |
| 141 | return false; |
| 142 | } |
| 143 | |
| 144 | if (whichType == TxoutType::NULL_DATA) { |
| 145 | nDataOut++; |
| 146 | } else if ((whichType == TxoutType::MULTISIG) && (!permit_bare_multisig)) { |
| 147 | reason = "bare-multisig"; |
| 148 | return false; |
| 149 | } else if ((txout.nAsset.IsExplicit() && txout.nAsset.GetAsset() == policyAsset) && IsDust(txout, dust_relay_fee)) { |
| 150 | reason = "dust"; |
| 151 | return false; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | // only one OP_RETURN txout is permitted |
nothing calls this directly
no test coverage detected