Skip to content
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

Closed
wants to merge 4 commits into from
Closed

Improve safemath signed int #714

wants to merge 4 commits into from

Conversation

cedricwalter
Copy link

Fixes #705

πŸš€ Description

Improve SafeMath to support signed int operations

  • πŸ“˜ I've reviewed the OpenZeppelin Contributor Guidelines
  • βœ… I've added tests where applicable to test my new functionality.
  • πŸ“– I've made sure that my contracts are well-documented.
  • 🎨 I've run the JS/Solidity linters and fixed any issues (npm run lint:all:fix).

@facuspagnuolo
Copy link
Contributor

@cedricwalter would you mind checking the CI status?

@cedricwalter
Copy link
Author

Yes i am looking at it now

@cedricwalter
Copy link
Author

was nothing a temporary error in the build, i've run all tests twice locally with yarn run test / npm run test and they are all green. After having committed some documentation, and let the travis build run, the build is green again

AugustoL
AugustoL previously approved these changes Feb 6, 2018
}

function add(int256 a, int256 b) internal pure returns (int256) {
return a + b;
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cedricwalter please fix

}

function add(int256 a, int256 b) internal pure returns (int256) {
return a + b;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cedricwalter please fix

Copy link
Contributor

@federicobond federicobond left a 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;
Copy link
Contributor

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)));
Copy link
Contributor

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?

Copy link
Author

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));
});
});
Copy link
Contributor

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);
}

}
Copy link
Contributor

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?

@frangio
Copy link
Contributor

frangio commented Apr 3, 2018

Closing due to inactivity. Superseded by #835.

@frangio frangio closed this Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve SafeMath to support signed int operations
5 participants