This uses the first 4 commits of #15045, rebased and added some comments. The diff is quite large already and I want to make it easy to review, so I'm splitting it into 2 PRs (transaction and script). Script one is WIP, I'll link it when I open it.
Interpretation of scripts is dependent on the script verification flags passed in.
In tests, we should always apply maximal verification flags when checking that a transaction is valid; any additional flags should invalidate the transaction. A transaction should not be valid because we forgot to include a flag, and we should apply all flags by default.
We should apply minimal verification flags when asserting that a transaction is invalid; if verification flags are applied, removing any one of them should mean the transaction is valid.
New verify flags must be backwards compatible; tests should check backwards compatibility and apply the new flags by default. All tx_invalid tests should continue to be invalid with the exact same verify flags. All tx_valid tests that don't pass with new flags should explicitly indicate that the flags need to be excluded, and fail otherwise.
- Flip the meaning of
verifyFlagsin tx_valid.json to mean excluded verification flags instead of included flags. Edit the test data accordingly. - Trim unneeded flags from tx_invalid.json.
- Add check to verify that tx_valid tests have maximal flags and tx_invalid tests have minimal flags.
- Add checks to verify that flags are soft forks (#10699) i.e. adding any flag should only decrease the number of acceptable scripts. Test by adding/removing random flags.