Division before multiple can lead to precision errors #28
Labels
1 (Low Risk)
Assets are not at risk. State handling, function incorrect as to spec, issues with comments
bug
Something isn't working
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
cyberboy
Vulnerability details
Impact
Performing multiplication before division is generally better to avoid loss of precision because Solidity integer division might truncate
Proof of Concept
https://github.com/code-423n4/2021-11-streaming/blob/main/Streaming/src/Locke.sol#L237-L238
globalStreamingSpeedPerSecond is later used for unstreamed for multiplication after performing division while calculation of globalStreamingSpeedPerSecond
Tools Used
Slither
Recommended Mitigation Steps
The code can be optimized to use
uint112((uint256(tdelta) * (uint256(unstreamed) * 106) / (endStream - lastUpdate) * 106
Or maybe just
(uint112((uint256(tdelta) * (uint256(unstreamed)) / (endStream - lastUpdate)
The text was updated successfully, but these errors were encountered: