Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
GregTonoski opened this issue Feb 1, 2023 · 5 comments

Comments

@GregTonoski
Copy link

GregTonoski commented Feb 1, 2023

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

{
  "hex": "0200000001a2c0d82460883696219dbca6f545f72963b2b3ee085d832eb5ef9a69a374af160000000000fdffffff01e011000000000000225120052e44f45a6e381be8e06d3f3362b58034a68ba98081e24de7bfc5795420a90b00000000",
  "complete": false,
  "errors": [
    {
      "txid": "16af74a3699aefb52e835d08eeb3b26329f745f5a6bc9d219636886024d8c0a2",
      "vout": 0,
      "witness": [
      ],
      "scriptSig": "",
      "sequence": 4294967293,
      "error": "Witness program was passed an empty witness"
    }
  ]
}

To reproduce


$ 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"}]'

@willcl-ark
Copy link
Member

The output of help signrawtransactionwithkey states:

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

You pass as the prevtxs argument:

[
  {
    "txid": "3152ecd0e7acc80b6f47a32276cb6137a2de7cee428c9388e6a4a1817b665711",
    "vout": 0,
    "scriptPubKey": "5120c38859777bc9c3294d3587035fc3823a146dabaab1fa250bc04e92f16887a065",
    "amount": 0.00004242
  }
]

And the error message states that:

"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?

I could not replicate your success behaviour after importing the descriptor:
will@ubuntu in …/src/bitcoin/src on  master [$?⇕] via C v12.2.0-gcc
₿ bitcoin-cli -regtest importdescriptors '[{"desc": "tr(cUTFbLPUaBAPmTKwjcDs4rWHUSEUbUBfkPMogrbTmQFnJA3vgrLE)#tdkpah70", "timestamp": "now"}]'
[
  {
    "success": true
  }
]

will@ubuntu in …/src/bitcoin/src on  master [$?⇕] via C v12.2.0-gcc
₿ bitcoin-cli -regtest signrawtransactionwithkey "02000000011157667b81a1a4e688938c42ee7cdea23761cb7622a3476f0bc8ace7d0ec523100000000000000000001e8030000000000002251203b82b2b2a9185315da6f80da5f06d0440d8a5e1457fa93387c2d919c86ec878600000000" '["cUTFbLPUaBAPmTKwjcDs4rWHUSEUbUBfkPMogrbTmQFnJA3vgrLE"]' '[{"txid": "3152ecd0e7acc80b6f47a32276cb6137a2de7cee428c9388e6a4a1817b665711", "vout": 0, "scriptPubKey": "5120c38859777bc9c3294d3587035fc3823a146dabaab1fa250bc04e92f16887a065", "amount": 0.00004242}]' "DEFAULT"
{
  "hex": "02000000011157667b81a1a4e688938c42ee7cdea23761cb7622a3476f0bc8ace7d0ec523100000000000000000001e8030000000000002251203b82b2b2a9185315da6f80da5f06d0440d8a5e1457fa93387c2d919c86ec878600000000",
  "complete": false,
  "errors": [
    {
      "txid": "3152ecd0e7acc80b6f47a32276cb6137a2de7cee428c9388e6a4a1817b665711",
      "vout": 0,
      "witness": [
      ],
      "scriptSig": "",
      "sequence": 0,
      "error": "Witness program was passed an empty witness"
    }
  ]
}

@GregTonoski
Copy link
Author

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"}]'

@achow101
Copy link
Member

achow101 commented Feb 21, 2023

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.

@bitcoin bitcoin deleted a comment from mauri146K Mar 4, 2023
@pinheadmz
Copy link
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.

@GregTonoski
Copy link
Author

Seems to be fixed in 26.0. Thanks.

Example:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants
@pinheadmz @achow101 @maflcko @willcl-ark @GregTonoski and others