Skip to content
Business logic Audit finding Beginner

Wrong implementation of CreditLimitByMedian.sol#getLockedAmount() makes it unable to unlock lockedAmount in CreditLimitByMedian model

The getLockedAmount function in CreditLimitByMedian.sol incorrectly subtracts 1 instead of the requested amount when decreasing locked funds, so users cannot unlock their locked amounts. An attacker could not exploit this directly, but it prevents legitimate users from unlocking funds.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

CreditLimitByMedian.sol L27-L78

function getLockedAmount(
    LockedInfo[] memory array,
    address account,
    uint256 amount,
    bool isIncrease
) public pure override returns (uint256) {
    if (array.length == 0) return 0;

    uint256 newLockedAmount;
    if (isIncrease) {
        ...
    } else {
        for (uint256 i = 0; i < array.length; i++) {
            if (array[i].lockedAmount > amount) {
                newLockedAmount = array[i].lockedAmount - 1;
            } else {
                newLockedAmount = 0;
            }

            if (account == array[i].staker) {
                return newLockedAmount;
            }
        }
    }

    return 0;
}

getLockedAmount() is used by UserManager.sol#updateLockedData() to update locked amounts.

Based on the context, at L66, newLockedAmount = array[i].lockedAmount - 1; should be newLockedAmount = array[i].lockedAmount - amount;.

The current implementation is wrong and makes it impossible to unlock lockedAmount in CreditLimitByMedian model.

Recommendation

Change to:

newLockedAmount = array[i].lockedAmount - amount;

kingjacob (Union) acknowledged

GalloDaSballo (judge) commented:

The warden identified a mistake in the accounting that would make it impossible to unlock funds, mitigation seems to be straightfoward

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

Root cause

Likely a typo in the subtraction: the code subtracts 1 instead of the amount parameter.

Impact

Users cannot unlock their locked amounts in the CreditLimitByMedian model, effectively locking funds indefinitely.

What the attacker needed

None

The fix

The code should be changed to subtract the amount parameter instead of 1.

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.

This is a smart contract bug where a function that should reduce a locked amount by the requested value instead reduces it by only 1. As a result, users can never fully unlock their funds. The fix is to subtract the correct amount.

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 WatchPug

View all

197 more disclosed reports, best first.

More from Union Finance 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.