-
Notifications
You must be signed in to change notification settings - Fork 38.6k
allow bitcoin-tx to parse partial transactions #8837
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
allow bitcoin-tx to parse partial transactions #8837
Conversation
|
Is this 01000000000100000000000000000000000000 supposed to be parsed as a zero input, one output to Wouldn't Following |
|
@fivepiece , I believe your second transaction is invalid. Commented transactions:
(in fact it'd be partially parsed as): Your other example |
|
@jnewbery I guess I should clarify my question then. I was wondering why My understanding was that you were out to implement a "blank" segwit transaction in that test, and I think [edit] |
|
Anyway thinking about this some more, feel free to disregard my suggestion. It's too ambiguous. Maybe the correct way is to fall back to parsing a non segwit transaction, as no inputs mean no witnesses too. |
|
Correct. If none of the inputs have witnesses or if the witnesses are all empty, then there shouldn't be a witness structure attached to the transaction From In this case there are no transaction inputs, so no witnesses, and so the witness dummy byte and flag shouldn't be set. |
|
Right re. Thanks for clearing it up. |
|
@laanwj - this very small change allows bitcoin-tx to parse partial transactions and includes a test case to cover the new functionality. Are you happy to merge this? |
|
I don't like "try to parse the transaction as pre-segwit transaction" much - This implies ambiguity, can the ambiguity cause problems here? If so I'd prefer if this was an explicit flag somewhere. |
|
I'll paste this here as well, commented in #-core-dev so specifically re. parsing partial transactions as pre-segwit (#8837), I actually hit this issue in my own toy parser and it shows in core too: http://paste.debian.net/plainh/8c80d8cd so having some flag would be great
|
|
The issue is that segwit only guarantees unambiguous encoding for valid complete transactions. In places where raw transactions are expected that consume inputs that are not necessarily complete, ambiguity is possible. This is the case for the decoderawtransaction and fundrawtransaction RPCs, and for bitcoin-tx. Since inputs to those are usually in fact not signed, they should usually not have any witnesses at all, and thus (trying to) decode without seems like a reasonable default. I do agree it's undesirable to have ambiguity in the first place, but I think a longer term solution will include a separate encoding for incomplete transactions. We may need that anyway for more complex signing such as for MAST and Schnorr, where the communication between the participants may include (primarily) information that does not end up in the final transaction. |
Not only a separate encoding, but it needs to be distinguishable non-ambiguously from completed transactions. |
|
Right ^, the difficulty is a 0 inputs, unfunded transaction looks a lot like segwit at first, then you might fail after it stops making sense, or like in the case I linked, maybe never fail.. unless there was a context to what this transaction was passed in for. (just my personal experience parsing partial transactions) |
|
The conversation in this PR seems to have wandered a bit into the desirability of having a separate encoding for partial transactions. I agree that's a good idea, but it seems out of scope for this PR. To clarify what this PR achieves:
|
Restore pre V0.13.1 functionality to bitcoin-tx and allow it to parse 0-input partial transactions.
0221a4f to
7451cf5
Compare
|
Yes, fair enough, it's an improvement. |
7451cf5 Allow bitcoin-tx to parse partial transactions (jnewbery)
7451cf5 Allow bitcoin-tx to parse partial transactions (jnewbery)
7451cf5 Allow bitcoin-tx to parse partial transactions (jnewbery)
7451cf5 Allow bitcoin-tx to parse partial transactions (jnewbery)
Segwit has added ambiguity for 0-input transactions (the 0 can be read as the dummy byte indicating that this is a segwit transcation).
bitcoin-tx needs to be able to parse 0-input partial transactions. This PR causes bitcoin-tx to call
DecodeHexTx()with thefTryNoWitnessflag set, so we attempt to deserialize the transaction as a pre-segwit transaction.This PR also adds new test cases to verify that bitcoin-tx parses a partial transaction correctly.