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

SIP-400 Fix for underflow error when offchain price timestamp is bigger than current block timestamp #2049

Merged
merged 1 commit into from
Jul 29, 2024

Conversation

noisekit
Copy link
Contributor

Simple Summary

Fix a bug in StalenessCircuitBreakerNode that results in an underflow error when the off-chain price update timestamp exceeds the current block timestamp.

Abstract

Propose an update to the StalenessCircuitBreakerNode script to handle situations where the off-chain price update timestamp is in the "future" for the current block. Accompany the bug fix with corresponding tests.

Motivation

Every chain mints blocks with a reasonable delay. If a fresh price update transaction retrieves a timestamp that is in the "future" relative to the current block, this results in an underflow error. Fixing this error will make the StalenessCircuitBreakerNode script more resilient and ensure its correct functioning under this particular condition.

Specification

Technical

We propose to adjust the StalenessCircuitBreakerNode contract to cater to situations where the off-chain price update timestamp exceeds the current block timestamp.

The proposed adjustment addresses the underflow error and ensures that the StalenessCircuitBreakerNode script does not fail due to this specific scenario.

In addition to the bug fix, we suggest adding new tests to the test suite that cover this particular case. Doing so will help maintain the robustness of the existing test suite and catch any future recurrences of this problem.

Incorrect implementation leading to arithmetic underflow

if (block.timestamp - priceNodeOutput.timestamp <= stalenessTolerance) {

to be fixed with

if (block.timestamp - stalenessTolerance <= priceNodeOutput.timestamp) {

This will ensure we do not get negative values when priceNodeOutput.timestamp is greater than block.timestamp

Copy link

vercel bot commented Jul 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sips ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2024 2:35am

@noisekit noisekit requested a review from kaleb-keny July 29, 2024 02:35
@kaleb-keny kaleb-keny merged commit f704536 into master Jul 29, 2024
2 of 3 checks passed
@kaleb-keny kaleb-keny deleted the sip-400 branch July 29, 2024 06:16
@kaleb-keny
Copy link
Member

thank you will setup the presentation for this, wednesady

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.

2 participants