Open sherlock-admin2 opened 1 month ago
You are very careful when checking if 2 contracts are identical. Here is the main difference when implement in solana. Previously, the same logic in solana also raised when auditing the evm contract. So we choose to use this version in solana. So this is by design...
0xeix
Medium
Spread is not updated for base tokens when performing base to base swap
Summary
Currently the function
handler()
is supposed to update the spread and the state afterwards of both base tokens when performing base to base swap. However, it does not do it.Vulnerability Detail
Take a look at how state updates are made inside of
handler()
function:https://github.com/sherlock-audit/2024-08-woofi-solana-deployment/blob/main/WOOFi_Solana/programs/woofi/src/instructions/swap.rs#L135-139
However, in the EVM implementation of the contracts, it's done the following way:
https://github.com/woonetwork/WooPoolV2/blob/main/contracts/WooPPV2.sol#L545-558
As you can see from code snippets above, in the first case we don't take spread into account at all. This results in an incorrect
spread
value being used when calculating amount for both operations (selling base to quote, selling quote to base) as we take not the average spread as in the EVM version but the spread of the base token:https://github.com/sherlock-audit/2024-08-woofi-solana-deployment/blob/main/WOOFi_Solana/programs/woofi/src/instructions/get_price.rs#L115
https://github.com/sherlock-audit/2024-08-woofi-solana-deployment/blob/main/WOOFi_Solana/programs/woofi/src/util/swap_math.rs#L54-58
https://github.com/sherlock-audit/2024-08-woofi-solana-deployment/blob/main/WOOFi_Solana/programs/woofi/src/util/swap_math.rs#L104-108
As the protocol states for the EVM and Solana contracts to be identical, this can be also considered as a deviation from the spec.
Impact
Incorrect spread being used may affect base amount calculation.
Code Snippet
Provided above.
Tool used
Manual Review
Recommendation
Calculate the average spread of the base token 1 and base token 2 by fetching their corresponding states from the oracle and use this spread in calculation of base amount in
swap_math
.