Some transactions can’t be decoded from hex strings #18028

issue ajtowns openend this issue on January 30, 2020
  1. ajtowns commented at 9:02 am on January 30, 2020: contributor

    While testing #18026 @fanquake had a transient error in rpc_rawtransaction.py where combinerawtransaction failed. The inputs to combinerawtransaction were two partial transactions:

    00200000000010104d5aa747ccd13d493aa4bf33b71752f23ef2c2fcff094d0d35aaa87aa4a0b260000000000ffffffff01c0ac0d0d00000000160014ec9331188271ac1a2629108e3ae0cde4589a0a4a0400473044022035e173a3fe3b7019dc8d4457f588711adf3453ff28df630db0dd720b5ed9fd0e022034b118b826af7f10fd4c197b69ffc0e6391b746f40fdf50f08dc95bf3fd657e1010047522103d23bb22861a28722b924c48169a969aff7d1c2ae121a8c7bbabbfb203acff9032103aee7be172b78cc85b65059408c320a9988a6bdba9580666facc1f4f16ee75ea552ae00000000
    1
    20200000000010104d5aa747ccd13d493aa4bf33b71752f23ef2c2fcff094d0d35aaa87aa4a0b260000000000ffffffff01c0ac0d0d00000000160014ec9331188271ac1a2629108e3ae0cde4589a0a4a040047304402201a91b10bc44d9ad9a0b57fde36ff776585de71e9b4625803d43507589f31c53d02205bb0f42bafe669b6e144d3bdb235b5d3333dc478636a1d1c6ee2e2160ad28f49010047522103d23bb22861a28722b924c48169a969aff7d1c2ae121a8c7bbabbfb203acff9032103aee7be172b78cc85b65059408c320a9988a6bdba9580666facc1f4f16ee75ea552ae00000000
    

    But the first first of these decodes “incorrectly” as:

     0{
     1  "txid": "90839dcde19bb9578ebcdf34ddea1eee5936fb8a17b5b1d36e9e7a1cd2093123",
     2  "hash": "90839dcde19bb9578ebcdf34ddea1eee5936fb8a17b5b1d36e9e7a1cd2093123",
     3  "version": 2,
     4  "size": 231,
     5  "vsize": 231,
     6  "weight": 924,
     7  "locktime": 0,
     8  "vin": [
     9  ],
    10  "vout": [
    11    {
    12      "value": 14269334974.70452737,
    13      "n": 0,
    14      "scriptPubKey": {
    15        "asm": "OP_ADD OP_HASH256 f33b71752f23ef2c2fcff094d0d35aaa87aa4a0b260000000000ffffffff01c0ac0d0d00000000160014ec9331188271ac1a2629108e3ae0cde4589a0a4a0400473044022035e173a3fe3b OP_2OVER dc8d4457f588711adf3453ff28df630db0dd720b5ed9fd0e02 34b118b826af7f10fd4c197b69ffc0e6391b746f40fdf50f08dc95bf3fd657e1 0 522103d23bb22861a28722b924c48169a969aff7d1c2ae121a8c7bbabbfb203acff9032103aee7be172b78cc85b65059408c320a9988a6bdba9580666facc1f4f16ee75ea552ae",
    16        "hex": "93aa4bf33b71752f23ef2c2fcff094d0d35aaa87aa4a0b260000000000ffffffff01c0ac0d0d00000000160014ec9331188271ac1a2629108e3ae0cde4589a0a4a0400473044022035e173a3fe3b7019dc8d4457f588711adf3453ff28df630db0dd720b5ed9fd0e022034b118b826af7f10fd4c197b69ffc0e6391b746f40fdf50f08dc95bf3fd657e1010047522103d23bb22861a28722b924c48169a969aff7d1c2ae121a8c7bbabbfb203acff9032103aee7be172b78cc85b65059408c320a9988a6bdba9580666facc1f4f16ee75ea552ae",
    17        "type": "nonstandard"
    18      }
    19    }
    20  ]
    21}
    

    because the flag gets decoded as “00” - no inputs, “01” - one output, the vin count and the last 15 bytes of the input txid get decoded as the output amount, and the sixteenth last byte of the input txid happens to be 0xd4 and there happen to be that many bytes left prior to the final sequence number, so it decodes successfully as a witlessness transaction, and everything breaks.

    For short transactions (less than 282 bytes or 564 hex digits) that’s a 1-in-256 chance of failure. (For longer transactions it’s a 1-in-16M chance of failure or less, so that’s probably no big deal)

  2. ajtowns added the label Bug on Jan 30, 2020
  3. meshcollider commented at 9:27 am on January 30, 2020: contributor
    Related to #9522 I believe
  4. ajtowns commented at 9:55 am on January 30, 2020: contributor

    Related to #9522 I believe

    Yep, that’s explains why this is much less likely than a 1-in-256 chance. Adding an additional sanity check for tx.vout[i].nValue < 0 || tx.vout[i].nValue > MAX_MONEY would fix the particular case, and reduce the chances of hitting this accidently by another 1-in-10,000.

  5. MarcoFalke commented at 1:41 pm on January 30, 2020: member
    Is this fixed by #17775 ?
  6. MarcoFalke closed this on Aug 4, 2022

  7. bitcoin locked this on Aug 4, 2023

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-10-04 22:12 UTC

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