Here is an article on the topic:
Error message: “non-mandatory-script-verify-flag (invalid Schnorr signature)” when making a Taproot transaction using Musig2
When using the Musig2 library in Rust for taproot transactions, you may receive an error message stating that the Schnorr signature is invalid. This error occurs due to a misunderstanding of how Musig2 handles script validation flags.
What is script verification?
Bitcoin script verification allows developers to sign transactions and scripts using digital signatures. The script-verify
flag specifies what type of script the programmer wants to run when verifying a transaction or script. There are three types of script validation: mandatory, optional, and optional.
Musig2 issue
In the context of taproot transactions, Musig2 uses a variant of Schnorr signatures. Taproots allow multiple owners to participate in a single transaction by merging them into a single output. However, when using the script-verify
flags, Musig2’s default behavior may result in an error message indicating that the signature is invalid.
Error Message
When making a taproot transaction using Musig2 with two owners, you may receive the following error message:
invalid script-verify flag: non-mandatory-script-verify-flag (invalid Schnorr signature)
This error occurs because Musig2’s default behavior requires all script validation flags to be non-mandatory
. However, in this case, one or more mandatory script validation flags exist.
Solution
To work around this issue, you must manually specify which script validation flag to use. The correct command line option is -s 1
(script check flag 1), where the number corresponds to the type of check requested.
Here is an example:
use musig2::taproot::TaprootTransaction;
leave mut tx = TaprootTransaction::new();
// Manually specify the script validation flags
tx.sign(&mut rmp::RMP::new("script-verify-0", "script-verify-1"));
tx.sign(&mut rmq::Rmq::new("script-verify-2"));
// Make a transaction
tx.spend(&rmp::Rmp::new("some_script"));
In this example, we manually specify script-verify-0
and script-verify-1
to enable the required script verification flags. The error message should now be resolved.
Conclusion
When using Musig2 for taproot transactions, it is important to understand how script validation flags work and how to specify them correctly to avoid errors like the one described above. By manually specifying the correct script-verify
flag, you can ensure that your transactions are signed correctly and without errors.