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

[amm] Prove construction safety for "hTokenOutForUnderlyingIn" and "underlyingOutForHTokenIn" #11

Open
PaulRBerg opened this issue May 20, 2021 · 2 comments
Labels
discussion Questions, feedback and general information. enhancement Improvement for an existing feature or system package:amm

Comments

@PaulRBerg
Copy link
Contributor

PaulRBerg commented May 20, 2021

Problem Statement

In the hTokenOutForUnderlyingIn and the underlyingOutForHTokenIn functions, the last operation is a subtraction:

hTokenOut = hTokenReserves - newHTokenReserves;

And:

normalizedUnderlyingOut = normalizedUnderlyingReserves - newNormalizedUnderlyingReserves;

The task is to derive a mathematical proof that it is not possible for this subtraction to revert.

Suggestions

  • Hack around with Mathematica. Build on top of my set of inequalities.
  • Use Echidna to fuzz the inputs and see if the fuzzer can find anything. Add an "assert" statement to let Echidna know that "hTokenReserves" must be greater than or equal to "newHTokenReserves", ditto for the other two vars.
@PaulRBerg
Copy link
Contributor Author

PaulRBerg commented May 20, 2021

Note that since this hasn't been proved mathematically yet, I added a require statement right before the last operation of both "hTokenOutForUnderlyingIn" and "underlyingOutForHTokenIn". But I didn't write tests that cover this require branch because I don't know any inputs which can trigger it.

@PaulRBerg PaulRBerg changed the title Proof construction safety for "fyTokenOutForUnderlyingIn" and "underlyingOutForFyTokenIn" Prove construction safety for "fyTokenOutForUnderlyingIn" and "underlyingOutForFyTokenIn" May 20, 2021
@PaulRBerg PaulRBerg transferred this issue from hifi-finance/hifi-amm Aug 9, 2021
@PaulRBerg PaulRBerg changed the title Prove construction safety for "fyTokenOutForUnderlyingIn" and "underlyingOutForFyTokenIn" [amm] Prove construction safety for "hTokenOutForUnderlyingIn" and "underlyingOutForHTokenIn" Aug 9, 2021
@PaulRBerg PaulRBerg added discussion Questions, feedback and general information. enhancement Improvement for an existing feature or system package:amm labels Aug 9, 2021
@PaulRBerg
Copy link
Contributor Author

PaulRBerg commented Jan 31, 2022

Benson worked on this and came up with a beautiful explanation for why this construction is safe in the realm of pure mathematics. Now the question is to prove whether Solidity’s inevitable rounding errors don’t break the purely mathematical logic.

Construction_Safety_for_OutForIn_Functions.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Questions, feedback and general information. enhancement Improvement for an existing feature or system package:amm
Projects
None yet
Development

No branches or pull requests

1 participant