Skip to content
Business logic Audit finding Beginner

maxTrainingDeposit can be bypassed

The deposit function checks the sender's current balance against a maximum training deposit limit, but a user can transfer their balance to another account and then deposit from the emptied account, bypassing the limit. An attacker could deposit more than the allowed maximum during the training phase.

c7e7eff Follow with chaduke and csanuragjain

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-01-derby-judging/issues/15

Found by

c7e7eff, chaduke, csanuragjain

Summary

It was observed that User can bypass the maxTrainingDeposit by transferring balance from one user to another

Vulnerability Detail

  1. Observe the deposit function
Solidity
function deposit(
    uint256 _amount,
    address _receiver
  ) external nonReentrant onlyWhenVaultIsOn returns (uint256 shares) {
    if (training) {
      require(whitelist[msg.sender]);
      uint256 balanceSender = (balanceOf(msg.sender) * exchangeRate) / (10 ** decimals());
      require(_amount + balanceSender <= maxTrainingDeposit);
    }
...
  1. So if User balance exceeds maxTrainingDeposit then request fails (considering training is true)
  2. Lets say User A has balance of 50 and maxTrainingDeposit is 100
  3. If User A deposit amount 51 then it fails since 50+51<=100 is false
  4. So User A transfer amount 50 to his another account
  5. Now when User A deposit, it does not fail since 0+51<=100

Impact

User can bypass maxTrainingDeposit and deposit more than allowed

Code Snippet

https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/MainVault.sol#L113

Tool used

Manual Review

Recommendation

If user specific limit is required then transfer should be check below:

Solidity
 require(_amountTransferred + balanceRecepient <= maxTrainingDeposit);

Discussion

sjoerdsommen

yes this is known, there is no solution to this and this is also not a huge problem

The original report as published on Sherlock, by c7e7eff. 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 deposit limit is enforced only on the sender's current balance, not on the total amount deposited or transferred, so moving funds to another account resets the check.

What the attacker needed

Training mode is active; user is whitelisted; user has a second account

The fix

The transfer function should also check the recipient's balance against the limit, as suggested in the recommendation.

How it was found

  1. User A has a balance of 50 and the maxTrainingDeposit is 100.
  2. User A tries to deposit 51, which fails because 50+51 is greater than 100.
  3. User A transfers their 50 balance to another account.
  4. User A then deposits 51 from the now-empty account, which passes because 0+51 is less than or equal to 100.

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 has a rule that limits how much a user can deposit during a training period. The rule checks the user's current balance, but a user can move their existing balance to a second account and then deposit from the first account, which now has a zero balance, so the limit check passes. This lets the user put in more money than the rule intended.

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 c7e7eff

View all

2 more disclosed reports, best first.

More from Derby

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.