Skip to content

fix: Bug. PSBTv2 support in trim() - #887

Closed
Garrysoon wants to merge 1 commit into
selfcustody:feat/silent-paymentsfrom
Garrysoon:feature/psbtv2-clean
Closed

Garrysoon wants to merge 1 commit into
selfcustody:feat/silent-paymentsfrom
Garrysoon:feature/psbtv2-clean

Conversation

@Garrysoon

@Garrysoon Garrysoon commented Jun 21, 2026 •

Copy link
Copy Markdown

Problem

When signing a PSBTv2 file, Krux silently downgraded it to v0. The trim() method in psbt.py created PSBT(self.psbt.tx) without passing the version parameter — embit defaults to v0, dropping all v2-specific fields:

  • Global: tx_version, locktime, input_count, output_count
  • Per-input: txid, vout, sequence
  • Per-output: value, script_pubkey

This meant a signed PSBTv2 sent back to Sparrow would be parsed as v0, potentially causing issues with transaction assembly.

Solution

Pass version=self.psbt.version to the PSBT constructor in trim(), and copy v2-specific fields from the original PSBT when present.

Changes

File Lines Description
src/krux/psbt.py +18 / -1 trim() preserves PSBTv2 version and v2 fields
tests/test_psbtv2.py +155 6 tests covering parse, serialize, trim, backward compatibility

How it works

# Before (bug):
psbt = PSBT(self.psbt.tx)  # version defaults to 0

# After (fix):
psbt = PSBT(self.psbt.tx, version=self.psbt.version)  # preserves v2

For v2 PSBTs, trim() now also copies:

tx_version, locktime from global scope
txid, vout, sequence per input
value, script_pubkey per output
For v0 PSBTs — all v2 fields are None, copy is skipped, behavior identical to before.

Testing
✅ 6/6 PSBTv2 unit tests passing
✅ 30/30 existing PSBT tests passing (15 pre-existing fails are unrelated mock issues)
⚠️ Tested only on simulator — no hardware testing with real PSBTv2 files from Sparrow/SeedSigner yet

@Garrysoon
Garrysoon force-pushed the feature/psbtv2-clean branch from e273adb to 792d066 Compare June 21, 2026 06:24
@qlrd

qlrd commented Jun 21, 2026 •

Copy link
Copy Markdown
Member

Thxs for finding @Garrysoon.

Some nits:

  • found that you hardcoded some already used constants, so it could be simplified (e.g., "abandon * 11 + about" have a constant for that)
  • please read the contributing guide; we didn't shipped yet to main (so maybe wasn't possible to check it), but you need to propose that this PR is being aimed to the correct branch
  • IMO this is not a feat commit, but instead a fix one

AFAIK this is (or could -- i don't have opinions on that) already being addressed on embit#87. Let's wait @odudex and @notTanveer can confirm the trim fix you proposed.

@Garrysoon
Garrysoon force-pushed the feature/psbtv2-clean branch from 792d066 to f79a903 Compare June 21, 2026 12:52
@Garrysoon
Garrysoon changed the base branch from main to develop June 21, 2026 12:56
@Garrysoon

Copy link
Copy Markdown
Author

Thxs for finding @Garrysoon.

Some nits:

  • found that you hardcoded some already used constants, so it could be simplified (e.g., "abandon * 11 + about" have a constant for that)
  • please read the contributing guide; we didn't shipped yet to main (so maybe wasn't possible to check it), but you need to propose that this PR is being aimed to the correct branch
  • IMO this is not a feat commit, but instead a fix one

AFAIK this is (or could -- i don't have opinions on that) already being addressed on embit#87. Let's wait @odudex and @notTanveer can confirm the trim fix you proposed.

done

@Garrysoon Garrysoon changed the title feat: add PSBTv2 support in trim() fix: add PSBTv2 support in trim() Jun 21, 2026
@Garrysoon Garrysoon changed the title fix: add PSBTv2 support in trim() Bug fix: add PSBTv2 support in trim() Jun 22, 2026
@Garrysoon Garrysoon changed the title Bug fix: add PSBTv2 support in trim() fix: add PSBTv2 support in trim() Jun 22, 2026
@Garrysoon Garrysoon changed the title fix: add PSBTv2 support in trim() fix: Bug. PSBTv2 support in trim() Jun 22, 2026
@odudex
odudex changed the base branch from develop to feat/silent-payments June 22, 2026 20:20
@odudex

odudex commented Jun 22, 2026

Copy link
Copy Markdown
Member

Please adapt the PR to feat/silent-payments branch so it can be evaluated. In this branch full PSBTv2 support is being introduced together with an Embit update.

@codecov

codecov Bot commented Jun 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.21%. Comparing base (2b6b5d0) to head (c141410).

Additional details and impacted files
@@                  Coverage Diff                  @@
##           feat/silent-payments     #887   +/-   ##
=====================================================
  Coverage                 97.20%   97.21%           
=====================================================
  Files                        84       84           
  Lines                     11145    11158   +13     
=====================================================
+ Hits                      10834    10847   +13     
  Misses                      311      311           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Preserve PSBTv2 version and v2-specific fields during signing.
Fixes silent v2->v0 downgrade when signing with trim=True (QR mode).

Changes:
- Pass version=self.psbt.version to PSBT constructor in trim()
- Copy tx_version, locktime from original PSBT
- Copy v2 input fields: txid, vout, sequence
- Copy v2 output fields: value, script_pubkey
- Replace hardcoded mnemonic with TEST_MNEMONIC constant

Adds 6 tests for PSBTv2 parse, serialize, trim, and backward compatibility.
@Garrysoon
Garrysoon force-pushed the feature/psbtv2-clean branch from f79a903 to c141410 Compare June 23, 2026 07:53
@Garrysoon Garrysoon closed this Jun 23, 2026
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.

3 participants