From 2347702e45e587d7887fae360dcfd8a2dbc208a0 Mon Sep 17 00:00:00 2001 From: Andy Tudhope Date: Wed, 10 Apr 2019 02:16:51 +0200 Subject: [PATCH] Slither and solium together --- contracts/utils/BancorFormula.sol | 32 +++++++++++++++++++++++-------- contracts/utils/SafeMath.sol | 12 +++++------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/contracts/utils/BancorFormula.sol b/contracts/utils/BancorFormula.sol index 6b4315b..241f17d 100644 --- a/contracts/utils/BancorFormula.sol +++ b/contracts/utils/BancorFormula.sol @@ -380,14 +380,30 @@ contract BancorFormula { uint256 z; uint256 w; - if (x >= 0xd3094c70f034de4b96ff7d5b6f99fcd8) {res += 0x40000000000000000000000000000000; x = x * FIXED_1 / 0xd3094c70f034de4b96ff7d5b6f99fcd8;} // add 1 / 2^1 - if (x >= 0xa45af1e1f40c333b3de1db4dd55f29a7) {res += 0x20000000000000000000000000000000; x = x * FIXED_1 / 0xa45af1e1f40c333b3de1db4dd55f29a7;} // add 1 / 2^2 - if (x >= 0x910b022db7ae67ce76b441c27035c6a1) {res += 0x10000000000000000000000000000000; x = x * FIXED_1 / 0x910b022db7ae67ce76b441c27035c6a1;} // add 1 / 2^3 - if (x >= 0x88415abbe9a76bead8d00cf112e4d4a8) {res += 0x08000000000000000000000000000000; x = x * FIXED_1 / 0x88415abbe9a76bead8d00cf112e4d4a8;} // add 1 / 2^4 - if (x >= 0x84102b00893f64c705e841d5d4064bd3) {res += 0x04000000000000000000000000000000; x = x * FIXED_1 / 0x84102b00893f64c705e841d5d4064bd3;} // add 1 / 2^5 - if (x >= 0x8204055aaef1c8bd5c3259f4822735a2) {res += 0x02000000000000000000000000000000; x = x * FIXED_1 / 0x8204055aaef1c8bd5c3259f4822735a2;} // add 1 / 2^6 - if (x >= 0x810100ab00222d861931c15e39b44e99) {res += 0x01000000000000000000000000000000; x = x * FIXED_1 / 0x810100ab00222d861931c15e39b44e99;} // add 1 / 2^7 - if (x >= 0x808040155aabbbe9451521693554f733) {res += 0x00800000000000000000000000000000; x = x * FIXED_1 / 0x808040155aabbbe9451521693554f733;} // add 1 / 2^8 + if (x >= 0xd3094c70f034de4b96ff7d5b6f99fcd8) { + res += 0x40000000000000000000000000000000; + x = x * FIXED_1 / 0xd3094c70f034de4b96ff7d5b6f99fcd8;} // add 1 / 2^1 + if (x >= 0xa45af1e1f40c333b3de1db4dd55f29a7) { + res += 0x20000000000000000000000000000000; + x = x * FIXED_1 / 0xa45af1e1f40c333b3de1db4dd55f29a7;} // add 1 / 2^2 + if (x >= 0x910b022db7ae67ce76b441c27035c6a1) { + res += 0x10000000000000000000000000000000; + x = x * FIXED_1 / 0x910b022db7ae67ce76b441c27035c6a1;} // add 1 / 2^3 + if (x >= 0x88415abbe9a76bead8d00cf112e4d4a8) { + res += 0x08000000000000000000000000000000; + x = x * FIXED_1 / 0x88415abbe9a76bead8d00cf112e4d4a8;} // add 1 / 2^4 + if (x >= 0x84102b00893f64c705e841d5d4064bd3) { + res += 0x04000000000000000000000000000000; + x = x * FIXED_1 / 0x84102b00893f64c705e841d5d4064bd3;} // add 1 / 2^5 + if (x >= 0x8204055aaef1c8bd5c3259f4822735a2) { + res += 0x02000000000000000000000000000000; + x = x * FIXED_1 / 0x8204055aaef1c8bd5c3259f4822735a2;} // add 1 / 2^6 + if (x >= 0x810100ab00222d861931c15e39b44e99) { + res += 0x01000000000000000000000000000000; + x = x * FIXED_1 / 0x810100ab00222d861931c15e39b44e99;} // add 1 / 2^7 + if (x >= 0x808040155aabbbe9451521693554f733) { + res += 0x00800000000000000000000000000000; + x = x * FIXED_1 / 0x808040155aabbbe9451521693554f733;} // add 1 / 2^8 z = y = x - FIXED_1; w = y * y / FIXED_1; diff --git a/contracts/utils/SafeMath.sol b/contracts/utils/SafeMath.sol index ff6c002..1528830 100644 --- a/contracts/utils/SafeMath.sol +++ b/contracts/utils/SafeMath.sol @@ -1,8 +1,6 @@ pragma solidity ^0.5.2; -/* - Library for basic math operations with overflow/underflow protection -*/ + library SafeMath { /** @dev returns the sum of _x and _y, reverts if the calculation overflows @@ -12,7 +10,7 @@ library SafeMath { */ function add(uint256 _x, uint256 _y) internal pure returns (uint256) { uint256 z = _x + _y; - require(z >= _x); + require(z >= _x, "SafeMath failed"); return z; } @@ -23,7 +21,7 @@ library SafeMath { @return difference */ function sub(uint256 _x, uint256 _y) internal pure returns (uint256) { - require(_x >= _y); + require(_x >= _y, "SafeMath failed"); return _x - _y; } @@ -39,7 +37,7 @@ library SafeMath { return 0; uint256 z = _x * _y; - require(z / _x == _y); + require(z / _x == _y, "SafeMath failed"); return z; } @@ -50,7 +48,7 @@ library SafeMath { @return quotient */ function div(uint256 _x, uint256 _y) internal pure returns (uint256) { - require(_y > 0); + require(_y > 0, "SafeMath failed"); uint256 c = _x / _y; return c;