Inadequate checks to confirm the correct status of the sequence/ sequencerUptimeFeed in PriceFeed.getPrice() contract
adeolu Follow with serial-coder
Originally disclosed on Code4rena
Submitted by adeolu, also found by serial-coder
The PriceFeed contract has sequencerUptimeFeed checks in place to assert if the sequencer on an L2 is running but these checks are not implemented correctly. The chainlink docs say that sequencerUptimeFeed can return a 0 value for startedAt if it is called during an “invalid round”.
startedAt: This timestamp indicates when the sequencer changed status. This timestamp returns 0 if a round is invalid. When the sequencer comes back up after an outage, wait for the
GRACE_PERIOD_TIMEto pass before accepting answers from the data feed. Subtract startedAt from block.timestamp and revert the request if the result is less than theGRACE_PERIOD_TIME.If the sequencer is up and the
GRACE_PERIOD_TIMEhas passed, the function retrieves the latest answer from the data feed using thedataFeedobject.
Please note that an “invalid round” is described to mean there was a problem updating the sequencer’s status, possibly due to network issues or problems with data from oracles, and is shown by a startedAt time of 0 and answer is 0. Further explanation can be seen as given by an official chainlink engineer as seen here in the chainlink public discord
Note: to view the provided image, please see the original submission here.
This makes the implemented check below in the PriceFeed.getPrice() to be useless if its called in an invalid round.
if (block.timestamp - startedAt <= GRACE_PERIOD_TIME) {
revert Errors.GRACE_PERIOD_NOT_OVER();
}
As startedAt will be 0, the arithmetic operation block.timestamp - startedAt will result in a value greater than GRACE_PERIOD_TIME (which is hardcoded to be 3600). I.e., block.timestamp = 1719739032, so 1719739032 - 0 = 1719739032 which is bigger than 3600. The code won’t revert.
Imagine a case where a round starts, at the beginning startedAt is recorded to be 0, and answer, the initial status is set to be 0. Note that docs say that if answer = 0, sequencer is up, if equals to 1, sequencer is down. But in this case here, answer and startedAt can be 0 initially, until after all data is gotten from oracles and update is confirmed then the values are reset to the correct values that show the correct status of the sequencer.
From these explanations and information, it can be seen that startedAt value is a second value that should be used in the check for if a sequencer is down/up or correctly updated. The checks in PriceFeed.getPrice() will allow for successfull calls in an invalid round because reverts don’t happen if answer == 0 and startedAt == 0 thus defeating the purpose of having a sequencerFeed check to ascertain the status of the sequencerFeed on L2 (i.e., if it is up/down/active or if its status is actually confirmed to be either).
if (answer == 1) {
// sequencer is down
revert Errors.SEQUENCER_DOWN();
}
if (block.timestamp - startedAt <= GRACE_PERIOD_TIME) {
// time since up
revert Errors.GRACE_PERIOD_NOT_OVER();
}
Impact
Inadequate checks to confirm the correct status of the sequencer/sequencerUptimeFeed in PriceFeed.getPrice() contract will cause getPrice() to not revert even when the sequencer uptime feed is not updated or is called in an invalid round.
Recommended Mitigation Steps
Add a check that reverts if startedAt is returned as 0.
Assessed type
Oracle
aviggiano (Size) confirmed and commented:
This looks valid. It’s weird that the Chainlink sample code does not implement the check suggested by the documentation, as the warden points out.
Fixed in https://github.com/SizeCredit/size-solidity/pull/140. CC: https://github.com/smartcontractkit/documentation/pull/1995.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity business logic bug in Size. Code4rena made it public on 16 September 2024. Found in the 2024-06-size audit contest (finding M-04), also found by 1 other warden.
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.