-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve safemath signed int #714
Improve safemath signed int #714
Conversation
@cedricwalter would you mind checking the CI status? |
Yes i am looking at it now |
was nothing a temporary error in the build, i've run all tests twice locally with yarn |
contracts/math/SafeMath.sol
Outdated
} | ||
|
||
function add(int256 a, int256 b) internal pure returns (int256) { | ||
return a + b; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cedricwalter shouldn't these have overflow checks too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cedricwalter please fix
contracts/math/SafeMath.sol
Outdated
} | ||
|
||
function add(int256 a, int256 b) internal pure returns (int256) { | ||
return a + b; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cedricwalter please fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @cedricwalter! Please address the concerns I raised below.
*/ | ||
function mul(uint256 a, uint256 b) internal pure returns (uint256) { | ||
if (a == 0) { | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's hard to understand the scope of the changes if you change the indentation, please respect the indentation of the rest of the file.
return 0; | ||
int256 constant INT256_MIN = int256((uint256(1) << 255)); | ||
|
||
int256 constant INT256_MAX = int256(~((uint256(1) << 255))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need these constants to check for overflow? Shouldn't the sign be enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dont think so, what do you mean with the sign?
let b = 2; | ||
await assertRevert(safeMath.multiply(a, b)); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep all tests related to the SafeMath contract in the same file.
result = SafeMath.add(a, b); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not add these to the same SafeMathMock to avoid confusion?
Closing due to inactivity. Superseded by #835. |
Fixes #705
π Description
Improve SafeMath to support signed int operations
npm run lint:all:fix
).