Skip to content

pset: fix pegin/issuance flag handling in extract_tx#265

Open
apoelstra wants to merge 2 commits intoElementsProject:masterfrom
apoelstra:2026-02_psbt
Open

pset: fix pegin/issuance flag handling in extract_tx#265
apoelstra wants to merge 2 commits intoElementsProject:masterfrom
apoelstra:2026-02_psbt

Conversation

@apoelstra
Copy link
Member

When extracting a transaction we were leaving bits set in the input indices, which is incorrect and leads to serialization round-tripping bugs.

Fixes #263.

Copy link
Member Author

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 7cc4c8a successfully ran local tests

Copy link
Member Author

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 7cc4c8a; successfully ran local tests

Copy link
Member

@delta1 delta1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 7cc4c8a; built and tested successfully

src/pset/mod.rs Outdated
};
let txin = TxIn {
previous_output: OutPoint::new(psetin.previous_txid, psetin.previous_output_index),
previous_output: OutPoint::new(psetin.previous_txid, dbg!(prev_index)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: stray dbg!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, this in in the actual extract_tx function so it's more than a nit. Fixed.

We have a convention that in memory, we don't have the pegin or witness flags
on the input index for TxIn, but we *do* keep these around in the Psbt::Input
map.
… witnesses

This test case was written by Claude and (fairly heavily) edited by me to add
the PSBT round-tripping and to tighten up some checks. Originally we thought
the bug was related to witness encoding, so the test covers various permutations
of null witnesses. Actually this was a red herring and the bug was just about
the pegin flag in the input index being preserved across PSBTs. But I left most
of the witness-deleting test in place anyway because it seems potentially useful.
Copy link
Member Author

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a9ba3ec successfully ran local tests

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PSBT::from_tx() → extract_tx() drops TxOutWitness (output surjection/range proofs), breaks explicit output tx serialization

2 participants