code-423n4 / 2021-09-wildcredit-findings

0 stars 0 forks source link

Reduce the number of divisions in _timeRateToBlockRateit #104

Closed code423n4 closed 3 years ago

code423n4 commented 3 years ago

Handle

pauliax

Vulnerability details

Impact

function _timeRateToBlockRateit contains an expression with 3 divs that could lead to rounding errors / loss of precision: return _uint / 365 / 86400 * BLOCK_TIME / 1e18; There are a lot of constant values that do not change. These can be precalculated and re-used.

Recommended Mitigation Steps

An example improvement: uint public constant DENOMINATOR = 365 86400 1e18; function _timeRateToBlockRate(uint _uint) private view returns(uint) { return _uint * BLOCK_TIME / DENOMINATOR; } This will also reduce the gas usage (fewer calculations) and improve the precision as now you will have 1 instead of 3 separate divisions unless you expect that this _uint of rate could be so high that the division is needed before the multiplication for it to not overflow.

talegift commented 3 years ago

Duplicate #36