Skip to content
Business logic Audit finding Intermediate

Staker.sol: Wrong values returned in edge cases of _calculateFloatPerSecond()

The _calculateFloatPerSecond() function returned values that were 1e18 times too large in edge cases where all rewards go to one token. This could cause an extremely large float token issuance rate, which would be disastrous.

hickuphh3 Follow

Originally disclosed on Code4rena

Submitted by hickuphh3

In _calculateFloatPerSecond(), the edge cases where full rewards go to either the long or short token returns

return (1e18 * k * longPrice, 0); and

return (0, 1e18 * k * shortPrice); respectively.

This is however 1e18 times too large. We can verify this by checking the equivalent calculation in the ‘normal case’, where we assume all the rewards go to the short token, ie. longRewardUnscaled = 0 and shortRewardUnscaled = 1e18. Plugging this into the calculation below,

return ((longRewardUnscaled * k * longPrice) / 1e18, (shortRewardUnscaled * k * shortPrice) / 1e18); results in

(0, 1e18 * k * shortPrice / 1e18) or (0, k * shortPrice).

As we can see, this would result in an extremely large float token issuance rate, which would be disastrous.

The edge cases should return (k * longPrice, 0) and (0, k * shortPrice) in the cases where rewards should go fully to long and short token holders respectively.

JasoonS (Float) confirmed:

Fix:

-return (1e18 * k * longPrice, 0);
+return (k * longPrice, 0);

and

-return (0, 1e18 * k * shortPrice);
+return (0, k * shortPrice);

DenhamPreen (Float) patched:

Resolved https://github.com/Float-Capital/monorepo/pull/1085

The original report as published on Code4rena, by hickuphh3. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

Impact

Could result in an extremely large float token issuance rate, which would be disastrous.

What the attacker needed

None

The fix

The fix was to remove the 1e18 multiplier from the edge case returns, and it was patched.

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.

In a smart contract, a function that calculates how many new tokens to create per second had a bug. In rare cases, it multiplied the result by a huge number (1e18), making the token creation rate enormous. This could break the system by creating too many tokens.

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.

More by hickuphh3

View all

43 more disclosed reports, best first.

More from Float Capital contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.