Backport of Bitcoin ABC D8835.
Test plan: src/bench/bench_bitcoin -filter=VerifyNestedIfScript
src/bench/bench_bitcoin -filter=VerifyNestedIfScript