Minting stake tokens is not updating the pool's borrowing fee rate
Minting stake tokens adds liquidity to the pool but does not update the borrowing fee rate, so the rate remains based on outdated pool balances. This can cause unfair borrowing fees and potentially unfair liquidations.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-05-elfi-protocol-judging/issues/136
Found by
mstpr-brainbot
Summary
When users mint new stake tokens, they provide liquidity to the pool, increasing the total amount and decreasing the borrowed utilization. However, this rate is not updated.
Vulnerability Detail
When users mint stake tokens, they add liquidity to the pool and increase the total amount held in the pool:
function _mintStakeToken(Mint.Request memory mintRequest) internal returns (uint256 stakeAmount) {
//..
-> pool.addBaseToken(cache.mintTokenAmount);
.
}
As we can see, the borrowing rate calculation will change accordingly. However, the rate is not updated:
function getLongBorrowingRatePerSecond(LpPool.Props storage pool) external view returns (uint256) {
if (pool.baseTokenBalance.amount == 0 && pool.baseTokenBalance.unsettledAmount == 0) {
return 0;
}
int256 totalAmount = pool.baseTokenBalance.amount.toInt256() + pool.baseTokenBalance.unsettledAmount;
if (totalAmount <= 0) {
return 0;
}
uint256 holdRate = CalUtils.divToPrecision(
pool.baseTokenBalance.holdAmount,
totalAmount.toUint256(),
CalUtils.SMALL_RATE_PRECISION
);
return CalUtils.mulSmallRate(holdRate, AppPoolConfig.getLpPoolConfig(pool.stakeToken).baseInterestRate);
}
Impact
Unfair accrual of borrowing fees. It can yield on lesser/higher fees for lps and position holders. It can also delay or cause unfair liquidations. Hence, high.
Code Snippet
Tool used
Manual Review
Recommendation
Just like the opening orders update the rates after the pools base amounts changes.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/0xCedar/elfi-perp-contracts/pull/47
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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 minting function updates the pool's base token balance but fails to call the function that recalculates the borrowing rate.
Impact
Unfair accrual of borrowing fees could yield lower or higher fees for liquidity providers and position holders, and may delay or cause unfair liquidations.
What the attacker needed
None
The fix
The protocol team fixed this issue in a pull request.
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.
In a lending pool, the interest rate borrowers pay depends on how much of the pool is borrowed. When someone adds money to the pool, the rate should go down. Here, adding money did not update the rate, so borrowers and lenders could pay or receive the wrong amount.
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.