From c13c7fafcfc1cf5d05557fd4c93887c761b81d0b Mon Sep 17 00:00:00 2001 From: nakul1010 Date: Wed, 25 Jun 2025 14:57:46 +0530 Subject: [PATCH 1/2] fix: assume witness-enabled parsing for version > 2 --- crates/bitcoin/src/parser.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/bitcoin/src/parser.rs b/crates/bitcoin/src/parser.rs index d7376dfa6..12552eb57 100644 --- a/crates/bitcoin/src/parser.rs +++ b/crates/bitcoin/src/parser.rs @@ -273,7 +273,8 @@ pub fn parse_transaction(raw_transaction: &[u8]) -> Result { let mut parser = BytesParser::new(raw_transaction); let version: i32 = parser.parse()?; - let allow_witness = (version & SERIALIZE_TRANSACTION_NO_WITNESS) == 0; + // Updated: For version > 2, assume witness is allowed regardless of the NO_WITNESS flag + let allow_witness = version > 2 || (version & SERIALIZE_TRANSACTION_NO_WITNESS) == 0; // TODO: bound maximum? let mut inputs: Vec = parser.parse_with(version)?; From ab4136b66086ca50fc13880feb8b06c93dc70530 Mon Sep 17 00:00:00 2001 From: nakul1010 Date: Wed, 25 Jun 2025 15:23:44 +0530 Subject: [PATCH 2/2] fix: clamp parse_with version to 2 for higher tx versions --- crates/bitcoin/src/parser.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/bitcoin/src/parser.rs b/crates/bitcoin/src/parser.rs index 12552eb57..daf0bea8e 100644 --- a/crates/bitcoin/src/parser.rs +++ b/crates/bitcoin/src/parser.rs @@ -272,17 +272,18 @@ pub fn parse_compact_uint(varint: &[u8]) -> Result<(u64, usize), Error> { pub fn parse_transaction(raw_transaction: &[u8]) -> Result { let mut parser = BytesParser::new(raw_transaction); let version: i32 = parser.parse()?; + // For version > 2, treat it as version 2 for parsing behavior + let effective_version = if version > 2 { 2 } else { version }; - // Updated: For version > 2, assume witness is allowed regardless of the NO_WITNESS flag - let allow_witness = version > 2 || (version & SERIALIZE_TRANSACTION_NO_WITNESS) == 0; + let allow_witness = (effective_version & SERIALIZE_TRANSACTION_NO_WITNESS) == 0; // TODO: bound maximum? - let mut inputs: Vec = parser.parse_with(version)?; + let mut inputs: Vec = parser.parse_with(effective_version)?; let mut flags: u8 = 0; if inputs.is_empty() && allow_witness { flags = parser.parse()?; - inputs = parser.parse_with(version)?; + inputs = parser.parse_with(effective_version)?; } // TODO: bound maximum?