Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TessKimy - Interest rate is not updated correct after debt repayment, it can cause higher borrowing rate #295

Closed
sherlock-admin3 opened this issue Sep 10, 2024 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A High severity issue. Reward A payout will be made for this issue

Comments

@sherlock-admin3
Copy link
Contributor

sherlock-admin3 commented Sep 10, 2024

TessKimy

Medium

Interest rate is not updated correct after debt repayment, it can cause higher borrowing rate

Summary

In BorrowLogic.sol the interest rate is updated. Due to wrong execution sequence, totalDebt is forwarded through interest rate strategy with wrong number.

Root Cause

The root cause of this problem is wrong sequence diagram. Repaid amount is determined just after the repayDebt() call and we need this data for correct interest rate update.

   reserve.updateInterestRates(
      totalSupplies,
      cache,
      params.asset,
      IPool(params.pool).getReserveFactor(),
      payback.assets,
      0,
      params.position,
      params.data.interestRateData
    );

    // update balances and total supplies
    payback.shares = balances.repayDebt(totalSupplies, payback.assets, cache.nextBorrowIndex);
&>  cache.nextDebtShares = totalSupplies.debtShares;

cache.nextDebtShares should be updated before updating the interest rate because it's used in interest rate calculation process.

&>  vars.totalDebt = _cache.nextDebtShares.rayMul(_cache.nextBorrowIndex);

    (vars.nextLiquidityRate, vars.nextBorrowRate) = IReserveInterestRateStrategy(_reserve.interestRateStrategyAddress)
      .calculateInterestRates(
      _position,
      _data,
      DataTypes.CalculateInterestRatesParams({
        liquidityAdded: _liquidityAdded,
        liquidityTaken: _liquidityTaken,
        totalDebt: vars.totalDebt,
        reserveFactor: _reserveFactor,
        reserve: _reserveAddress
      })
    );

Internal pre-conditions

N/A

External pre-conditions

N/A

Attack Path

In order to demonstrate the impact following scenario will be appropriate.

  1. Alice has 100WETH debt.
  2. Alice repaid her debt now totalDebt should be reduced but instead it will keep same.
  3. Borrowing rate will be higher than expected because totalDebt will remain high.

Impact

High - Because of wrong execution sequence, interest rate is affected. Interest rate will affect borrowing index and this is crucial for correct execution and calculation. In the conclusion, it will affect the reserve index.

Reserve indexes is also important, because they are used to calculate the price of shares. Relation between assets and shares is given in following equation:

$Shares * Index = Assets$

If an user repay his debt, the next user have to pay higher than expected because borrow index will be higher than expected.

Mitigation

It should update the interest rate just after determining the nextDebtShares variable

    // update balances and total supplies
    payback.shares = balances.repayDebt(totalSupplies, payback.assets, cache.nextBorrowIndex);
    cache.nextDebtShares = totalSupplies.debtShares;

    reserve.updateInterestRates(
      totalSupplies,
      cache,
      params.asset,
      IPool(params.pool).getReserveFactor(),
      payback.assets,
      0,
      params.position,
      params.data.interestRateData
    );

Duplicate of #413

@github-actions github-actions bot added Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A High severity issue. labels Sep 20, 2024
@sherlock-admin3 sherlock-admin3 changed the title Special Macaroon Shetland - Interest rate is not updated correct after debt repayment, it can cause higher borrowing rate TessKimy - Interest rate is not updated correct after debt repayment, it can cause higher borrowing rate Oct 3, 2024
@sherlock-admin3 sherlock-admin3 added the Reward A payout will be made for this issue label Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A High severity issue. Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

1 participant