FraxlendPair.changeFee() doesn’t update interest before changing fee.
The changeFee() function updates the protocol fee without first accruing interest, so when interest is later calculated, the new fee is applied retroactively to the period before the change. This can cause the protocol to receive an incorrect fee amount, potentially higher than intended.
Originally disclosed on Code4rena
Submitted by auditor0517
This function is changing the protocol fee that is used during interest calculation here.
But it doesn’t update interest before changing the fee so the _feesAmount will be calculated wrongly.
Proof of Concept
As we can see during pause() and unpause(), _addInterest() must be called before any changes.
But with the changeFee(), it doesn’t update interest and the _feesAmount might be calculated wrongly.
- At time
T1, _currentRateInfo.feeToProtocolRate = F1. - At
T2, the owner had changed the fee toF2. - At
T3, _addInterest() is called duringdeposit()or other functions. - Then during this calculation,
F1should be applied fromT1toT2andF2should be applied fromT2andT3. But it usesF2fromT1toT2.
Recommended Mitigation Steps
Recommend modifying changeFee() like below.
function changeFee(uint32 _newFee) external whenNotPaused {
if (msg.sender != TIME_LOCK_ADDRESS) revert OnlyTimeLock();
if (_newFee > MAX_PROTOCOL_FEE) {
revert BadProtocolFee();
}
_addInterest(); //+++++++++++++++++++++++++++++++++
currentRateInfo.feeToProtocolRate = _newFee;
emit ChangeFee(_newFee);
}
DrakeEvans (Frax) confirmed, but disagreed with severity and commented:
Disagree with severity as it can be mitigated by calling
addInterest()beforehand by admin or regular user. But we will address it anyway for convenience. We assume admins are not malicious.
Admins might not be malicious, but without knowing about the issue (i.e. if the warden hasn’t reported this) they wouldn’t call
addInterest()beforehand, leading to higher interest than intended.
Maintaining severity as it is a potential leakage.
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 protocol fee amount could be calculated incorrectly, potentially leading to higher fees than intended for the period before the fee change.
What the attacker needed
Admin changes fee; interest not accrued beforehand
The fix
The changeFee() function should call _addInterest() before updating the fee rate.
How it was found
- At time T1, the protocol fee rate is F1.
- At time T2, the owner changes the fee to F2 using changeFee().
- At time T3, _addInterest() is called during deposit() or another function.
- The interest calculation applies F2 to the entire period from T1 to T3, instead of F1 from T1 to T2 and F2 from T2 to T3.
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 contract, interest is calculated periodically. The protocol takes a cut of that interest, called a fee. If you change the fee percentage without first calculating the interest owed up to that moment, the new fee gets applied to past interest too, which is unfair. This report points out that the function to change the fee skips that important step.
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.