blockchain tips and tricks

Does It Do Any Maths?

If you expect your smart contract to perform mathematical calculations, refrain from using arithmetic operators like plus(+), minus(-), multiply(*), divide(/), and modulus (%). Without proper checks, they have the potential to introduce underflow and overflow vulnerabilities.

Use Openzeppelin’s SafeMath library for unsigned integer operations.

pragma solidity ^0.5.5;

import "@openzeppelin/contracts/math/SafeMath.sol";

contract BasicSafeMath {

  using SafeMath for uint;
  function doSomeMath(uint _a, uint _b) public returns (uint) {
    return _a.sub(_b);

Leave a Reply

Your email address will not be published. Required fields are marked *