Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

TrungOre - Attackers can deposit into vaults after the de-peg event is triggered to steal the funds. #85

Closed
sherlock-admin opened this issue Mar 27, 2023 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Mar 27, 2023

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.

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.

modifier epochHasNotStarted(uint256 _id) {
    if (block.timestamp > epochConfig[_id].epochBegin)
        revert EpochAlreadyStarted();
    _;
}

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,

  1. Assume that, epochBegin = 5, epochEnd = 10.
  2. 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
  3. At the same block, the attacker deposits 100ETH into the HedgeVault (the attacker can deposit because 5 <= block.timestamp (=5) <= 10).
  4. 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.

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 the block.timestamp lies in the interval [epochBegin+1, epochEnd] instead of [epochBegin, epochEnd].

Duplicate of #480

@github-actions github-actions bot closed this as completed Apr 3, 2023
@github-actions github-actions bot added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Apr 3, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

1 participant