doesn’t calculate the current borrowing amount for the provider, including the provider’s borrowed shares and accumulated fees due to inconsistency in collateralRatio calculation
The collateral ratio calculation in the rigidRedemption function uses only the borrowed amount, ignoring borrowed shares and accumulated fees, unlike the liquidation function which uses getBorrowedOf. This inconsistency could allow a provider to redeem more than they should, potentially causing a loss to the protocol.
turvy_fuzz Follow with SpicyMeatball
Originally disclosed on Code4rena
Submitted by turvy_fuzz, also found by SpicyMeatball
Lines of code
Proof of Concept
Borrowers collateralRatio in the liquidation() function is calculated by:
uint256 onBehalfOfCollateralRatio = (depositedAsset[onBehalfOf] * assetPrice * 100) / getBorrowedOf(onBehalfOf);
Notice it calls the getBorrowedOf() function, which calculates the current borrowing amount for the borrower, including the borrowed shares and accumulated fees, not just the borrowed amount.
function getBorrowedOf(address user) public view returns (uint256) {
return borrowed[user] + feeStored[user] + _newFee(user);
}
However, the providers collateralRatio in the rigidRedemption() function is calculated by:
uint256 providerCollateralRatio = (depositedAsset[provider] * assetPrice * 100) / borrowed[provider];
Here, the deposit asset is divided by only the borrowed amount, missing out on the borrowed shares and accumulated fees.
Tools Used
Visual Studio Code
Recommended Mitigation Steps
Be consistent with collateralRatio calculation.
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
What the attacker needed
Provider has borrowed with accumulated fees
The fix
The collateral ratio calculation in rigidRedemption should use getBorrowedOf(provider) instead of borrowed[provider] to be consistent with the liquidation function.
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 system, your collateral ratio shows how much you've borrowed compared to your deposit. This report found that one function calculates that ratio incorrectly by leaving out fees and shared borrowing, which could let someone take out more than they're allowed.
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.