rpc: fundrawtransaction would create a TX with incorrect fee #16242

issue web3shannon opened this issue on June 19, 2019
  1. web3shannon commented at 9:39 AM on June 19, 2019: contributor

    This bug was found when I try to use fundrawtransaction to add inputs to an Atomic Swap TX. There are a lot of opcodes in the TX, which look like:

    "vout": [
        {
          "value": 100.00000000,
          "n": 0,
          "scriptPubKey": {
          "asm": "OP_IF 2 032f3c19a70214f1cc4adb09f9c2fbd97b42c739003b6d7f45b8d1387566fd978b 02e8cc90cad5436865e869bc78bf06af0a662c0542e313be1a4392ce905b75d7bc 2 OP_CHECKMULTISIG OP_ELSE 2485 OP_CHECKLOCKTIMEVERIFY OP_DROP 039787806b54b82d29de040ff7009f5afcbd56ee4f7fb863557eca57cad4d71a43 OP_CHECKSIG OP_ENDIF",
          ...
        }
        ...
    ]
    

    These opcodes are not considered in fundrawtransaction when calculating nBytes. So nBytes and the corresponding nFeeNeeded would get a relatively low value.

    https://github.com/bitcoin/bitcoin/blob/44d81723236114f9370f386f3b3310477a6dde43/src/wallet/wallet.cpp#L2996

    https://github.com/bitcoin/bitcoin/blob/44d81723236114f9370f386f3b3310477a6dde43/src/wallet/wallet.cpp#L1764

    But when I use sendrawtransaction to send the TX. It will take these opcodes into consideration when calculating nSize. nSize has a relatively high value, so the TX can't pass the relay fee check and sendrawtransaction returns "min relay fee not met".

    https://github.com/bitcoin/bitcoin/blob/44d81723236114f9370f386f3b3310477a6dde43/src/validation.cpp#L584

    https://github.com/bitcoin/bitcoin/blob/44d81723236114f9370f386f3b3310477a6dde43/src/txmempool.cpp#L52

    This is the first time I know the opcodes should be considered in the calculation of transaction fee. But when I go through all the calls of function GetVirtualTransactionSize, I find some pass nSigOpCost into it but some don't. It's weird and I can't figure it out.

  2. fanquake added the label RPC/REST/ZMQ on Jun 19, 2019
  3. sipa commented at 10:13 AM on June 19, 2019: member

    fundrawtransaction cannot possibly estimate how many bytes are needed to spend outputs it does not understand. The best we can do here is improve the messaging (e.g. show a warning or error when this is the case).

  4. web3shannon commented at 10:38 AM on June 19, 2019: contributor

    I didn't mention "spend output". I mean, the TX generated by fundrawtransaction can not be sendrawtransaction in some cases. 😂

  5. MarcoFalke commented at 1:00 PM on June 19, 2019: member

    Could you add steps to reproduce, so that readers of this issue don't have to recreate your use case from scratch?

  6. MarcoFalke commented at 4:17 PM on April 26, 2020: member

    Is this still an issue with a recent version of Bitcoin Core? If yes, what are the steps to reproduce?

  7. MarcoFalke closed this on Apr 26, 2020

  8. DrahtBot locked this on Feb 15, 2022

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:14 UTC

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