`FluidLocker::_getUnlockingPercentage()` uses 540 instead of `540 days` leading to stuck funds as the unlocking percentage will be bigger than `100%` and underflow
The FluidLocker contract's unlocking percentage calculation used 540 instead of 540 days, causing the percentage to exceed 100% and underflow when computing the tax flow rate. This forced users to either take an 80% penalty for instant unlock or have their funds stuck.
0x73696d616f Follow with Drynooo, merlinboii and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-11-superfluid-locking-contract-judging/issues/21
Found by
0x73696d616f, Drynooo, merlinboii, zxriptor
Summary
FluidLocker::_getUnlockingPercentage() calculates the amount to unlock when unvesting via the FluidLocker. It incorrectly uses 540 instead of 540 days, yielding a massive error such that the unlocking percentage will be much bigger than 10_000 and underflow.
function _getUnlockingPercentage(uint128 unlockPeriod) internal pure returns (uint256 unlockingPercentageBP) {
unlockingPercentageBP = (
_PERCENT_TO_BP
* (
((80 * _SCALER) / Math.sqrt(540 * _SCALER)) * (Math.sqrt(unlockPeriod * _SCALER) / _SCALER)
+ 20 * _SCALER
)
) / _SCALER;
}
Note: due to other bugs in the calculation it will not revert.
Root Cause
In FluidLocker:388 it uses 540 instead of 540 days.
Internal pre-conditions
None.
External pre-conditions
None.
Attack Path
- User unlocks their Fluid from the
FluidLocker, but it reverts because of the mentioned underflow. The funds within the locker will be stuck unless the user instantly unlocks and takes a80%penalty.
Impact
User is forced to take a 80% penalty or have the funds stuck.
PoC
The calculation is presented in the summary. Essentially, as 540 is used in the denominator, much smaller than the correct 540 days (which is the maximum unlock period, when the percentage becomes 100%), the value will be much bigger than 10_000.
As the unlocking percentage is bigger than 10_000, the unlock flow rate
unlockFlowRate = (globalFlowRate * int256(_getUnlockingPercentage(unlockPeriod))).toInt96()
/ int256(_BP_DENOMINATOR).toInt96();
will be bigger than the global flow rate, so it reverts when calculating the tax flow rate taxFlowRate = globalFlowRate - unlockFlowRate;.
Mitigation
Use 540 days instead of 540.
Discussion
0xPilou
Fix for this issue is included in the following PR : https://github.com/superfluid-finance/fluid/pull/6
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/superfluid-finance/fluid/pull/6
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
The contract used the literal value 540 instead of 540 days (the intended maximum unlock period) in the unlocking percentage formula.
Impact
Users are forced to either take an 80% penalty for instant unlock or have their funds stuck.
What the attacker needed
User has locked funds in FluidLocker
The fix
The issue was fixed by using 540 days instead of 540 in the calculation.
How it was found
- User attempts to unlock their Fluid from the FluidLocker.
- The transaction reverts due to an underflow in the tax flow rate calculation.
- The user's funds remain stuck unless they choose instant unlock with an 80% penalty.
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 smart contract that locks funds for a period had a mistake in its maths: it used a small number (540) where it should have used a much larger number (540 days in seconds). This made the calculated unlock percentage go above 100%, which broke the normal unlock process. Users could only get their funds back by accepting a large penalty.
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.