From e952c764958c1f7819496f015ded14452729288d Mon Sep 17 00:00:00 2001 From: Ragnar Date: Thu, 13 Mar 2025 17:25:38 +0100 Subject: [PATCH 1/2] Update fib.rs --- tests/integration-tests/fib.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/integration-tests/fib.rs b/tests/integration-tests/fib.rs index 959afc2fd..2fed3b053 100644 --- a/tests/integration-tests/fib.rs +++ b/tests/integration-tests/fib.rs @@ -3,17 +3,26 @@ #[nexus_rt::main] #[nexus_rt::public_input(n)] fn main(n: u32) -> u32 { - let mut a = 0; - let mut b = 1; - + // Handle edge cases if n == 0 { - return a; + return 0; + } + if n == 1 { + return 1; } - for _ in 2..n { - let c = a + b; + let mut a = 0u32; + let mut b = 1u32; + + for _ in 2..=n { + // Check for potential overflow before addition + if let Some(c) = a.checked_add(b) { a = b; - b = c; + b = c; + } else { + // In case of overflow, return max value + return u32::MAX; + } } b From 257f1c53352ab150a36796a699ad6160903920e8 Mon Sep 17 00:00:00 2001 From: Ragnar Date: Wed, 2 Apr 2025 14:47:00 +0200 Subject: [PATCH 2/2] Update fib.rs --- tests/integration-tests/fib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration-tests/fib.rs b/tests/integration-tests/fib.rs index 2fed3b053..199a4aed0 100644 --- a/tests/integration-tests/fib.rs +++ b/tests/integration-tests/fib.rs @@ -14,7 +14,7 @@ fn main(n: u32) -> u32 { let mut a = 0u32; let mut b = 1u32; - for _ in 2..=n { + for _ in 2..n { // Check for potential overflow before addition if let Some(c) = a.checked_add(b) { a = b;