Skip to content
Business logic Audit finding Intermediate

[H-1]

The Solana vault deposit function did not check that the deposited token matched the allowed token, so an attacker could deposit a worthless token while claiming it was USDC. This would credit them with USDC on the other chain, potentially draining the vault.

0rpse Follow with 0xNirix, LZ_security and 12 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-09-orderly-network-solana-contract-judging/issues/40

Found by

0rpse, 0xNirix, LZ_security, Q7, S3v3ru5, Tendency, chinepun, dod4ufn, g, krikolkk, pashap9990, sh1v, shaflow01, ubermensch, xKeywordx

Summary

There are no checks to ensure that the deposit_token matches the allowed_token in the solana_vault::deposit function. This allows an attacker to deposit any tokens and get minted USDC on the other chain. The system assumes that an allowed token is deposited every time and this assumption is wrong.

Root Cause

In deposit.rs, the Deposit struct lacks a constraint to verify that deposit_token.key() matches the allowed_token.mint_account.

This check could also be added inside the solana_vault::deposit or the deposit.rs::apply functions directly, but currently, none of these functions have this check either.

deposit_params.token_hash is a user-controlled input param provided by the user when they call the solana_vault::deposit function. It is intended to represent the hash of the token the user is depositing. The problem is that there is no enforced relationship with deposit_token. There is no constraint that enforces that deposit_params.token_hash corresponds to the actual deposit_token mint provided in the accounts.

Internal pre-conditions

  1. The allowed_token account is configured to accept a specific token (USDC) with allowed_token.allowed == true.
  2. The allowed_token.mint_account is set to the mint address of the allowed token (USDC).
  3. The vault is initialized and operational, expecting deposits of the allowed token.

External pre-conditions

  1. The attacker possesses another token, e.g., WIF or another memecoin.
  2. The attacker has a token account associated with this memecoin and owns, let's say 10.000 tokens which are worth 1$. Assume a price/coin of 0.0001$.
  3. The attacker knows the token_hash corresponding to the allowed token (USDC).

Attack Path

The attacker calls the deposit Function and provides:

  • WIF as deposit_token
  • with an amount of 10.000
  • deposit_params.token_hash that corresponds to USDC token_hash
  • includes the allowed_token that the Vault is configured to accept (USDC).

Program Execution:

  • The function deposit.rs::transfer_token_ctx transfers the tokens from the attacker's user_token_account to the vault's vault_token_account.
  • Due to the missing constraint, the program does not verify that deposit_token.key() matches allowed_token.mint_account.
  • The deposit.rs::apply function increments vault_authority.deposit_nonce by 1.
  • After that, the apply function creates the VaultDepositParams object, setting token_hash to be equal to whatever token_hash the user provided inside the DepositParams struct.
  • The program records the deposit as if the allowed token (USDC) was deposited.
  • It sends a message to the other chain indicating that the allowed token was deposited.

Resulting Impact:

  • On the other chain, the attacker is credited with USDC equivalent to the amount of tokens deposited (10.000 USDC).
  • The vault holds the WIF tokens, which are worth 1$ (for the sake of this example). The attacker can even create a random coin with no value and make the deposit.

Impact

For the Protocol:

  • The protocol suffers a financial loss equivalent to the amount of USDC incorrectly credited to the attacker on the other chain.
  • The vault ends up holding unauthorized tokens instead of the intended allowed tokens.

For the Attacker:

  • The attacker gains USDC on the other chain without depositing the equivalent value of the allowed token.
  • The attacker can drain the vault.

PoC

Not necessary. Check the solana-vault/packages/solana/contracts/programs/solana-vault/src/instructions/vault_instr/deposit.rs::Deposit struct definition here. There are no checks that enforce deposit_token == allowed_token.

You can also check the Solana Vault deposit function implementation solana-vault/packages/solana/contracts/programs/solana-vault/src/lib.rs::deposit here and see that it doesn't have this check, nor does the solana-vault/packages/solana/contracts/programs/solana-vault/src/instructions/vault_instr/deposit.rs::apply function -- check it here.

Mitigation

Add a new constraint in deposit.rs::Deposit struct.

Update the deposit_token account definition in deposit.rs to include a constraint that ensures the deposit_token mint matches the allowed_token.mint_account.

Rust
#[account(
    constraint = deposit_token.key() == allowed_token.mint_account @ VaultError::InvalidDepositToken
)]

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/OrderlyNetwork/solana-vault/pull/4

gjaldon

This issue is fixed here. The recommended constraint was added to deposit.rs::Deposit struct.

The original report as published on Sherlock, by 0rpse. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The deposit instruction lacked a constraint verifying that the deposited token's mint address equals the allowed token's mint address.

Impact

The attacker could drain the vault by depositing worthless tokens and receiving USDC on the other chain, causing financial loss to the protocol.

What the attacker needed

Attacker possesses a worthless token; Attacker knows the token_hash of the allowed token; Vault is initialized and operational

The fix

The issue was fixed by adding a constraint to the Deposit struct that checks the deposited token's mint matches the allowed token's mint account.

How it was found

  1. The attacker calls the deposit function with a worthless token as deposit_token.
  2. The attacker sets deposit_params.token_hash to the hash of the allowed token (USDC).
  3. The attacker includes the allowed_token account configured for USDC.
  4. The program transfers the worthless tokens to the vault without checking the token mint.
  5. The program records the deposit as if USDC was deposited and sends a message to the other chain.
  6. The attacker is credited with USDC on the other chain.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A vault on Solana accepts deposits and credits you with USDC on another blockchain. It should only accept a specific token, like USDC, but it didn't check which token you actually sent. So you could send a worthless token and still get credited with valuable USDC.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by 0rpse

View all

23 more disclosed reports, best first.

More from Orderly Solana Vault Contract

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.