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.
Submitted by hickuphh3, also found by rayn and WatchPug
_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];
}
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.