From 8d966f18ad92c22ff1101c3a4cdc1f709778187e Mon Sep 17 00:00:00 2001 From: Jon C Date: Mon, 31 Aug 2026 19:54:43 +0200 Subject: [PATCH] program: Move splippage check during withdraw-stake #### Problem The stake pool program allows users to withdraw whole stake accounts in certain situations. In those cases, the amount of lamports withdrawn gets truncated downt to the current amount of lamports in the account. The program also allows users to specify slippage when withdrawing from the pool. The withdraw-stake instruction runs the slippage check before the withdrawal amount has been rounded down when withdrawing a stake account, potentially violating the slippage param set by the user. #### Summary of changes Move the slippage check down to after the withdraw amount has been changed. --- program/src/processor.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/program/src/processor.rs b/program/src/processor.rs index 231961b8..c49f44f8 100644 --- a/program/src/processor.rs +++ b/program/src/processor.rs @@ -2879,12 +2879,6 @@ impl Processor { return Err(StakePoolError::WithdrawalTooSmall.into()); } - if let Some(minimum_lamports_out) = minimum_lamports_out { - if withdraw_lamports < minimum_lamports_out { - return Err(StakePoolError::ExceededSlippage.into()); - } - } - let split_from_rent = rent.minimum_balance(stake_split_from.data_len()); let stake_minimum_delegation = stake::tools::get_minimum_delegation()?; let stake_state = try_from_slice_unchecked::( @@ -3061,6 +3055,12 @@ impl Processor { Some((validator_stake_info, withdraw_source)) }; + if let Some(minimum_lamports_out) = minimum_lamports_out { + if withdraw_lamports < minimum_lamports_out { + return Err(StakePoolError::ExceededSlippage.into()); + } + } + Self::token_burn( token_program_info.clone(), burn_from_pool_info.clone(),