3 ms·
Why does the fix work like that - only checking for this one scenario when you decrement by type max? [1] In Solidity, where it's a serious security risk, befo
by ryanjshaw 3y ago
Why does the fix work like that - only checking for this one scenario when you decrement by type max? [1]
In Solidity, where it's a serious security risk, before the language performed overflow checks itself, library authors would perform the arithmetic operation and then e.g. check if the result is larger than the original value in the case of a positive subtrahend [2].
[1] https://github.com/apache/kvrocks/pull/1581/commits/dc5140dd0c7ffdbb028fad238154622a60853b23 https://github.com/apache/kvrocks/pull/1581/commits/dc5140dd...
[2] https://github.com/KingdomStudiosIO/contracts/blob/51873b574236822c31d5825351f2492af303fc2d/contracts/libraries/SignedSafeMath.sol#L67 https://github.com/KingdomStudiosIO/contracts/blob/51873b574...