bitcoinjs-lib icon indicating copy to clipboard operation
bitcoinjs-lib copied to clipboard

Stricter validation for Taproot addresses

Open motorina0 opened this issue 3 years ago • 3 comments
trafficstars

I want to ask/clarify if it is OK to add stricter validation rules for taproot addresses. For witness v0 it is checked if the data has a length of 20 or 32, otherwise it is considered an invalid address.

For witness v1 (taproot) such a check is not performed. So a an address of the form bcrt1sw50qt2uwha would be considered valid. Since taproot has been activated on mainnet already and it is known that the data length must be 32 then a check similar to witness v0 can be added. This would prevent loss of funds in case another wallet generates a faulty witness v1 address.

I'm not sure if witness v1 is set in stone or some other types of data will be allowed in the future. Either way, the validation can be relaxed at that point.

The changes include:

  • add if (decodeBech32.version === 1) ... check for toOutputScript()
  • add return payments.p2tr({ output, network }).address as string; to fromOutputScript()
    • after p2tr is merged
  • increase FUTURE_SEGWIT_MIN_VERSION to 2

motorina0 avatar Nov 22 '21 12:11 motorina0

Yes. We will need to do this. Rather than shim some solution in, we should wait on p2tr. I am still debating with myself on how to handle p2tr.

junderw avatar Nov 22 '21 18:11 junderw

do we have an example of, say, v7 valid address..?

Overtorment avatar Dec 05 '21 12:12 Overtorment

nvm, found some test vectors here: https://github.com/bitcoin/bips/blob/edffe529056f6dfd33d8f716fb871467c3c09263/bip-0350.mediawiki#Addresses_for_segregated_witness_outputs (e.g. this one is v16 BC1SW50QGDZ25J)

Overtorment avatar Dec 05 '21 13:12 Overtorment