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: 101/111
Findings: 1
Award: $15.92
🌟 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
15.9228 USDC - $15.92
The developers are using a constant named MAX_CARDINALITY
as the maximum size of the _observations parameter
uint16 constant MAX_CARDINALITY = 365; // 1 year function binarySearch( Observation[MAX_CARDINALITY] storage _observations, uint24 _newestObservationIndex, uint24 _oldestObservationIndex, uint32 _target, uint16 _cardinality, uint32 _time )
which is used as a buffer to store one year's observations and do search through the function binarySearch. However, it only defines 365 observations (not the Solidity's year, which is 60*60*24*365 >>> 365) for the whole year, meaning that it may not be enough (for sure) to store all of the records/observations.
Suppose that the rate of observations is twice a day. That means, for the day 182/183 it will start overwriting the initial ones (ring buffer) which leads to just searching for a "time-block" of 6 months instead of the year the devs wanted. From the code:
/** * @dev Sets max ring buffer length in the Account.observations Observation list. * As users transfer/mint/burn tickets new Observation checkpoints are recorded. * The current `MAX_CARDINALITY` guarantees a one year minimum, of accurate historical lookups. ...
Manual analysis
Use the 1 year
from Solidity instead of hard-coding the value (check for gas too because loading every time such a big array would make it cost A LOT, which could incur in an OOG)
Error
#0 - asselstine
2023-07-20T20:40:07Z
1 years
is no longer valid Solidity, but I agree that we need harmony between the number of observations and the granularity of observations to get a consistent length of recorded history
#1 - c4-sponsor
2023-07-20T20:40:11Z
asselstine marked the issue as sponsor confirmed
#2 - Picodes
2023-08-07T17:20:26Z
Downgrading to low, as assuming the contract is properly configured and PERIOD_LENGTH
is correct it would store for ex 1 observation / day so would indeed have a 1 year lookup.
#3 - c4-judge
2023-08-07T17:20:30Z
Picodes changed the severity to QA (Quality Assurance)
#4 - c4-judge
2023-08-08T14:32:42Z
Picodes marked the issue as grade-b