What does 1.sub(-1) equal using SafeMath?

What will be result for
a.sub(b);
if

a = 1;
b= -1;

using openzeppeline safemath?

1 Like

Hi @JackBekket,

Welcome to the community :wave:

SafeMath operates on uint256. See the OpenZeppelin documentation for details: https://docs.openzeppelin.com/contracts/3.x/api/math#SafeMath-sub-uint256-uint256-

The following will not compile on Remix:

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.2.0/contracts/math/SafeMath.sol";

contract MyContract {
    
    using SafeMath for uint256;
    
    function calculate() public pure returns (uint256) {
        uint256 a = 1;
        return a.sub(-1);
    }
}

Hi @JackBekket,

I just wanted to follow up and see if you had any more questions on this?