messages that have nominal_hash_rate (F32) is accepting weird values that are not suitable for a hashrate information. messages affected include: UpdateChannel and OpenChannel;
a test example below:
diff --git a/sv2/subprotocols/mining/src/update_channel.rs b/sv2/subprotocols/mining/src/update_channel.rs
index f2f728cb..25d44348 100644
--- a/sv2/subprotocols/mining/src/update_channel.rs
+++ b/sv2/subprotocols/mining/src/update_channel.rs
@@ -89,3 +89,28 @@ impl fmt::Display for UpdateChannelErrorOwned {
)
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use alloc::vec;
+ use binary_sv2::Deserialize;
+
+ // Spec 5.3.7: nominal_hash_rate represents hashrate in h/s and must be >= 0.
+ // The parser currently accepts NaN for f32 fields, which is a spec violation.
+ #[test]
+ fn test_update_channel_accepts_nan_hashrate() {
+ let mut data = vec![
+ 0x00, 0x00, 0x00, 0x00, // channel_id: 0
+ ];
+ // nominal_hash_rate: NaN (0x7FC00000 in LE)
+ data.extend_from_slice(&f32::NAN.to_le_bytes());
+ data.extend_from_slice(&[0u8; 32]); // maximum_target
+ let parsed = UpdateChannel::from_bytes(&mut data)
+ .expect("parser should accept NaN hash rate (spec 5.3.7 violation)");
+ assert!(
+ parsed.nominal_hash_rate.is_nan(),
+ "nominal_hash_rate should be NaN to demonstrate the bug"
+ );
+ }
messages that have
nominal_hash_rate(F32) is accepting weird values that are not suitable for a hashrate information. messages affected include: UpdateChannel and OpenChannel;a test example below: