Skip to content

Commit 68f7d1d

Browse files
committed
Create (MANDATORY|STANDARD)_SCRIPT_VERIFY_FLAGS constants
1 parent d4ffe4e commit 68f7d1d

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
945945

946946
// Check against previous transactions
947947
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
948-
if (!CheckInputs(tx, state, view, true, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC))
948+
if (!CheckInputs(tx, state, view, true, STANDARD_SCRIPT_VERIFY_FLAGS))
949949
{
950950
return error("AcceptToMemoryPool: : ConnectInputs failed %s", hash.ToString());
951951
}

src/main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ inline bool AllowFree(double dPriority)
309309
// This does not modify the UTXO set. If pvChecks is not NULL, script checks are pushed onto it
310310
// instead of being performed inline.
311311
bool CheckInputs(const CTransaction& tx, CValidationState &state, CCoinsViewCache &view, bool fScriptChecks = true,
312-
unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC,
312+
unsigned int flags = STANDARD_SCRIPT_VERIFY_FLAGS,
313313
std::vector<CScriptCheck> *pvChecks = NULL);
314314

315315
// Apply the effects of this transaction on the UTXO set represented by view

src/miner.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
276276
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)
277277
continue;
278278

279+
// Note that flags: we don't want to set mempool/IsStandard()
280+
// policy here, but we still have to ensure that the block we
281+
// create only contains transactions that are valid in new blocks.
279282
CValidationState state;
280-
if (!CheckInputs(tx, state, view, true, SCRIPT_VERIFY_P2SH))
283+
if (!CheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS))
281284
continue;
282285

283286
CTxUndo txundo;

src/rpcrawtransaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ Value signrawtransaction(const Array& params, bool fHelp)
722722
{
723723
txin.scriptSig = CombineSignatures(prevPubKey, mergedTx, i, txin.scriptSig, txv.vin[i].scriptSig);
724724
}
725-
if (!VerifyScript(txin.scriptSig, prevPubKey, mergedTx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC, 0))
725+
if (!VerifyScript(txin.scriptSig, prevPubKey, mergedTx, i, STANDARD_SCRIPT_VERIFY_FLAGS, 0))
726726
fComplete = false;
727727
}
728728

src/script.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ bool SignSignature(const CKeyStore &keystore, const CScript& fromPubKey, CTransa
16701670
}
16711671

16721672
// Test solution
1673-
return VerifyScript(txin.scriptSig, fromPubKey, txTo, nIn, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC, 0);
1673+
return VerifyScript(txin.scriptSig, fromPubKey, txTo, nIn, STANDARD_SCRIPT_VERIFY_FLAGS, 0);
16741674
}
16751675

16761676
bool SignSignature(const CKeyStore &keystore, const CTransaction& txFrom, CTransaction& txTo, unsigned int nIn, int nHashType)

src/script.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ enum
4444
SCRIPT_VERIFY_NOCACHE = (1U << 3), // do not store results in signature cache (but do query it)
4545
};
4646

47+
// Mandatory script verification flags that all new blocks must comply with for
48+
// them to be valid. (but old blocks may not comply with) Currently just P2SH,
49+
// but in the future other flags may be added, such as a soft-fork to enforce
50+
// strict DER encoding.
51+
static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS = SCRIPT_VERIFY_P2SH;
52+
53+
// Standard script verification flags that standard transactions will comply
54+
// with. However scripts violating these flags may still be present in valid
55+
// blocks and we must accept those blocks.
56+
static const unsigned int STANDARD_SCRIPT_VERIFY_FLAGS = MANDATORY_SCRIPT_VERIFY_FLAGS |
57+
SCRIPT_VERIFY_STRICTENC;
58+
4759
enum txnouttype
4860
{
4961
TX_NONSTANDARD,

0 commit comments

Comments
 (0)