Skip to content

Conversation

@notTanveer
Copy link

@notTanveer notTanveer commented Jun 15, 2025

This PR improves PSBT (Partially Signed Bitcoin Transaction) v2 support, especially strict validation and compatibility with BIP 370 test vectors. It also adds a comprehensive set of tests for PSBTv2 edge cases and locktime determination.


Details

1. PSBTv2 Compliance and Parsing Improvements

  • Updated method signatures in src/embit/liquid/pset.py to allow passing the version parameter down to read_value and its parent implementations. This ensures correct handling of versioned PSBT fields.
  • Adjusted calls to super().read_value to pass along the version argument, improving extensibility and correctness for PSBTv2.

2. PSBT View Updates

  • Modified src/embit/psbtview.py:
    • The input() and output() methods now pass the version parameter when reading from the stream, allowing PSBT-in and out scopes to parse versioned fields correctly.

3. Comprehensive PSBTv2 Test Vectors

  • Added a new test file: tests/tests/test_psbtV2.py containing:
    • Test vectors based on BIP 370 PSBTv2.
    • Tests for invalid PSBTv0/PSBTv2 edge cases (e.g., wrong/missing fields, invalid locktimes).
    • Tests for valid PSBTv2 minimal and full-featured transactions.
    • Tests for locktime determination logic in PSBTv2, including edge cases with multiple locktimes (height and time).

Motivation

  • Ensures full BIP 370 compliance, increasing interoperability and correctness for PSBTv2 parsing and validation.
  • Catches subtle bugs and regressions through comprehensive test coverage.
  • Lays the groundwork for future PSBTv2 features and broader Elements/Liquid support.

Testing

  • Run pytest tests/tests/test_psbtV2.py to verify all BIP 370 test vectors and locktime cases.
  • Built from the referenced PR and generated various PSBTs, then imported them into embit to confirm correct parsing — everything worked as expected.
  • Would love for others to build Bitcoin Core + CLI from PR #21283, try it out, and share your observations here.

References

@notTanveer notTanveer marked this pull request as ready for review June 22, 2025 11:30
@notTanveer notTanveer changed the title Add PSBTv2 (BIP-370) Support to Embit PSBTv2 (BIP-370) Support Jul 24, 2025
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