Skip to content

Commit f4b2ce8

Browse files
committed
Merge #7387: Get rid of inaccurate ScriptSigArgsExpected
52b29dc Get rid of inaccurate ScriptSigArgsExpected (Pieter Wuille)
2 parents 7726c48 + 52b29dc commit f4b2ce8

File tree

5 files changed

+6
-70
lines changed

5 files changed

+6
-70
lines changed

src/policy/policy.cpp

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -135,45 +135,20 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
135135
const CScript& prevScript = prev.scriptPubKey;
136136
if (!Solver(prevScript, whichType, vSolutions))
137137
return false;
138-
int nArgsExpected = ScriptSigArgsExpected(whichType, vSolutions);
139-
if (nArgsExpected < 0)
140-
return false;
141-
142-
// Transactions with extra stuff in their scriptSigs are
143-
// non-standard. Note that this EvalScript() call will
144-
// be quick, because if there are any operations
145-
// beside "push data" in the scriptSig
146-
// IsStandardTx() will have already returned false
147-
// and this method isn't called.
148-
std::vector<std::vector<unsigned char> > stack;
149-
if (!EvalScript(stack, tx.vin[i].scriptSig, SCRIPT_VERIFY_NONE, BaseSignatureChecker()))
150-
return false;
151138

152139
if (whichType == TX_SCRIPTHASH)
153140
{
141+
std::vector<std::vector<unsigned char> > stack;
142+
// convert the scriptSig into a stack, so we can inspect the redeemScript
143+
if (!EvalScript(stack, tx.vin[i].scriptSig, SCRIPT_VERIFY_NONE, BaseSignatureChecker(), 0))
144+
return false;
154145
if (stack.empty())
155146
return false;
156147
CScript subscript(stack.back().begin(), stack.back().end());
157-
std::vector<std::vector<unsigned char> > vSolutions2;
158-
txnouttype whichType2;
159-
if (Solver(subscript, whichType2, vSolutions2))
160-
{
161-
int tmpExpected = ScriptSigArgsExpected(whichType2, vSolutions2);
162-
if (tmpExpected < 0)
163-
return false;
164-
nArgsExpected += tmpExpected;
165-
}
166-
else
167-
{
168-
// Any other Script with less than 15 sigops OK:
169-
unsigned int sigops = subscript.GetSigOpCount(true);
170-
// ... extra data left on the stack after execution is OK, too:
171-
return (sigops <= MAX_P2SH_SIGOPS);
148+
if (subscript.GetSigOpCount(true) > MAX_P2SH_SIGOPS) {
149+
return false;
172150
}
173151
}
174-
175-
if (stack.size() != (unsigned int)nArgsExpected)
176-
return false;
177152
}
178153

179154
return true;

src/script/standard.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -161,27 +161,6 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
161161
return false;
162162
}
163163

164-
int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned char> >& vSolutions)
165-
{
166-
switch (t)
167-
{
168-
case TX_NONSTANDARD:
169-
case TX_NULL_DATA:
170-
return -1;
171-
case TX_PUBKEY:
172-
return 1;
173-
case TX_PUBKEYHASH:
174-
return 2;
175-
case TX_MULTISIG:
176-
if (vSolutions.size() < 1 || vSolutions[0].size() < 1)
177-
return -1;
178-
return vSolutions[0][0] + 1;
179-
case TX_SCRIPTHASH:
180-
return 1; // doesn't include args needed by the script
181-
}
182-
return -1;
183-
}
184-
185164
bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
186165
{
187166
vector<valtype> vSolutions;

src/script/standard.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
7171
const char* GetTxnOutputType(txnouttype t);
7272

7373
bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet);
74-
int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned char> >& vSolutions);
7574
bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);
7675
bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
7776

src/test/script_P2SH_tests.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,6 @@ BOOST_AUTO_TEST_CASE(AreInputsStandard)
346346
// 22 P2SH sigops for all inputs (1 for vin[0], 6 for vin[3], 15 for vin[4]
347347
BOOST_CHECK_EQUAL(GetP2SHSigOpCount(txTo, coins), 22U);
348348

349-
// Make sure adding crap to the scriptSigs makes them non-standard:
350-
for (int i = 0; i < 3; i++)
351-
{
352-
CScript t = txTo.vin[i].scriptSig;
353-
txTo.vin[i].scriptSig = (CScript() << 11) + t;
354-
BOOST_CHECK(!::AreInputsStandard(txTo, coins));
355-
txTo.vin[i].scriptSig = t;
356-
}
357-
358349
CMutableTransaction txToNonStd1;
359350
txToNonStd1.vout.resize(1);
360351
txToNonStd1.vout[0].scriptPubKey = GetScriptForDestination(key[1].GetPubKey().GetID());

src/test/transaction_tests.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,6 @@ BOOST_AUTO_TEST_CASE(test_Get)
310310

311311
BOOST_CHECK(AreInputsStandard(t1, coins));
312312
BOOST_CHECK_EQUAL(coins.GetValueIn(t1), (50+21+22)*CENT);
313-
314-
// Adding extra junk to the scriptSig should make it non-standard:
315-
t1.vin[0].scriptSig << OP_11;
316-
BOOST_CHECK(!AreInputsStandard(t1, coins));
317-
318-
// ... as should not having enough:
319-
t1.vin[0].scriptSig = CScript();
320-
BOOST_CHECK(!AreInputsStandard(t1, coins));
321313
}
322314

323315
BOOST_AUTO_TEST_CASE(test_IsStandard)

0 commit comments

Comments
 (0)