本文へ移動
Contact

TECHFUND
Media

Hi AUDIT
2026/3/17

Solana Program Security Pitfalls and How to Prevent Them

Building programs on Solana is not just about ensuring the code works — it’s about ensuring it cannot be abused. Since Solana programs manage real value on-chain, even a small validation mistake can result in huge financial loss.

Four bugs we keep seeing in Solana codebases. Same mistakes, different protocols, different teams. Here’s what they are and how to fix them.

1. Missing Signer Check

Solana checks signatures. Your program still has to check the rest. If your code only matches public keys without verifying is_signer, the attacker doesn't need a private key — they just need to know Alice's public key, which is on-chain and completely public.

When sensitive operations like withdrawals depend on authority validation, a missing signer check becomes a critical vulnerability.

Exploit Scenario

Here is one example there is no constraint that authority actually signs the transaction .

An attacker can identify a vault owned by Alice and pass Alice’s public key as the authority account when interacting with the program. Since the program only checks for key equality and does not verify that the authority actually signed the transaction, they can bypass the authorization mechanism. As a result, they can withdraw funds from the vault without ever passing Alice’s private key.

Example Contract

fn withdraw(
    _program_id: &Pubkey,
    accounts: &[AccountInfo],
    amount: u64,
) -> ProgramResult {
let account_info_iter = &mut accounts.iter();
    let vault = next_account_info(account_info_iter)?;
    let authority = next_account_info(account_info_iter)?;
    let recipient = next_account_info(account_info_iter)?;
    let mut vault_state = Vault::deserialize(&mut&**vault.data.borrow())?;
    // Only checking pubkey match
    if vault_state.authority != *authority.key {
        return Err(ProgramError::IncorrectAuthority);
    }
    // @audit : Missing signer check here!
    vault_state.balance -= amount;
    // transfer logic omitted...
    vault_state.serialize(&mut &mut **vault.data.borrow_mut())?;
    Ok(())
}

How to fix it

Always make sure that authority have signed the transaction.

fn withdraw(
    _program_id: &Pubkey,
    accounts: &[AccountInfo],
    amount: u64,
) -> ProgramResult {
let account_info_iter = &mut accounts.iter();
    let vault = next_account_info(account_info_iter)?;
    let authority = next_account_info(account_info_iter)?;
    let recipient = next_account_info(account_info_iter)?;
    let mut vault_state = Vault::deserialize(&mut &**vault.data.borrow())?;
    // Only checking pubkey match
    if vault_state.authority != *authority.key {
        return Err(ProgramError::IncorrectAuthority);
    }
    
     // added constraint
      if !authority.is_signer {
    return Err(ProgramError::MissingRequiredSignature);
      } 
     vault_state.balance -= amount;
    // transfer logic omitted...
    vault_state.serialize(&mut &mut **vault.data.borrow_mut())?;
    Ok(())
}

2. Missing Ownership Check

Every Solana account has an owner — a program ID that tells who have rights to write to it. Your program should be checking that. But most not do this.

Without verifying that the expected program ID matches the owner of a passed-in account, an attacker can create a fake account with manipulated data to satisfy other preconditions.

Even the malicious account will have a different owner (program ID), if no ownership validation is performed, the program may trust attacker-controlled data and proceed as if it were valid program state.

Exploit Scenario

Let’s consider a lending protocol that allows users to withdraw collateral based on their UserPosition account.

The program:

  • Deserializes the UserPosition account

  • Reads collateral_amount

  • Allows withdrawal if sufficient collateral exists

But there is no check that the UserPosition account is owned by the lending program.

An attacker can:

  • Create their own account

  • Serialize fake UserPosition data

  • Set collateral_amount = 1_000_000

  • Pass the malicious account into the withdraw instruction

Because the program never verifies ownership, it trusts the faked data and releases real funds.

Example Contract

fn withdraw(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
) -> ProgramResult {
let account_info_iter = &mut accounts.iter();
    let user_position = next_account_info(account_info_iter)?;
    let vault = next_account_info(account_info_iter)?;

    // @audit : Missing ownership check

    let position_data = UserPosition::deserialize(
        &mut &**user_position.data.borrow()
    )?;

    if position_data.collateral_amount == 0 {
        return Err(ProgramError::InsufficientFunds);
    }

    // withdraw logic...
    Ok(())
}

