-
Notifications
You must be signed in to change notification settings - Fork 21
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
fuzzing: add invariant tests in fuzz pipeline #1123
Comments
Input from @jalextowle
|
we will have two testing pipelines, lets call them "fuzz bots" and "interactive fuzz tests"; these pipelines are both "fuzzing" but they're using two different workflows. (numbers correspond to the categories in #1123) The fuzz bot workflow deploys a handful of random trading agents in a docker container from infra onto an AWS workstation. There is a forever-loop of random trades happening on hyperdrive, as well as some "control bots" that ensure e.g. there is sufficient liquidity (lp bots), the market is rational (arb bots), etc. In parallel to this forever-loop process is a secondary "invariant checking" process that uses the database values to check all of the invariants every time a block is mined. This system of paired processes would be deployed by us, e.g. every time hyperdrive has a new release, and will run as long as we want to. The "intaractive fuzz test" workflow is a python file per check that uses the Interactive Hyperdrive workflow to spin up a specific state and test that check. This will include random elements. These can be included in our agent0 CI. These are the checks in the second category:
This category isn't to say that there is no fuzzing element, just to say that it is not part of the fuzz bot workflow. Each of them has its own explanation, but broadly I think the idea is these things are explicit situations that wouldn't necessarily come up by running a random trading bot. In other words, each of them assumes we're setting up some contrived state and checking a condition, instead of checking the condition after any random state. opening and immediately closing a trade shouldn't result in profit -- the likelihood of a random bot opening & closing a trade immediately is low; we should have a notebook that fuzzes the amount, but explicitly does this open-then-close workflow and checks the profit amounts given a set of open positions, the final state of the reserves will be the same no matter what order the positions are closed in (path independence) -- we randomly open some positions, save state, then in a loop close them at random, then check reserve levels if all of the funds are removed from Hyperdrive, there is no base left in the contract -- we randomly open positions, then close them all, then check base balance LP share price shouldn't change by more x% when distributing excess idle -- we set up scenarios with random LP shares & idle, and then check share price changes during distribution trades are never executed with negative interest rates -- we execute all possible trades (with random values) with a negative rate and confirm that it never is executed Those last three might end up in category 1 if all of the funds are removed from Hyperdrive, there is no base left in the contract LP share price shouldn't change by more x% when distributing excess idle could be checked at each block as well |
Opened issues can be found here: https://github.com/delvtech/hyperdrive/issues?q=is%3Aissue+label%3Apython+ |
TODOs after convo with @jrhea and @jalextowle: Files to update
expected_vault_shares = (
pool_state.pool_info.share_reserves
+ pool_state.pool_info.shorts_outstanding / pool_state.pool_info.share_price
+ pool_state.gov_fees_accrued
+ pool_state.pool_info.withdrawal_shares_proceeds
+ pool_state.pool_info.zombie_share_reserves
)
current_share_reserves = pool_state.pool_info.share_reserves
minimum_share_reserves = pool_state.pool_config.minimum_share_reserves
if not current_share_reserves >= minimum_share_reserves:
... also move this to be above the solvency check.
# NOTE: This would be prone to false positives.
# If the transaction would have failed anyway,
# then we don't know that it failed bc of checkpoint failure or bc e.g. open long was for too much
Crash Report
|
After #1231, we have the following left:
Holding off for now to test if previous crashes is fixed in version v0.4.0
Still need to randomly set on/off for each bot.
Implementing feature in follow up PR
Waiting for present value checks to be written
Took a quick look, calculating effective share reserves doesn't have zombie shares in the rust sdk. Need to dig deeper. |
Fixes a collection of issues defined in #1123
Revisiting, such that advance time is now True for this, and open_random_trades doesn't pass a position duration for the first trade |
Added descriptions to make the tests easier to grok here #1233 |
Additional todos:
|
|
|
|
|
We added assertions for the path independence test to ensure transactions are closed within the same checkpoint (#1242). However, it's a bit of a heavy lift to add the feature for multiple transactions on the same block for interactive hyperdrive, mostly due to keeping everything synchronous in interactive hyperdrive. This feature is detailed in #1244, but we're working around this for now by turning off variable interest for the path independence test. |
TODOs after latest convo
Moved the above 2 tasks to their own issue delvtech/hyperdrive-rs#126 because we do not believe they are presently causing failures.
|
|
new TODOs (@slundqui is on this):
|
|
|
Adds the following checks: 1. PV always >= idle 2. ∆ lp share price should never be more than 0.1% Part of #1123
achieved in #1265 |
Closing this issue as all tasks have been completed. |
These issues
delvtech/hyperdrive#253
delvtech/hyperdrive#534
outline a list of "invariants" (assumed truths) that should hold in hyperdrive at any time.
We've sorted them into two categories:
Present value interactive test
do all trades (add & remove liquidity, open & close longs & shorts)
The text was updated successfully, but these errors were encountered: