Dan Emmons
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;
}

--

--

Dan Emmons
Dan Emmons

Written by Dan Emmons

A leader who strives to make issues that seem complex, overwhelming, or insurmountable more manageable for the Team & provide exceptional service to my clients.

Responses (1)