sherlock-audit / 2023-02-gmx-judging

17 stars 11 forks source link

hack3r-0m - loss of precision while diving `block.timestamp` due to runding towards 0 #226

Closed sherlock-admin closed 1 year ago

sherlock-admin commented 1 year ago

hack3r-0m

medium

loss of precision while diving block.timestamp due to runding towards 0

Summary

loss of precision while diving block.timestamp due to runding towards 0

Vulnerability Detail

uint256 timeKey = block.timestamp / divisor;

if divisor > 1e9 then this value is always 0, if divisor > 1e8 then this value is always 1

Impact

such rounding can lead to loss of precision and incrementing same key slot again and again

Code Snippet

https://github.com/sherlock-audit/2023-02-gmx/blob/main/gmx-synthetics/contracts/market/MarketUtils.sol#L542

Tool used

Manual Review

Recommendation

add bounds for possible values of divisor or apply precision