Certora Audit Fixes#304
Merged
jalextowle merged 21 commits intomainfrom Jun 13, 2023
Merged
Conversation
…ve-interest-checks
Hyperdrive Gas Benchmark
This comment was automatically generated by workflow using github-action-benchmark. |
jrhea
approved these changes
Jun 13, 2023
This was referenced Jun 15, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses the remaining Certora issues reported before June 12th, 2023. Specifically this PR addresses the following questions:
Week 1 Question E
Question calculateSharesInGivenBondsOut and calculateBondsInGivenSharesOut in YieldSpaceMath.sol : for non-zero amount to receive, the functions can return a zero amount to pay. Can this be problematic?
Mitigation The mitigation of question E from Week 1 was to write a test that tests trades at various orders of magnitude to verify that the
YieldSpaceMathfunction in question (calculateSharesInGivenBondsOut) doesn't return zero when reasonable values are provided. (The only pool in which this would be conceivable is a USDC pool, and even then, the input amount would have to be on the order of 1 wei which has a tiny value relative to gas costs).Week 4 Question A.1
Question The inputs calculated in HyperdriveLP.sol for the average times have a great loss of accuracy since there is a transition between 18 decimals to seconds and then back to 18 decimals. An error of 1e18 seconds in longAverageMaturityTime is then multiplied by a factor of 1e18/ _positionDuration ~ 1e10.
Mitigation The mitigation of question A.1 from Week 4 was to accept the suggestion by adding
_calculateTimeRemainingScaledto avoid descaling and rescaling the average time remaining values inHyperdriveLP.Week 4 Question A.2
Question The netCurveTrade has units of [bonds] but maxCurveTrade has units of [shares] or [bonds/price]. So the ‘else’ branch where the net curve trade is negative, there seems to be a mixture of units, and the value that is passed to the calculateSharesInGivenBondsOut should be in bonds, not shares.
Mitigation The mitigation of question A.2 from Week 4 was to update
calculatePresentValueto make use of the newYieldSpaceMath.calculateMaxBuy. After thinking about the problem, we realized that we didn't need to useHyperdriveMath.calculateMaxLongbecause when we apply the net trade we can assume that the amount of longs outstanding is zero (we close them all and still have outstanding shorts). With this in mind, all we need to do is calculate the amount of shorts that need to be closed to get to a spot price approximating one. We use the change in bonds fromcalculateMaxBuy, which addresses the units mismatch. The logic itself was also updated based on the recent work oncalculateMaxLong.