No slippage check for leverageStrategy function
The leverageStrategy function in the lending contract borrows and swaps tokens without any slippage limit or deadline, so the amount borrowed can be larger than the user intended. A user opening a leveraged position could therefore end up with more debt than expected if the swap executes at an unfavourable price.
Source: https://github.com/sherlock-audit/2024-12-numa-audit-judging/issues/182
Found by
jokr
Summary
When a user opens a leveraged position using the CNumaToken.leverageStrategy() function, there is no slippage protection to limit the price at which tokens are bought by the strategy contract. As a result, if the tokens are purchased at an unfavorable price, the user may incur more debt than expected. Additionally, the function lacks a deadline parameter to ensure that the transaction is executed within a specified timeframe. Without this parameter, if the transaction is delayed, the user has no control over the price at which the tokens are purchased, increasing their risk.
Root Cause
In CNumaToken.sol:193, there is no slippage check for the borrowAmount. As a result, if the tokens are purchased at a worse price than expected, the user may incur more debt than intended.
function leverageStrategy(
uint _suppliedAmount, // 1O Numa
uint _borrowAmount, // 40 Numa -> rETH
CNumaToken _collateral,
uint _strategyIndex
) external {
// ...
// how much to we need to borrow to repay vault
// @audit-issue There should slippage protection here. Otherwise user will incur more debt if tokens are swap at worst price
uint borrowAmount = strat.getAmountIn(_borrowAmount, false);
uint accountBorrowBefore = accountBorrows[msg.sender].principal;
borrowInternalNoTransfer(borrowAmount, msg.sender);
require(
(accountBorrows[msg.sender].principal - accountBorrowBefore) ==
borrowAmount,
"borrow ko"
);
// swap
EIP20Interface(underlying).approve(address(strat), borrowAmount);
(uint collateralReceived, uint unUsedInput) = strat.swap(
borrowAmount,
_borrowAmount,
false
);
}
The closeLeverageStrategy function also lacks slippage protection.
Internal pre-conditions
No response
External pre-conditions
No response
Attack Path
Let's assume 1 Numa = 0.1 rETH.
- The user calls
leverageStrategy(10, 40, cNuma)to open a 5x leveraged position in Numa tokens. - 10 Numa will be supplied by the user, and 40 Numa will be flash-borrowed from the Numa Vault by the cReth contract.
- These 50 Numa will be supplied as collateral to the cNuma market.
- The cReth contract will then borrow rETH against the provided collateral (50 Numa in step 3) and exchange it for Numa to repay the 40 Numa flash loan taken in step 2.
- The user expects to incur 4 rETH of debt (40 Numa * 0.1 rETH per Numa). However, there is no control over the price at which the swap occurs. If the swap happens at a worse price, for example, 1 Numa = 0.15 rETH, the user will incur 6 rETH of debt instead of the expected 4 rETH. This price discrepancy results in a loss for the user.
Impact
User will incur more debt that expected due to lack of slippage check.
PoC
No response
Mitigation
Add slippage protection for borrowAmount in leverageStrategy function.
function leverageStrategy(
uint _suppliedAmount, // 1O Numa
uint _borrowAmount, // 40 Numa -> rETH
CNumaToken _collateral,
uint _strategyIndex
) external {
// ...
// how much to we need to borrow to repay vault
// @audit-issue There should slippage protection here. Otherwise user will incur more debt if tokens are swap at worst price
uint borrowAmount = strat.getAmountIn(_borrowAmount, false);
+ require(borrowAmount <= maxBorrowAmount);
uint accountBorrowBefore = accountBorrows[msg.sender].principal;
borrowInternalNoTransfer(borrowAmount, msg.sender);
require(
(accountBorrows[msg.sender].principal - accountBorrowBefore) ==
borrowAmount,
"borrow ko"
);
// swap
EIP20Interface(underlying).approve(address(strat), borrowAmount);
(uint collateralReceived, uint unUsedInput) = strat.swap(
borrowAmount,
_borrowAmount,
false
);
}
Also add slippage protection for closeLeverageStrategy function.
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
Likely the function computes the borrow amount from the strategy's current exchange rate and passes it straight to the borrow and swap calls without a caller-supplied maximum or deadline.
Impact
A user could incur more debt than expected because the swap price is not bounded, and the closeLeverageStrategy function has the same gap.
What the attacker needed
User opens a leveraged position; swap executes at an unfavourable price
The fix
The function should accept a caller-supplied maximum borrow amount (and a deadline) and revert when the computed borrow amount exceeds it; the same protection should be added to closeLeverageStrategy.
How it was found
- The user calls leverageStrategy with a supplied amount and a borrow amount to open a leveraged position.
- The supplied tokens are combined with a flash loan from the Numa Vault.
- The combined tokens are supplied as collateral to the cNuma market.
- The contract borrows rETH against that collateral and swaps it for Numa to repay the flash loan.
- Because no price limit is enforced, the swap can execute at a worse rate and the user's debt grows.
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 open a leveraged position, the contract borrows some tokens and swaps them for you. Slippage is the gap between the price you expected and the price you actually got. Here the contract never sets a maximum acceptable price, so a bad swap silently leaves you owing more than you planned.
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.