Title: Generate P2WSH - redeemScript does not correspond to witnessScript Post by: barno on March 31, 2020, 02:39:51 PM I want to generate P2WSH to study it. I read the spec https://bitcoincore.org/en/segwit_wallet_dev/#creation-of-p2sh-p2wsh-address but I have an error during spend it. (redeemScript does not correspond to witnessScript)
I create a bash script to generate private and public key, and I will report only the part to create redeem script etc. Public key Code: 02aa31bcc43d302bd217761e3268b3fde67078a8ddcb157517f9c69633f5f9e214 Witness script Code: SCRIPT="76a9"$PBLENGTH$PBH"88AC" Create Script Hash, use sha256 once Code: ADDR_SHA=`printf $SCRIPT | xxd -r -p | openssl sha256| sed 's/^.* //'` Create redeem script (i.e. 0x0020{32-byte scripthash}) Code: REDEEMSCRIPT="0020"$ADDR_SHA Create SCRIPTPUBKEY (OP_HASH160 hash160(redeemScript) OP_EQUAL) where hash160 is Sha256 and ripemd160 Code: ADDR_160=$(printf $(printf $REDEEMSCRIPT | xxd -r -p | openssl sha256| sed 's/^.* //') | xxd -r -p | openssl ripemd160 | sed 's/^.* //') Create Address (regtest, prefix is C4) Code: ADDR=`printf $VERSION_PREFIX_ADDRESS$ADDR_160 | xxd -p -r | base58 -c` Then I create a transaction from this address to anther address. I have 50 bitcoin available. Code:
At that moment I have this error redeemScript does not correspond to witnessScript TX_DATA: Code: { UTXO Code: $ bitcoin-cli getrawtransaction 4de43b38df24ff350ac9821637ea8996fa33d20aa99677b86918f577697a3e15 2 Title: Re: Generate P2WSH - redeemScript does not correspond to witnessScript Post by: achow101 on March 31, 2020, 05:04:58 PM It looks like you've run into a bug in Bitcoin Core
Specifically, for historical reasons, Bitcoin Core will sometimes automatically convert P2PKH scripts into P2WPKH outputs when doing segwit stuff. So what happened is that when it checks whether the redeemScript matches the witnessScript, it mistakenly computes the P2WPKH script for your P2PKH witnessScript instead of the P2WSH script that you are expecting. This causes a mismatch and the error. You could try omitting the redeemScript field from your call to signrawtransactionwithkey but it may fail to sign then. I've opened a PR (https://github.com/bitcoin/bitcoin/pull/18484) to fix this. Title: Re: Generate P2WSH - redeemScript does not correspond to witnessScript Post by: barno on April 01, 2020, 03:39:55 PM It looks like you've run into a bug in Bitcoin Core Specifically, for historical reasons, Bitcoin Core will sometimes automatically convert P2PKH scripts into P2WPKH outputs when doing segwit stuff. So what happened is that when it checks whether the redeemScript matches the witnessScript, it mistakenly computes the P2WPKH script for your P2PKH witnessScript instead of the P2WSH script that you are expecting. This causes a mismatch and the error. You could try omitting the redeemScript field from your call to signrawtransactionwithkey but it may fail to sign then. I've opened a PR (https://github.com/bitcoin/bitcoin/pull/18484) to fix this. Thanks for reply. I tried to omit the redeem script Code: $ bitcoin-cli signrawtransactionwithkey $TX_DATA '["'$PK'"]' '[{"txid":"'$TXID'","vout":'$VOUT',"scriptPubKey":"'$SCRIPTPUBKEY'","witnessScript":"'$WITNESSCRIPT'","amount":"'$TOTAL_UTXO_AMOUNT'"}]' But I get the same error Title: Re: Generate P2WSH - redeemScript does not correspond to witnessScript Post by: barno on April 13, 2020, 09:24:36 PM I create another script P2SH-P2WSH wrap P2PK and I get the same error.
Code: $ cat compressed_public_key_1.txt Create transaction and sign it Code: $ TX_DATA=$(bitcoin-cli createrawtransaction '[{"txid":"'$TXID'","vout":'$VOUT'}]' '[{"'$ADDR_DEST'":'$AMOUNT'}]') I don't try with custom script yet Title: Re: Generate P2WSH - redeemScript does not correspond to witnessScript Post by: achow101 on April 13, 2020, 10:14:40 PM That is also expected due to this bug. The fix for the bug has been merged and will be available with 0.20.0. Once that is released, you should be able to sign your transactions.
Title: Re: Generate P2WSH - redeemScript does not correspond to witnessScript Post by: barno on April 14, 2020, 06:52:55 AM Yes I saw the PR!
I thought that another example should be interest to understand the bug ;) Title: Re: Generate P2WSH - redeemScript does not correspond to witnessScript Post by: BTCW on July 13, 2020, 03:39:18 PM Yes I saw the PR! I thought that another example should be interest to understand the bug ;) I too have a redeemscript problem that I'm trying to figure out. Did you ever sort yours? Does yours work in 0.20 as expected? My question is about P2SH and not P2WSH, but I think we have things in common. Check it out if you have the time, thanks: https://bitcointalk.org/index.php?topic=5261766 |