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

Rename math operations #107

Merged
merged 7 commits into from
Dec 12, 2023
Merged

Conversation

QGarchery
Copy link
Contributor

Fixes cantina issue #127.

The only places where this differs from rounding towards negative infinity are the following:

  1. int256 err = (utilization - TARGET_UTILIZATION).wDivDown(errNormFactor);
  2. int256 speed = ADJUSTMENT_SPEED.wMulDown(err);
  3. the first computation coeff.wMulDown(err) in
    return (coeff.wMulDown(err) + WAD).wMulDown(int256(_rateAtTarget));

Those all have a consistent effect: under-estimating the error. This is why I think that only renaming those functions is enough

@QGarchery QGarchery requested review from adhusson, MathisGD and a team December 8, 2023 18:03
@QGarchery QGarchery self-assigned this Dec 8, 2023
@QGarchery QGarchery requested review from Rubilmax, MerlinEgalite and Jean-Grimal and removed request for a team December 8, 2023 18:03
Copy link
Contributor

@Rubilmax Rubilmax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested alternatives, but I think it's fine having them named wMul and wDiv too

src/libraries/MathLib.sol Outdated Show resolved Hide resolved
Copy link
Contributor

@adhusson adhusson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that current names are misleading. Not sure about the best new names.

  • just wMul(etc) makes sense because regular solidity regular division truncates.
  • wMul[zero,0,etc] (etc) is more explicit and probably better since those new names will coexist with wDivDown(uint) (etc).

@MathisGD MathisGD assigned MathisGD and unassigned QGarchery Dec 12, 2023
Copy link
Contributor

@MerlinEgalite MerlinEgalite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting issue it seems

@MerlinEgalite
Copy link
Contributor

conflicts :/

@MerlinEgalite
Copy link
Contributor

There are failing tests

@MathisGD MathisGD merged commit 37dce62 into post-cantina Dec 12, 2023
3 checks passed
@MathisGD MathisGD deleted the refactor/rename-math-operations branch December 12, 2023 12:21
@Rubilmax Rubilmax mentioned this pull request Dec 19, 2023
@@ -10,11 +10,13 @@ int256 constant WAD_INT = int256(WAD);
/// @custom:contact security@morpho.org
/// @notice Library to manage fixed-point arithmetic on signed integers.
library MathLib {
function wMulDown(int256 a, int256 b) internal pure returns (int256) {
/// @dev Returns the multiplication of `a` by `b` (in WAD) rounded towards 0.
function wMulTo0(int256 a, int256 b) internal pure returns (int256) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My two cents/nitpick: using the full word "zero" would maybe be more clean.

  1. it's easy to get confused between char 0 and o and O. Having "zero" directly in the name is also much more explicit
  2. probably it's not comfortable to have a number inside a function when you need to type it

Note: The solidity style guide does not have a strong opinion about having numbers inside the function's name

@MathisGD MathisGD mentioned this pull request Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants