Skip to content

Oracle Failure & Manipulation Testing#178

Open
UlyanaAndrukhiv wants to merge 13 commits intomainfrom
UlianaAndrukhiv/149-oracle-failure-and-manipulation-testing
Open

Oracle Failure & Manipulation Testing#178
UlyanaAndrukhiv wants to merge 13 commits intomainfrom
UlianaAndrukhiv/149-oracle-failure-and-manipulation-testing

Conversation

@UlyanaAndrukhiv
Copy link
Contributor

Closes: #149

Note: this PR should be merged after

Description

Adds comprehensive test coverage for oracle failure modes, extreme price scenarios, and DEX/oracle price deviation circuit breaker to ensure the protocol maintains security when price data is compromised, unavailable, or manipulated.

Tests added (fork_oracle_edge_cases_test.cdc)

Price Feed Failures

  • test_oracle_nil_price — oracle returns nil for FLOW; any operation requiring pricing (health check) must revert due to force-unwrap panic

Invalid Price Data

  • test_oracle_zero_price — oracle price set to 0.0; position creation fails with PriceOracle must return a price greater than 0.0 if available postcondition
  • test_oracle_near_zero_price_extreme_health — FLOW price set to $0.00000001; health drops to near-zero (0.000000016), position becomes liquidatable
  • test_oracle_very_large_price_no_overflow — WETH price set to UFix64.max; verifies no overflow in UFix128 math, health returns CEILING_HEALTH, available balance unchanged

DEX/Oracle Price Deviation & Circuit Breaker

  • test_dex_oracle_deviation_boundary_exact_threshold — boundary tests for dexOraclePriceDeviationInRange helper at exactly 300 bps, 301 bps, both directions, and equal prices
  • test_dex_oracle_deviation_blocks_liquidation — DEX price deviates 16.7% from oracle; liquidation blocked with DEX/oracle price deviation too large
  • test_dex_oracle_within_threshold_liquidation_succeeds — DEX price within 3% of oracle; liquidation proceeds normally
  • test_governance_tightens_dex_deviation_threshold — governance tightens threshold from 300 bps to 100 bps; previously allowed 2.19% deviation now blocked

Extreme Price Scenarios

  • test_flash_crash_triggers_liquidation — FLOW drops 50% ($1.00 → $0.50) in single block; health drops from 1.33 to 0.67, position becomes liquidatable, full liquidation flow executed and verified
  • test_flash_pump_increase_doubles_health — FLOW doubles ($1.00 → $2.00); health jumps from 1.6 to 3.2, user borrows at inflated price, price corrects back demonstrating pump-and-dump risk

@UlyanaAndrukhiv UlyanaAndrukhiv self-assigned this Feb 20, 2026
@UlyanaAndrukhiv UlyanaAndrukhiv marked this pull request as ready for review February 24, 2026 12:00
@UlyanaAndrukhiv UlyanaAndrukhiv requested a review from a team as a code owner February 24, 2026 12:00
@UlyanaAndrukhiv UlyanaAndrukhiv linked an issue Feb 24, 2026 that may be closed by this pull request
@@ -0,0 +1,697 @@
#test_fork(network: "mainnet", height: 142528994)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice this test making use of any deployed Mainnet state. If so, we can just make this a standard Cadence test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it uses the mainnet tokens, like MOET. I'm kinda okay with keeping this forked, as ideally, we'd ALSO add oracle failure cases with the band oracle, rather than just the mock oracle.

Copy link
Member

@Kay-Zee Kay-Zee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good.

Only comments for me are that we should also try to do some of these tests with the existing on chain oracles, like the band or pyth oracle.

That shouldn't block this PR, since i think testing with the mock is still useful, but would love to just show that the real oracles would also behave in the same way. (even though the assumption is that they will, due to the interface behaviour)

@@ -0,0 +1,697 @@
#test_fork(network: "mainnet", height: 142528994)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it uses the mainnet tokens, like MOET. I'm kinda okay with keeping this forked, as ideally, we'd ALSO add oracle failure cases with the band oracle, rather than just the mock oracle.

UlyanaAndrukhiv and others added 5 commits March 3, 2026 17:21
Co-authored-by: Kan Zhang <kan.zhang@flowfoundation.com>
Co-authored-by: Jordan Schalm <jordan.schalm@gmail.com>
…hub.com:onflow/FlowCreditMarket into UlianaAndrukhiv/149-oracle-failure-and-manipulation-testing
Base automatically changed from UlianaAndrukhiv/148-multiple-collateral-testing to main March 3, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Oracle Failure & Manipulation Testing

3 participants