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.
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.
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
- Call the deposit function with amount set to zero for any position ID.
- 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.