setAnnualInterestBips() can be abused to keep a market’s reserve ratio at 90%
A borrower can repeatedly call setAnnualInterestBips() to reduce the interest rate by a tiny amount, which resets the market's reserve ratio to 90% for two weeks. By repeating this every two weeks, the borrower can keep the reserve ratio at 90% indefinitely, even if the market was deployed with a higher ratio, reducing the assets available for lenders to withdraw.
MiloTruck Follow with T1MOH, elprofesor and 6 others
Originally disclosed on Code4rena
Submitted by MiloTruck, also found by T1MOH, elprofesor, trachev, t0x1c, ast3ros, joaovwfreire, CaeraDenoir, and rvierdiiev
If a borrower calls setAnnualInterestBips() to reduce a market’s annual interest rate, its reserve ratio will be set to 90% for 2 weeks:
WildcatMarketController.sol#L472-L485
// If borrower is reducing the interest rate, increase the reserve
// ratio for the next two weeks.
if (annualInterestBips < WildcatMarket(market).annualInterestBips()) {
TemporaryReserveRatio storage tmp = temporaryExcessReserveRatio[market];
if (tmp.expiry == 0) {
tmp.reserveRatioBips = uint128(WildcatMarket(market).reserveRatioBips());
// Require 90% liquidity coverage for the next 2 weeks
WildcatMarket(market).setReserveRatioBips(9000);
}
tmp.expiry = uint128(block.timestamp + 2 weeks);
}
This is meant to give lenders the option to withdraw from the market should they disagree with the decrease in annual interest rate.
However, such an implementation can be abused by a borrower in a market where the reserve ratio above 90%:
-
Borrower deploys a market with a reserve ratio at 95%.
-
A lender, who agrees to a 95% reserve ratio, deposits into the market.
-
Borrower calls
setAnnualInterestBips()to reduceannualInterestBipsby 1.- This causes the market’s reserve ratio to be set to 90% for 2 weeks.
-
After 2 weeks, the borrower calls
setAnnualInterestBips()and decreasesannualInterestBipsby 1 again. -
By repeating steps 3 and 4, the borrower can effectively keep the market’s reserve ratio at 90% forever.
In the scenario above, the 5% reduction in reserve ratio works in favor of the borrower since they do not have to keep as much assets in the market. The amount of assets that all lenders can withdraw at any given time will also be 5% less than what it should be.
Note that it is possible for a market to be deployed with a reserve ratio above 90% if the protocol’s MaximumReserveRatioBips permits. For example, MaximumReserveRatioBips is set to 100% in current tests:
uint16 constant MaximumReserveRatioBips = 10_000;
Impact
In a market where the reserve ratio is above 90%, a borrower can repeatedly call setAnnualInterestBips() every two weeks to keep the reserve ratio at 90%.
This is problematic, as a market’s reserve ratio is not meant to be adjustable post-deployment, since the borrower and their lenders must agree to a fixed reserve ratio beforehand.
Recommended Mitigation
In setAnnualInterestBips(), consider setting the market’s reserve ratio to 90% only if it is lower:
WildcatMarketController.sol#L472-L485
// If borrower is reducing the interest rate, increase the reserve
// ratio for the next two weeks.
- if (annualInterestBips < WildcatMarket(market).annualInterestBips()) {
+ if (annualInterestBips < WildcatMarket(market).annualInterestBips() && WildcatMarket(market).reserveRatioBips() < 9000) {
TemporaryReserveRatio storage tmp = temporaryExcessReserveRatio[market];
if (tmp.expiry == 0) {
tmp.reserveRatioBips = uint128(WildcatMarket(market).reserveRatioBips());
// Require 90% liquidity coverage for the next 2 weeks
WildcatMarket(market).setReserveRatioBips(9000);
}
tmp.expiry = uint128(block.timestamp + 2 weeks);
}
laurenceday (Wildcat) commented:
Tricky one that we went over several times with wardens. 90% was presented here to illustrate the functionality of setting a higher reserve, rather than one we actually wanted to use. Turns out I misjudged the willingness to bikeshed this point. Not going to quibble over this being a medium, since it’s on me and my documentation.
The relationship between APR and willingness to grant credit is not linear - a 20% decrease in APR may induce far more than that amount of deposits to exit. At the same time, however, insisting on a full return of assets for a small decrease renders the credit facility useless to the borrower, while still leaving them liable to pay interest - in that situation, they might as well force a market closed and restart a different one.
We’ve ultimately chosen to - for this first wave of markets - utilize the following formula:
newReserve = max(max(100%, 2 * (oldRate - newRate)/oldRate)), oldReserve)As an example, reducing the lender APR of a market from 5% to 3% will require an 80% reserve ratio (twice the 40% relative difference), but if the previous ratio was higher than this, it persists. Meeting point between competing sets of interests.
We’ve implemented this over the course of a few commits.
For images provided, refer to the original comment.
I understand the sponsor’s dissatisfaction about those findings and appreciate the insightful comment, as well as the proposed formula which would avoid the issue. However, it’s my duty to judge the issues with respect to this audit’s codebase (source of truth).
laurenceday (Wildcat) confirmed
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
Impact
The borrower can keep the reserve ratio at 90% indefinitely, reducing the assets available for lenders to withdraw by up to 5% compared to the agreed ratio.
What the attacker needed
Market deployed with reserve ratio above 90%; borrower controls the market; lender deposits into the market
The fix
The function should set the reserve ratio to 90% only if the current ratio is lower than 90%, as recommended in the report.
How it was found
- Borrower deploys a market with a reserve ratio at 95%.
- A lender deposits into the market.
- Borrower calls setAnnualInterestBips() to reduce annualInterestBips by 1, causing the reserve ratio to be set to 90% for 2 weeks.
- After 2 weeks, the borrower calls setAnnualInterestBips() and decreases annualInterestBips by 1 again.
- By repeating steps 3 and 4, the borrower can keep the reserve ratio at 90% forever.
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 market, the reserve ratio is the portion of deposits that must be kept available for lenders to withdraw. The code allows the borrower to lower the interest rate, and when they do, it temporarily sets the reserve ratio to 90% for two weeks. The bug is that the borrower can keep doing this every two weeks, so the reserve ratio stays at 90% even if it was supposed to be higher, meaning lenders have less money they can take out.
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.