Skip to content

[Contracts] open-market: TWAP guard against settlement-price manipulation #1762

Description

@Olowodarey

Problem
The TWAP ring buffer exists in liquidity.rs, but settlement/resolution can still read a spot price that a single large swap moved. This enables last-block price manipulation of payouts.

Requirements

  • Add a settlement helper that requires the spot vs. TWAP deviation to be within a configurable max-deviation (bps); revert PriceDeviationTooHigh otherwise.
  • Return TwapInsufficientHistory (already modeled) when the window isn't covered, instead of silently using a short window.
  • Config value stored/validated in config.rs.

Acceptance Criteria

  • Manipulated spot price beyond the deviation band is rejected at settlement; normal price passes. Covered by tests.

Files

  • contracts/open-market/src/liquidity.rs
  • contracts/open-market/src/market.rs
  • contracts/open-market/src/config.rs
  • contracts/open-market/tests/twap_validation_tests.rs

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third Campaign

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions