[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
- The
allowed_tokenaccount is configured to accept a specific token (USDC) withallowed_token.allowed == true. - The
allowed_token.mint_accountis set to the mint address of the allowed token (USDC). - The vault is initialized and operational, expecting deposits of the allowed token.
External pre-conditions
- The attacker possesses another token, e.g., WIF or another memecoin.
- 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$.
- The attacker knows the
token_hashcorresponding to the allowed token (USDC).
Attack Path
The attacker calls the deposit Function and provides:
WIFasdeposit_token- with an amount of
10.000 deposit_params.token_hashthat corresponds to USDC token_hash- includes the
allowed_tokenthat the Vault is configured to accept (USDC).
Program Execution:
- The function
deposit.rs::transfer_token_ctxtransfers the tokens from the attacker'suser_token_accountto the vault'svault_token_account. - Due to the missing constraint, the program does not verify that
deposit_token.key()matchesallowed_token.mint_account. - The
deposit.rs::applyfunction incrementsvault_authority.deposit_nonceby 1. - After that, the
applyfunction creates theVaultDepositParamsobject, settingtoken_hashto be equal to whatevertoken_hashthe user provided inside theDepositParamsstruct. - 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.
#[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.
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
- The attacker calls the deposit function with a worthless token as deposit_token.
- The attacker sets deposit_params.token_hash to the hash of the allowed token (USDC).
- The attacker includes the allowed_token account configured for USDC.
- The program transfers the worthless tokens to the vault without checking the token mint.
- The program records the deposit as if USDC was deposited and sends a message to the other chain.
- 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.