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

Improve VolatilityOracle accuracy and manipulation resistance #219

Merged
merged 4 commits into from
Nov 21, 2023

Conversation

haydenshively
Copy link
Member

@haydenshively haydenshively commented Nov 16, 2023

Addresses

Fix for 45

  • Increase FEE_GROWTH_AVG_WINDOW from 6 hours to 72 hours, making it cost 12x more to manipulate. This measurement isn't precise enough to pick up intra-day variance in the first place (was just noise before), so the increase doesn't hurt anything.
  • Reduce IV_CHANGE_PER_SECOND by a factor of 4
  • Linearly interpolate between IV samples instead of discretely jumping, giving Borrowers a heads up as to where IV is headed. In case of manipulation, this forces the attacker to wait and hope that Borrowers don't respond. It also helps in normal operation, as Borrowers are less likely to become liquidatable all at once, reducing congestion and price impact.

Fix for 38
The issue is not as bad as the report would have one believe:

  • Currently there's no way to short, but due to opportunity cost, users should still withdraw if they're not making money
  • Soon there will be a way to short, using something like Panoptic
  • Governance can adjust nSigma between 4 and 8 (from a default of 5), so it should be relatively easy to compensate for any systematic error.

That said, there's one simple improvement that I've implemented here -- an exponential moving average for IV, where the upwards gain is 5x larger than the downwards gain. This smooths out changes (similar to the linear interpolation described above) and empirically causes it to match the "true" IV more closely.

Note

One post-facto explanation for this is that when the price moves rapidly, sophisticated actors are the first to update their Uniswap positions, making our measurement more accurate for a brief period. Once the dumber capital catches up and creates passive positions in the new trading range, IV becomes artificially depressed again.

image image

@haydenshively haydenshively force-pushed the fix-16-volatility-accuracy branch from e3fadb4 to ed27613 Compare November 18, 2023 02:29
@haydenshively haydenshively merged commit 0174667 into sherlock-audit-fixes Nov 21, 2023
1 of 4 checks passed
@haydenshively haydenshively deleted the fix-16-volatility-accuracy branch November 21, 2023 21:01
haydenshively added a commit that referenced this pull request Nov 30, 2023
* Increase FEE_GROWTH_AVG_WINDOW so it's harder to manipulate

* Allow IV to increase faster than it decreases to match CEX more closely

* Interpolate between old and new IV samples instead of jumping

* Switch to EMA updates for smoother IV
haydenshively added a commit that referenced this pull request Dec 9, 2023
* Increase FEE_GROWTH_AVG_WINDOW so it's harder to manipulate

* Allow IV to increase faster than it decreases to match CEX more closely

* Interpolate between old and new IV samples instead of jumping

* Switch to EMA updates for smoother IV
haydenshively added a commit that referenced this pull request Dec 9, 2023
* Increase FEE_GROWTH_AVG_WINDOW so it's harder to manipulate

* Allow IV to increase faster than it decreases to match CEX more closely

* Interpolate between old and new IV samples instead of jumping

* Switch to EMA updates for smoother IV
haydenshively added a commit that referenced this pull request Dec 9, 2023
* Increase FEE_GROWTH_AVG_WINDOW so it's harder to manipulate

* Allow IV to increase faster than it decreases to match CEX more closely

* Interpolate between old and new IV samples instead of jumping

* Switch to EMA updates for smoother IV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant