signrawtransactionwithkey command shouldn’t output the “Witness program was passed an empty witness” error for a TapRoot transaction #27017

issue GregTonoski openend this issue on February 1, 2023
  1. GregTonoski commented at 4:27 pm on February 1, 2023: none

    There is the irrelevant error message output by the signrawtransactionwithkey command.

    Expected behavior

    Hex string of the raw transaction with signature OR meaningful message about an alternative way to achieve one.

    Actual behavior

     0{
     1  "hex": "0200000001a2c0d82460883696219dbca6f545f72963b2b3ee085d832eb5ef9a69a374af160000000000fdffffff01e011000000000000225120052e44f45a6e381be8e06d3f3362b58034a68ba98081e24de7bfc5795420a90b00000000",
     2  "complete": false,
     3  "errors": [
     4    {
     5      "txid": "16af74a3699aefb52e835d08eeb3b26329f745f5a6bc9d219636886024d8c0a2",
     6      "vout": 0,
     7      "witness": [
     8      ],
     9      "scriptSig": "",
    10      "sequence": 4294967293,
    11      "error": "Witness program was passed an empty witness"
    12    }
    13  ]
    14}
    

    To reproduce

    0
    1$ signrawtransactionwithkey "02000000011157667b81a1a4e688938c42ee7cdea23761cb7622a3476f0bc8ace7d0ec523100000000000000000001e8030000000000002251203b82b2b2a9185315da6f80da5f06d0440d8a5e1457fa93387c2d919c86ec878600000000" '["cUTFbLPUaBAPmTKwjcDs4rWHUSEUbUBfkPMogrbTmQFnJA3vgrLE"]' '[{"txid": "3152ecd0e7acc80b6f47a32276cb6137a2de7cee428c9388e6a4a1817b665711", "vout": 0, "scriptPubKey": "5120c38859777bc9c3294d3587035fc3823a146dabaab1fa250bc04e92f16887a065", "amount": 0.00004242}]' "DEFAULT"
    

    System information

    Console in Bitcoin Core 24.0.1 portable, Windows 11. (Occurs in both cases of a descriptor wallet loaded and not loaded). Hint: signrawtransactionwithwallet works fine if preceded with the importdescriptors ‘[{“desc”: “tr(cUTFbLPUaBAPmTKwjcDs4rWHUSEUbUBfkPMogrbTmQFnJA3vgrLE)#tdkpah70”, “timestamp”: “now”}]’

  2. GregTonoski added the label Bug on Feb 1, 2023
  3. maflcko added the label RPC/REST/ZMQ on Feb 2, 2023
  4. willcl-ark commented at 1:16 pm on February 20, 2023: contributor

    The output of help signrawtransactionwithkey states:

     03. prevtxs                          (json array, optional) The previous dependent transaction outputs
     1     [
     2       {                            (json object)
     3         "txid": "hex",             (string, required) The transaction id
     4         "vout": n,                 (numeric, required) The output number
     5         "scriptPubKey": "hex",     (string, required) script key
     6         "redeemScript": "hex",     (string) (required for P2SH) redeem script
     7         "witnessScript": "hex",    (string) (required for P2WSH or P2SH-P2WSH) witness script
     8         "amount": amount,          (numeric or string) (required for Segwit inputs) the amount spent
     9       },
    10       ...
    11     ]
    

    You pass as the prevtxs argument:

    0[
    1  {
    2    "txid": "3152ecd0e7acc80b6f47a32276cb6137a2de7cee428c9388e6a4a1817b665711",
    3    "vout": 0,
    4    "scriptPubKey": "5120c38859777bc9c3294d3587035fc3823a146dabaab1fa250bc04e92f16887a065",
    5    "amount": 0.00004242
    6  }
    7]
    

    And the error message states that:

    0"error": "Witness program was passed an empty witness"
    

    Assuming that txid: 3152ecd0e7acc80b6f47a32276cb6137a2de7cee428c9388e6a4a1817b665711 is a V1 P2TR output, then it will need a valid witnessScript element to be supplied to avoid hitting the returned script error..

    If using the key path to spend theoutput can be spent with the secret key corresponding to the internal_pubkey using a witness stack consisting of a single element: a BIP340 signature on the signature hash.

    What error message would you consider to be more appropriate here?

     0will@ubuntu in …/src/bitcoin/src on  master [$?] via C v12.2.0-gcc
     1₿ bitcoin-cli -regtest importdescriptors '[{"desc": "tr(cUTFbLPUaBAPmTKwjcDs4rWHUSEUbUBfkPMogrbTmQFnJA3vgrLE)#tdkpah70", "timestamp": "now"}]'
     2[
     3  {
     4    "success": true
     5  }
     6]
     7
     8will@ubuntu in …/src/bitcoin/src on  master [$?] via C v12.2.0-gcc
     9₿ bitcoin-cli -regtest signrawtransactionwithkey "02000000011157667b81a1a4e688938c42ee7cdea23761cb7622a3476f0bc8ace7d0ec523100000000000000000001e8030000000000002251203b82b2b2a9185315da6f80da5f06d0440d8a5e1457fa93387c2d919c86ec878600000000" '["cUTFbLPUaBAPmTKwjcDs4rWHUSEUbUBfkPMogrbTmQFnJA3vgrLE"]' '[{"txid": "3152ecd0e7acc80b6f47a32276cb6137a2de7cee428c9388e6a4a1817b665711", "vout": 0, "scriptPubKey": "5120c38859777bc9c3294d3587035fc3823a146dabaab1fa250bc04e92f16887a065", "amount": 0.00004242}]' "DEFAULT"
    10{
    11  "hex": "02000000011157667b81a1a4e688938c42ee7cdea23761cb7622a3476f0bc8ace7d0ec523100000000000000000001e8030000000000002251203b82b2b2a9185315da6f80da5f06d0440d8a5e1457fa93387c2d919c86ec878600000000",
    12  "complete": false,
    13  "errors": [
    14    {
    15      "txid": "3152ecd0e7acc80b6f47a32276cb6137a2de7cee428c9388e6a4a1817b665711",
    16      "vout": 0,
    17      "witness": [
    18      ],
    19      "scriptSig": "",
    20      "sequence": 0,
    21      "error": "Witness program was passed an empty witness"
    22    }
    23  ]
    24}
    
  5. GregTonoski commented at 8:54 am on February 21, 2023: none

    I could not replicate your success behaviour after importing the descriptor:

    The success behaviour is different from the not-replicated one:

    Hint: signrawtransactionwithwallet works fine if preceded with the importdescriptors ‘[{“desc”: “tr(cUTFbLPUaBAPmTKwjcDs4rWHUSEUbUBfkPMogrbTmQFnJA3vgrLE)#tdkpah70”, “timestamp”: “now”}]’

  6. achow101 commented at 5:52 pm on February 21, 2023: member

    signrawtransactionwithkey does not currently support taproot (and it is not clear whether it ever will) as there is not enough information provided with just a private key in order to be able to sign such transactions.

    The raw transaction workflow is basically deprecated in favor of using PSBTs. Signing with just keys is also basically deprecated in favor of using descriptors.

  7. bitcoin deleted a comment on Mar 4, 2023
  8. pinheadmz commented at 1:55 pm on April 27, 2023: member
    This issue is unlikely to be fixed in Bitcoin Core. We’ll close for now, but feel free to open another issue or pull request with a fix.
  9. pinheadmz closed this on Apr 27, 2023

  10. GregTonoski commented at 8:27 pm on December 21, 2023: none

    Seems to be fixed in 26.0. Thanks.

    Example:

    0./bitcoin-cli.exe -testnet signrawtransactionwithkey 020000000165ef750aac862b0177cadb77961bf1a936e2bec0376b286f5b4e1b6255cf3a960000000000fdffffff012c1a0000000000002251203b82b2b2a9185315da6f80da5f06d0440d8a5e1457fa93387c2d919c86ec878600000000 '["cV628xvqToz45dwdPmTcJ9RgEVnWMwP8dpZBGzb9LfTk3sBHFNwc"]' '[{"txid":"963acf55621b4e5b6f286b37c0bee236a9f11b9677dbca77012b86ac0a75ef65","vout":0,"scriptPubKey":"512055355ca83c973f1d97ce0e3843c85d78905af16b4dc531bc488e57212d230116","amount":0.00008000}]'
    1{
    2  "hex": "0200000000010165ef750aac862b0177cadb77961bf1a936e2bec0376b286f5b4e1b6255cf3a960000000000fdffffff012c1a0000000000002251203b82b2b2a9185315da6f80da5f06d0440d8a5e1457fa93387c2d919c86ec87860140308269219d1226be9f9da12d9a816e56fc6fb8f51c987c21c286687dfada7174c2070a8f18c475bca939ba2dd3c5af8762cfddd0dac190ed1dfbc51eb060763a00000000",
    3  "complete": true
    4}
    

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-06-29 07:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me