diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 82ee80c374..d4304aaf25 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -4014,7 +4014,7 @@ impl Bank { self.store_account(pubkey, new_account); } - pub fn withdraw(&self, pubkey: &Pubkey, lamports: u64) -> Result<()> { + fn withdraw(&self, pubkey: &Pubkey, lamports: u64) -> Result<()> { match self.get_account(pubkey) { Some(mut account) => { let min_balance = match get_system_account_kind(&account) { @@ -4024,9 +4024,11 @@ impl Bank { .minimum_balance(nonce::State::size()), _ => 0, }; - if lamports + min_balance > account.lamports { - return Err(TransactionError::InsufficientFundsForFee); - } + + lamports + .checked_add(min_balance) + .filter(|required_balance| *required_balance <= account.lamports()) + .ok_or(TransactionError::InsufficientFundsForFee)?; account.lamports -= lamports; self.store_account(pubkey, &account);