signrawtransaction without "amount" creates invalid signature #12429

issue bitcoinhodler opened this issue on February 14, 2018
  1. bitcoinhodler commented at 12:29 AM on February 14, 2018: contributor

    The bitcoin-cli help states that for each "prevtxs", "amount" is a required field. When I use signrawtransaction to do an offline signing of a segwit spend, if I omit this field, instead of an error message, I get an invalid signature.

    Expected behavior

    When I omit the required "amount" field, I expect bitcoin-cli to report an error message. (Perhaps, for backward compatibility, it should only be an error if the amount is actually used in the signature calculation.)

    Actual behavior

    I get a complete, apparently good transaction, but when I attempt to broadcast it using sendrawtransaction, I get the following error:

    64: non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation) (code -26)
    

    When I include amount, I get a good transaction that differs only in the witness signatures for this input.

    To reproduce

    I'm running on my own Linux build of Bitcoin Core from tag v0.16.0rc3.

    This script shows the issue [output]. The first call to signrawtransaction is missing the amount.

  2. fanquake added the label RPC/REST/ZMQ on Feb 14, 2018
  3. jonasschnelli commented at 9:46 AM on February 14, 2018: contributor

    When you provide the amount during an offline signing process with signrawtransaction , I would expect that the outpoint – where you have provided the invalid amount – is not available (because the UTXO set is not present nor do you have wallet unspents). In a such case (complete offline signing), I'd say it's impossible to detect an invalid amount.

  4. bitcoinhodler commented at 8:57 PM on February 14, 2018: contributor

    It's impossible to detect an invalid amount, but it's easy to detect when no amount at all is given, which is what I'm asking for.

  5. bitcoinhodler commented at 9:16 PM on February 14, 2018: contributor

    From bitcoin-cli help signrawtransaction:

    2. "prevtxs"       (string, optional) An json array of previous dependent transaction outputs
         [               (json array of json objects, or 'null' if none provided)
           {
             "txid":"id",             (string, required) The transaction id
             "vout":n,                  (numeric, required) The output number
             "scriptPubKey": "hex",   (string, required) script key
             "redeemScript": "hex",   (string, required for P2SH or P2WSH) redeem script
             "amount": value            (numeric, required) The amount spent
           }
           ,...
        ]
    

    When I fail to provide the other required fields (scriptPubKey, txid, or vout) I get the following:

    error code: -3
    error message:
    Missing txid
    

    Shouldn't amount behave the same way?

  6. Empact referenced this in commit e0a0afb407 on Feb 16, 2018
  7. Empact referenced this in commit 3693cdfeed on Feb 16, 2018
  8. Empact referenced this in commit 4e56afb570 on Feb 16, 2018
  9. Empact referenced this in commit 4351a8c50e on Feb 16, 2018
  10. Empact referenced this in commit 60dc3ca5d2 on Feb 16, 2018
  11. Empact referenced this in commit f948695ece on Mar 1, 2018
  12. Empact referenced this in commit 7b48455141 on Apr 11, 2018
  13. coolmagic commented at 11:04 AM on June 26, 2018: none

    any update on this, I am getting the same

  14. Empact referenced this in commit ac02b0cfbe on Jun 29, 2018
  15. Empact referenced this in commit 177f3201b4 on Jun 29, 2018
  16. Empact referenced this in commit a471cc401a on Jun 29, 2018
  17. Empact referenced this in commit b7104b191a on Jul 9, 2018
  18. Empact referenced this in commit a1636737e6 on Jul 9, 2018
  19. laanwj closed this on Jul 10, 2018

  20. laanwj referenced this in commit fad42e8c4a on Jul 10, 2018
  21. PastaPastaPasta referenced this in commit f5459232f7 on Jul 17, 2020
  22. PastaPastaPasta referenced this in commit 8bacc96f07 on Jun 27, 2021
  23. PastaPastaPasta referenced this in commit 5ecee84163 on Jun 28, 2021
  24. PastaPastaPasta referenced this in commit d1ad6b157f on Jun 29, 2021
  25. MarcoFalke locked this on Sep 8, 2021

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: 2026-04-13 15:15 UTC

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