Skip to content

Conversation

@remedcu
Copy link
Contributor

@remedcu remedcu commented May 5, 2020

Task List:

  • Added the check to include equal values to return zero in subCap (Reverted)
  • Better gas optimization for mulCap (Reverted)
  • RAB Pragma Updated

Updating to the latest commit as of 5th May 2020
*/
function subCap(uint _a, uint _b) internal pure returns (uint) {
if (_b > _a)
if (_b >= _a)
Copy link
Member

Choose a reason for hiding this comment

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

">" was OK as if they are equal l34 will return 0.
_a==_b is not an edge case so better treated normally. And "a>=b" is more gas intensive than "a>b" as from a compiler perspective it expends to "a>b || a==b".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood.

// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (_a == 0)
uint c = _a * _b;
if (c == 0)
Copy link
Member

@clesaege clesaege May 5, 2020

Choose a reason for hiding this comment

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

This code change creates a critical vulnerability, we can have "c==0" while "a!=0" and "b!=0" when there is an overflow (ex: a=2^255 and b=2). In this case your code would return 0 while the correct return would be UINT_MAX.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Understood.

@remedcu remedcu changed the title Optimization of CappedMath.sol RAB Pragma of CappedMath Updated May 6, 2020
@clesaege clesaege merged commit 8be2ce9 into kleros:master May 6, 2020
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.

2 participants