From 2b8f96d468d89290baf744eba53c28fff1589ecd Mon Sep 17 00:00:00 2001 From: EthanYuan Date: Tue, 5 Nov 2024 00:31:33 +0800 Subject: [PATCH] fix: prevent overflow in time difference calculation in --- verifier/src/utilities/bitcoin.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/verifier/src/utilities/bitcoin.rs b/verifier/src/utilities/bitcoin.rs index da33070..11b2366 100644 --- a/verifier/src/utilities/bitcoin.rs +++ b/verifier/src/utilities/bitcoin.rs @@ -20,16 +20,16 @@ pub fn calculate_next_target( end_time: u32, flags: u8, ) -> Target { - let expected = DIFFCHANGE_TIMESPAN; + let expected = DIFFCHANGE_TIMESPAN as i64; let actual = { - let mut actual = end_time - start_time; + let mut actual = (end_time as i64) - (start_time as i64); if actual < expected / 4 { actual = expected / 4; } if actual > expected * 4 { actual = expected * 4; } - actual + actual as u32 }; let le_bytes = {