timewindow
can be changed unexpectedly that blocks users from calling deposit
function
#483
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
selected for report
This submission will be included/highlighted in the audit report
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Lines of code
https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L87-L91
https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L152-L174
https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L327-L338
https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L287-L289
Vulnerability details
Impact
As shown by the following
epochHasNotStarted
modifier, which is used by thedeposit
function below, users can only deposit whenblock.timestamp <= idEpochBegin[id] - timewindow
holds true. Before depositing, a user can check if this relationship is true at that moment; if so, she or he can call thedeposit
function. However, just before the user'sdeposit
function call is executed, the admin unexpectedly calls theVaultFactory.changeTimewindow
function below, which further calls theVault.changeTimewindow
function below, to increase thetimewindow
. Since the admin'sVaultFactory.changeTimewindow
transaction is executed before the user'sdeposit
transaction and thetimewindow
change takes effect immediately, it is possible that the user'sdeposit
function call will revert. Besides wasting gas, the user can feel confused and unfair because her or hisdeposit
transaction should be executed successfully ifVaultFactory.changeTimewindow
is not called unexpectedly.https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L87-L91
https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L152-L174
https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/VaultFactory.sol#L327-L338
https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L287-L289
Proof of Concept
Please add the following
error
and append the following test intest\AssertTest.t.sol
. This test will pass to demonstrate the described scenario.Tools Used
VSCode
Recommended Mitigation Steps
When calling the
VaultFactory.createNewMarket
orVaultFactory.deployMoreAssets
function, thetimewindow
, which is configured for that moment, can be taken into account in the created asset'sepochBegin
.Then, https://github.com/code-423n4/2022-09-y2k-finance/blob/main/src/Vault.sol#L87-L91 can be updated to the following code.
The text was updated successfully, but these errors were encountered: