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

Unsigned transactions cannot be parsed by bitcoind #129

Open
jasonbcox opened this issue Sep 3, 2021 · 5 comments
Open

Unsigned transactions cannot be parsed by bitcoind #129

jasonbcox opened this issue Sep 3, 2021 · 5 comments

Comments

@jasonbcox
Copy link

Steps to reproduce

  1. Setup a transaction in ElectrumABC
  2. Preview the transaction (do not sign it)
  3. Click 'Copy' to copy the raw tx to clipboard
  4. bitcoin-cli decoderawtransaction <raw-tx-hex>

Expected output

{
  "txid": "db...4d",
  "hash": "db...4d",
  "version": 2,
  "size": 85,
  "locktime": 0,
  "vin": [
    {
      "txid": "ed...f6",
      "vout": 1,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "sequence": 4294967295
    }
  ]...

(note empty script sig)

Actual output

error code: -22                                                                
error message:                                                                                                                                                                                                                   
TX decode failed

Investigation at a glance

The raw hex output by ElectrumABC appears to fill in some garbage in the scriptSig instead of the scriptSig byte length expected to be 0 (which will give output like in the Expected Output section above). The expected output was generated using createrawtransaction (see example here: https://developer.bitcoin.org/examples/transactions.html#simple-raw-transaction ) and comparing its output fed back into decoderawtransaction against the output from ElectrumABC.

@PiRK
Copy link
Collaborator

PiRK commented Sep 8, 2021

So, when a transaction has an unsigned input, the serialized script is
41000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000021000000000000000000000000000000000000000000000000000000000000000000

It looks like garbage indeed.

@PiRK
Copy link
Collaborator

PiRK commented Sep 8, 2021

The code is confusing, because of all the branching. It seems that unsigned transactions get through an "estimate_size" branch, in which a blank pubkey ("210000...") and a blank Schnorr signature ("410000...") are used in the serialization.

But simply forcing the other branch (estimate_size=Falase) does not produce a raw tx that works for "decoderawtransaction" either.

@PiRK
Copy link
Collaborator

PiRK commented Oct 19, 2021

This could be the issue: https://github.com/Bitcoin-ABC/ElectrumABC/blob/master/electroncash/transaction.py#L673

There is additional (non standard) data added to each input when unsigned transactions are generated. So my initial assessment was wrong, it is not causes by dummy signatures being added.

Related discussions:

@PiRK
Copy link
Collaborator

PiRK commented Oct 19, 2021

Confirmed: if I comment out that block, the hex is a proper unsigned tx that can be decoded by the node.
But it has a bunch of side effects, like being unable to sign and broadcast the generated transaction. I'll have another look at this a bit later. This is calling for a refactoring of the transaction.py module.

@jasonbcox
Copy link
Author

Thanks for doing a proper investigation. Looking forward to the fix.

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

No branches or pull requests

2 participants