How to fix it

Make sure that account ownership is verified before deserializing or trusting state.

fn withdraw(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
) -> ProgramResult {
let account_info_iter = &mut accounts.iter();
    let user_position = next_account_info(account_info_iter)?;
    let vault = next_account_info(account_info_iter)?;
 
   // Added ownership check  
 if user_position.owner != program_id {
    return Err(ProgramError::IncorrectProgramId);
    }
    
  let position_data = UserPosition::deserialize(
        &mut &**user_position.data.borrow()
    )?;
  
  if position_data.collateral_amount == 0 {
        return Err(ProgramError::InsufficientFunds);
    }
    // withdraw logic...
    Ok(())
}

3. Division By Zero

Rust panics on division by zero. In a Solana program that means the instruction dies right there — no recovery, no fallback.

Exploit Scenario

Let’s take an example of function that calculates token price:

pub fn calculate_price(accounts: &[AccountInfo]) -> ProgramResult {
    let account_info_iter = &mut accounts.iter();
    let pool_state = next_account_info(account_info_iter)?;

   let state = PoolState::deserialize(&mut &**pool_state.data.borrow())?;
    // @audit - No zero check
    let price = state.total_assets / state.total_supply;
    msg!("Current price: {}", price);
    Ok(())
}

When the total supply becomes zero, the instruction crashes and the transaction fails. If an attacker can intentionally cause this situation, they can repeatedly make the instruction fail, which results in a denial-of-service (DoS) for the protocol.

How to fix it

Always check that denominator should not be zero before division :

pub fn calculate_price(accounts: &[AccountInfo]) -> ProgramResult {
    let account_info_iter = &mut accounts.iter();
    let pool_state = next_account_info(account_info_iter)?;

   let state = PoolState::deserialize(&mut &**pool_state.data.borrow())?;
    // check if total_supply is zero revert 
    if state.total_supply == 0 {
    return Err(ProgramError::InvalidArgument);
     }
    let price = state.total_assets / state.total_supply;
    msg!("Current price: {}", price);
    Ok(())
}

4. Integer Overflow & Underflow

Solana runs in release mode by default. Rust doesn’t panic on overflow there — it wraps silently and keeps going.

What Is Overflow?

Overflow happens when a number exceeds the maximum value allowed by its type.

Example (using u64) :

let max = u64::MAX;
let result = max + 1; // overflow

Instead of failing, the value wraps around to 0 in release builds.

What Is Underflow?

Underflow happens when subtracting a larger number from a smaller one in unsigned integers.

let balance: u64 = 10;
let result = balance - 20; // underflow

Instead of becoming negative, it wraps around to a very large number.

Example

Let’s take an example of withdraw function .

If sender_balance = 100 and amount = 200, the subtraction in the example causes an underflow because the program does not check whether the sender has sufficient balance. Instead of failing, the subtraction wraps around due to the behavior of unsigned integers. In the case of a u64, the result becomes approximately 2^64 - 100, giving the sender a near-infinite balance.

pub fn safe_transfer(sender_balance: u64, amount: u64) -> Result<u64, ProgramError> {
    let new_balance = sender_balance
        .checked_sub(amount)
        .ok_or(ProgramError::InsufficientFunds)?;

    Ok(new_balance)
}

How to fix it

Make sure proper checks are added before the calculations so it doesn’t underflow/overflow or use checked arithmetic (checked_add, checked_sub, checked_mul, checked_div) for all value calculations.

Conclusion

These aren’t exotic bugs. I’ve seen all four of them in production codebases, sometimes in the same audit. The fix is almost always one line — the hard part is that it’s easy to skip when everything else looks fine.

If you’re building on Solana, get your code reviewed with us before it hits mainnet.

Hoping that you learned something from this blog. See you again next time in another awesome blog. Good Luck & WAGMI :)🤝

For Solana audits, reach out to us.

Author: Mohini Vasisth

Security Researcher at TECHFUND


Hi AUDIT

Hi AUDIT is a high speed, high quality, best price security audit service, providing automated audit SaaS and consulting for web3 startups.
View More