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

Merge bitcoin/bitcoin#36224: test: Add test coverage for `PartiallySignedTransaction::Merge()`

Public commit record

What the developer wrote

Authored by merge-script

100/100 · Strong
Merge bitcoin/bitcoin#36224: test: Add test coverage for `PartiallySignedTransaction::Merge()`

7b124184394e016d6e3c119c50ff08d1512dfab9 test: merge PSBT `m_tx_modifiable` coverage and renaming bit positions with BIP370 flags (nebula-21)
776fb263759693a5db6aa11a8a464662d5f36da4 test: merge PSBT `fallback_locktime` coverage (nebula-21)
6fc2ebd5216975de40e9ef3b1dea1de623268794 test: only merge PSBTs with same version (nebula-21)

Pull request description:

This PR adds test coverage for `PartiallySignedTransaction::Merge()` divided into 3 tests:

Only merge PSBTs with same version: The test can be triggered with this mutant as an example:

```diff
diff --git a/src/psbt.cpp b/src/psbt.cpp
index 51fb19591a..cf5eef0089 100644
--- a/src/psbt.cpp
+++ b/src/psbt.cpp
@@ -43,7 +43,7 @@ bool PartiallySignedTransaction::Merge(const PartiallySignedTransaction& psbt)
return false;
}
if (GetVersion() != psbt.GetVersion()) {
- return false;
+ return true;
}

for (unsigned int i = 0; i < inputs.size(); ++i) {
```

Merge PSBT `fallback_locktime` coverage: If the psbt has no fallback locktime, it adopts the one from the psbt it is merging. The test can be triggered with this mutant as an example:

```diff
diff --git a/src/psbt.cpp b/src/psbt.cpp
index 51fb19591a..ce909eb062 100644
--- a/src/psbt.cpp
+++ b/src/psbt.cpp
@@ -53,7 +53,7 @@ bool PartiallySignedTransaction::Merge(const PartiallySignedTransaction& psbt)
outputs[i].Merge(psbt.outputs[i]);
}
MergeGlobalXPubs(psbt);
- if (fallback_locktime == std::nullopt && psbt.fallback_locktime != std::nullopt) fallback_locktime = psbt.fallback_locktime;
+ if (fallback_locktime == std::nullopt || psbt.fallback_locktime != std::nullopt) fallback_locktime = psbt.fallback_locktime;

// Set m_tx_modifiable only if either PSBT had it set
if (m_tx_modifiable.has_value() || psbt.m_tx_modifiable.has_value()) {
```

While writing this test I had a question: If both PSBTs have a `fallback_locktime` value, the "this" (receiving side) wins silently. Is this the expected behavior? Why not keep the max or directly fail merging if we have two conflicting fallback_locktimes? The test can be triggered with this mutant as one of the various examples:

```diff
diff --git a/src/psbt.cpp b/src/psbt.cpp
index 51fb19591a..29eb910014 100644
--- a/src/psbt.cpp
+++ b/src/psbt.cpp
@@ -56,7 +56,7 @@ bool PartiallySignedTransaction::Merge(const PartiallySignedTransaction& psbt)
if (fallback_locktime == std::nullopt && psbt.fallback_locktime != std::nullopt) fallback_locktime = psbt.fallback_locktime;

// Set m_tx_modifiable only if either PSBT had it set
- if (m_tx_modifiable.has_value() || psbt.m_tx_modifiable.has_value()) {
+ if (m_tx_modifiable.has_value() && psbt.m_tx_modifiable.has_value()) {
// In general, we AND the modifiable flags
std::bitset<8> this_modifiable = m_tx_modifiable.value_or(0);
std::bitset<8> psbt_modifiable = psbt.m_tx_modifiable.value_or(0);
```

ACKs for top commit:
polespinasa:
ACK 7b124184394e016d6e3c119c50ff08d1512dfab9
fametrano:
reACK 7b124184394e016d6e3c119c50ff08d1512dfab9
sedited:
ACK 7b124184394e016d6e3c119c50ff08d1512dfab9

Tree-SHA512: 216746a77e8967441d55bb2b988a0a069292a993476afb2f33daa66356df2b8e837ad9d3fdde550623f106c9ba0fe3333230a844cafc62e772364dd8a2bf3d4f
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit only adds new unit tests for an existing PSBT merging function and renames some hard-coded bit numbers to named constants. It does not change any production code, so it cannot introduce a security vulnerability or fix one directly.

Recommended action

No security action required; treat as normal test-only improvement. Reviewers may optionally verify the test assertions accurately reflect the intended BIP370 merge semantics documented in src/psbt.cpp.

Security signals we found

No strong security signals were identified.

Risk score

Why this scored 15/100

Our methodology →
Potential impact 0/30
Exploitability 0/25
Stealth signal 0/15
Affected reach 0/15
Confidence 10/10
Evidence quality 5/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.