Bitcoin Forum
May 03, 2024, 12:07:19 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Bitcoin / Bitcoin Technical Support / Constructing raw P2WSH by hand: witnessScript does not match scriptPubKey on: September 02, 2020, 07:01:12 PM
I've been trying to create and spend from a P2WSH transaction, for learning purposes, and have been unable to construct a correct spending transaction.

Here are all my steps, starting from a fresh wallet :
1. Get wallet address, public key, and private key, mine some blocks to it:
Code:
ADRESS=bitcoin-cli getnewaddress
PUBKEY=parse(bitcoin-cli getaddressinfo $ADRESS) //gets result.pubkey from command result
PRIVKEY=bitcoin-cli dumpprivkey $ADDRESS
bitcoin-cli dumpprivkey $ADDRESS

2. Grab an unspent output from "bitcoin-cli listunspent" and create a P2WSH output transaction:
Code:
UTX= //grab here
TX=bitcoin-tx -create in=$UTX:0 outscript=49.99:"0x21 0x$PUBKEY OP_CHECKSIGVERIFY":W

3. Sign and broadcast:
Code:
bitcoin-cli signrawtransactionwithkey "$TX" '["$PRIVKEY"]'
NEWTX=bitcoin-cli sendrawtransaction [/* the hex from the output of the above command */]

4. Create a transaction spending from NEWTX (still sending to myself):
Code:
SECONDTX=bitcoin-tx -create in=$NEWTX:0 outscript=49.98:"0x21 0x$PUBKEY OP_CHECKSIGVERIFY":W

5. Attempt to sign it:
Code:
SERIALISEDSCRIPT=//serialse it into 21$PUBKEYad - verify with bitcoin-cli decodescript
bitcoin-cli signrawtransactionwithkey $SECONDTX '["$PRIVKEY"]' '[{"txid": "$NEWTX", "vout": 0, "scriptPubKey": "/* the scriptpubkey from NEWTX */", "witnessScript":"$SERIALISEDSCRIPT", "amount": 49.99}]'

At this point I'm getting the error
Code:
redeemScript/witnessScript does not match scriptPubKey
.

I cannot figure out why it wouldn't match. My serialisation would be the obvious culprit, but decodescript confirms it is correct. I have found https://bitcointalk.org/index.php?topic=5236818.0, but that bug was apparently fixed in Bitcoin Core 0.20, and I am on the latest release (0.20.1).

Any pointers would be greatly appreciated.

Here's the standard support template, if necessary:
Bitcoin Client Software and Version Number: 0.20.1
Operating System: Linux 64-bit
System Hardware Specs: N/A
Description of Problem: See above
Any Related Addresses: N/A (regtest network)
Any Related Transaction IDs: N/A
Screenshot of the problem: N/A
Log Files from the Bitcoin Client: N/A
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!