The USer will receive less amount than user expected
The redemption function checks the minimum redeem amount before deducting the fee, so the user can receive less than the specified minimum. An attacker could exploit this to receive a smaller payout than expected.
aman Follow with blackhole and eeshenggoh
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-05-elfi-protocol-judging/issues/251
The protocol has acknowledged this issue.
Found by
aman, blackhole, eeshenggoh
Summary
While redeeming the stack tokens, The user provides the minRedeemAmount to ensure they receive at least that amount. However, within executeRedeemStakeToken function, the minRedeemAmount check is used before deducting the fee . which could result in the user receive less amount than the expected amount.
Vulnerability Detail
The Protocol allows user to specify the minRedeemAmount to insure that the user will receive this amount or in other case the transaction will revert. The User will first submit a request for Redemption where he also specify this minRedeemAmount which user expect to receive. The Issue is in the execute redemption request flow.
function _executeRedeemStakeToken(
LpPool.Props storage pool,
Redeem.Request memory params,
address baseToken
) internal returns (uint256) {
...
cache.redeemTokenAmount = CalUtils.usdToToken(
cache.unStakeUsd,
cache.tokenDecimals,
OracleProcess.getLatestUsdUintPrice(baseToken, false)
);
if (pool.getPoolAvailableLiquidity() < cache.redeemTokenAmount) {
revert Errors.RedeemWithAmountNotEnough(params.account, params.redeemToken);
}
@> if (params.minRedeemAmount > 0 && cache.redeemTokenAmount < params.minRedeemAmount) {
revert Errors.RedeemStakeTokenTooSmall(cache.redeemTokenAmount);
}
...
FeeProcess.chargeMintOrRedeemFee(
redeemFee,
params.stakeToken,
params.redeemToken,
params.account,
FeeProcess.FEE_REDEEM,
false
);
VaultProcess.transferOut(
params.stakeToken,
params.redeemToken,
params.receiver,
@> cache.redeemTokenAmount - cache.redeemFee
);
pool.subPoolAmount(pool.baseToken, cache.redeemTokenAmount);
StakeToken(params.stakeToken).burn(params.account, params.unStakeAmount);
stakingAccountProps.subStakeAmount(params.stakeToken, params.unStakeAmount);
return cache.redeemTokenAmount;
}
As it can be observed from above code that we first convert the unStkaeUsd amount and store receive value in cache.redeemTokenAmount.Than we check for minRedeemAmount
and than we deduct the fee and transfer the remaining redeemTokenAmount to user.
Following case would occur due to this:
- Bob submit a request to redeem 10e18 token and expect to receive 9e18 token.
- the Protocol convert the amount using latest oracle price and get 9 token as redeemTokenAmount.
- The
cache.redeemTokenAmount < params.minRedeemAmountcheck will pass as 9e18 < 9e18. - The
RedeemFeeRate=10andRATE_PRECISION=100000Now Applying these values to calculate the Fee amount is9e18*10/100000= 9e14. - The amount Bob will receive is
9e18-9e14≈8.9e17.
This applies on both functions _executeRedeemStakeUsd and _executeRedeemStakeToken.
Impact
The user will receive less amount than expected.
Code Snippet
Tool used
Manual Review
Recommendation
Use slippage check after deducting the Fee.
diff --git a/elfi-perp-contracts/contracts/process/RedeemProcess.sol b/elfi-perp-contracts/contracts/process/RedeemProcess.sol
index dedfe16e..eb6c84fe 100644
--- a/elfi-perp-contracts/contracts/process/RedeemProcess.sol
+++ b/elfi-perp-contracts/contracts/process/RedeemProcess.sol
@@ -200,9 +200,7 @@ library RedeemProcess {
tokenDecimals,
OracleProcess.getLatestUsdUintPrice(params.redeemToken, false)
);
- if (params.minRedeemAmount > 0 && redeemTokenAmount < params.minRedeemAmount) {
- revert Errors.RedeemStakeTokenTooSmall(redeemTokenAmount);
- }
if (pool.getMaxWithdraw(params.redeemToken) < redeemTokenAmount) {
revert Errors.RedeemWithAmountNotEnough(params.account, params.redeemToken);
}
@@ -219,6 +217,9 @@ library RedeemProcess {
FeeProcess.FEE_REDEEM,
false
);
+ if (params.minRedeemAmount > 0 && redeemTokenAmount-redeemFee < params.minRedeemAmount) {
+ revert Errors.RedeemStakeTokenTooSmall(redeemTokenAmount);
+ }
StakeToken(params.stakeToken).burn(account, params.unStakeAmount);
StakeToken(params.stakeToken).transferOut(params.redeemToken, params.receiver, redeemTokenAmount - redeemFee);
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 minimum redeem amount check is performed before the fee is deducted, so the final transferred amount can be below the minimum.
Impact
The user will receive less amount than expected.
What the attacker needed
User initiates a redemption with a minimum amount
The fix
The slippage check should be performed after deducting the fee.
How it was found
- Bob submits a redemption request for 10e18 tokens with a minimum redeem amount of 9e18.
- The protocol converts the amount using the latest oracle price and gets 9e18 as redeemTokenAmount.
- The check `cache.redeemTokenAmount < params.minRedeemAmount` passes because 9e18 is not less than 9e18.
- The fee is calculated as 9e18 * 10 / 100000 = 9e14.
- Bob receives 9e18 - 9e14 ≈ 8.9e17, which is less than his minimum of 9e18.
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.
When you redeem tokens, you can set a minimum amount you want to receive. The code checks this minimum before subtracting the fee, so after the fee is taken, you might get less than your minimum. This means the protection doesn't work as intended.
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.