Repository navigation
Conversation
AmanBoronbaev
left a comment
There was a problem hiding this comment.
The version check in case 20 fixes the loss of the witness version. Could the regression test assert require.ErrorIs(t, err, address.UnsupportedWitnessProgLenError(20))? With require.Error, a regression that rejects every v1 address during checksum decoding would also pass this case.
The comment above the v1 case could say “this library has no address type for a v1 20-byte program.” A 20-byte program is within the 2–40 byte range for v1 in the BIP 350 reference decoder, even though it does not represent a Taproot output. That distinction matters if DecodeAddress gains support for unknown witness programs later.
245869d to
38c7fc6
Compare
|
Thank you for the review, @AmanBoronbaev! Updated
I also reran the address package tests locally, and all tests passed. |
AmanBoronbaev
left a comment
There was a problem hiding this comment.
Confirmed on 38c7fc6. The v0 control still returns an AddressWitnessPubKeyHash, and the v1 case now checks UnsupportedWitnessProgLenError(20) and a nil address. I ran go test -race -count=1 ./... and go vet ./... in the address module. Both passed.
allocz
left a comment
There was a problem hiding this comment.
Makes sense, as we should not encode p2wpkh programs with bech32m.
In DecodeAddress, case 20 previously returned an AddressWitnessPubKeyHash without checking witnessVer == 0, causing a Bech32m-encoded witness v1 20-byte program to silently downgrade to a v0 P2WPKH address. Reject non-v0 20-byte witness programs with UnsupportedWitnessProgLenError and add a regression test.
38c7fc6 to
f56a445
Compare
Change Description
In
DecodeAddress,case 20previously returned anAddressWitnessPubKeyHashwithout checking
witnessVer == 0. BecausedecodeSegWitAddressacceptsBech32m witness v1+ programs and
DecodeAddressallowswitnessVer == 0 || 1,a Bech32m-encoded witness v1 20-byte program silently decoded as a witness v0
P2WPKH address.
This PR:
case 20inDecodeAddresstowitnessVer == 0and returnsUnsupportedWitnessProgLenError(len(witnessProg))for non-v0 20-bytewitness programs (aligned with BIP-341 / BIP-350).
TestDecodeAddressRejectsWitnessV1TwentyBytePrograminaddress/regression_test.go → address/address_test.gocovering both the positive v0 control and therejected v1 20-byte regression case.
Steps to Test
Pull Request Checklist
Testing
Code Style and Documentation
📝 Please see our Contribution Guidelines for further guidance.