Skip to content

Instantly share code, notes, and snippets.

@bitdollarfund
Last active January 28, 2018 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitdollarfund/b870e853adf910cc46f358adac44fe28 to your computer and use it in GitHub Desktop.
Save bitdollarfund/b870e853adf910cc46f358adac44fe28 to your computer and use it in GitHub Desktop.
pragma solidity 0.4.18;
contract SafeMath {
function safeMul(uint a, uint b) internal pure returns (uint) {
uint c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function safeSub(uint a, uint b) internal pure returns (uint) {
assert(b <= a);
return a - b;
}
function safeAdd(uint a, uint b) internal pure returns (uint) {
uint c = a + b;
assert(c>=a && c>=b);
return c;
}
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment