Skip to content

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

Open

Description

@code423n4

Handle

hickuphh3

Vulnerability details

Impact

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.

Recommended Mitigation Steps

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.

Activity

  1. added a commit that references this issue on Aug 6, 2021
  2. JasoonS commented on Aug 10, 2021

    @JasoonS
    Collaborator

    Fix:

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

    and

    -return (0, 1e18 * k * shortPrice);
    +return (0, k * shortPrice);
  3. DenhamPreen commented on Aug 12, 2021

    @DenhamPreen
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions