We currently have two callsites for SCRIPT_ERR_PUBKEYTYPE:
- A pre-tapscript policy error behind the
SCRIPT_VERIFY_STRICTENCflag: https://github.com/bitcoin/bitcoin/blob/4de26b111f4d9b116d0d4930f8bbd69889b3cf75/src/script/interpreter.cpp#L220 - A consensus error in Tapscript: https://github.com/bitcoin/bitcoin/blob/4de26b111f4d9b116d0d4930f8bbd69889b3cf75/src/script/interpreter.cpp#L368
It would be good for readability and testability to have separate errors for both cases, as they are quite distinct (policy vs. consensus, format vs. emptiness).
This PR adds SCRIPT_ERR_TAPSCRIPT_EMPTY_PUBKEY for the consensus error path.
This change would make our error handling more consistent. We have more granular errors for other pubkey error paths already: SCRIPT_ERR_WITNESS_PUBKEYTYPE, SCRIPT_ERR_DISCOURAGE_UPGRADABLE_PUBKEYTYPE. We also have separate errors for MINIMAL_IF: SCRIPT_ERR_MINIMALIF for the policy error pre-tapscript, and SCRIPT_ERR_TAPSCRIPT_MINIMALIF for the consensus error post-tapscript.
Tests:
Added a test case to script_tests and ran build/bin/test_bitcoin --run_test=script_tests --log_level=success.
0test/script_tests.cpp:144: info: check '[["aa","#SCRIPT# 0 CHECKSIG","#CONTROLBLOCK#",0.00000001],"","0x51 0x20 #TAPROOTOUTPUT#","P2SH,WITNESS,TAPROOT","TAPSCRIPT_EMPTY_PUBKEY","TAPSCRIPT: OP_CHECKSIG with empty pubkey must fail"] (with flags 165d5d)' has passed
1...
Ran DIR_UNIT_TEST_DATA="$(pwd)/../qa-assets/unit_test_data" build/bin/test_bitcoin --run_test=script_assets_tests --log_level=success.
Updated feature_taproot.py and ran build/test/functional/feature_taproot.py.
Looking forward to your feedback.