Inconsistent use of epochBegin could lock user funds
Two functions compared the current block timestamp against the epoch start time with different strictness, so both could run in the same block at the exact start time. A deposit made after the null-epoch trigger in that block was left out of the recorded total, which could skew emission payouts and lock remaining funds.
Source: https://github.com/sherlock-audit/2023-03-Y2K-judging/issues/480
Found by
Inspex, KingNFT, TrungOre, b4by_y0d4, berndartmueller, datapunk, evan, minhtrng, roguereddwarf, sinarette, toshii, volodya, yixxas
Summary
The epochBegin timestamp is used inconsistently and could lead to user funds being locked.
Vulnerability Detail
The function ControllerPeggedAssetV2.triggerNullEpoch checks for timestamp like this:
if (block.timestamp < uint256(epochStart)) revert EpochNotStarted();
The modifier epochHasNotStarted (used by Carousel.deposit) checks it like this:
if (block.timestamp > epochConfig[_id].epochBegin)
revert EpochAlreadyStarted();
Both functions can be called when block.timestamp == epochBegin. This could lead to a scenario where a deposit happens after triggerNullEpoch is called (both in the same block). Because triggerNullEpoch sets the value for finalTVL, the TVL that comes from the deposit is not accounted for. If emissions have been distributed this epoch, this will lead to the incorrect distribution of emissions and once all emissions have been claimed the remaining assets will not be claimable, due to reversion in withdraw when trying to send emissions:
function previewEmissionsWithdraw(uint256 _id, uint256 _assets)
public
view
returns (uint256 entitledAmount)
{
entitledAmount = _assets.mulDivDown(emissions[_id], finalTVL[_id]);
}
...
//in withdraw:
uint256 entitledEmissions = previewEmissionsWithdraw(_id, _assets);
if (epochNull[_id] == false) {
entitledShares = previewWithdraw(_id, _assets);
} else {
entitledShares = _assets;
}
if (entitledShares > 0) {
SemiFungibleVault.asset.safeTransfer(_receiver, entitledShares);
}
if (entitledEmissions > 0) {
emissionsToken.safeTransfer(_receiver, entitledEmissions);
}
The above could also lead to revert through division by 0 if finalTVL is set to 0, even though the deposit after was successful.
Impact
incorrect distribution, Loss of deposited funds
Code Snippet
Tool used
Manual Review
Recommendation
The modifier epochHasNotStarted should use >= as comparator
Discussion
3xHarry
fix PR: https://github.com/Y2K-Finance/Earthquake/pull/130
IAm0x52
Fix looks good to me. Small inequality change for consistency
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely an off-by-one comparison mismatch: one check used a strict less-than while the other used a strict greater-than, leaving the exact start timestamp accepted by both.
Impact
Emissions could be distributed incorrectly and deposited funds could become unclaimable, with a possible revert from division by zero when the recorded total is zero.
What the attacker needed
Deposit and null-epoch trigger in same block; block timestamp equals epoch start
The fix
The start-time check in the deposit modifier should use a greater-or-equal comparison so deposits are rejected once the epoch has begun; the text says a fix pull request was made and reviewed as good.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A vault tracks how much money is inside so it can share rewards fairly. Two parts of the code disagreed about whether the vault had 'started' at the exact start second, so a deposit could slip in after the books were closed. That deposit was not counted, and later withdrawals could fail or pay the wrong amount.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.