Skip to content

feat: add decentralized oracle aggregator with medianizer and outlier trimming (#69) - #200

Open
bellofuad34-ctrl wants to merge 5 commits into
agnesnaomiolim-cloud:mainfrom
bellofuad34-ctrl:feat/69-oracle-aggregator
Open

feat: add decentralized oracle aggregator with medianizer and outlier trimming (#69)#200
bellofuad34-ctrl wants to merge 5 commits into
agnesnaomiolim-cloud:mainfrom
bellofuad34-ctrl:feat/69-oracle-aggregator

Conversation

@bellofuad34-ctrl

@bellofuad34-ctrl bellofuad34-ctrl commented Aug 31, 2026

Copy link
Copy Markdown

Closes #69


Summary

Implements a decentralized oracle aggregator with medianizer and outlier trimming, addressing #69.

Changes

  • contracts/oracle-aggregator/src/lib.rs: New Soroban contract OracleAggregator that:
    • Accepts price pushes from N authorized data feeds (add_feed / remove_feed, admin-only).
    • Computes a manipulation-resistant median price, not a mean, so a single spiked feed cannot skew the result.
    • Performs iterative outlier trimming: values whose deviation from the running median exceeds a configurable threshold (in basis points, default 5%) are dropped before the final median is computed.
    • Enforces heartbeat staleness: price updates older than a configurable window (default 300s) are rejected at write time and ignored at read time.
    • Uses strict fixed-point integer math (u128 with saturating_mul, no floating point, no overflow risk).
    • Requires auth on admin operations and feed pushes.
  • contracts/oracle-aggregator/src/math.rs: Pure, overflow-safe math module (median, median_of_sorted, trimmed_median, deviation_bps, is_outlier, is_stale, mid) with exhaustive unit tests.
  • contracts/oracle-aggregator/tests/oracle_aggregator_tests.rs: Property-based tests (proptest) verifying mathematical safety across edge-case input vectors (extreme u128 values, zero references, clustered adversarial feeds), plus end-to-end contract tests including the required +500% spike scenario (1 of 5 oracles spiked; aggregated price stays stable).
  • Cargo.toml: Registers the contract as a workspace member and removes lto/panic from the per-package profile override (these keys are invalid in [profile.*.package.*] per the Cargo reference and blocked the whole workspace from parsing; CI on main was already red on Build).
  • Cargo.lock: Updated for the new workspace member.

Verification

  • cargo build -p oracle-aggregator --target wasm32-unknown-unknown --release succeeds.
  • cargo test -p oracle-aggregator passes: 8 unit tests + 12 integration/property tests.
  • cargo clippy -p oracle-aggregator is clean.
  • End-to-end: with 4 honest feeds at ~100 and 1 feed at +500%, get_price returns the honest median (100), not the spike.

@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@bellofuad34-ctrl Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@agnesnaomiolim-cloud

Copy link
Copy Markdown
Owner

This branch has a conflict; resolve it.

@agnesnaomiolim-cloud

Copy link
Copy Markdown
Owner

CI check failed; please resolve that.

Resolve Cargo.lock/Cargo.toml conflicts with main.
Fix security-scan workflow: invalid \\$\{{ matrix.os }}\ reference (no
matrix defined) broke the whole workflow; correct kube-bench download URL,
k6 action, and k6 script name.
- compliance-kube-bench referenced \\$\{{ matrix.os }}\ but the job has no
  matrix, which invalidates the whole workflow and fails the run before any
  job starts. Use the correct kube-bench release asset URL instead.
- fix escaped quotes in the curl command.
- use the existing grafana/k6-action@v0.3.1 and correct k6 script name.
@bellofuad34-ctrl

Copy link
Copy Markdown
Author

Hi maintainers 👋 -- this PR is ready for review and merge.

What has been updated:

  • Merge conflict resolved: latest main merged into feat/69-oracle-aggregator; Cargo.lock/Cargo.toml conflicts fixed (contracts/oracle-aggregator retained as a workspace member). PR is now mergeable.
  • security-scan workflow fixed: the compliance-kube-bench job referenced ${{ matrix.os }} with no matrix defined, which invalidated the whole workflow and made every run fail before starting a job. Corrected the kube-bench download URL, fixed escaping, and pointed the k6 job at the existing grafana/k6-action and benchmarks/k6/security-pen.js.

Maintainer actions needed:

  1. Approve the pending workflow runs -- several checks (CI/CD Pipeline, Lint, etc.) are waiting on first-time-contributor approval.
  2. Note: the security-scan check still shows red on this PR because GitHub runs the base branch's workflow file for fork PRs; the broken file lives on main. This PR includes the fix, so it will take effect on main after merge. (Main also has unrelated pre-existing issues -- an invalid kube feature leader-election and a corrupted src/controller/leader.rs -- that affect all PRs.)

Could you review and merge? Thanks!

@bellofuad34-ctrl

Copy link
Copy Markdown
Author

@agnesnaomiolim-cloud this PR is ready to merge -- branch conflict is resolved and the broken security-scan workflow has been fixed in this branch. Could you please approve the pending workflow runs and merge? Thank you!

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.

## [Contract] Decentralized Oracles Aggregator with Medianizer & Outlier Trimming

2 participants