Skip to content

Commit

Permalink
Merge pull request #164 from overlay-market/s/remove-utils-errors
Browse files Browse the repository at this point in the history
Remove `contracts/utils/Errors.sol`
  • Loading branch information
magnetto90 authored Jan 23, 2024
2 parents e91e252 + 605aa74 commit 7448737
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 246 deletions.
14 changes: 6 additions & 8 deletions contracts/libraries/LogExpMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
// XXX: 0.8.10; unchecked functions
pragma solidity 0.8.10;

import "../utils/Errors.sol";

/* solhint-disable */

/**
Expand Down Expand Up @@ -115,14 +113,14 @@ library LogExpMath {
// x^y = exp(y * ln(x)).

// The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range.
_require(x < 2 ** 255, Errors.X_OUT_OF_BOUNDS);
require(x < 2 ** 255, "x out of bounds");
int256 x_int256 = int256(x);

// We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In
// both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end.

// This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range.
_require(y < MILD_EXPONENT_BOUND, Errors.Y_OUT_OF_BOUNDS);
require(y < MILD_EXPONENT_BOUND, "y out of bounds");
int256 y_int256 = int256(y);

int256 logx_times_y;
Expand All @@ -141,9 +139,9 @@ library LogExpMath {
logx_times_y /= ONE_18;

// Finally, we compute exp(y * ln(x)) to arrive at x^y
_require(
require(
MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT,
Errors.PRODUCT_OUT_OF_BOUNDS
"product out of bounds"
);

return uint256(exp(logx_times_y));
Expand All @@ -156,7 +154,7 @@ library LogExpMath {
* Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`.
*/
function exp(int256 x) internal pure returns (int256) {
_require(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT, Errors.INVALID_EXPONENT);
require(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT, "invalid exponent");

unchecked {
if (x < 0) {
Expand Down Expand Up @@ -328,7 +326,7 @@ library LogExpMath {
*/
function ln(int256 a) internal pure returns (int256) {
// The real natural logarithm is not defined for negative numbers or zero.
_require(a > 0, Errors.OUT_OF_BOUNDS);
require(a > 0, "out of bounds");

unchecked {
if (LN_36_LOWER_BOUND < a && a < LN_36_UPPER_BOUND) {
Expand Down
238 changes: 0 additions & 238 deletions contracts/utils/Errors.sol

This file was deleted.

0 comments on commit 7448737

Please sign in to comment.