Guys, what is the benefit of using safeMath library even after o.8.0.

This is what is written in comments of the library:


// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

Nov 28, 2021, 1:09 PM
Solidity 0.8+ have overflow check for + and * operations. But there is no built in safe math for subtraction and dividing.
Nov 30, 2021, 3:39 PM
That's wrong
Also - and / are checked
Nov 30, 2021, 3:44 PM
+
Nov 30, 2021, 3:47 PM
So, no reason to use safemath library at all.


I wonder why it even exists, it specifically states for use above 0.8๐Ÿ˜…
Nov 30, 2021, 3:55 PM
They explicitly state that since 0.8 it is not needed anymore, they are keeping it for now to not break old code that used it and it can be useful for the custom error messages
https://github.com/OpenZeppelin/openzeppelin-contracts/issues/2465
Nov 30, 2021, 4:42 PM
Its highly useful if you are debugging transactions
Coming from a guy who wasted an hour trying to figure out what was reverting on a simple subtraction underflow :)
Nov 30, 2021, 4:45 PM
Also that is true
Nov 30, 2021, 4:45 PM
ohk , thanks a lot , that makes sense
Nov 30, 2021, 4:53 PM
Read here lol
Safemath doesn't have anything particular about "complex math"
Nov 30, 2021, 5:02 PM
I mean if there are calculations with very big or small numbers*
Nov 30, 2021, 5:04 PM
for floating point operation, try wad ray math https://github.com/dapphub/ds-math
Nov 30, 2021, 5:14 PM
Thanks๐Ÿ‘๐Ÿป
Nov 30, 2021, 5:34 PM

ยฉ 2024 Draquery.com All rights reserved.