Zero rates on new quoted tokens allow an attacker to take an interest free quota
When a new token is added to the quota system, its interest rate defaults to zero until the next epoch update. An attacker can borrow a large amount of that token and pay no quota interest for that period, causing a loss of interest revenue for the protocol.
function addQuotaToken(address token) external override gaugeOnly {
if (quotaTokensSet.contains(token)) {
revert TokenAlreadyAddedException();
}
quotaTokensSet.add(token); //@audit rates here are `0` by default.
totalQuotaParams[token].cumulativeIndexLU = 1;
emit AddQuotaToken(token);
}
This function is used to add a new token, when the token is added the rates are set to 0 by default up until a general epoch update before the real rate gets set for the token here.
function _checkAndUpdateEpoch() internal {
uint16 epochNow = IGearStakingV3(voter).getCurrentEpoch(); // U:[GA-14]
if (epochNow > epochLastUpdate) {
epochLastUpdate = epochNow; // U:[GA-14]
if (!epochFrozen) {
// The quota keeper should call back to retrieve quota rates for needed tokens
_poolQuotaKeeper().updateRates(); //@audit
}
emit UpdateEpoch(epochNow); // U:[GA-14]
}
}
However, the problem is the fact that once this new token is added, and the rate is 0, an attacker can request a huge quota even up to the configured limit without having to pay any interest to the protocol all through the period where rate = 0.
Impact
A malicious user can request a very high quota and not pay any interest all through the period when the rate is defaulted to 0.
Recommended Mitigation Steps
Consider atomically updating the rates in the instance where a new quoted token is added.
@Koolex, what that snippet means is the malicious user can take a completely risk free position while exposing the system since the rate is defaulted to 0; i.e., they can just request a very high quota, which in this case would be the configured maximum for said asset thats’s to be used to limit protocol’s exposure. So in this case they do not pay any interest all throughout this period when these rates are 0, which is why I submitted this as High.
To go into a bit more details on the whole context of the quota logic:
@Bauchibred - can you please provide a PoC on how a user can request a huge quota on zero rate? Not necessarily with code. but a breakdown of the call flow. The above proof lacking this.
@Koolex, requesting a huge quota is by just taking up a borrow position against the collateral and whenever calculating the debt from the borrowed position or the revenue change, the methods shown in the report above and dropdown below from PoolQuotaKeeper are used.
Call flow breakdown with code snippets
A user can request a borrow credit against the collateral token here we’d have the deltaDebt to be non-zero which is what I mean by a huge quota. Now for each position there are two fees to be charged, one based on pool utilisation and another based on the quota fees from PoolQuotaKeeperV3 and since the quota interest has been defaulted to zero before the next epoch as hinted in the report whenever paying back the protocol loses out on this interest, (i.e., the quota interest):
That’s to say when the user decides to repay, or their position is being interacted with the amount of debt is gotten by _calcDebt, but no quota interest is being calculated for them cause while calculating the debt for the position we have 0 interest rate being returned for cumulativeQuotaInterest. As such, it’s not being considered for the overall accrued interest:
Also in the same light revenue change for quota would always be 0 during modification of collateral/debt or even liquidation that’s queried in the vault by the _calcQuotaRevenueChange() helper function:
/// @dev Computes the pool quota revenue change given the current rate and the quota change
function calcQuotaRevenueChange(uint16 rate, int256 change) internal pure returns (int256) {
return change * int256(uint256(rate)) / int16(PERCENTAGE_FACTOR);
}
Edit: Took consideration of @0xAlix2’s comment below and explicitly attached the fact that the interest which Loopfi is losing out on is their “quota interest” and not the whole debt’s interest as they assume. To note, why we are talking about debt in this discussion is cause I needed to showcase where the huge quota is requested since asked by the judge. Do check the diffs for the edit. In my opinion, this fact can also be seen clearly even from the title of the report that the user is getting an “interest free quota” and not an interest free debt.
NB: This same issue was reported and fixed in the original Gearbox protocol, see 7.3 which this is a fork of. Albeit in that instance it was assessed as a Medium, I submitted as high cause per C4 standards and as hinted here already, it doesn’t need any hypothetical path to be actualised.
There’s some confusion here, having 0 cdd.cumulativeQuotaInterest doesn’t mean no interest. Let me explain, Loopfi has 2 separate interest rates, there’s the quota interest and the default credit interest, as seen the credit interest calculation has nothing to do with the Quota’s logic, you can confirm this from Loopfi’s docs.
I also had this fuzzing test that confirms this, that you can add in src/test/unit/CDPVault.t.sol:
Assuming the test is wrong (which I don’t think so), and the quota interest is 0, we can manually manipulate the quota index (so that it matches the initially set index here) so that the resulting quota interest is 0:
We can see that the Quota interest is indeed 0, but the user is casually paying the other “credit” interest.
As a result, there’s always some interest being paid to the protocol.
Edit: My response mainly refuted the following, showing that interest will always be paid regardless of the Quota.
an attacker can request a huge quota even up to the configured limit without having to pay any interest to the protocol
Assuming that the Quotas interest will always be 0 (I still doubt it, as the above test shows this, unless I’m missing something), for this to be high, assets need to be “stolen/lost/compromised”, how is this happening here?
@Bauchibred - I’m already aware that the issue was already reported elsewhere; in fact, if you search the in the codebase (in the lib) you would find the fixed version. Somehow, the devs overlooked it.
To summarize the impact, quota interest won’t be paid during the period where rate = 0, max time of this is one epoch. In normal cases, I would consider this as a Medium. However, I have re-assessed it above as High for the following reasons:
It can happen on each new token added.
Can be done at scale (i.e., many users) or one user with a huge amount, as a result loss of interest for LPs who voted for it.
It undermines the intended functionality from voting (CA vs LP) on quota rate, if there is any.
The original report as published on Code4rena, by Bauchibred. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Impact
The protocol loses quota interest revenue for the period when the rate is zero, which can be up to one epoch, and this can happen for each new token added and at scale.
What the attacker needed
A new token is added to the quota system; attacker borrows before the next epoch update
The fix
The rates should be updated atomically when a new quoted token is added, so that the zero-rate period does not exist.
How it was found
A new token is added to the quota system via addQuotaToken, which sets its rate to zero.
Before the next epoch update, an attacker borrows a large amount of that token, up to the configured quota limit.
The attacker repays after the epoch update, having paid no quota interest for the period when the rate was zero.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
In this lending protocol, users pay two kinds of interest: a base interest on borrowed assets and an extra 'quota interest' that depends on how much of a particular token is borrowed. When a new token is added, its quota interest rate is set to zero until the next scheduled update. This means a user can borrow a lot of that token and, for that short period, pay no quota interest at all, which costs the protocol money.
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.