DecomposePeginWitness: fix deserialization flags for MerkleBlock proof
What changed, and why it matters
This commit fixes a mismatch in how a Merkle block proof is unpacked inside a 'pegin' (a transaction that moves coins from a parent blockchain into this Elements sidechain). The proof was being read as if it might contain witness data, but it is always written without witness data. This mismatch could cause the proof to fail to decode in some situations, which could break peg-in validation or processing.
Apply the one-line patch to ensure MerkleBlock proofs are deserialized with SERIALIZE_TRANSACTION_NO_WITNESS, matching the serialization flags used in CreatePeginWitnessInner. Run the feature_dynafed functional tests to confirm the fix.
Security signals we found
Serialization/deserialization flag mismatch
Witness-data format mismatch in MerkleBlock proof
Peg-in witness decomposition failure
Functional test failure observed in feature_dynafed
Evidence from the diff
In src/pegins.cpp, DecomposePeginWitness previously constructed a CDataStream for the MerkleBlock proof using PROTOCOL_VERSION alone. The corresponding serialization in CreatePeginWitnessInner uses PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS. The patch adds SERIALIZE_TRANSACTION_NO_WITNESS to the deserialization flags so that encoding and decoding flags match. The commit message notes this was observed as a deserialization failure in the feature_dynafed functional test’s test_transition_mempool_eject case, where the Merkle block proof comes from the same chain as the pegin.
Changed components
src/pegins.cppDecomposePeginWitnessPeg-in witness handlingMerkleBlock proof deserializationInspect captured patch +1 / −1
diff --git a/src/pegins.cpp b/src/pegins.cpp
index 72551d2..8e44936 100644
--- a/src/pegins.cpp
+++ b/src/pegins.cpp
@@ -577,7 +577,7 @@ bool DecomposePeginWitness(const CScriptWitness& witness, CAmount& value, CAsset
tx = elem_tx;
}
- CDataStream ss_proof(stack[5], SER_NETWORK, PROTOCOL_VERSION);
+ CDataStream ss_proof(stack[5], SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
if (Params().GetConsensus().ParentChainHasPow()) {
Sidechain::Bitcoin::CMerkleBlock tx_proof;
ss_proof >> tx_proof;
Why this scored 27/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.