executeYieldBorrowERC20() checking yieldCap is wrong
The yield cap check in executeYieldBorrowERC20 used the wrong index to calculate total supply, making the cap inaccurate. An attacker could borrow more than the intended yield cap, creating a security risk.
Submitted by bin2chen, also found by oakcobalt
In executeYieldBorrowERC20(), we will check whether stakerAddr exceeds yieldCap.
function executeYieldBorrowERC20(InputTypes.ExecuteYieldBorrowERC20Params memory params) internal {
...
ValidateLogic.validateYieldBorrowERC20(params, poolData, assetData, groupData);
@> vars.totalSupply = VaultLogic.erc20GetTotalCrossSupply(assetData, groupData.borrowIndex);
// check asset level yield cap limit
vars.totalBorrow = VaultLogic.erc20GetTotalCrossBorrowInGroup(groupData, groupData.borrowIndex);
require(
(vars.totalBorrow + params.amount) <= vars.totalSupply.percentMul(assetData.yieldCap),
Errors.YIELD_EXCEED_ASSET_CAP_LIMIT
);
// check staker level yield cap limit
vars.stakerBorrow = VaultLogic.erc20GetUserCrossBorrowInGroup(groupData, vars.stakerAddr, groupData.borrowIndex);
require(
(vars.stakerBorrow + params.amount) <= vars.totalSupply.percentMul(ymData.yieldCap),
Errors.YIELD_EXCEED_STAKER_CAP_LIMIT
);
The code above, calculating totalSupply using totalSupply = totalScaledCrossSupply * groupData.borrowIndex to calculate supply is wrong. The correct way to calculate supply is to use: assetData.supplyIndex.
Impact
With an incorrect value for totalSupply, the check for yieldCap will be inaccurate, leading to a security risk.
Recommended Mitigation
function executeYieldBorrowERC20(InputTypes.ExecuteYieldBorrowERC20Params memory params) internal {
...
ValidateLogic.validateYieldBorrowERC20(params, poolData, assetData, groupData);
- vars.totalSupply = VaultLogic.erc20GetTotalCrossSupply(assetData, groupData.borrowIndex);
+ vars.totalSupply = VaultLogic.erc20GetTotalCrossSupply(assetData, assetData.supplyIndex);
// check asset level yield cap limit
vars.totalBorrow = VaultLogic.erc20GetTotalCrossBorrowInGroup(groupData, groupData.borrowIndex);
Assessed type
Context
thorseldon (BendDAO) confirmed and commented:
Fixed here.
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
Likely the code used the borrow index instead of the supply index when calculating total supply for the yield cap check.
Impact
The yield cap check could be bypassed, allowing borrowing beyond the intended limit and creating a security risk.
What the attacker needed
Access to executeYieldBorrowERC20
The fix
The issue was fixed by using assetData.supplyIndex instead of groupData.borrowIndex when calculating total supply.
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 limit on borrowing was calculated using the wrong number. Because the total supply was wrong, the limit check could pass when it should not, letting someone borrow more than 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.