1 min readApr 25, 2018
It’s essentially the same type of overflow that can occur in any type of arithmetic, since multiplication is just repetitive addition.
This problem is easy to avoid:
using SafeMath for uint256;
Then instead of adding or multiplying directly with the + or * operators, you call add or mul, and the necessary required overflow checks are done for you.
someNumber.mul(someOtherNumber);
https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/math/SafeMath.sol
The implementation of SafeMath.mul:
/** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b)
internal pure returns (uint256 c) { if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}