-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
PSBT: missing witness_utxo for segwit inputs #8039
Comments
I think we only do this when displaying QR codes. Is that what you mean? See e.g. this test: electrum/electrum/tests/test_wallet_vertical.py Line 2654 in 30ac889
In the normal flow, where tx.to_qr_data() is not called, the input includes PSBT_IN_NON_WITNESS_UTXO and lacks PSBT_IN_WITNESS_UTXO .
|
It happened while signing from a standard BIP-44 legacy account; converting the
It's from my custom branch, but it shouldn't be related to anything I do, since I create the psbt with If it's not enough info to reproduce yet, I should be able to open the initial PR for #7897 tomorrow; it might be easier to reproduce on the PR's branch, since the current Ledger plugin doesn't use psbt. |
Something is weird with your tx. The input has both electrum/electrum/transaction.py Line 1253 in 335f55a
|
Indeed, another weird thing about this psbt is that the both outputs have the BIP32 derivation info, while that's only relevant for the change output. |
That's expected. The wallet adds all the info it has. No idea about the witness utxo weirdness though. |
You are completely right, the |
Reopened, as there might still be an inconsistency with the standard. My understanding is the following:
Currently, electrum seems to only put the non_witness_utxo and skip the witness_utxo for segwitv0 inputs. I can easily fix it in the plugin code before sending to the device − but mentioning it anyway as I think it's not matching the expectations of BIP174. |
I don't see why you would want both non_witness_utxo and witness_utxo present at the same time. It is a waste of space and potential for inconsistency (if they mismatch). The witness_utxo can be cleanly calculated from the non_witness_utxo (and the prevout_idx). IIRC Bitcoin Core might be including both but only for compatibility reasons with old versions of itself. In my reading, the spec allows this:
So I mean, if there is a real motivating use case, we could include both, but if it's only old versions of Bitcoin Core then I don't see the point. If the ledger firmware code is expecting both, I would argue it is that firmware that should be changed. :) |
The specs is indeed not super explicit. Since PSBT_IN_WITNESS_UTXO can be computed from PSBT_IN_NON_WITNESS_UTXO, it would seem that it's redundant at first sight. My reasoning on why that's not the right reading of the specs is the following:
Because of this, my impression is that relying on the non-witness-utxo should be considered the legacy quirk, and the witness-utxo is the way to go. It's true that the witness utxo is redundant data if the non-witness-utxo is present, but it is very little redundant data − while for segwitv1 the non-witness-utxo includes potentially a lot of useless data. I'd like to hear the opinion of @achow101 if he wants to chime in. In the current implementation, the Ledger app always uses the witness utxo for segwitv0 or segwitv1 inputs, but gives a warning for segwitv0 inputs if the non-witness-utxo is missing (to protect from the exploitable edge-cases). |
Non-witness UTXO is required for non-segwit inputs, and may be included for segwit inputs. Witness UTXO is required for segwit inputs, and should not be included for non-segwit inputs. Segwit inputs can have both fields in order to deal with the sighash issue, but also for backwards compatibility with (versions of) software written before the issue was discovered. |
where does the spec say that? weird that no one complained for years that we are only putting non-witness-utxo for segwit v0 inputs. |
s/required/expected The simple signer algorithm described in the BIP looks for the presence of witness UTXO to determine how to sign. |
The simple signer algorithm also expects the lack of Anyway, I don't think the spec is explicit about this, but I've found practical examples of incompatibility (cryptoadvance/specter-desktop#868, cryptoadvance/specter-desktop#1046), so I've changed this now in d3227d7. |
Currently, electrum seems to be adding the witness_utxo for legacy P2PKH inputs; per BIP-174, the PSBT_IN_WITNESS_UTXO should only be present for inputs which spend segwit outputs.
This affects the new Ledger bitcoin app, which relies on this assumption when signing PSBTs with legacy inputs.
The text was updated successfully, but these errors were encountered: