Platform: Code4rena
Start Date: 07/07/2023
Pot Size: $121,650 USDC
Total HM: 36
Participants: 111
Period: 7 days
Judge: Picodes
Total Solo HM: 13
Id: 258
League: ETH
Rank: 59/111
Findings: 1
Award: $140.30
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: bin2chen
Also found by: 0x11singh99, 0xWaitress, 0xbepresent, ABAIKUNANBAEV, ArmedGoose, Bauchibred, DadeKuma, GREY-HAWK-REACH, GalloDaSballo, Inspecktor, Jeiwan, Kaysoft, MohammedRizwan, Rolezn, Vagner, alexzoid, alymurtazamemon, ayden, banpaleo5, catellatech, dacian, erebus, eyexploit, fatherOfBlocks, grearlake, joaovwfreire, keccak123, kutugu, lanrebayode77, markus_ether, nadin, naman1778, rvierdiiev, squeaky_cactus, volodya, yixxas
140.2996 USDC - $140.30
The binarySearch does not check for overlap between the left and right index of the sliding window, and loops indefinitely when satisfies item not exists in list until revert or gas is exhausted.
while (true) { // We start our search in the middle of the `leftSide` and `rightSide`. // After each iteration, we narrow down the search to the left or the right side while still starting our search in the middle. currentIndex = (leftSide + rightSide) / 2; beforeOrAtIndex = uint16(RingBufferLib.wrap(currentIndex, _cardinality)); beforeOrAtDrawId = _drawRingBuffer[beforeOrAtIndex]; afterOrAtIndex = uint16(RingBufferLib.nextIndex(currentIndex, _cardinality)); afterOrAtDrawId = _drawRingBuffer[afterOrAtIndex]; bool targetAtOrAfter = beforeOrAtDrawId <= _targetLastClosedDrawId; // Check if we've found the corresponding Observation. if (targetAtOrAfter && _targetLastClosedDrawId <= afterOrAtDrawId) { break; } // If `beforeOrAtTimestamp` is greater than `_target`, then we keep searching lower. To the left of the current index. if (!targetAtOrAfter) { rightSide = currentIndex - 1; } else { // Otherwise, we keep searching higher. To the left of the current index. leftSide = currentIndex + 1; } }
According to the code only targetAtOrAfter &&_targetLastClosedDrawId <= afterOrAtDrawId
can break loop, if no element in the list meets the condition, it loops indefinitely until the array index overflows or exhausts gas
Manual review
Should check leftSide > rightSide
to break the loop
Loop
#0 - c4-sponsor
2023-07-20T23:11:16Z
asselstine marked the issue as sponsor confirmed
#1 - Picodes
2023-08-07T16:27:23Z
There is a small chance of wasted gas due to this search never ending, but the report doesn't dig into the potential impact of this finding. Downgrading to Low.
#2 - c4-judge
2023-08-07T16:27:27Z
Picodes changed the severity to QA (Quality Assurance)
#3 - c4-judge
2023-08-08T14:31:10Z
Picodes marked the issue as grade-a