Skip to content

Conversation

@jalextowle
Copy link
Contributor

@jalextowle jalextowle commented Mar 1, 2024

Addresses Spearbit Issue #60.

Fixes: #762.

This PR implements several changes that attempt to improve Hyperdrive's liveness properties without relying on hacks like the one that Spearbit mentioned in issue #60. The two primary methods of achieving better liveness used in this PR are:

  • Allowing calculations with small inputs to fail in calculateNetCurveTradeSafe since YieldSpaceMath has a fundamental with small inputs.
  • Being more consistent about bubbling up failures safely rather than reverting in low-level functions. This allows us to handle failures in calculatePresentValue and distributeExcessIdle on a case-by-case basis.

@jalextowle jalextowle requested a review from jrhea March 1, 2024 03:16
@github-actions
Copy link

github-actions bot commented Mar 1, 2024

Hyperdrive Gas Benchmark

Benchmark suite Current: fe74cf5 Previous: 46c834d Deviation Status
addLiquidity: min 34062 gas 1546 gas 2103.2342% 🚨
addLiquidity: avg 140229 gas 67936 gas 106.4134% 🚨
addLiquidity: max 357573 gas 293159 gas 21.9724% 🚨
checkpoint: min 29254 gas 1182 gas 2374.9577% 🚨
checkpoint: avg 105941 gas 48477 gas 118.5387% 🚨
checkpoint: max 200343 gas 191559 gas 4.5855% 🚨
closeLong: min 31422 gas 1492 gas 2006.0322% 🚨
closeLong: avg 99511 gas 29374 gas 238.7724% 🚨
closeLong: max 217472 gas 152303 gas 42.7890% 🚨
closeShort: min 31335 gas 1494 gas 1997.3896% 🚨
closeShort: avg 98170 gas 33444 gas 193.5355% 🚨
closeShort: max 180066 gas 149156 gas 20.7233% 🚨
initialize: min 31328 gas 1451 gas 2059.0627% 🚨
initialize: avg 248556 gas 213962 gas 16.1683% 🚨
initialize: max 319514 gas 253953 gas 25.8162% 🚨
openLong: min 33503 gas 1499 gas 2135.0233% 🚨
openLong: avg 126931 gas 51658 gas 145.7141% 🚨
openLong: max 248238 gas 185562 gas 33.7763% 🚨
openShort: min 33798 gas 1520 gas 2123.5526% 🚨
openShort: avg 136267 gas 51482 gas 164.6886% 🚨
openShort: max 330066 gas 181325 gas 82.0301% 🚨
redeemWithdrawalShares: min 46869 gas 1488 gas 3049.7984% 🚨
redeemWithdrawalShares: avg 72051 gas 22375 gas 222.0156% 🚨
redeemWithdrawalShares: max 143334 gas 109301 gas 31.1370% 🚨
removeLiquidity: min 31161 gas 1530 gas 1936.6667% 🚨
removeLiquidity: avg 208533 gas 151225 gas 37.8959% 🚨
removeLiquidity: max 325574 gas 325781 gas -0.0635%

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

@jalextowle
Copy link
Contributor Author

After taking a step back, the present value shouldn’t cause problems with liveness. If we can’t calculate the LP share price for the checkpoint event, so be it. It’s not the end of the world. Similarly, if we can’t calculate the present value in “getDistributeExcessIdleParams”, we can just skip distributing excess idle.

Making these changes will allow me to revert the changes in the netting test and will give us additional assurances that liveness will not be compromised due to being unable to calculate the present value. When I do this tomorrow, I’ll consider reverting the change that allows the trading function to fail in calculateNetCurveTradeSafe.

@jalextowle jalextowle force-pushed the jalextowle/audit/spearbit-60 branch from 657efc7 to 9abab7a Compare March 1, 2024 18:34
@jalextowle jalextowle changed the title Spearbit #60: Fail if calculateSharesOutGivenBondsInDownSafe underflows Spearbit #60: Safety and Liveness Improvements Mar 1, 2024
Copy link
Contributor

@jrhea jrhea left a comment

Choose a reason for hiding this comment

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

General comment here is that i think some of this conditionals are going to be hard to write tests for

@jalextowle jalextowle force-pushed the jalextowle/audit/spearbit-60 branch from 6a7b1cd to e26fb07 Compare March 5, 2024 21:11
@jalextowle jalextowle enabled auto-merge (squash) March 6, 2024 03:39
@jalextowle jalextowle force-pushed the jalextowle/audit/spearbit-60 branch from d4d912b to 371fc08 Compare March 6, 2024 03:41
@jalextowle jalextowle merged commit b263f8b into main Mar 6, 2024
@jalextowle jalextowle deleted the jalextowle/audit/spearbit-60 branch March 6, 2024 20:38
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.

Checkpoint liveness issue with small net curve trade

4 participants