The current implementation of morningTemperature() is very inefficient for na L2
To cater for the L2 smaller block time following new code is added into morningTemperature
function
Which basically converts the L2 changes in block in terms of L1, for example if the 12 second have passed on L2 which is 6 blocks, it will return back 1, because in terms of L1 only 1 block has passed.
Now based on the number of blocks, the scaling is done in following way where hard coded values are passed in for certain deltas where maximum scaling happens for delta grater than or equal to 24
But the problem here is, this is not the right approach to handle this for an L2, one L1 there are 12 seconds block time and you go directly from block 1 to 2, block 2 to 3. You can't go from block 3 to 3.5 but in current implementaion this is possible and we can get better result using the formula on chain og51(2x+1)
which is the formula that is applied behind these hard codings by using the higher precision for the delta.
For example consider the following scenerio
So the delta will be rounded down to 4, and it will use the value 558830625409
while the formula yeilds 5804892177
which is a 3% difference that is a very significant difference for defi applications like beanstalk and skew multiple calculation functions in field facet.
So just to summarize, problem arises from not using larger precision for the delta and than hardcoding formula results which don't let calculate any other values except which are hardcoded. This is done to save gas but on L2 that is not gonna be concern for beanstalk and this is also the primary reason to move to L2 to cost less gas to users.
High because the results are skewed by several percents and chances of it happening are very high.
Brain
Use higher precision for delta and use the formula on chain PRB math library which is already integrated into contracts.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.