Skip to content
Business logic Audit finding Advanced

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.

bin2chen Follow with oakcobalt

Originally disclosed on Code4rena

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.


The original report as published on Code4rena, by bin2chen. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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.

More by bin2chen

View all

139 more disclosed reports, best first.

More from BendDAO Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.