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

update rounding behavior in calculateSolvencyAfterShort #1061

Merged
merged 4 commits into from
Jun 18, 2024

Conversation

dpaiton
Copy link
Member

@dpaiton dpaiton commented Jun 17, 2024

Resolved Issues

working towards delvtech/hyperdrive-rs#29

Description

The solvency after short check used divDown to convert from base to shares, but the open short function uses divUp. Therefore it was possible to have the solvency check say "all good" and then open short reverts. This fixes that problem.

I also added some intermediate checks so that the function fails gracefully in more situations.

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, the corresponding checklist can
be removed.

[[Reviewer Name]]

  • Tokens
    • Do all approve calls use forceApprove?
    • Do all transfer calls use safeTransfer?
    • Do all transferFrom calls use msg.sender as the from address?
      • If not, is the function access restricted to prevent unauthorized
        token spend?
  • Low-level calls (call, delegatecall, staticcall, transfer, send)
    • Is the returned success boolean checked to handle failed calls?
    • If using delegatecall, are there strict access controls on the
      addresses that can be called? It shouldn't be possible to delegatecall
      arbitrary addresses, so the list of possible targets should either be
      immutable or tightly controlled by an admin.
  • Reentrancy
    • Are functions that make external calls or transfer ether marked as nonReentrant?
      • If not, is there documentation that explains why reentrancy is
        not a concern or how it's mitigated?
  • Gas Optimizations
    • Is the logic as simple as possible?
    • Are the storage values that are used repeatedly cached in stack or
      memory variables?
    • If loops are used, are there guards in place to avoid out-of-gas
      issues?
  • Visibility
    • Are all payable functions restricted to avoid stuck ether?
  • Math
    • Is all of the arithmetic checked or guarded by if-statements that will
      catch underflows?
    • If Safe functions are altered, are potential underflows and
      overflows caught so that a failure flag can be thrown?
    • Are all of the rounding directions clearly documented?
  • 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?

@dpaiton dpaiton marked this pull request as ready for review June 17, 2024 22:37
@dpaiton dpaiton changed the title update rounding behavior in solvency check update rounding behavior in calculateSolvencyAfterShort Jun 17, 2024
@coveralls
Copy link
Collaborator

coveralls commented Jun 17, 2024

Pull Request Test Coverage Report for Build 9555621955

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 92.124%

Totals Coverage Status
Change from base Build 9523138246: 0.0%
Covered Lines: 1965
Relevant Lines: 2133

💛 - Coveralls

Copy link
Contributor

@jalextowle jalextowle left a comment

Choose a reason for hiding this comment

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

LGTM once the nits are addressed.

@coveralls
Copy link
Collaborator

coveralls commented Jun 17, 2024

Pull Request Test Coverage Report for Build 9555779516

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 92.124%

Totals Coverage Status
Change from base Build 9523138246: 0.0%
Covered Lines: 1965
Relevant Lines: 2133

💛 - Coveralls

Copy link

github-actions bot commented Jun 17, 2024

Hyperdrive Gas Benchmark

Benchmark suite Current: 57240de Previous: e5525e9 Deviation Status
addLiquidity: min 33937 gas 33937 gas 0% 🟰
addLiquidity: avg 156470 gas 155877 gas 0.3804% 🚨
addLiquidity: max 429437 gas 429437 gas 0% 🟰
checkpoint: min 40316 gas 40316 gas 0% 🟰
checkpoint: avg 144612 gas 144636 gas -0.0166%
checkpoint: max 255830 gas 255830 gas 0% 🟰
closeLong: min 31361 gas 31361 gas 0% 🟰
closeLong: avg 136498 gas 136439 gas 0.0432% 🚨
closeLong: max 2621435 gas 2621435 gas 0% 🟰
closeShort: min 31327 gas 31327 gas 0% 🟰
closeShort: avg 132281 gas 132305 gas -0.0181%
closeShort: max 402622 gas 272530 gas 47.7349% 🚨
initialize: min 31349 gas 31349 gas 0% 🟰
initialize: avg 333288 gas 333352 gas -0.0192%
initialize: max 399922 gas 399922 gas 0% 🟰
openLong: min 33370 gas 33370 gas 0% 🟰
openLong: avg 174259 gas 174248 gas 0.0063% 🚨
openLong: max 335241 gas 335241 gas 0% 🟰
openShort: min 33936 gas 33936 gas 0% 🟰
openShort: avg 169132 gas 168925 gas 0.1225% 🚨
openShort: max 416115 gas 415870 gas 0.0589% 🚨
redeemWithdrawalShares: min 31251 gas 31251 gas 0% 🟰
redeemWithdrawalShares: avg 74764 gas 75830 gas -1.4058%
redeemWithdrawalShares: max 305633 gas 305633 gas 0% 🟰
removeLiquidity: min 31301 gas 31301 gas 0% 🟰
removeLiquidity: avg 215692 gas 214933 gas 0.3531% 🚨
removeLiquidity: max 404194 gas 404194 gas 0% 🟰

This comment was automatically generated by workflow using github-action-benchmark.

@coveralls
Copy link
Collaborator

coveralls commented Jun 17, 2024

Pull Request Test Coverage Report for Build 9555912671

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 92.124%

Totals Coverage Status
Change from base Build 9523138246: 0.0%
Covered Lines: 1965
Relevant Lines: 2133

💛 - Coveralls

@coveralls
Copy link
Collaborator

coveralls commented Jun 17, 2024

Pull Request Test Coverage Report for Build 9555967822

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 92.124%

Totals Coverage Status
Change from base Build 9523138246: 0.0%
Covered Lines: 1965
Relevant Lines: 2133

💛 - Coveralls

@dpaiton dpaiton force-pushed the dpaiton/update-solvency-check branch from aff8116 to 57240de Compare June 17, 2024 23:24
@dpaiton dpaiton enabled auto-merge June 17, 2024 23:25
@coveralls
Copy link
Collaborator

coveralls commented Jun 17, 2024

Pull Request Test Coverage Report for Build 9556234202

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 92.124%

Totals Coverage Status
Change from base Build 9523138246: 0.0%
Covered Lines: 1965
Relevant Lines: 2133

💛 - Coveralls

@dpaiton dpaiton added this pull request to the merge queue Jun 17, 2024
Merged via the queue into main with commit 41f0a71 Jun 18, 2024
32 checks passed
@dpaiton dpaiton deleted the dpaiton/update-solvency-check branch June 18, 2024 00:34
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.

3 participants