From af6559c437316273c51b65b15f711dabeff9140e Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 22 Jun 2026 20:12:21 +0100 Subject: [PATCH 1/4] feat: bound pause reason to 256 bytes with SLAError::InvalidInput (#68) Add MAX_REASON_LEN constant (256) and SLAError::InvalidInput variant. Validate reason.len() before persisting PauseInfo, returning InvalidInput on violation instead of silently accepting multi-kilobyte payloads. --- apexchainx_calculator/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apexchainx_calculator/src/lib.rs b/apexchainx_calculator/src/lib.rs index 7919e4f..b7f37a0 100644 --- a/apexchainx_calculator/src/lib.rs +++ b/apexchainx_calculator/src/lib.rs @@ -55,6 +55,9 @@ const PAUSED_KEY: Symbol = symbol_short!("PAUSED"); /// Pause metadata (reason, timestamp, caller). (#66) const PAUSE_INFO_KEY: Symbol = symbol_short!("PAUSEINF"); +/// Maximum length (in bytes) for the pause reason string. (#68) +const MAX_REASON_LEN: usize = 256; + /// Cumulative SLA statistics (SLAStats struct). (#29) const STATS_KEY: Symbol = symbol_short!("STATS"); @@ -247,6 +250,8 @@ pub enum SLAError { InvalidPenaltyAmount = 14, /// Computed reward amount is invalid (e.g., zero or negative). (SC-W5-046) InvalidRewardAmount = 15, + /// Input parameter violates documented constraints (e.g., reason too long). (#68) + InvalidInput = 16, } // ----------------------------------------------------------------------- @@ -782,6 +787,10 @@ impl SLACalculatorContract { Self::check_version(&env)?; Self::require_admin(&env, &caller)?; + if reason.len() > MAX_REASON_LEN as u32 { + return Err(SLAError::InvalidInput); + } + let paused_at = env.ledger().timestamp(); env.storage().instance().set(&PAUSED_KEY, &true); env.storage().instance().set( From 85ea71b1b504b741d98b04c108701ee9a7ba36af Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 22 Jun 2026 20:12:30 +0100 Subject: [PATCH 2/4] test: add test_pause_rejects_long_reason for reason >256 bytes (#68) Verifies that a 257-byte pause reason triggers a HostError panic (SLAError::InvalidInput). --- apexchainx_calculator/src/tests.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apexchainx_calculator/src/tests.rs b/apexchainx_calculator/src/tests.rs index e05f544..79f3fa1 100644 --- a/apexchainx_calculator/src/tests.rs +++ b/apexchainx_calculator/src/tests.rs @@ -1918,6 +1918,16 @@ fn test_pause_stores_reason_and_timestamp() { let _ = info.paused_at; } +#[test] +#[should_panic(expected = "HostError")] +fn test_pause_rejects_long_reason() { + let (env, client, actors) = setup(); + // 257-byte reason exceeds MAX_REASON_LEN (256) + let long_reason = + soroban_sdk::String::from_str(&env, &"A".repeat(257)); + client.pause(&actors.admin, &long_reason); +} + #[test] fn test_unpause_clears_pause_info() { let (env, client, actors) = setup(); From b0cb2999f0b822130978f3a9e192b5189dfcf26b Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 22 Jun 2026 20:27:20 +0100 Subject: [PATCH 3/4] fix: use correct should_panic expected pattern for InvalidInput (#68) Use expected=" --- apexchainx_calculator/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apexchainx_calculator/src/tests.rs b/apexchainx_calculator/src/tests.rs index 79f3fa1..2eecdec 100644 --- a/apexchainx_calculator/src/tests.rs +++ b/apexchainx_calculator/src/tests.rs @@ -1919,7 +1919,7 @@ fn test_pause_stores_reason_and_timestamp() { } #[test] -#[should_panic(expected = "HostError")] +#[should_panic(expected = "#16")] fn test_pause_rejects_long_reason() { let (env, client, actors) = setup(); // 257-byte reason exceeds MAX_REASON_LEN (256) From 8f14e14c7b42cae963fa3fc56b0f1a37e2585943 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 22 Jun 2026 20:31:35 +0100 Subject: [PATCH 4/4] style: fix cargo fmt in test_pause_rejects_long_reason (#68) Line break in assignment violated rustfmt. Merged to single line. --- apexchainx_calculator/src/tests.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apexchainx_calculator/src/tests.rs b/apexchainx_calculator/src/tests.rs index 2eecdec..c57dc61 100644 --- a/apexchainx_calculator/src/tests.rs +++ b/apexchainx_calculator/src/tests.rs @@ -1923,8 +1923,7 @@ fn test_pause_stores_reason_and_timestamp() { fn test_pause_rejects_long_reason() { let (env, client, actors) = setup(); // 257-byte reason exceeds MAX_REASON_LEN (256) - let long_reason = - soroban_sdk::String::from_str(&env, &"A".repeat(257)); + let long_reason = soroban_sdk::String::from_str(&env, &"A".repeat(257)); client.pause(&actors.admin, &long_reason); }