Skip to content
Business logic Audit finding Intermediate

ConvexStakingWrapper#deposit() depositors may lose their funds when the _amount is huge

The deposit function casts a 256-bit amount to 192 bits without checking, so a huge deposit is recorded as a much smaller value while the full amount is transferred. A depositor could lose the difference between the recorded and actual amounts.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug, also found by danb, gzeon, Heartless, and pauliax

When the value of _amount is larger than type(uint192).max, due to unsafe type casting, the recorded deposited amount can be much smaller than their invested amount.

ConvexStakingWrapper.sol#L228-L250

function deposit(uint256 _pid, uint256 _amount)
    external
    whenNotPaused
    nonReentrant
{
    _checkpoint(_pid, msg.sender);
    deposits[_pid][msg.sender].epoch = currentEpoch();
    deposits[_pid][msg.sender].amount += uint192(_amount);
    if (_amount > 0) {
        IERC20 lpToken = IERC20(
            IRewardStaking(convexPool[_pid]).poolInfo(_pid).lptoken
        );

        lpToken.safeTransferFrom(msg.sender, address(this), _amount);
        lpToken.safeApprove(convexBooster, _amount);
        IConvexDeposits(convexBooster).deposit(_pid, _amount, true);
        lpToken.safeApprove(convexBooster, 0);
        uint256 pid = masterChef.pid(address(lpToken));
        masterChef.deposit(msg.sender, pid, _amount);
    }

    emit Deposited(msg.sender, _amount);
}

Proof of Concept

When _amount = uint256(type(uint192).max) + 1:

  • At L235, uint192(_amount) = 0, deposits[_pid][msg.sender].amount = 0;
  • At L241, uint256(type(uint192).max) + 1 will be transferFrom msg.sender.

Expected results:

deposits[_pid][msg.sender].amount == uint256(type(uint192).max) + 1;

Actual results:

deposits[_pid][msg.sender].amount = 0.

The depositor loses all their invested funds.

Recommended Mitigation Steps

Consider adding a upper limit for the _amount parameter:

require(_amount <= type(uint192).max, "...");

ryuheimat (Concur) confirmed

Alex the Entreprenerd (judge) decreased severity to Medium and commented:

The warden has shown how casting without safe checks can cause the accounting to break and cause end users to lose deposited tokens.

While the finding has merit, I believe that because this applies to niche situations, and is conditional on specific inputs, that Medium Severity is more appropriate.


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

The code casts a uint256 amount to uint192 without checking that it fits, causing truncation.

Impact

The depositor could lose all their invested funds because the recorded amount is zero while the full amount is transferred.

What the attacker needed

Attacker is the depositor; deposit amount exceeds type(uint192).max

The fix

The code should be fixed by adding an upper limit check on the _amount parameter.

How it was found

  1. Call deposit with an amount equal to type(uint192).max + 1.
  2. The contract records the deposited amount as 0 due to truncation.
  3. The contract transfers the full amount from the caller.

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 stores deposit amounts in a smaller number format (192 bits) than the input (256 bits). If you deposit a number too big for the smaller format, it wraps around to a tiny number, but the contract still takes your full deposit. You end up with almost nothing recorded.

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 Concur 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.