Quote pools are expected to have same base token and quote token but this is not enforced in swaps
Source: https://github.com/sherlock-audit/2024-08-woofi-solana-deployment-judging/issues/64
Found by
S3v3ru5, g
Summary
The missing constraint that enforces quote pools should have the same base and quote token will cause swap fees to be deducted from non-quote pools.
By design, quote pools are pools with the same base and quote token. The development team has confirmed this. All swap fees should come from quote pools.
// record fee into account
woopool_quote.sub_reserve(swap_fee).unwrap();
woopool_quote.add_unclaimed_fee(swap_fee).unwrap();
Root Cause
In swap.rs:79-84, there is no constraint that enforces that the pool used as the quote pool has the same base token and quote token.
#[account(mut,
has_one = wooconfig,
constraint = woopool_quote.token_mint == woopool_from.quote_token_mint,
constraint = woopool_quote.authority == woopool_from.authority,
)]
woopool_quote: Box<Account<'info, WooPool>>,
This means that non-quote pools can be used as quote pools during swaps and swap fees will be deducted from these.
// record fee into account
woopool_quote.sub_reserve(swap_fee).unwrap();
woopool_quote.add_unclaimed_fee(swap_fee).unwrap();
Internal pre-conditions
None
External pre-conditions
None
Attack Path
- Anyone can execute swaps by invoking the
swapinstruction and passing a non-quote pool as awoopool_quote. The constraints will allow it as long as thewoopool_quote's base token is the same as thewoopool_from's quote token and the pools have the same owners.
Impact
Swap fees can be deducted from non-quote pools instead of quote pools only.
PoC
No response
Mitigation
Consider adding a constraint that enforces that the quote pool is a pool with the same base and quote token.
Discussion
toprince
Need investigation here. Same with https://github.com/sherlock-audit/2024-08-woofi-solana-deployment-judging/issues/40
toprince
should be Not valid.
- all pools' quote_token_mint is USDC after create pool
- constraint = woopool_quote.token_mint == woopool_from.quote_token_mint
- above constraint should make sure the quote pool is USDC
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/woonetwork/WOOFi_Solana/pull/29
gjaldon
The added constraints to swap() fixes the issue.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A high-severity business logic bug in WOOFi Swap on Solana. Sherlock made it public on 16 October 2024. Found in the 535 audit contest (finding H-2), also found by 1 other warden.
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.