Skip to content
This repository has been archived by the owner on Sep 17, 2021. It is now read-only.

Solidity v0.8.0 Breaking Changes #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/libraries/AddressStringUtil.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ library AddressStringUtil {
require(len % 2 == 0 && len > 0 && len <= 40, 'AddressStringUtil: INVALID_LEN');

bytes memory s = new bytes(len);
uint256 addrNum = uint256(addr);
uint256 addrNum = uint160(addr);
for (uint256 i = 0; i < len / 2; i++) {
// shift right and truncate all but the least significant byte to extract the byte at position 19-i
uint8 b = uint8(addrNum >> (8 * (19 - i)));
Expand Down
10 changes: 5 additions & 5 deletions contracts/libraries/BitMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,27 @@ library BitMath {
require(x > 0, 'BitMath::leastSignificantBit: zero');

r = 255;
if (x & uint128(-1) > 0) {
if (x & type(uint128).max > 0) {
r -= 128;
} else {
x >>= 128;
}
if (x & uint64(-1) > 0) {
if (x & type(uint64).max > 0) {
r -= 64;
} else {
x >>= 64;
}
if (x & uint32(-1) > 0) {
if (x & type(uint32).max > 0) {
r -= 32;
} else {
x >>= 32;
}
if (x & uint16(-1) > 0) {
if (x & type(uint16).max > 0) {
r -= 16;
} else {
x >>= 16;
}
if (x & uint8(-1) > 0) {
if (x & type(uint8).max > 0) {
r -= 8;
} else {
x >>= 8;
Expand Down
26 changes: 13 additions & 13 deletions contracts/libraries/FixedPoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ library FixedPoint {
uint256 _x;
}

uint8 public constant RESOLUTION = 112;
uint256 public constant Q112 = 0x10000000000000000000000000000; // 2**112
uint256 private constant Q224 = 0x100000000000000000000000000000000000000000000000000000000; // 2**224
uint8 private constant RESOLUTION = 112;
uint256 private constant Q112 = 0x10000000000000000000000000000;
uint256 private constant Q224 = 0x100000000000000000000000000000000000000000000000000000000;
uint256 private constant LOWER_MASK = 0xffffffffffffffffffffffffffff; // decimal of UQ*x112 (lower 112 bits)

// encode a uint112 as a UQ112x112
Expand Down Expand Up @@ -78,13 +78,13 @@ library FixedPoint {
uint224 uppero_lowers = uint224(upper_other) * lower_self; // * 2^-112

// so the bit shift does not overflow
require(upper <= uint112(-1), 'FixedPoint::muluq: upper overflow');
require(upper <= type(uint112).max, 'FixedPoint::muluq: upper overflow');

// this cannot exceed 256 bits, all values are 224 bits
uint256 sum = uint256(upper << RESOLUTION) + uppers_lowero + uppero_lowers + (lower >> RESOLUTION);

// so the cast does not overflow
require(sum <= uint224(-1), 'FixedPoint::muluq: sum overflow');
require(sum <= type(uint224).max, 'FixedPoint::muluq: sum overflow');

return uq112x112(uint224(sum));
}
Expand All @@ -95,30 +95,30 @@ library FixedPoint {
if (self._x == other._x) {
return uq112x112(uint224(Q112));
}
if (self._x <= uint144(-1)) {
if (self._x <= type(uint144).max) {
uint256 value = (uint256(self._x) << RESOLUTION) / other._x;
require(value <= uint224(-1), 'FixedPoint::divuq: overflow');
require(value <= type(uint224).max, 'FixedPoint::divuq: overflow');
return uq112x112(uint224(value));
}

uint256 result = FullMath.mulDiv(Q112, self._x, other._x);
require(result <= uint224(-1), 'FixedPoint::divuq: overflow');
require(result <= type(uint224).max, 'FixedPoint::divuq: overflow');
return uq112x112(uint224(result));
}

// returns a UQ112x112 which represents the ratio of the numerator to the denominator
// can be lossy
// lossy if either numerator or denominator is greater than 112 bits
function fraction(uint256 numerator, uint256 denominator) internal pure returns (uq112x112 memory) {
require(denominator > 0, 'FixedPoint::fraction: division by zero');
if (numerator == 0) return FixedPoint.uq112x112(0);

if (numerator <= uint144(-1)) {
if (numerator <= type(uint144).max) {
uint256 result = (numerator << RESOLUTION) / denominator;
require(result <= uint224(-1), 'FixedPoint::fraction: overflow');
require(result <= type(uint224).max, 'FixedPoint::fraction: overflow');
return uq112x112(uint224(result));
} else {
uint256 result = FullMath.mulDiv(numerator, Q112, denominator);
require(result <= uint224(-1), 'FixedPoint::fraction: overflow');
require(result <= type(uint224).max, 'FixedPoint::fraction: overflow');
return uq112x112(uint224(result));
}
}
Expand All @@ -135,7 +135,7 @@ library FixedPoint {
// square root of a UQ112x112
// lossy between 0/1 and 40 bits
function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) {
if (self._x <= uint144(-1)) {
if (self._x <= type(uint144).max) {
return uq112x112(uint224(Babylonian.sqrt(uint256(self._x) << 112)));
}

Expand Down
8 changes: 5 additions & 3 deletions contracts/libraries/FullMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity >=0.4.0;
// license is CC-BY-4.0
library FullMath {
function fullMul(uint256 x, uint256 y) internal pure returns (uint256 l, uint256 h) {
uint256 mm = mulmod(x, y, uint256(-1));
uint256 mm = mulmod(x, y, type(uint256).max);
l = x * y;
h = mm - l;
if (mm < l) h -= 1;
Expand All @@ -16,10 +16,10 @@ library FullMath {
uint256 h,
uint256 d
) private pure returns (uint256) {
uint256 pow2 = d & -d;
uint256 pow2 = d & (~d+1);
d /= pow2;
l /= pow2;
l += h * ((-pow2) / pow2 + 1);
l += h * ((~pow2+1) / pow2 + 1);
uint256 r = 1;
r *= 2 - d * r;
r *= 2 - d * r;
Expand All @@ -29,6 +29,7 @@ library FullMath {
r *= 2 - d * r;
r *= 2 - d * r;
r *= 2 - d * r;

return l * r;
}

Expand All @@ -48,4 +49,5 @@ library FullMath {
require(h < d, 'FullMath: FULLDIV_OVERFLOW');
return fullDiv(l, h, d);
}

}