Skip to content
Business logic Audit finding Intermediate

Manager can get around min reserves check, draining all funds from Collateral.sol

The manager withdrawal function enforces a minimum reserve balance, but the ordinary withdraw function does not. A manager could deposit funds, make a manager withdrawal, then withdraw their deposit, draining the contract's balance to zero.

obront Follow with joestakey, Trust and 11 others

Originally disclosed on Code4rena

Submitted by obront, also found by joestakey, Trust, wait, Madalad, hansfriese, deliriusz, rvierdiiev, HE1M, 8olidity, zaskoh, hihen, cccz, and csanuragjain

When a manager withdraws funds from Collateral.sol, there is a check in the managerWithdrawHook to confirm that they aren’t pushing the contract below the minimum reserve balance.

require(collateral.getReserve() - _amountAfterFee >= getMinReserve(), "reserve would fall below minimum");

However, a similar check doesn’t happen in the withdraw() function.

The manager can use this flaw to get around the reserve balance by making a large deposit, taking a manager withdrawal, and then withdrawing their deposit.

Proof of Concept

Imagine a situation where the token has a balance of 100, deposits of 1000, and a reserve percentage of 10%. In this situation, the manager should not be able to make any withdrawal.

But, with the following series of events, they can:

  • Manager calls deposit() with 100 additional tokens
  • Manager calls managerWithdraw() to pull 100 tokens from the contract
  • Manager calls withdraw() to remove the 100 tokens they added

The result is that they are able to drain the balance of the contract all the way to zero, avoiding the intended restrictions.

Recommended Mitigation Steps

Include a check on the reserves in the withdraw() function as well as managerWithdraw().

Picodes (judge) commented:

From what I understand, although it’s not clear from the documentation or the code, this minReserve requirement is here to keep some funds in the contract to allow for withdrawals but does not provide any additional safety, and it should be clear for users that a compromised manager would immediately lead to a loss of all funds.

Picodes (judge) commented:

I’ll merge all issues regarding the manager being able to withdraw all funds, regardless of the method, the core issue being that the managerWithdrawHook check is easily bypassable.

ramenforbreakfast (prePO) confirmed

Picodes (judge) decreased severity to Medium and commented:

Flagging as best for this centralization issue, combined with the other finding by the same warden #255


The original report as published on Code4rena, by obront. 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 minimum reserve check is only applied in the manager withdrawal hook, not in the ordinary withdraw function, so a deposit followed by a manager withdrawal and a normal withdrawal bypasses it.

Impact

A manager could drain the contract's balance to zero, bypassing the intended minimum reserve restriction; the judge noted this is a centralisation issue and that a compromised manager would immediately lead to a loss of all funds.

What the attacker needed

Manager role on the contract

The fix

The reserve check should also be applied in the withdraw function, not only in managerWithdraw.

How it was found

  1. The manager deposits additional tokens into the contract.
  2. The manager calls managerWithdraw to take tokens out.
  3. The manager calls withdraw to remove the tokens they deposited.

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 holds money for users and has a rule that a manager cannot take so much that the contract falls below a safety buffer. The manager can get around this rule by first adding their own money, then taking money out through the manager route, and finally taking their own money back out through the normal route. This leaves the contract empty even though the rule was meant to prevent that.

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 obront

View all

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