New treasury rate should not affect existing loan
The contract owner can change the treasury fee rate at any time, and the new rate applies to existing loans. This means a lender who agreed to a 5% fee could suddenly face a 50% fee when claiming interest, reducing their payout.
minhquanym Follow with d3e4 and rbserver
Originally disclosed on Code4rena
Submitted by minhquanym, also found by d3e4 and rbserver
In the protocol, lenders have to pay a small treasury fee when they claim their interest. The contract owner can change this _treasuryRate at any time using the function setTreasuryRate().
// @audit treasury rate should not affect existing loan
function setTreasuryRate(uint256 rate) external onlyOwner {
if (rate > MathUtils._BASIS_POINTS) {
revert Errors.InvalidParameters();
}
_treasuryRate = rate;
emit UpdateTreasuryRate(rate);
}
However, when the admin changes the rate, the new treasury rate will also be applied to active loans, which is not the agreed-upon term between the lenders and borrowers when they supplied the NFT and created the loan.
Proof of Concept
Consider the following scenario:
- Alice and Bob have an active loan with an accumulated interest of 1 ETH and
_treasuryRate = 5%. - The admin suddenly changes the
_treasuryRateto50%. Now, if Alice claims the interest, she needs to pay 0.5 ETH to the treasury and keep 0.5 ETH. - Alice can either accept it and keep 0.5 ETH interest or front-run the admin transaction and claim before the
_treasuryRateis updated.
The point is, Alice only agreed to pay a 5% treasury rate at the beginning, so the new rate should not apply to her.
Recommended Mitigation Steps
Consider storing the treasuryRate in the loan struct. The loan struct is not kept in storage, so the gas cost will not increase significantly.
Alternatively, consider adding a timelock mechanism to prevent the admin from changing the treasury rate.
Marked as primary because of the concise explanation and the mitigation suggestion.
wukong-particle (Particle) confirmed and commented:
Acknowledged the issue, though the fix might not be the same as suggested. We will mitigate it with an upper bound on the treasury rate, and perhaps the timelock mechanism.
wukong-particle (Particle) commented:
Mitigated.
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 treasury rate is stored as a single global variable that is read at claim time, so any change applies to all loans regardless of when they were created.
Impact
Lenders could lose a significant portion of their earned interest if the owner raises the treasury rate, though they could front-run the change to claim at the old rate.
What the attacker needed
An active loan with accumulated interest; the contract owner changes the treasury rate
The fix
The treasury rate should be stored per loan at creation time, or a timelock should be added to rate changes; the project acknowledged the issue and mitigated it with an upper bound and possibly a timelock.
How it was found
- Alice and Bob have an active loan with accumulated interest and a 5% treasury rate.
- The admin changes the treasury rate to 50%.
- Alice claims the interest and must pay 0.5 ETH to the treasury instead of the expected 0.05 ETH.
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.
A smart contract lets people lend and borrow using NFTs as collateral. Lenders pay a small fee to the protocol's treasury when they collect interest. The owner can change that fee percentage whenever they want, and the change affects loans that were already active. So a lender might have agreed to a 5% fee but later be charged 50%, which is unfair.
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.