Skip to content

feat(oracle): add deterministic Binance index feed - #418

Merged
ByteYue merged 1 commit into
mainfrom
codex/oracle-binance-provider
Aug 3, 2026
Merged

feat(oracle): add deterministic Binance index feed#418
ByteYue merged 1 commit into
mainfrom
codex/oracle-binance-provider

Conversation

@ByteYue

@ByteYue ByteYue commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds the independently reviewable Binance price provider described in Galxe/gravity-audit#1038.

  • implements sourceType=3 with Binance USD-M indexPriceKlines
  • maps each delivery nonce to one immutable closed bucket
  • validates exact open/close timestamps and emits the contract PricePayload ABI
  • rejects active-feed history changes during registration and runtime reconciliation
  • enables source type 3 execution with the existing 500,000 callback gas budget
  • documents provider URI, canonical payload, restart semantics, and operator-local endpoint configuration

Depends on the merged generic Oracle core in #416/#417 and the merged PriceFeedResolver in Galxe/gravity_chain_core_contracts#114.

Deterministic mapping

For delivery nonce n:

bucketStart(n) = configuredBucketStart + (n - 1) * interval
bucketEnd(n)   = bucketStart(n) + interval - 1
sourcePosition = bucketEnd(n)
roundId        = bucketStart(n) / interval
resolvedAt     = bucketEnd(n)

The adapter requests exactly one bucket with startTime, endTime, and limit=1. It accepts exactly one row whose openTime and closeTime match the requested bucket.

Safety properties

  • Binance base URL is validator-local configuration and is rejected in the on-chain URI.
  • Task parameters use an allowlist; pair and interval inputs are validated.
  • HTTP connect/request timeouts and a 64 KiB streamed response limit bound resource use.
  • Prices must be positive and exactly representable at the configured precision.
  • A confirmed source position must match the configured nonce-to-bucket history.
  • Runtime reconciliation is fallible and fails closed on a history mismatch.
  • Existing source type 0 behavior and its 500,000 gas policy are unchanged.
  • No credentials, user-specific paths, Polygon/Polymarket code, live-network E2E, or SDK/demo files are included.

Validation

  • cargo test -p reth-pipe-exec-layer-relayer: 39 passed, 1 pre-existing external-RPC test ignored
  • cargo test -p reth-pipe-exec-layer-ext-v2 onchain_config::jwk_oracle: 9 passed
  • localhost HTTP test exercises reqwest request construction, bounded response reading, canonical wrapper encoding, and state advancement without external traffic
  • cargo fmt --all -- --check: passed
  • cargo clippy -p reth-pipe-exec-layer-relayer --all-targets --no-deps: passed with five pre-existing warnings in factory.rs/eth_client.rs; no warnings in the new provider
  • cargo clippy -p reth-pipe-exec-layer-ext-v2 --lib --no-deps: completed with existing package warnings
  • full staged diff check and credential/path scan: passed

Non-goals

  • Polygon/Polymarket settlement provider
  • SDK deterministic or live multi-validator E2E
  • frontend/demo runtime
  • multi-provider aggregation
  • deployment or task activation

Tracks Galxe/gravity-audit#1038 and Galxe/gravity-audit#1033.

Add the source type 3 Binance USD-M indexPriceKlines adapter with deterministic nonce-to-bucket mapping, exact closed-bucket validation, bounded HTTP responses, and fixed-point payload encoding.

Reject task history mismatches during registration and runtime reconciliation, retain the existing 500,000 callback gas policy, and document the canonical PriceFeedResolver payload.

Tests cover URI/config validation, restart mapping, response parsing, precision bounds, localhost HTTP transport, canonical wrapper encoding, manager reconciliation, and execution calldata.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 458c734350

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +226 to +227
let expected = config.round_for_delivery_nonce(latest_onchain_nonce)?.source_position;
if latest_onchain_position != 0 && latest_onchain_position != expected {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Bind the market configuration to an active feed ID

When an existing feed URI is replaced with one that keeps the same feedId, bucket origin, and interval but changes pair, this check still succeeds because it validates only the derived timestamp. Subsequent payloads are tagged with the original feedId but contain prices from the new market, and the callback payload carries no pair identifier with which downstream code could detect the switch. Persist and verify the immutable market configuration, or require a new feedId for any pair change.

Useful? React with 👍 / 👎.

"Reconciling local source with confirmed on-chain progress"
);
source.reconcile_progress(onchain_nonce, onchain_position).await;
source.reconcile_progress(onchain_nonce, onchain_position).await?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate positions when the confirmed nonce matches locally

When a price poll has already advanced local state to nonce n and the next call reports the same on-chain nonce with a conflicting nonzero source position, this fallible reconciliation is skipped by the guard above because current_position is already nonzero. The source therefore misses the advertised runtime history check and proceeds to emit nonce n + 1 from an incompatible history; reconciliation must also run, or explicitly error, when equal nonces have different positions.

Useful? React with 👍 / 👎.

@ByteYue
ByteYue merged commit 17bd08b into main Aug 3, 2026
33 checks passed
@ByteYue
ByteYue deleted the codex/oracle-binance-provider branch August 3, 2026 10:57
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.

1 participant