From beb4c924cea8b552f96f21fc79a04b32137a7a96 Mon Sep 17 00:00:00 2001 From: Prisca Chidimma Maduka Date: Thu, 30 Oct 2025 09:24:44 +0100 Subject: [PATCH] - Add additional_coinbase_script_data len to max_extranonce_size - Use range2_len for extended extranonce allocation --- .../roles-logic-sv2/src/channel_logic/channel_factory.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs b/protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs index 2d4d0b429a..1288f4106a 100644 --- a/protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs +++ b/protocols/v2/roles-logic-sv2/src/channel_logic/channel_factory.rs @@ -345,7 +345,10 @@ impl ChannelFactory { additional_coinbase_script_data: Option<&[u8]>, ) -> Result<(Vec>, Option), Error> { let extended_channels_group = 0; - let max_extranonce_size = self.extranonces.get_range2_len() as u16; + let max_extranonce_size = self.extranonces.get_len() as u16 + + additional_coinbase_script_data + .map(|bs| bs.len()) + .unwrap_or(0) as u16; if min_extranonce_size <= max_extranonce_size { // SECURITY is very unlikely to finish the ids btw this unwrap could be used by an // attacker that want to disrupt the service maybe we should have a method @@ -368,9 +371,10 @@ impl ChannelFactory { return Err(e); } }; + // Using max_extranonce_size here, will overflow since it includes additional coinbase script data let extranonce = self .extranonces - .next_extended(max_extranonce_size as usize) + .next_extended(self.extranonces.get_range2_len()) .unwrap(); let extranonce_with_stripped_data = extranonce .into_prefix(self.extranonces.get_prefix_len(), &[])