code-423n4 / 2021-06-tracer-findings

1 stars 0 forks source link

The `currentHour` variable in `Pricing` could be out of sync #142

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

shw

Vulnerability details

Impact

The recordTrade function in Pricing updates the currentHour variable by 1 every hour. However, if there is no trade (i.e., the recordTrade is not called) during this hour, the currentHour is out of sync with the actual hour. As a result, the averagePriceForPeriod function uses the prices before 24 hours and causes errors on the average price.

Proof of Concept

Referenced code: Pricing.sol#L90-L94

Recommended Mitigation Steps

Calculate how much time passed (e.g., (block.timestamp - startLastHour) / 3600) to update the currentHour variable correctly.