The protocol will not be able to add liquidity on the curve with another token with a balance
The CurveSpell contract only approves the Curve pool to spend the borrowed token, not the other tokens used for liquidity. As a result, adding liquidity with a second token that the protocol holds will fail because the pool cannot transfer it.
Bauer Follow with nobody2018
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-04-blueberry-judging/issues/47
Found by
Bauer, nobody2018
Summary
The CurveSpell protocol only ensure approve curve pool to spend its borrow token. Hence, it will not be able to add liquidity on the curve with another token with a balance.
Vulnerability Detail
The openPositionFarm() function enables user to open a leveraged position in a yield farming strategy by borrowing funds and using them to add liquidity to a Curve pool, while also taking into account certain risk management parameters such as maximum LTV and position size. When add liquidity on curve ,the protocol use the borrowed token and the collateral token, it checks the number of tokens in the pool and creates an array of the supplied token amounts to be passed to the add_liquidity function. Then the curve will transfer the tokens from the protocol and mint lp tokens to the protocol. However, the protocol only ensure approve curve pool to spend its borrow token. Hence, it will not be able to add liquidity on the curve with another token with a balance.
// 3. Add liquidity on curve
_ensureApprove(param.borrowToken, pool, borrowBalance);
if (tokens.length == 2) {
uint256[2] memory suppliedAmts;
for (uint256 i = 0; i < 2; i++) {
suppliedAmts[i] = IERC20Upgradeable(tokens[i]).balanceOf(
address(this)
);
}
ICurvePool(pool).add_liquidity(suppliedAmts, minLPMint);
} else if (tokens.length == 3) {
uint256[3] memory suppliedAmts;
for (uint256 i = 0; i < 3; i++) {
suppliedAmts[i] = IERC20Upgradeable(tokens[i]).balanceOf(
address(this)
);
}
ICurvePool(pool).add_liquidity(suppliedAmts, minLPMint);
} else if (tokens.length == 4) {
uint256[4] memory suppliedAmts;
for (uint256 i = 0; i < 4; i++) {
suppliedAmts[i] = IERC20Upgradeable(tokens[i]).balanceOf(
address(this)
);
}
ICurvePool(pool).add_liquidity(suppliedAmts, minLPMint);
}
Impact
The protocol will not be able to add liquidity on the curve with another token with a balance.
Code Snippet
Tool used
Manual Review
Recommendation
Allow the curve pool to spend tokens that have a balance in the protocol to add liquidity
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 contract approves only the borrowed token for the Curve pool, omitting approval for the other tokens whose balances are supplied to add_liquidity.
What the attacker needed
Protocol holds a non-borrow token balance; user calls openPositionFarm with a Curve pool
The fix
The contract should approve the Curve pool to spend all tokens that have a balance and are used for adding liquidity.
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 add money to a savings pool, you must first give the pool permission to take that money from your account. Here, the code only gave permission for one type of token (the borrowed one), not for the other token it also wanted to deposit. So the pool could not take the second token, and the deposit failed.
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.