diff --git a/src/core_read.cpp b/src/core_read.cpp --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -180,29 +180,6 @@ return result; } -// Check that all of the input and output scripts of a transaction contains -// valid opcodes -bool CheckTxScriptsSanity(const CMutableTransaction &tx) { - // Check input scripts for non-coinbase txs - if (!CTransaction(tx).IsCoinBase()) { - for (const auto &i : tx.vin) { - if (!i.scriptSig.HasValidOps() || - i.scriptSig.size() > MAX_SCRIPT_SIZE) { - return false; - } - } - } - // Check output scripts - for (const auto &o : tx.vout) { - if (!o.scriptPubKey.HasValidOps() || - o.scriptPubKey.size() > MAX_SCRIPT_SIZE) { - return false; - } - } - - return true; -} - bool DecodeHexTx(CMutableTransaction &tx, const std::string &strHexTx) { if (!IsHex(strHexTx)) { return false; @@ -213,7 +190,7 @@ CDataStream ssData(txData, SER_NETWORK, PROTOCOL_VERSION); try { ssData >> tx; - if (ssData.eof() && CheckTxScriptsSanity(tx)) { + if (ssData.eof()) { return true; } } catch (const std::exception &e) { diff --git a/test/functional/rpc_rawtransaction.py b/test/functional/rpc_rawtransaction.py --- a/test/functional/rpc_rawtransaction.py +++ b/test/functional/rpc_rawtransaction.py @@ -16,7 +16,14 @@ from collections import OrderedDict from io import BytesIO -from test_framework.messages import CTransaction, ToHex +from test_framework.messages import ( + COutPoint, + CTransaction, + CTxIn, + CTxOut, + ToHex, +) +from test_framework.script import CScript from test_framework.test_framework import BitcoinTestFramework from test_framework.txtools import pad_raw_tx from test_framework.util import ( @@ -491,6 +498,29 @@ decrawtx = self.nodes[0].decoderawtransaction(rawtx) assert_equal(decrawtx['version'], 0x7fffffff) + ########################################## + # Decoding weird scripts in transactions # + ########################################## + + self.log.info('Decode correctly-formatted but weird transactions') + tx = CTransaction() + # empty + self.nodes[0].decoderawtransaction(ToHex(tx)) + # truncated push + tx.vin.append(CTxIn(COutPoint(42, 0), b'\x4e\x00\x00')) + tx.vin.append(CTxIn(COutPoint(42, 0), b'\x4c\x10TRUNC')) + tx.vout.append(CTxOut(0, b'\x4e\x00\x00')) + tx.vout.append(CTxOut(0, b'\x4c\x10TRUNC')) + self.nodes[0].decoderawtransaction(ToHex(tx)) + # giant pushes and long scripts + tx.vin.append(CTxIn(COutPoint(42, 0), CScript([b'giant push'*10000]))) + tx.vout.append(CTxOut(0, CScript([b'giant push'*10000]))) + self.nodes[0].decoderawtransaction(ToHex(tx)) + + self.log.info('Refuse garbage after transaction') + assert_raises_rpc_error(-22, 'TX decode failed', + self.nodes[0].decoderawtransaction, ToHex(tx) + '00') + if __name__ == '__main__': RawTransactionsTest().main()