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.
Originally disclosed on Code4rena
Submitted by csanuragjain
User can bypass the userWithdrawLimitPerPeriod check by transferring the balance to another account.
Proof of Concept
- Assume
userWithdrawLimitPerPeriodis set to1000 - User A has current deposit of amount
2000and wants to withdraw everything instantly - User A calls the withdraw function and takes out the
1000amount
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);
}
- Remaining
1000amount cannot be withdrawn sinceuserWithdrawLimitPerPeriodis reached
function hook(
address _sender,
uint256 _amountBeforeFee,
uint256 _amountAfterFee
) external override onlyCollateral {
...
require(userToAmountWithdrawnThisPeriod[_sender] + _amountBeforeFee <= userWithdrawLimitPerPeriod, "user withdraw limit exceeded");
...
}
- User simply transfers his balance to his other account and withdraw from that account
- 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
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
- Set the per-period withdrawal limit to a known value.
- Have an account with a deposit larger than the limit.
- Withdraw up to the limit from the first account.
- Transfer the remaining balance to a second account.
- 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.