Skip to content

Oracle updates can be frontrun by stakers to gain a profit #4

Open

Description

@code423n4

Handle

tensors

Vulnerability details

Impact

A staker can scan the mempool for upcoming oracle updates and frontrun them by withdrawing.
If the price moves in favor of his position he does nothing, if it moves against him he withdraws his earned fees.

This is possible because the stake and withdraw methods aren't queued and executed on the next oracle update, instead they're executed whenever the staker sends the appropriate transaction.

Proof of Concept

https://github.com/code-423n4/2021-08-floatcapital/blob/bd419abf68e775103df6e40d8f0e8d40156c2f81/contracts/contracts/Staker.sol#L948

https://github.com/code-423n4/2021-08-floatcapital/blob/bd419abf68e775103df6e40d8f0e8d40156c2f81/contracts/contracts/LongShort.sol#L669

Here updateSystem call just returns nothing if the price oracle is unchanged, allowing the staker to withdraw instantly.

Recommended Mitigation Steps

This is difficult to mitigate. Maybe a queue system for stakers as well?

Activity

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

    @JasoonS
    Collaborator

    0 - non-critical

    If the price moves in favor of his position he does nothing, if it moves against him he withdraws his earned fees.

    That is not how staking works. You constantly earn FLT reward while you are staked (per second). On every full system price update the rate at which you earn fees changes, absolute worst case is the market moves 'against you' and you earn zero FLT rewards after that point, then withdrawing gains you nothing. (actually it costs you because there is an unstake fee).

  3. moose-code commented on Aug 11, 2021

    @moose-code
    Collaborator

    Agree with Jason. There is a misunderstanding of how the system functions.

  4. Stentonian commented on Aug 11, 2021

    @Stentonian
    Collaborator

    Also agree with @JasoonS.

    The term "earned fees" here is confusing:

    if it moves against him he withdraws his earned fees.

    There are no fees earned by stakers. The fees are paid by the stakers to withdraw. I'm guessing @JasoonS you interpreted this as FLT.

  5. 0xean commented on Aug 26, 2021

    @0xean
    Collaborator

    Based on my understanding of the system the warden is partially correct in that a staker could look in the mempool and see that the next update was going to be favorable for FLT accruance on specific side of the market and enter prior the to update occurring. I don't see the same incentive on withdrawal because at worst after the next price update they may receive no FLT.

    So the question is how much does an "attacker" really gain by this small window in which they entered with unfair knowledge of the future state of the system. Given that they would have to already have an open position on that side of the market (because otherwise it would have to be minted on the next update) and that also means that side of the market is going to be on the losing side of the next update (since the FLT accrual rate is getting better), there seems like very little advantage to be gained here.

    Could a user theoretically mint both long and short and hold each until the right moment to stake them without unhedged price risk, yes. But they would be better off simply staking them now since it's a zero sum game.

    Based on this, downgrading to 0 - non critical.

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