Skip to content
Business logic Audit finding Beginner

Anyone can extend withdraw wait period by depositing zero collateral

The deposit function in MochiVault.sol allows anyone to deposit zero collateral into any position, which resets the last deposit timestamp and extends the withdrawal wait period. An attacker could repeatedly call this with zero amount to indefinitely lock all users out of withdrawing their collateral.

harleythedog Follow

Originally disclosed on Code4rena

Submitted by harleythedog, also found by WatchPug

Impact

In MochiVault.sol, the deposit function allows anyone to deposit collateral into any position. A malicious user can call this function with amount = 0, which would reset the amount of time the owner has to wait before they can withdraw their collateral from their position. This is especially troublesome with longer delays, as a malicious user would only have to spend a little gas to lock out all other users from being able to withdraw from their positions, compromising the functionality of the contract altogether.

Proof of Concept

the deposit function here

Notice that calling this function with amount = 0 is not disallowed. This overwrites lastDeposit\[\_id], extending the wait period before a withdraw is allowed.

Recommended Mitigation Steps

I would recommend adding:

require(amount > 0, "zero")

at the start of the function, as depositing zero collateral does not seem to be a necessary use case to support.

It may also be worthwhile to consider only allowing the owner of a position to deposit collateral.

ryuheimat (Mochi) confirmed

The original report as published on Code4rena, by harleythedog. 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 deposit function does not check that the deposited amount is greater than zero, and it allows anyone to deposit into any position, so a zero-amount deposit still updates the last deposit timestamp.

Impact

An attacker could repeatedly deposit zero collateral to indefinitely extend the withdrawal wait period for all users, effectively locking their funds and compromising the contract's functionality.

What the attacker needed

None

The fix

The deposit function should require that the amount is greater than zero, and it may also be worthwhile to restrict deposits to the position owner.

How it was found

  1. Call the deposit function with amount set to zero for any position ID.
  2. The lastDeposit timestamp for that position is overwritten, extending the wait period before withdrawal is allowed.

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.

In this smart contract, users deposit collateral and must wait a certain time before they can withdraw it. The contract lets anyone add collateral to any position, and even adding zero collateral resets the waiting timer. So an attacker can keep resetting the timer for everyone, preventing them from ever withdrawing.

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 harleythedog

View all

14 more disclosed reports, best first.

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