feat: implement BFT multi-oracle state aggregator and slash engine (#… - #1030
Merged
Mosas2000 merged 2 commits intoAug 20, 2026
Merged
Conversation
Contributor
Author
|
Done, please review |
Contributor
|
I spotted a critical Sybil vulnerability in the oracle_hub.rs smart contract where an attacker can bypass the BFT consensus by passing an array of duplicate active addresses in reporting_nodes to artificially inflate the valid_count |
Contributor
|
@DevNetlife You need to enforce uniqueness within the reporting_nodes vector during the submit_bft_aggregate execution to ensure the quorum represents strictly distinct oracle nodes. |
Contributor
Author
|
Working on it. |
Contributor
|
This is highly robust now, thank you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: Implement Consensus-Driven Byzantine Fault Tolerant (BFT) Multi-Oracle State Aggregator and Slash Engine
Closes #1007
Description
This PR implements a Byzantine Fault Tolerant (BFT) consensus state aggregator and slash engine across the backend API services (
bftOracleAggregator.service.ts) and the Soroban smart contract oracle module (contracts/soroban/src/oracle_hub.rs).Previously, price and health score updates relied on individual feeds or simple arithmetic averages, leaving circuit breakers and automated asset pausing mechanisms vulnerable to single-source outlier prices and flash crashes. This update enforces a 2f + 1 quorum agreement across 3f + 1 independent oracle providers, applies median-of-medians filtering with weighted stake voting algorithms, and automatically slashes bad oracle nodes in the database registry (
provider_health_registry) when reported values deviate by > 5σ from consensus.Changes Included
Backend Services & API (
backend/)backend/src/services/bftOracleAggregator.service.ts):backend/src/services/providerHealthRegistry.service.ts):flagAndSlashProvider()method to update provider status to slashed, persist penalty details, and record maintenance notes.backend/src/database/migrations/049_bft_oracle_aggregator.ts):bft_oracle_providers,bft_consensus_rounds, andbft_slashing_eventswith appropriate indexes.backend/src/database/types.ts.backend/src/api/routes/bftOracle.routes.ts):/api/v1/bft-oracleendpoints (POST /aggregate,POST /providers,GET /providers,GET /rounds/:assetCode,GET /slashing-events).Soroban Smart Contract Module (
contracts/soroban/)contracts/soroban/src/oracle_hub.rs):OracleHubContractfor on-chain BFT consensus validation.calculate_required_quorum.submit_bft_aggregatefor storing cryptographically signed multi-oracle aggregate state.slash_oracle_nodefor on-chain node revocation and event publication.contracts/soroban/src/lib.rs&Cargo.toml):pub mod oracle_hub;and registeredoracle_hub_testtarget.Verification & Testing
Backend Unit Tests
Ran unit test suite covering quorum calculation, median-of-medians, stake weighting, network partitions, and > 5σ outlier slashing: