Posts

Showing posts with the label #SafeMath

Ethereum Smart Contract Safe Math Checks

An overflow/underflow happens when an arithmetic operation reach the maximum or minimum size of the type.  An overflow condition gives incorrect results and, particularly if the possibility has not been anticipated, can compromise a program’s reliability and security. SafeMath  is a solidity math library especially designed to support  safe  math operations: safe means that it prevents overflow when working with  uint . You can find it in zeppelin-solidity  SafeMath . pragma solidity 0.4.24; // @title SafeMath // @dev Math operations with safety checks that throw on error library SafeMath { function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); return c; } function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } function mul(uint256 a, uint256 b) internal pure returns (uint256) { ...