SIP-400 Fix for underflow error when offchain price timestamp is bigger than current block timestamp #2049
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.
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
to be fixed with
This will ensure we do not get negative values when
priceNodeOutput.timestamp
is greater thanblock.timestamp