This repository has been archived by the owner on Oct 1, 2023. It is now read-only.
roguereddwarf - VaultV2: epochHasNotStarted
and epochHasStarted
modifiers are not well-defined which can lead to loss of user funds
#42
Labels
Duplicate
A valid issue that is a duplicate of an issue with `Has Duplicates` label
Escalation Resolved
This issue's escalations have been approved/rejected
Medium
A valid Medium severity issue
Reward
A payout will be made for this issue
roguereddwarf
high
VaultV2:
epochHasNotStarted
andepochHasStarted
modifiers are not well-defined which can lead to loss of user fundsSummary
The
VaultV2
contract defines theepochHasNotStarted
andepochHasStarted
modifiers.They ensure that certain functions can only be called when the epoch has not started or has started.
The issue is that when
block.timestamp==epochBegin
both checks pass. I.e. the epoch has started and has not started at the same time.This can lead to edge cases where in the worst case users lose their funds.
Vulnerability Detail
Let's have a look at the checks that the modifiers perform and let's assume
block.timestamp==epochBegin
.The check in
epochHasNotStarted
passes:Also the check in
epochHasStarted
passes:So what is the edge case that can occur that leads to a loss of user funds?
The issue comes down to the fact that a deposit can be made after the epoch has been resolved.
The
deposit
function checks thatepochHasNotStarted
:https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/VaultV2.sol#L93-L104
The
resolveEpoch
function checks thatepochHasStarted
:https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/VaultV2.sol#L290-L299
As we have seen both checks pass when
block.timestamp==epochBegin
.So what can happen is that a user wants to make a last second deposit but before his transaction is processed and within the same block the controller resolves the epoch and triggers a NULL epoch (assuming there were no funds in one of the Vaults prior to the deposit of the user) with the
ControllerPeggedAssetV2.triggerNullEpoch
function.In the
ControllerPeggedAssetV2.triggerNullEpoch
function, theclaimTVL
is set which means that the user that performs the deposit in a later transaction of the same block cannot withdraw any funds.Impact
User funds can be lost.
Code Snippet
https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/VaultV2.sol#L432-L436
https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/VaultV2.sol#L440-L444
https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/VaultV2.sol#L93-L104
https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/VaultV2.sol#L290-L299
https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/Controllers/ControllerPeggedAssetV2.sol#L208-L264
Tool used
Manual Review
Recommendation
The modifiers have to be well-defined.
To make it consistent with Controller logic the epoch should have started when
block.timestamp==epochBegin
.This means that the check in
epochHasNotStarted
should not pass in this case.Fix:
Duplicate of #480
The text was updated successfully, but these errors were encountered: