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

fix absolute_max_long in rust sdk #41

Closed
slundqui opened this issue Apr 25, 2024 · 1 comment
Closed

fix absolute_max_long in rust sdk #41

slundqui opened this issue Apr 25, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@slundqui
Copy link
Contributor

absolute_max_long is failing due to target_share_reserves < effective_share_reserves with arithmetic operation overflow here:
https://github.com/delvtech/hyperdrive/blob/1576e4c4368dd9c21b2df60274f223271e793d46/crates/hyperdrive-math/src/long/max.rs#L214

This is the pool state that caused this issue:

pool_config = {
   base_token='0x610178dA211FEF7D417bC0e6FeD39F05609AD788',
   vault_shares_token='0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e',
   linker_factory='0x5FbDB2315678afecb367f032d93F642f64180aa3',
   linker_code_hash=b'\x91\xa6<\xce\xc3\xbbXQ\xa0\x88\xc4G\xd5\xd3@`4AP\xbe+q\xac`\xc1\x97\x82\x7f\xd1HIL',
   initial_vault_share_price=FixedPoint("1.0"), minimum_share_reserves=FixedPoint("0.206282109669978528"),
   minimum_transaction_amount=FixedPoint("2.4934863032025728"),
   position_duration=30801600,
   checkpoint_duration=82800,
   time_stretch=FixedPoint("0.168128366020933774"),
   governance='0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
   fee_collector='0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
   sweep_collector='0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
   fees={
      curve=FixedPoint("0.063774932363567072"),
      flat=FixedPoint("0.180852177854770176"),
      governance_lp=FixedPoint("0.19281944111115744"),
      governance_zombie=FixedPoint("0.052803595874591256")
   }
}

pool_info = {
   share_reserves=FixedPoint("26176.625462115783671808"),
   share_adjustment=FixedPoint("0.0"),
   zombie_base_proceeds=FixedPoint("0.0"),
   zombie_share_reserves=FixedPoint("0.0"),
   bond_reserves=FixedPoint("73185.723713861986104902"),
   lp_total_supply=FixedPoint("26176.41918000611369328"),
   vault_share_price=FixedPoint("1.000001457064193671"),
   longs_outstanding=FixedPoint("0.0"),
   long_average_maturity_time=FixedPoint("0.0"),
   shorts_outstanding=FixedPoint("0.0"),
   short_average_maturity_time=FixedPoint("0.0"),
   withdrawal_shares_ready_to_withdraw=FixedPoint("0.0"),
   withdrawal_shares_proceeds=FixedPoint("0.0"),
   lp_share_price=FixedPoint("1.00000145706419367"),
   long_exposure=FixedPoint("0.0")
}
slundqui referenced this issue 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?
@ryangoree ryangoree transferred this issue from delvtech/hyperdrive May 1, 2024
@dpaiton dpaiton changed the title Fix absolute_max_long in rust sdk fix absolute_max_long in rust sdk May 3, 2024
@wakamex
Copy link
Contributor

wakamex commented May 3, 2024

closed in favor of #45

@wakamex wakamex closed this as completed May 3, 2024
@dpaiton dpaiton added the bug Something isn't working label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants