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

Various bug fixes in rust sdk #1005

Closed
wants to merge 8 commits into from
Closed

Conversation

slundqui
Copy link
Contributor

@slundqui slundqui commented Apr 25, 2024

Resolved Issues

This solves various rust crashes resulting from python fuzz testing.
delvtech/hyperdrive-rs#41

Description

Fixes the following issues:

  • Max long guesses is below the minimum transaction amount, so calc_open_long throws a minimum transaction amount error. We clamp the guess to be minimum transaction amount. and do a final check at the end to ensure the max amount is greater than the minimum transaction amount.
  • We catch a case in absolute_max_long where the target_share_reserves < effective_share_reserves. In this case, we throw an error in absolute_max_long, and catch it and return 0 in calc_max_long.

Review Checklists

Please check each item before approving the pull request. While going
through the checklist, it is recommended to leave comments on items that are
referenced in the checklist to make sure that they are reviewed. If there are
multiple reviewers, copy the checklists into sections titled ## [Reviewer Name].
If the PR doesn't touch Solidity and/or Rust, the corresponding checklist can
be removed.

[[Reviewer Name]]

Rust

  • Testing
    • Are there new or updated unit or integration tests?
    • Do the tests cover the happy paths?
    • Do the tests cover the unhappy paths?
    • Are there an adequate number of fuzz tests to ensure that we are
      covering the full input space?
    • If matching Solidity behavior, are there differential fuzz tests that
      ensure that Rust matches Solidity?

@slundqui slundqui force-pushed the slundquist/calc-max-long-fix branch from 9485122 to 7590280 Compare April 25, 2024 20:50
max_bond_amount = absolute_max_bond_amount;
// We expect by definition for the pool to be solvent with the absolute max bond amount.
maybe_solvency =
self.solvency_after_short(max_bond_amount, spot_price, checkpoint_exposure);
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn’t we already check that this isn’t insolvent on line 294? I might be missing something, but I don’t expect this to be solvent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, my mistake, I didn't realize this was in the absolute_max_short function. Is it safe to say here then that if absolute_max_short_guess returns a value that is insolvent, that the pool doesn't allow for a short at all? Or is there a better initial guess we can use here

Copy link
Contributor

Choose a reason for hiding this comment

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

We might be able to use a better initial guess. We could always use 0, or we could allow “cross-overs” by allowing invalid solutions so that we can proceed with iterations. The latter sounds fine to me since Newton’s should get to a solution that is solvent after a few iterations.

This check was based on my (erroneous) thinking at implementation-time that this algorithm would never cross over the solution

@slundqui
Copy link
Contributor Author

slundqui commented Apr 26, 2024

Won't merge here in favor of making a PR to the new https://github.com/delvtech/hyperdrive-rs repo, will link and close once that PR is up.

@slundqui
Copy link
Contributor Author

Closing in favor of delvtech/hyperdrive-rs#5

@slundqui slundqui closed this Apr 26, 2024
slundqui pushed a commit to delvtech/hyperdrive-rs that referenced this pull request Apr 30, 2024
PR originally from delvtech/hyperdrive#1005

# Resolved Issues
This solves various rust crashes resulting from python fuzz testing.
https://github.com/delvtech/hyperdrive/issues/1004

# Description
Fixes the following issues:
- Max long guesses is below the minimum transaction amount, so
`calc_open_long` throws a minimum transaction amount error. We clamp the
guess to be minimum transaction amount. and do a final check at the end
to ensure the max amount is greater than the minimum transaction amount.
- We catch a case in `absolute_max_long` where the
`target_share_reserves < effective_share_reserves`. In this case, we
throw a better descriptive panic.
- We short circuit `calc_max_long` and return 0 if the spot price after
a minimum long exceeds the max spot price.
- Fixing bug with wheel build script.
- Building and uploading to pypi on tag instead of push to main.

# Review Checklists

Please check each item **before approving** the pull request. While
going
through the checklist, it is recommended to leave comments on items that
are
referenced in the checklist to make sure that they are reviewed. If
there are
multiple reviewers, copy the checklists into sections titled `##
[Reviewer Name]`.
If the PR doesn't touch Solidity and/or Rust, the corresponding
checklist can
be removed.

## [[Reviewer Name]]

### Rust

- [ ] **Testing**
    - [ ] Are there new or updated unit or integration tests?
    - [ ] Do the tests cover the happy paths?
    - [ ] Do the tests cover the unhappy paths?
- [ ] Are there an adequate number of fuzz tests to ensure that we are
          covering the full input space?
- [ ] If matching Solidity behavior, are there differential fuzz tests
that
          ensure that Rust matches Solidity?
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.

2 participants