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

libratus - Missing null epoch check in triggerEndEpoch #371

Closed
sherlock-admin opened this issue Mar 27, 2023 · 0 comments
Closed

libratus - Missing null epoch check in triggerEndEpoch #371

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

libratus

medium

Missing null epoch check in triggerEndEpoch

Summary

There is no check for zero TVL in triggerEndEpoch meaning that null epoch can be treated like a normal one

Vulnerability Detail

If any vault's TVL is zero the epoch is not considered valid and the funds are given back to depositors. No fees are taken and no balance transfers are made between the vaults. From triggerNullEpoch:

        if (premiumVault.totalAssets(_epochId) == 0) {
            premiumVault.resolveEpoch(_epochId);
            collateralVault.resolveEpoch(_epochId);

            premiumVault.setClaimTVL(_epochId, 0);
            collateralVault.setClaimTVL(
                _epochId,
                collateralVault.finalTVL(_epochId)
            );

            collateralVault.setEpochNull(_epochId);
        } else if (collateralVault.totalAssets(_epochId) == 0) {
            premiumVault.resolveEpoch(_epochId);
            collateralVault.resolveEpoch(_epochId);

            premiumVault.setClaimTVL(_epochId, premiumVault.finalTVL(_epochId));
            collateralVault.setClaimTVL(_epochId, 0);

            premiumVault.setEpochNull(_epochId);
        } else revert VaultNotZeroTVL();

However, it is also possible to call triggerEndEpoch, because this function does not check whether there is a vault with 0 TVL. It will take fees and transfer premium to collateral vault. This is vastly different from triggerNullEpoch behavior.

Let's say the epoch is invalid because there are no deposits to collateral vault. If triggerEndEpoch is called, premium depositors lose their funds as those will be transferred to collateral vault. On the other hand, with triggerNullEpoch they would have gotten them back since the epoch would be marked invalid.

Impact

Premium depositors will not get their funds back in case of null epoch

Code Snippet

https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/Controllers/ControllerPeggedAssetV2.sol#L232-L251

Tool used

Manual Review

Recommendation

Revert triggerEndEpoch if either of the vaults has no deposits

Duplicate of #108

@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