Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added suggested changes from Quantstamp audit feedback. #5

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/ExponentLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ library ExponentLib {
pure
returns (int256)
{
assert(_x < 172 * FixidityLib.fixed1());
require(_x < 172 * FixidityLib.fixed1());
int256 x = _x;
int256 r = FixidityLib.fixed1();
while (x >= 10 * FixidityLib.fixed1()) {
Expand Down
24 changes: 12 additions & 12 deletions contracts/FixidityLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ library FixidityLib {
}

/**
* @notice Maximum value that can be converted to fixed point. Optimize for
* @notice Minimum value that can be converted to fixed point. Optimize for
* deployment.
* @dev Test minNewFixed() equals -(maxInt256()) / fixed1()
* Hardcoded to 24 digits.
Expand Down Expand Up @@ -151,8 +151,8 @@ library FixidityLib {
pure
returns (int256)
{
assert(x <= maxNewFixed());
assert(x >= minNewFixed());
require(x <= maxNewFixed());
require(x >= minNewFixed());
return x * fixed1();
}

Expand Down Expand Up @@ -199,7 +199,7 @@ library FixidityLib {
pure
returns (int256)
{
assert(_originDigits <= 38 && _destinationDigits <= 38);
require(_originDigits <= 38 && _destinationDigits <= 38);

uint8 decimalDifference;
if ( _originDigits > _destinationDigits ){
Expand All @@ -214,8 +214,8 @@ library FixidityLib {
// decimalDifference = abs(_destinationDigits - _originDigits)
// decimalDifference < 38
// 10**38 < 2**128-1
assert(x <= maxInt256()/uint128(10)**uint128(decimalDifference));
assert(x >= minInt256()/uint128(10)**uint128(decimalDifference));
require(x <= maxInt256()/uint128(10)**uint128(decimalDifference));
require(x >= minInt256()/uint128(10)**uint128(decimalDifference));
return x*(uint128(10)**uint128(decimalDifference));
}
// _originDigits == digits())
Expand Down Expand Up @@ -271,9 +271,9 @@ library FixidityLib {
pure
returns (int256)
{
assert(numerator <= maxNewFixed());
assert(denominator <= maxNewFixed());
assert(denominator != 0);
require(numerator <= maxNewFixed());
require(denominator <= maxNewFixed());
require(denominator != 0);
int256 convertedNumerator = newFixed(numerator);
int256 convertedDenominator = newFixed(denominator);
return divide(convertedNumerator, convertedDenominator);
Expand Down Expand Up @@ -420,7 +420,7 @@ library FixidityLib {
* Test reciprocal(2*fixed1()*fixed1()) returns 0 // Testing how the fractional is truncated
*/
function reciprocal(int256 x) public pure returns (int256) {
assert(x != 0);
require(x != 0);
return (fixed1()*fixed1()) / x; // Can't overflow
}

Expand All @@ -436,8 +436,8 @@ library FixidityLib {
*/
function divide(int256 x, int256 y) public pure returns (int256) {
if (y == fixed1()) return x;
assert(y != 0);
assert(y <= maxFixedDivisor());
require(y != 0);
require(y <= maxFixedDivisor());
return multiply(x, reciprocal(y));
}
}
2 changes: 1 addition & 1 deletion contracts/LogarithmLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ library LogarithmLib {
* Test ln(1) returns -82
*/
function ln(int256 value) public pure returns (int256) {
assert(value >= 0);
require(value >= 0);
int256 v = value;
int256 r = 0;
while (v <= FixidityLib.fixed1() / 10) {
Expand Down