examples icon indicating copy to clipboard operation
examples copied to clipboard

feat(schnorr,bitcoin): CRP-2533 add taproot transactions and improvements

Open altkdf opened this issue 1 year ago • 1 comments

This PR adds pay-to-taproot (P2TR) transactions to the basic_bitcoin example (see the modified README.md for more details):

  • P2TR raw key spend: this address is the encoded untweaked public key. IMPORTANT: this type of address is INSECURE to use with more than one signer, i.e., with multisignatures.
  • P2TR script spend: in this case, the MAST contains exactly one script allowing to spend with exactly one key.

Note that those addresses are mutually exclusive, i.e. a P2TR raw key address cannot be used for alternatively spending with scripts and vice versa. This is not a technical limitation but a limitation of the current API. The API will likely be extended to support alternative paths if there will be a reasonable use case.

This PR also implements small improvements like more precise fee computation based on transaction weight instead of serialized transaction, better code structure to accommodate P2TR, simplifications in the code where the bitcoin crate implements whatever was implemented in basic_bitcoin, updated bitcoin crate dependency, etc.

Notice that the motoko example is not modified in this PR but will be in another PR. The reason for the delay is the non-negligible implementation effort due to the complexity of P2TR.

altkdf avatar Jul 05 '24 17:07 altkdf

To test this canister, I deployed it on om77v-qqaaa-aaaap-ahmrq-cai with the Schnorr API implemented by the mock canister 6fwhw-fyaaa-aaaap-qb7ua-cai.

Bitcoin Testnet Addresses

P2pkh mot21Ef7HNDpDJa4CBzt48WpEX7AxNyaqx

key spend tb1pkkrwg6e9s5zf3jmftu224rc5ppax26g5yzdg03rhmqw84359xgpsv5mn2y

script spend tb1pnm743sjkw9tq3zf9uyetgqkrx7tauthmxnsl5dtyrwnyz9r7lu8qdtcnnc

Transactions

p2tr, script -> key:

(3->2 spend) Blockstream Block Explorer

p2tr, key -> p2pkh:

(2->2 spend) Blockstream Block Explorer

Blockstream Block Explorer

(2->2 spend) Blockstream Block Explorer

p2pkh -> pt2r script:

(2->2 spend) Blockstream Block Explorer

Errors

There was exactly one “exceeded instruction limit“ error in p2tr key path spending, but I’m not sure what this was and why, currently. Otherwise no errors.

altkdf avatar Jul 05 '24 18:07 altkdf