Skip to content
DoS Audit finding Intermediate

[M] Incorrect Validation in `Pool.sol#transferLPs` lead to a DOS attack

The transferLPs function required the approved allowance to exactly equal the owner's current LP balance rather than merely covering the transfer amount. An attacker could send a tiny amount of LP tokens to the owner beforehand, changing the balance so the transfer reverts and the tokens stay stuck with the original owner.

oxcm Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-01-ajna-judging/issues/116

Found by

oxcm

Summary

The code in the transferLPs function has an incorrect validation check, where it requires allowances_ to be strictly equal to lenderLpBalance, instead of just allowances_ being greater than transferAmount.

Vulnerability Detail

In the transferLPs() function, transferAmount is being compared to allowances_[owner_][newOwner_][index] and lenderLpBalance. If the values are not strictly equal, the function will revert with a NoAllowance error.

Due to the requirement of transferLPs() that allowances_ must equal lenderLpBalance, the user can only enter lpsAmountToApprove_ as the current lenderLpBalance when using approveLpOwnership().

This results in transferLPs() reverting with NoAllowance if lenderLpBalance undergoes any change, allowing attackers to design a DOS attack.

However, this validation is not necessary as it should only require allowances_ to be greater than transferAmount.

Impact

An attacker could exploit this vulnerability by transferring a small amount of LP tokens to the owner before the transfer to the new owner is initiated. This would cause the allowances_ value to be less than lenderLpBalance, causing the transfer to revert and the tokens to remain in the original owner's account.

Code Snippet

Relevant code snippet from transferLPs function:

https://github.com/sherlock-audit/2023-01-ajna/blob/main/contracts/src/base/Pool.sol#L238-L250

function transferLPs(
        address owner_,
        address newOwner_,
        uint256[] calldata indexes_
    ) external override nonReentrant {
        LenderActions.transferLPs(
            buckets,
            _lpTokenAllowances,
            owner_,
            newOwner_,
            indexes_
        );
    }

https://github.com/sherlock-audit/2023-01-ajna/blob/main/contracts/src/libraries/external/LenderActions.sol#L512-L558

function transferLPs(
        mapping(uint256 => Bucket) storage buckets_,
        mapping(address => mapping(address => mapping(uint256 => uint256))) storage allowances_,
        address owner_,
        address newOwner_,
        uint256[] calldata indexes_
    ) external {
        uint256 indexesLength = indexes_.length;

        uint256 tokensTransferred;

        for (uint256 i = 0; i < indexesLength; ) {
            uint256 index = indexes_[i];
            if (index > MAX_FENWICK_INDEX) revert InvalidIndex();

            uint256 transferAmount = allowances_[owner_][newOwner_][index];

            Bucket storage bucket = buckets_[index];
            Lender storage lender = bucket.lenders[owner_];

            uint256 lenderDepositTime = lender.depositTime;

            uint256 lenderLpBalance;

            if (bucket.bankruptcyTime < lenderDepositTime) lenderLpBalance = lender.lps;

            if (transferAmount == 0 || transferAmount != lenderLpBalance) revert NoAllowance();

            delete allowances_[owner_][newOwner_][index]; // delete allowance

            // move lp tokens to the new owner address
            Lender storage newLender = bucket.lenders[newOwner_];

            newLender.lps += transferAmount;

            newLender.depositTime = Maths.max(lenderDepositTime, newLender.depositTime);

            // reset owner lp balance for this index
            delete bucket.lenders[owner_];

            tokensTransferred += transferAmount;

            unchecked { ++i; }
        }

        emit TransferLPTokens(owner_, newOwner_, indexes_, tokensTransferred);
    }

Tool used

Manual Review / ChatGPT

Recommendation

The validation check in the transferLPs function should be updated to allow for allowances_ to be greater than transferAmount, rather than requiring them to be strictly equal. The updated code would look like this:

Solidity
if (transferAmount == 0 || allowances_[owner_][newOwner_][index] < transferAmount) revert NoAllowance();

and change approveLpOwnership() to:

Solidity
function approveLpOwnership(
    address allowedNewOwner_,
    uint256 index_
) external nonReentrant {
    _lpTokenAllowances[msg.sender][allowedNewOwner_][index_] = type(uint256).max;
}

Discussion

grandizzy

removing will fix, will be addressed after sherlock contest

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

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 allowance check compared the approved amount for strict equality with the owner's live LP balance instead of checking it was at least the transfer amount.

Impact

An attacker could block transfers of LP tokens by making the allowance and balance mismatch, so the tokens remain in the original owner's account; the text does not say whether this was fixed.

What the attacker needed

Attacker can send LP tokens to the owner; owner has approved a transfer

The fix

The check should require the allowance to be at least the transfer amount, and approval should set the allowance to the maximum value.

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.

A smart contract lets people approve someone else to move their tokens. Here the check was too strict: it demanded the approved amount match the owner's balance exactly, not just be enough. Because anyone can nudge that balance by sending a tiny token amount, a griefer could make every transfer fail, locking the tokens in place.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by oxcm

View all

1 more disclosed report, best first.

More from Ajna #2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.