Skip to content
Business logic Audit finding Intermediate

Bypass userWithdrawLimitPerPeriod check

The per-account withdrawal limit could be bypassed by transferring the token balance to a second account, which then had its own fresh limit. An attacker could therefore withdraw more than the intended maximum in a single period.

Anurag Jain Follow

Originally disclosed on Code4rena

Submitted by csanuragjain

User can bypass the userWithdrawLimitPerPeriod check by transferring the balance to another account.

Proof of Concept

  1. Assume userWithdrawLimitPerPeriod is set to 1000
  2. User A has current deposit of amount 2000 and wants to withdraw everything instantly
  3. User A calls the withdraw function and takes out the 1000 amount
function withdraw(uint256 _amount) external override nonReentrant {
    uint256 _baseTokenAmount = (_amount * baseTokenDenominator) / 1e18;
    uint256 _fee = (_baseTokenAmount * withdrawFee) / FEE_DENOMINATOR;
    if (withdrawFee > 0) { require(_fee > 0, "fee = 0"); }
    else { require(_baseTokenAmount > 0, "amount = 0"); }
    _burn(msg.sender, _amount);
    uint256 _baseTokenAmountAfterFee = _baseTokenAmount - _fee;
    if (address(withdrawHook) != address(0)) {
      baseToken.approve(address(withdrawHook), _fee);
      withdrawHook.hook(msg.sender, _baseTokenAmount, _baseTokenAmountAfterFee);
      baseToken.approve(address(withdrawHook), 0);
    }
    baseToken.transfer(msg.sender, _baseTokenAmountAfterFee);
    emit Withdraw(msg.sender, _baseTokenAmountAfterFee, _fee);
  }
  1. Remaining 1000 amount cannot be withdrawn since userWithdrawLimitPerPeriod is reached
function hook(
    address _sender,
    uint256 _amountBeforeFee,
    uint256 _amountAfterFee
  ) external override onlyCollateral {
...
require(userToAmountWithdrawnThisPeriod[_sender] + _amountBeforeFee <= userWithdrawLimitPerPeriod, "user withdraw limit exceeded");
...
}
  1. User simply transfers his balance to his other account and withdraw from that account
  2. Since withdraw limit is tied to account, this new account will be allowed to make withdrawal thus bypassing userWithdrawLimitPerPeriod

Recommended Mitigation Steps

User should only be allowed to transfer leftover limit. For example if User already utilized limit X then he should only be able to transfer userWithdrawLimitPerPeriod-X.

ramenforbreakfast (prePO) confirmed


The original report as published on Code4rena, by csanuragjain. 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 the withdrawal limit was tracked per account rather than per underlying owner, and transfers did not carry over the used limit.

Impact

A user could withdraw more than the per-period limit by spreading withdrawals across accounts.

What the attacker needed

Two accounts controlled by the same user; a deposit larger than the withdrawal limit

The fix

The report recommends allowing a user to transfer only the unused portion of their limit, so the used amount follows the balance.

How it was found

  1. Set the per-period withdrawal limit to a known value.
  2. Have an account with a deposit larger than the limit.
  3. Withdraw up to the limit from the first account.
  4. Transfer the remaining balance to a second account.
  5. Withdraw from the second account, which has its own unused limit.

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 withdrawal limit is meant to cap how much one person can take out in a set time. Here the limit was counted per account, not per person, so moving the balance to another account reset the counter. That let someone take out more than the limit allowed.

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 Anurag Jain

View all

63 more disclosed reports, best first.

More from prePO 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.