If borrower or kicker got blacklisted by asset contract their collateral or bond funds can be permanently frozen with the pool
The Ajna protocol's repayDebt and withdrawBonds functions always send funds to msg.sender, with no way to specify a different recipient. If a borrower or kicker is blacklisted by the collateral or quote token contract, their collateral or bond funds become permanently frozen in the pool.
Source: https://github.com/sherlock-audit/2023-01-ajna-judging/issues/75
Found by
hyh
Summary
It's impossible for borrower or kicker to transfer their otherwise withdraw-able funds to another address. If for some reason borrower or kicker got blacklisted by collateral or quote token contract (correspondingly), these funds will be permanently frozen as now there is no mechanics to move them to another address or specify the recipient for the transfer.
Vulnerability Detail
If during the duration of a loan the borrower got blacklisted by collateral asset contract, let's say it is USDC, there is no way to retrieve the collateral. These collateral funds will be permanently locked at the Pool contract balance.
Similar, although less dangerous as both duration and exposure is less, situation takes place with kicker's balance, that is referenced by msg.sender only and so bonds due will be frozen with the pool if that address be blacklisted.
For lender's case there is a position managing possibility via Pool's transferLPs() and PositionManager's memorializePositions() and reedemPositions(), but for a borrower and a kicker there is no way to transfer funds due ownership or even specify transfer recipient, so the corresponding collateral and bond funds will be frozen with the pool if current beneficiary be blacklisted.
Impact
Principal funds of borrower or kicker being permanently frozen in full, but backlisting is a low probability event, so setting the severity to be medium.
Code Snippet
When it is vars.pull BorrowerActions's repayDebt() require borrowerAddress_ == msg.sender:
function repayDebt(
AuctionsState storage auctions_,
mapping(uint256 => Bucket) storage buckets_,
DepositsState storage deposits_,
LoansState storage loans_,
PoolState calldata poolState_,
address borrowerAddress_,
uint256 maxQuoteTokenAmountToRepay_,
uint256 collateralAmountToPull_
) external returns (
RepayDebtResult memory result_
) {
Borrower memory borrower = loans_.borrowers[borrowerAddress_];
...
if (vars.pull) {
// only intended recipient can pull collateral
if (borrowerAddress_ != msg.sender) revert BorrowerNotSender();
// calculate LUP only if it wasn't calculated by repay action
if (!vars.repay) result_.newLup = _lup(deposits_, result_.poolDebt);
uint256 encumberedCollateral = borrower.t0Debt != 0 ? Maths.wdiv(vars.borrowerDebt, result_.newLup) : 0;
if (borrower.collateral - encumberedCollateral < collateralAmountToPull_) revert InsufficientCollateral();
// stamp borrower t0Np when pull collateral action
vars.stampT0Np = true;
borrower.collateral -= collateralAmountToPull_;
result_.poolCollateral -= collateralAmountToPull_;
}
Then funds are being sent in ERC20Pool and ERC721Pool to msg.sender with no option to specify another address:
https://github.com/sherlock-audit/2023-01-ajna/blob/main/contracts/src/ERC20Pool.sol#L184-L230
function repayDebt(
address borrowerAddress_,
uint256 maxQuoteTokenAmountToRepay_,
uint256 collateralAmountToPull_
) external nonReentrant {
PoolState memory poolState = _accruePoolInterest();
...
collateralAmountToPull_ = _roundToScale(collateralAmountToPull_, _bucketCollateralDust(0));
RepayDebtResult memory result = BorrowerActions.repayDebt(
...
);
...
if (collateralAmountToPull_ != 0) {
// update pool balances state
poolBalances.pledgedCollateral = result.poolCollateral;
// move collateral from pool to sender
_transferCollateral(msg.sender, collateralAmountToPull_);
}
}
https://github.com/sherlock-audit/2023-01-ajna/blob/main/contracts/src/ERC721Pool.sol#L194-L238
function repayDebt(
address borrowerAddress_,
uint256 maxQuoteTokenAmountToRepay_,
uint256 noOfNFTsToPull_
) external nonReentrant {
PoolState memory poolState = _accruePoolInterest();
RepayDebtResult memory result = BorrowerActions.repayDebt(
...
);
...
if (noOfNFTsToPull_ != 0) {
// update pool balances state
poolBalances.pledgedCollateral = result.poolCollateral;
// move collateral from pool to sender
_transferFromPoolToAddress(msg.sender, borrowerTokenIds[msg.sender], noOfNFTsToPull_);
}
}
The same issue takes place in withdrawBonds() as msg.sender can be blacklisted in between kicking and withdrawing:
https://github.com/sherlock-audit/2023-01-ajna/blob/main/contracts/src/base/Pool.sol#L318-L327
/**
* @inheritdoc IPoolLiquidationActions
* @dev write state:
* - reset kicker's claimable accumulator
*/
function withdrawBonds() external {
uint256 claimable = auctions.kickers[msg.sender].claimable;
auctions.kickers[msg.sender].claimable = 0;
_transferQuoteToken(msg.sender, claimable);
}
I.e. if as of time of kicking msg.sender wasn't blacklisted, but they were added to blacklist before auctions.kickers[msg.sender].claimable were withdrawn, it will be permanently locked on the Pool's balance.
Tool used
Manual Review
Recommendation
Consider adding the recipient argument to the repayDebt() and withdrawBonds() functions, so the balance beneficiary msg.sender can specify what address should receive the funds, for example:
https://github.com/sherlock-audit/2023-01-ajna/blob/main/contracts/src/base/Pool.sol#L318-L327
/**
* @inheritdoc IPoolLiquidationActions
* @dev write state:
* - reset kicker's claimable accumulator
*/
- function withdrawBonds() external {
+ function withdrawBonds(address recipient) external {
uint256 claimable = auctions.kickers[msg.sender].claimable;
auctions.kickers[msg.sender].claimable = 0;
- _transferQuoteToken(msg.sender, claimable);
+ _transferQuoteToken(recipient, claimable);
}
This will also help for the situation when NFT collateral was put in by a contract borrower without onERC721Received implementation, so repayDebt() initiated _transferNFT() -> safeTransferFrom() call will fail for msg.sender and the ability to use a recipient become crucial.
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
The functions repayDebt and withdrawBonds hard-code msg.sender as the recipient of funds, with no parameter to specify an alternative address.
Impact
The borrower's collateral or the kicker's bond funds could be permanently frozen in full if their address is blacklisted, though blacklisting is a low-probability event.
What the attacker needed
Borrower or kicker address gets blacklisted; blacklisting occurs before funds are withdrawn
The fix
The functions repayDebt and withdrawBonds should be changed to accept a recipient argument so the beneficiary can direct funds to another address.
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.
Some tokens, like USDC, can block specific addresses from sending or receiving them. This report says that if a user's address gets blocked, any funds they have in this lending pool cannot be moved to another address, because the pool only ever sends funds back to the same address that calls the function. So the money stays stuck in the pool forever.
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.