Miniscript was targeting P2WSH, and as such can currently only be used in wsh()
descriptors. This pull request introduces support for Tapscript in Miniscript and makes Miniscript available inside tr()
descriptors. It adds support for both watching and signing TapMiniscript descriptors.
The main changes to Miniscript for Tapscript are the following:
- A new
multi_a
fragment is introduced with the same semantics asmulti
. Like in other descriptorsmulti
andmulti_a
can exclusively be used in respectively P2WSH and Tapscript. - The
d:
fragment has theu
property under Tapscript, since theMINIMALIF
rule is now consensus. See also #24906. - Keys are now serialized as 32 bytes. (Note this affects the key hashes.)
- The resource consumption checks and calculation changed. Some limits were lifted in Tapscript, and signatures are now 64 bytes long.
The largest amount of complexity probably lies in the last item. Scripts under Taproot can now run into the maximum stack size while executing a fragment. For instance if you’ve got a stack size of 999
due to the initial witness plus some execution that happened before and try to execute a hash256
it would DUP
(increasing the stack size 1000
), HASH160
and then push the hash on the stack making the script fail.
To make sure this does not happen on any of the spending paths of a sane Miniscript, we introduce a tracking of the maximum stack size during execution of a fragment. See the commits messages for details. Those commits were separated from the resource consumption change, and the fuzz target was tweaked to sometimes pad the witness so the script runs on the brink of the stack size limit to make sure the stack size was not underestimated.
Existing Miniscript unit, functional and fuzz tests are extended with Tapscript logic and test cases. Care was taken for seed stability in the fuzz targets where we cared more about them.
The design of Miniscript for Tapscript is the result of discussions between various people over the past year(s). To the extent of my knowledge at least Pieter Wuille, Sanket Kanjalkar, Andrew Poelstra and Andrew Chow contributed thoughts and ideas.