Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add timestamp check #72

Merged
merged 24 commits into from
Dec 9, 2024
Merged

feat(core): add timestamp check #72

merged 24 commits into from
Dec 9, 2024

Conversation

mariocao
Copy link
Member

@mariocao mariocao commented Dec 6, 2024

Motivation

To enhance the security and integrity of the SEDA protocol, we need to ensure that results cannot be posted with timestamps that precede their corresponding requests. This validation prevents potential temporal inconsistencies in the DR (Data Request) lifecycle.

Explanation of Changes

The changes introduce timestamp validation in the SedaCoreV1 contract:

  1. Added a new error type InvalidResultTimestamp for cases where result timestamps precede request timestamps
  2. Extended the storage layout with a requestTimestamps mapping to track timestamps of pending requests
  3. Modified postRequest to store the request timestamp
  4. Enhanced postResult to:
    • Validate that result timestamps are after request timestamps
    • Clean up the timestamp storage when processing results
    • Revert with InvalidResultTimestamp if validation fails

Important

The implementation allows for backwards compatibility by not enforcing validation for requests not tracked by this contract (where requestTimestamp = 0). Is this what we want?

Testing

Added new test cases in test/core/SedaCoreV1.test.ts:

  1. Modified the test fixtures to include an edge case with an invalid timestamp (set to 1 unix timestamp - 1970-01-01T00:00:01Z)
  2. Added a new test case should reject results with invalid timestamps that:
    • Posts a request
    • Attempts to post a result with a timestamp from 1970
    • Verifies that the transaction reverts with InvalidResultTimestamp error

Related PRs and Issues

Copy link
Member

@Thomasvdam Thomasvdam left a comment

Choose a reason for hiding this comment

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

The implementation allows for backwards compatibility by not enforcing validation for requests not tracked by this contract (where requestTimestamp = 0). Is this what we want?

This makes sense to me for our reference implementation. If people want to add additional 'freshness' constraints they can implement that in their own core contract or another contract in between.

@mariocao mariocao merged commit f0ec1fa into main Dec 9, 2024
1 check passed
@mariocao mariocao deleted the feat/timestamp branch December 9, 2024 19:58
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.

✨ Add “result timestamp window” to core contract
2 participants