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

Swap out ln and exp for Solmate versions #1992

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

TomAFrench
Copy link
Contributor

@TomAFrench TomAFrench commented Nov 8, 2022

Description

This swaps out the exp and ln implementations for the solmate version.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Dependency changes
  • Code refactor / cleanup
  • Documentation or wording changes
  • Other

Checklist:

  • The diff is legible and has no extraneous changes
  • Complex code has been commented, including external interfaces
  • Tests are included for all code paths
  • The base branch is either master, or there's a description of how to merge

Issue Resolution

@TomAFrench TomAFrench marked this pull request as ready for review November 8, 2022 17:51
@TomAFrench TomAFrench added the do not merge Code playground or showcase - not intended to be merged label Nov 8, 2022
@TomAFrench
Copy link
Contributor Author

An alternative to explore, we could use PRBMath's implementation. It doesn't have the crazy optimisation theory maths but switching from using base e to base 2 should definitely save gas.

Copy link
Contributor

@nventuro nventuro left a comment

Choose a reason for hiding this comment

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

I'm in favor of this renaming, but I'd do this in two steps. On the first PR, we create NewLogExpMath and rename the existing one to ReferenceLogExpMath (changing the imports as well). We have equivalence tests etc. Then, on a second PR (once we have confidence in the new impl), we rename NewLogExpMath to LogExpMath, and change the imports from Reference to LogExpMath.

This may be slightly annoying as we'll need to touch the imports twice, but it clearly defines the point in which we change impls, and provides a clean diff (since we'll just have renames, unlike in this PR where the reference is a seemingly new file, and the new impl is also hard to review since the diff is messy (because it replaces old code).

int256 expectedLn = ReferenceLogExpMath.ln(a);
int256 actualLn = LogExpMath.ln(a);

assertApproxEqAbs(actualLn, expectedLn, 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, I'm surprised this passes with such little difference.

int256 expectedExp = ReferenceLogExpMath.exp(a);
int256 actualExp = LogExpMath.exp(a);

assertApproxEqRel(actualExp, expectedExp, 1e2);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's good to test that they are quite close, but we also definitely want some ffi testing to test that the maximum error remains what it used to be.

@nventuro
Copy link
Contributor

nventuro commented Nov 11, 2022

Have you performed any gas measurements to compare them? Also bytecode size differences.

@TomAFrench
Copy link
Contributor Author

Have you performed any gas measurements to compare them? Also bytecode size differences.

Not as of yet. My major concern is the removal of the 36 digit variant of ln so I was wanting to test pow against the TS implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge Code playground or showcase - not intended to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants