Bitcoin Forum
May 06, 2024, 12:45:45 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: P2WSH Bitcoin Core Witness Script Empty Error  (Read 91 times)
Talkist (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 12


View Profile
December 05, 2023, 01:46:26 PM
Merited by pooya87 (4), LoyceV (4), o_e_l_e_o (4)
 #1

I am trying to spend a P2WSH output. Here are the steps I have taken:

I have created a P2WSH output via bitcoin-cli. These are the details of the P2WSH output:
Code:
Type
V0_P2WSH
scriptPubKey (asm)
OP_0 OP_PUSHBYTES_32 a2b95877500eb4180401640c5649c55ce578584f865e4f1609f9971ca19d6f40
scriptPubKey (hex)
0020a2b95877500eb4180401640c5649c55ce578584f865e4f1609f9971ca19d6f40
Spending tx
Unspent

You can also view it here: https://blockstream.info/testnet/tx/3010534df31914f938014d34d0bd402ce1a741a46624b28abcfd2462126331a5?expand

In order to spend that output, I am first creating a transaction via bitcoin-cli as such:

Code:
bitcoin-cli createrawtransaction [{\"txid\":\"3010534df31914f938014d34d0bd402ce1a741a46624b28abcfd2462126331a5\",\"vout\":0}] [{\"tb1q77vr56qx6y5vs2zzt9qc85ge62j30r6vaccfxl\":0.0000007}]

This outputs the following serialization:

Code:
0200000001a53163126224fdbc8ab22466a441a7e12c40bdd0344d0138f91419f34d5310300000000000fdffffff014600000000000000160014f7983a6806d128c82842594183d119d2a5178f4c00000000

I now try to sign the message:

Code:
bitcoin-cli signrawtransactionwithwallet "0200000001a53163126224fdbc8ab22466a441a7e12c40bdd0344d0138f91419f34d5310300000000000fdffffff014600000000000000160014f7983a6806d128c82842594183d119d2a5178f4c00000000" [{\"txid\":\"3010534df31914f938014d34d0bd402ce1a741a46624b28abcfd2462126331a5\",\"vout\":0,\"scriptPubKey\":\"0020a2b95877500eb4180401640c5649c55ce578584f865e4f1609f9971ca19d6f40\",\"witnessScript\":\"4c02efef754c14f7983a6806d128c82842594183d119d2a5178f4cac\",\"amount\":0.0000007}]

This does not work however, as I always get the following error:

Code:
{
  "hex": "0200000001a53163126224fdbc8ab22466a441a7e12c40bdd0344d0138f91419f34d5310300000000000fdffffff014600000000000000160014f7983a6806d128c82842594183d119d2a5178f4c00000000",
  "complete": false,
  "errors": [
    {
      "txid": "3010534df31914f938014d34d0bd402ce1a741a46624b28abcfd2462126331a5",
      "vout": 0,
      "witness": [
      ],
      "scriptSig": "",
      "sequence": 4294967293,
      "error": "Witness program was passed an empty witness"
    }
  ]
}

I do not understand why I receive a Witness program was passed an empty witness error, as I am explicitly passing a witness script in the command line. Is there a bug or what am I missing?

The witness script that was hashed is
Code:
OP_PUSHDATA1 EFEF OP_DROP OP_PUSHDATA1 f7983a6806d128c82842594183d119d2a5178f4c OP_CHECKSIG
which serializes to
Quote
4c02EFEF754c14f7983a6806d128c82842594183d119d2a5178f4cac

I have been told this transaction is non standart but I thought the (witness) redeem can be chosen freely?

Thanks for any help.
1714999545
Hero Member
*
Offline Offline

Posts: 1714999545

View Profile Personal Message (Offline)

Ignore
1714999545
Reply with quote  #2

1714999545
Report to moderator
Even in the event that an attacker gains more than 50% of the network's computational power, only transactions sent by the attacker could be reversed or double-spent. The network would not be destroyed.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714999545
Hero Member
*
Offline Offline

Posts: 1714999545

View Profile Personal Message (Offline)

Ignore
1714999545
Reply with quote  #2

1714999545
Report to moderator
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3388
Merit: 6581


Just writing some code


View Profile WWW
December 05, 2023, 11:51:48 PM
Merited by pooya87 (2), ABCbits (1)
 #2

Bitcoin Core doesn't know how to sign non-standard scripts. Script is not easy to analyze, so Bitcoin Core sticks to specific templates and patterns that it can analyze. Your script does not follow any of those patterns, so it is unable to produce any valid signatures. Furthermore, since it doesn't recognize the script, it will not place it in the witness. Thus the transaction you get after using signrawtransactionwithwallet is completely unsigned, and in fact, identical to what you passed in.

pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10550



View Profile
December 06, 2023, 06:48:35 AM
 #3

Code:
OP_PUSHDATA1 EFEF OP_DROP OP_PUSHDATA1 f7983a6806d128c82842594183d119d2a5178f4c OP_CHECKSIG

FWIW you don't need to push data smaller than 76 bytes using OP_PUSHDATA1 since it is wasteful. All you need to do is to use the size itself, which means using 0x02 and 0x14 instead of 0x4c02 and 0x4c14 respectively for the two data pushes which saves 2 bytes.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Talkist (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 12


View Profile
December 06, 2023, 03:09:08 PM
 #4

Quote
Bitcoin Core doesn't know how to sign non-standard scripts. Script is not easy to analyze, so Bitcoin Core sticks to specific templates and patterns that it can analyze. Your script does not follow any of those patterns, so it is unable to produce any valid signatures. Furthermore, since it doesn't recognize the script, it will not place it in the witness. Thus the transaction you get after using signrawtransactionwithwallet is completely unsigned, and in fact, identical to what you passed in.

Thanks, noted. Does this mean every unlocking script in a P2WSH transaction is non-standard? If yes, does this mean P2WSH redeem scripts are not broadcasted by every client that only broadcasts standard transactions?

Quote
FWIW you don't need to push data smaller than 76 bytes using OP_PUSHDATA1 since it is wasteful. All you need to do is to use the size itself, which means using 0x02 and 0x14 instead of 0x4c02 and 0x4c14 respectively for the two data pushes which saves 2 bytes.

Thanks for the tip. Noted.
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3388
Merit: 6581


Just writing some code


View Profile WWW
December 06, 2023, 03:43:02 PM
 #5

Quote
Bitcoin Core doesn't know how to sign non-standard scripts. Script is not easy to analyze, so Bitcoin Core sticks to specific templates and patterns that it can analyze. Your script does not follow any of those patterns, so it is unable to produce any valid signatures. Furthermore, since it doesn't recognize the script, it will not place it in the witness. Thus the transaction you get after using signrawtransactionwithwallet is completely unsigned, and in fact, identical to what you passed in.

Thanks, noted. Does this mean every unlocking script in a P2WSH transaction is non-standard? If yes, does this mean P2WSH redeem scripts are not broadcasted by every client that only broadcasts standard transactions?
No, nodes do not inspect the contents of redeem or witness scripts for standardness checks.

Perhaps a better term would be "well known script template".

Talkist (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 12


View Profile
December 14, 2023, 03:48:25 PM
 #6

Thanks guys! Thanks to your direction I managed to sign it myself and now have my first transaction of the type indicated
that I signed myself. I am happy!

Without you I couldn't have done it!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!