AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 12 Bitcoin

Add typed accessors for the PSBT fields read while signing

Public commit record

What the developer wrote

Authored by Salvatore Ingala

95/100 · Strong
Add typed accessors for the PSBT fields read while signing

Accessing PSBT fields needed raw validation at the caller's site, which
ends up mixing the PSBT validation logic with the actual signing logic.

Introduce sign_psbt/psbt_fields.{c,h}, where each accessor owns the
structural validation of exactly one field and returns a typed value.

Every accessor returns a tri-state psbt_field_status_t, so that a caller
can always tell a field that is not in the map from one that could not be
read. The length policy of each field - an exact size, or a maximum -
lives here rather than next to call_get_merkleized_map_value.

Note the accessors return an enum whose ERROR value is -1, which is
truthy. Therefore, every one of the 26 call sites compares against
PSBT_FIELD_PRESENT explicitly.

This is a pure refactor: no behavioral change. In particular the two
optional fields keep the exact defaulting policy they had before, which
is deliberately left alone here and fixed in the next commit:
- the four nSequence reads in txhashes.c fall back to 0xFFFFFFFF on any
non-PRESENT status, as they did on any failed read before;
- psbt_get_global_fallback_locktime keeps its 9-byte varint buffer and
reports every read failure as ABSENT, yielding locktime 0.
Both are marked as such in the accessor docs.

The three unit tests covering the removed u32 wrapper are dropped, as
they are subsumed by a test added here against the real accessor.
The two remaining tests in test_get_merkleized_map_value.c now assert
the named statuses.

Unit tests are added for the new accessors.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification
The short version

What changed, and why it matters

This commit is a code cleanup (refactor) in Ledger's Bitcoin app. It moves the logic for reading PSBT (Partially Signed Bitcoin Transaction) fields into dedicated helper functions with clearer success/error/absent status codes. The author explicitly states there is no behavior change; the patch preserves existing handling of two optional fields exactly as before, with fixes for those edge cases planned in a follow-up commit. The changes add unit tests and improve code clarity, but do not by themselves fix a security bug.

Recommended action

No immediate security action required. Treat as a normal code-quality refactor. Review the planned follow-up commit that will tighten the defaulting behavior for PSBT_IN_SEQUENCE and PSBT_GLOBAL_FALLBACK_LOCKTIME, as that may have actual security relevance.

Security signals we found

01

Refactor of PSBT field parsing with explicit tri-state status codes

02

New unit tests assert distinction between ABSENT and ERROR statuses

03

Commit message explicitly states 'pure refactor: no behavioral change'

04

Two optional fields retain legacy defaulting behavior, marked for future fix

05

No direct evidence of vulnerability fix or exploit mitigation in this commit

Risk score

Why this scored 12/100

Our methodology →
Potential impact 0/30
Exploitability 0/25
Stealth signal 0/15
Affected reach 0/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.