You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.
sherlock-admin opened this issue
Mar 27, 2023
· 0 comments
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelMediumA valid Medium severity issueRewardA payout will be made for this issue
Attackers can deposit into vaults after the de-peg event is triggered to steal the funds.
Summary
When a de-peg event is triggered at block.timestamp == epochBegin, the attacker can deposit into the vault in the same block to get more funds.
Vulnerability Detail
Function Carousel.deposit() is used to mint shares for users when they deposit ETH into the vault.
function deposit(
uint256 _id,
uint256 _assets,
address _receiver
)
public
override(VaultV2)
epochIdExists(_id)
epochHasNotStarted(_id)
minRequiredDeposit(_assets)
nonReentrant
{
/// ...
}
The function let the user deposit in the epoch_id if the modifier epochHasNotStarted(_id) is satisfied. In other words, the user can deposit into epoch _id if the current block.timestamp is <= epochConfig[_id].epochBegin.
However, the de-peg event for an epoch can be triggered if the block.timestamp lies in the interval [epochBegin, epochEnd] which means epochBegin <= block.timestamp <= epochEnd.
function triggerDepeg(uint256 _marketId, uint256 _epochId) public {
/// ...
if (uint256(epochStart) > block.timestamp) revert EpochNotStarted();
if (block.timestamp > uint256(epochEnd)) revert EpochExpired();
/// ...
}
So when a de-peg event is triggered at block.timestamp = epochBegin, users still can deposit into the corresponding epoch in the same block which creates an opportunity for the attackers to steal the fund.
For instance,
Assume that, epochBegin = 5, epochEnd = 10.
When block.timestamp = 5 (= epochBegin), function ControllerPeggedAssetV2.triggerDepeg() is called to trigger an de-peg event.
--> Suppose that we have finalTVL[HedgeVault] = 100, claimTVL[HedgeVault] = 200
At the same block, the attacker deposits 100ETH into the HedgeVault (the attacker can deposit because 5 <= block.timestamp (=5) <= 10).
The attacker immediately calls Carousel.withdraw() to withdraw his entitled deposited assets, he gets: entitledShares = 100 * 200 / 100 = 200 ETH
--> The attacker just uses 100 ETH to get 200 ETH which makes the users who call withdraw() later unable to claim their funds.
Function ControllerPeggedAssetV2.triggerDepeg() just can be called when the block.timestamp lies in the interval [epochBegin+1, epochEnd] instead of [epochBegin, epochEnd].
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelMediumA valid Medium severity issueRewardA payout will be made for this issue
TrungOre
high
Attackers can deposit into vaults after the de-peg event is triggered to steal the funds.
Summary
When a de-peg event is triggered at
block.timestamp == epochBegin
, the attacker can deposit into the vault in the same block to get more funds.Vulnerability Detail
Function
Carousel.deposit()
is used to mint shares for users when they deposit ETH into the vault.The function let the user deposit in the epoch
_id
if the modifierepochHasNotStarted(_id)
is satisfied. In other words, the user can deposit into epoch_id
if the currentblock.timestamp
is<= epochConfig[_id].epochBegin
.However, the de-peg event for an epoch can be triggered if the
block.timestamp
lies in the interval [epochBegin
,epochEnd
] which meansepochBegin <= block.timestamp <= epochEnd
.So when a de-peg event is triggered at
block.timestamp = epochBegin
, users still can deposit into the corresponding epoch in the same block which creates an opportunity for the attackers to steal the fund.For instance,
epochBegin = 5
,epochEnd = 10
.block.timestamp = 5 (= epochBegin)
, functionControllerPeggedAssetV2.triggerDepeg()
is called to trigger an de-peg event.--> Suppose that we have
finalTVL[HedgeVault] = 100
,claimTVL[HedgeVault] = 200
5 <= block.timestamp (=5) <= 10
).Carousel.withdraw()
to withdraw his entitled deposited assets, he gets:entitledShares = 100 * 200 / 100 = 200 ETH
--> The attacker just uses 100 ETH to get 200 ETH which makes the users who call
withdraw()
later unable to claim their funds.Impact
The attacker can steal the vault's fund
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/Controllers/ControllerPeggedAssetV2.sol#L71
Tool used
Manual Review
Recommendation
Function
ControllerPeggedAssetV2.triggerDepeg()
just can be called when theblock.timestamp
lies in the interval [epochBegin+1
,epochEnd
] instead of [epochBegin
,epochEnd
].Duplicate of #480
The text was updated successfully, but these errors were encountered: