From 21297e2b2cb36bc824ce75e8eb0217132171f7f3 Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 11 Jan 2018 11:11:43 -0300 Subject: [PATCH 1/2] Add documentation to safemath functions Fixes #655 --- contracts/math/SafeMath.sol | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/contracts/math/SafeMath.sol b/contracts/math/SafeMath.sol index 234daf656..d490dbe79 100644 --- a/contracts/math/SafeMath.sol +++ b/contracts/math/SafeMath.sol @@ -6,6 +6,10 @@ pragma solidity ^0.4.18; * @dev Math operations with safety checks that throw on error */ library SafeMath { + + /** + * @dev Multiplies two numbers, throws on overflow. + */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; @@ -15,6 +19,9 @@ library SafeMath { return c; } + /** + * @dev Integer division of two numbers, truncating the quotient. + */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 uint256 c = a / b; @@ -22,11 +29,17 @@ library SafeMath { return c; } + /** + * @dev Substracts two numbers, throws if subtrahend is greater than minuend. + */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } + /** + * @dev Adds two numbers, throws on overflow. + */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; assert(c >= a); From 49b42e86963df7192e7024e0e5bd30fa9d7ccbef Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Mon, 15 Jan 2018 15:44:06 -0300 Subject: [PATCH 2/2] Minor change in SafeMath sub documentation --- contracts/math/SafeMath.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/math/SafeMath.sol b/contracts/math/SafeMath.sol index d490dbe79..027379b3a 100644 --- a/contracts/math/SafeMath.sol +++ b/contracts/math/SafeMath.sol @@ -30,7 +30,7 @@ library SafeMath { } /** - * @dev Substracts two numbers, throws if subtrahend is greater than minuend. + * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a);