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.
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.