Title: Same private key, different P2WSH address Post by: vneos on July 09, 2024, 09:38:32 AM Hi all, I'm having problems trying to convert a private key to a P2WSH address.
Using the tool provided on this site: https://secretscan.org/Bech32 (https://secretscan.org/Bech32), the P2WSH address obtained for private key '1' is Code: bc1qpac4ht6afshdx2tctnhjnetz7u6g3j9zhwwmc4cqkdsa2jumq42qd3drf7 But when I use bitcoin core, the address I get using private key '1' is Code: bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3 Why is there this discrepancy? Best regards. Title: Re: Same private key, different P2WSH address Post by: ABCbits on July 09, 2024, 10:04:11 AM I tried reading source code for bitcoinaddress[1], but couldn't understand what kind of redeem script would be generated. But i'm fairly sure that BIP 173 and bitcoinaddress use different redeem script which caused the discrepancy.
[1] https://github.com/fortesp/bitcoinaddress/blob/master/bitcoinaddress/address.py#L130 (https://github.com/fortesp/bitcoinaddress/blob/master/bitcoinaddress/address.py#L130) Title: Re: Same private key, different P2WSH address Post by: vjudeu on July 09, 2024, 11:23:54 AM Code: SHA-256(210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ac)=1863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262 Edit: I thought they are always spendable, but it is worse: they are locked into invalid Script. Code: $ ./bitcoin-cli -testnet decodescript 210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ac Title: Re: Same private key, different P2WSH address Post by: nc50lc on July 10, 2024, 05:09:48 AM Quote from: vneos But when I use bitcoin core, the address I get using private key '1' is This is the correct address which is properly imported to Bitcoin Core,Code: bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3 you probably used this descriptor: wsh(pk(0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798)) pubKey can be replaced by its WIF prvKey pair for non-watching-only wallets. Code: bc1qpac4ht6afshdx2tctnhjnetz7u6g3j9zhwwmc4cqkdsa2jumq42qd3drf7 Which will not work since its redeeem script would be the public key itself. Title: Re: Same private key, different P2WSH address Post by: ABCbits on July 10, 2024, 09:06:53 AM I forget to mention this earlier. If you want to create address based on single private key as spend condition, you better use either P2TR or P2WPKH. Those option have lower input/output size, which means you could pay less fee.
--snip-- Good catch, those website/library doesn't include include 0x21 (which push the 33 byte data) and 0xAC (OP_CHECKSIG). But i didn't expect Bitcoin Core parse the script (which only contain public key) in that way. Title: Re: Same private key, different P2WSH address Post by: pooya87 on July 11, 2024, 11:06:18 AM This highlights the risk of using unpopular tools that aren't reviewed and lack enough tests; or in this case I should say tools that have wrong tests which is worse because it is creating a false sense of correctness!
A quick look at the source code shows their test vector for P2WSH with a single pubkey is wrong as well: https://github.com/fortesp/bitcoinaddress/blob/da9dd65e529600bc7ad0b5427c91bbff533fe773/tests/test_address.py#L20-L21 The correct address is bc1q6gmqnd9x8q40gusftcxw84sjmdszcp3hv0ur3k7aufvjwzw5y77sl2kknp |