I’d like to improve the Taproot control size check in IsWitnessStandard. Rather than just checking emptiness, we should perform all three checks implemented in VerifyTaprootControlBlockSize (see below). This way we can invalidate the transaction earlier when it’s clear that the control size is incompatible with consensus rules (saving compute).
Old checks:
control.size() > 0
New checks:
control.size() >= TAPROOT_CONTROL_BASE_SIZEcontrol.size() <= TAPROOT_CONTROL_MAX_SIZE(control.size() - TAPROOT_CONTROL_BASE_SIZE) % TAPROOT_CONTROL_NODE_SIZE == 0
For example, a single byte control block wouldn’t be empty, but it would be invalid because it’s shorter than TAPROOT_CONTROL_BASE_SIZE (33).
429aed9 is the behavioral change (just one LOC).
d7bbd8d adds the VerifyTaprootControlBlockSize helper function without changing behavior. I have a separate PR out with only that change: #34139.
I ran:
cmake -B build -DENABLE_WALLET=OFF && cmake --build build -j 8 && ctest --test-dir build -j 8
Looking forward to your feedback.