LybraPeUSDVaultBase.rigidRedemption should use getBorrowedOf instead of borrowed
The rigidRedemption function uses the borrowed mapping instead of getBorrowedOf, which excludes fees, so the debt check and collateral ratio are understated. An attacker could redeem more than allowed and perform redemptions even when the provider's actual collateral ratio is below 100%.
Submitted by cccz
In LybraPeUSDVaultBase, the return value of getBorrowedOf represents the user’s debt, while borrowed only represents the user’s borrowed funds and does not include fees. Using borrowed instead of getBorrowedOf in rigidRedemption results in:
- The requirement for the
peusdAmountparameter is smaller than it actually is. - The calculated
providerCollateralRatiois larger, so thatrigidRedemptioncan be performed, even if the actualproviderCollateralRatiois less than 100e18.
function rigidRedemption(address provider, uint256 peusdAmount) external virtual {
require(configurator.isRedemptionProvider(provider), "provider is not a RedemptionProvider");
require(borrowed[provider] >= peusdAmount, "peusdAmount cannot surpass providers debt");
uint256 assetPrice = getAssetPrice();
uint256 providerCollateralRatio = (depositedAsset[provider] * assetPrice * 100) / borrowed[provider];
require(providerCollateralRatio >= 100 * 1e18, "provider's collateral ratio should more than 100%");
_repay(msg.sender, provider, peusdAmount);
uint256 collateralAmount = (((peusdAmount * 1e18) / assetPrice) * (10000 - configurator.redemptionFee())) / 10000;
depositedAsset[provider] -= collateralAmount;
collateralAsset.transfer(msg.sender, collateralAmount);
emit RigidRedemption(msg.sender, provider, peusdAmount, collateralAmount, block.timestamp);
}
Proof of Concept
Recommended Mitigation Steps
Change to:
function rigidRedemption(address provider, uint256 peusdAmount) external virtual {
require(configurator.isRedemptionProvider(provider), "provider is not a RedemptionProvider");
- require(borrowed[provider] >= peusdAmount, "peusdAmount cannot surpass providers debt");
+ require(getBorrowedOf(provider) >= peusdAmount, "peusdAmount cannot surpass providers debt");
uint256 assetPrice = getAssetPrice();
- uint256 providerCollateralRatio = (depositedAsset[provider] * assetPrice * 100) / borrowed[provider];
+ uint256 providerCollateralRatio = (depositedAsset[provider] * assetPrice * 100) / getBorrowedOf(provider);
require(providerCollateralRatio >= 100 * 1e18, "provider's collateral ratio should more than 100%");
_repay(msg.sender, provider, peusdAmount);
uint256 collateralAmount = (((peusdAmount * 1e18) / assetPrice) * (10000 - configurator.redemptionFee())) / 10000;
depositedAsset[provider] -= collateralAmount;
collateralAsset.transfer(msg.sender, collateralAmount);
emit RigidRedemption(msg.sender, provider, peusdAmount, collateralAmount, block.timestamp);
}
Assessed type
Error
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 code uses the borrowed mapping, which excludes fees, instead of getBorrowedOf, which includes fees, when checking debt and calculating the collateral ratio.
Impact
An attacker could redeem more PeUSD than the provider's actual debt allows and perform rigid redemptions even when the provider's collateral ratio is below 100%, potentially taking more collateral than entitled.
What the attacker needed
Provider is a redemption provider; caller has PeUSD to redeem
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.
This is a smart contract bug where a function checks the wrong number for a user's debt. The debt includes fees, but the code only looks at the base borrowed amount, so it thinks the user owes less than they do. That lets someone redeem more collateral than they should, even when the account is undercollateralised.
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.