Skip to content
Business logic Audit finding Intermediate

PooledCreditLine : termination likely fails because _principleWithdrawable is treated as shares

The terminate function in PooledCreditLine calculates a principal withdrawal amount in borrowAsset units but then passes it to withdrawShares as if it were a share amount. This mismatch likely causes termination to fail or withdraw an incorrect number of shares.

hickuphh3 Follow

Originally disclosed on Code4rena

Submitted by hickuphh3, also found by rayn and WatchPug

LenderPool.sol#L404-L406

_principalWithdrawable is denominated in the borrowAsset, but subsequently treats it as the share amount to be withdrawn.

// _notBorrowed = borrowAsset amount that isn't borrowed
// totalSupply[_id] = ERC1155 total supply of _id
// _borrowedTokens = borrower's specified borrowLimit
uint256 _principalWithdrawable = _notBorrowed.mul(totalSupply[_id]).div(_borrowedTokens);

SAVINGS_ACCOUNT.withdrawShares(_borrowAsset, _strategy, _to, _principalWithdrawable.add(_totalInterestInShares), false);

Recommended Mitigation Steps

The amount of shares to withdraw can simply be _sharesHeld.

Note that this comes with the assumption that terminate() is only called when the credit line is ACTIVE or EXPIRED (consider ensuring this condition on-chain), because _sharesHeld excludes principal withdrawals, so the function will fail once a lender withdraws his principal.

function terminate(uint256 _id, address _to) external override onlyPooledCreditLine nonReentrant {
  address _strategy = pooledCLConstants[_id].borrowAssetStrategy;
  address _borrowAsset = pooledCLConstants[_id].borrowAsset;
  uint256 _sharesHeld = pooledCLVariables[_id].sharesHeld;

  SAVINGS_ACCOUNT.withdrawShares(_borrowAsset, _strategy, _to, _sharesHeld, false);
  delete pooledCLConstants[_id];
  delete pooledCLVariables[_id];
}

ritik99 (Sublime) confirmed


The original report as published on Code4rena, by hickuphh3. 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

What the attacker needed

Credit line is ACTIVE or EXPIRED; terminate() is called

The fix

The amount of shares to withdraw should simply be _sharesHeld, and the function should only be callable when the credit line is ACTIVE or EXPIRED.

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 this smart contract, there are two different units: the actual token amount (borrowAsset) and shares that represent ownership in a savings account. The code calculates an amount in tokens but then uses it as if it were shares, which can cause the withdrawal to fail or give the wrong result.

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 hickuphh3

View all

43 more disclosed reports, best first.

More from Sublime contest

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.