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.
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.
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.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.