Skip to content

feat(contract): implement oracle data expiry logic and stale age verification - #521

Open
Ranjeet2063 wants to merge 1 commit into
ChianLojistics:mainfrom
Ranjeet2063:feat/issue-390-oracle-data-expiry
Open

Ranjeet2063 wants to merge 1 commit into
ChianLojistics:mainfrom
Ranjeet2063:feat/issue-390-oracle-data-expiry

Conversation

@Ranjeet2063

Copy link
Copy Markdown

Closes #390

Summary of Changes

This pull request implements the oracle data expiry logic and stale age verification for the oracle security smart contract:

  1. Error Enum Extension:

    • Added StaleData = 170 error code to Error enum for signaling expired or stale oracle data readings.
  2. Constants & Types:

    • Defined MAX_STALE_AGE (3600 seconds / 1 hour) as the default allowable stale age window.
    • Defined MAX_STALE_AGE_TEMPERATURE (300 seconds / 5 minutes) for cold-chain and time-sensitive readings.
    • Introduced DataKey::OracleData and OracleData struct (feed_id: Symbol, value: i128, timestamp: u64).
  3. Storage & State Transitions:

    • Implemented record_oracle_data to store authenticated oracle data points on-chain.
    • Updated submit_report to automatically synchronize persistent OracleData storage upon consensus snapshot calculation.
    • Implemented get_oracle_data to query the latest recorded feed data.
  4. Condition Verification with Expiry Gates:

    • Implemented verify_condition(env, feed_id, min, max) enforcing now - data.timestamp <= max_age_seconds (or MAX_STALE_AGE), returning Err(Error::StaleData) if exceeded.
    • Implemented verify_data_condition(env, data, min, max, custom_max_age) for custom SLA verification windows.
    • Implemented verify_temperature_condition(env, feed_id, min_temp, max_temp) enforcing the tight 5-minute cold-chain expiry window.
  5. Test Coverage:

    • Unit tests added covering data recording and retrieval.
    • Fresh condition verification in-range and out-of-range behavior.
    • Stale data rejection past max allowable window.
    • Custom feed max_age_seconds enforcement.
    • 5-minute temperature window boundary testing.
    • Consensus report submission updating oracle data state.

…fication

- Add StaleData error code to contract error enum
- Define MAX_STALE_AGE and MAX_STALE_AGE_TEMPERATURE constants
- Store and expose OracleData struct with feed_id, value, and timestamp
- Implement record_oracle_data and get_oracle_data
- Implement verify_condition, verify_data_condition, and verify_temperature_condition
- Add comprehensive test suite covering stale age validation, boundary timestamps, and cold-chain window
Copilot AI balanced review requested due to automatic review settings October 7, 2026 16:23
@vercel

vercel Bot commented Oct 7, 2026

Copy link
Copy Markdown

@Ranjeet2063 is attempting to deploy a commit to the Ebeleokolo's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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][CO-09] Oracle Data Expiry Logic

2 participants