Integer overflow weakness similar kill the Ethereum – for more details, please see below (url):
But SafeMath to protect from overflows.
c >= a causes integer overflow happen
arithmetic: c=a+b-M (where M = 2**256 is the max unit256 plus one)
If c >=a replace to get a + b -M >=a
Cancelling and recording terms and get b >= M
Result: b is a uint256 and thus b < M
write an algebraic expression in a certain order. We start with the terms that have the largest exponents and work our way down to the constants. Using the commutative property of addition, we can rearrange the terms and put this expression in correct order, like this.
Before you evaluate an algebraic expression, you need to simplify it. This will make all your calculations much easier. Here are the basic steps to follow to simplify an algebraic expression:
remove parentheses by multiplying factors
use exponent rules to remove parentheses in terms with exponents
combine like terms by adding coefficients
combine the constants
How does the SafeMath library of OpenZeppelin protect your code from integer overflow?