bitcoin/bitcoin — pull request #5253 by petertodd (2014-11-10 07:58:17+00:00)
Title: Check against MANDATORY flags prior to accepting to mempool

Previously transactions were only tested again the STANDARD_SCRIPT_VERIFY_FLAGS prior to mempool acceptance, so any bugs in those flags that allowed actually-invalid transactions to pass would
result in allowing invalid transactions into the mempool. Fortunately there is a second check in CreateNewBlock() that would prevent those transactions from being mined, resulting in an invalid block, however this could still be exploited as a DoS attack.

An example transaction failing this test that was previously allowed into the mempool is:

0100000001db7f1e5f08248867e5825fdb24e6d8ce4de652e27f6c22a26e3c9380866ea3e6000000008e0047304402203d82f29cdff31153f533039fe7c3dd854e899b7372b8f1d22c50839bbb9481490220425c983fc9ae879853da193b83aecac8b64825ab01583f4ec10a6b18ae51ced60144410778d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71a1518063243acd4dfe96b66e3f2ec8013c8e072cd09b3834a19f81f659cc3455ac91ffffffff01881300000000000017a914e661a2229cc824329c9409f49d99cb5ac350c9288700000000

which spends:

0778d430274f8c5ec1321338151e9f27f4c676a008bdf8638d07c0b6be9ab35c71a1518063243acd4dfe96b66e3f2ec8013c8e072cd09b3834a19f81f659cc3455 CHECKSIG NOT

with a valid signature. The existing, broken, STRICTENC, implementation causes the CHECKSIG to return false even though the signature is valid against the mandatory flags.