If the user send more quote tokens than input tokens or the system used less tokens than the one provided, the user does get refunded the unused tokens.
In the same way, the flashLoan function calculates the minimum amount that should be received by the contract :
However, it does not refund any additional tokens provided that were not used, in case provided tokens > receiveQuoteAmount or provided tokens > receiveBaseAmount.
This loss can be even more pronounced if there is a sudden price change due to increased volatility, a higher slippage factor k, or because of high value trades.
0xMaroutis
medium
Users can lose funds when buying shares or executing flashLoan
Summary
During the buying of shares or the execution of a flashloan, the protocol does not refund the user for the unused tokens.
Vulnerability Detail
When buying shares, the function only uses the minimum amount provided between the base input and quote input.
If the user send more quote tokens than input tokens or the system used less tokens than the one provided, the user does get refunded the unused tokens.
In the same way, the
flashLoan
function calculates the minimum amount that should be received by the contract :However, it does not refund any additional tokens provided that were not used, in case
provided tokens > receiveQuoteAmount or provided tokens > receiveBaseAmount
.This loss can be even more pronounced if there is a sudden price change due to increased volatility, a higher slippage factor
k
, or because of high value trades.Impact
Loss of funds for users.
Code Snippet
https://github.com/sherlock-audit/2023-12-dodo-gsp/blob/main/dodo-gassaving-pool/contracts/GasSavingPool/impl/GSPTrader.sol#L138-L141 https://github.com/sherlock-audit/2023-12-dodo-gsp/blob/main/dodo-gassaving-pool/contracts/GasSavingPool/impl/GSPTrader.sol#L186-L189 https://github.com/sherlock-audit/2023-12-dodo-gsp/blob/main/dodo-gassaving-pool/contracts/GasSavingPool/impl/GSPFunding.sol#L69
Tool used
Manual Review
Recommendation
Refund back the unused tokens to users.
Duplicate of #74