agent0.hyperfuzz.unit_fuzz.fuzz_path_independence

Script to verify that the state of pool reserves is invariant to the order in which positions are closed.

# Test procedure - spin up local chain, deploy hyperdrive without fees - execute random trades

  • from [open_long, open_short]

  • trade amount in uniform[min_trade_amount, max_trade_amount) base

  • advance one block (12 sec) betwen each trade.

  • advance time randomly between trades

  • the maximum time advance between first and last trade is in [0, position_duration)

  • set the variable rate to 0

  • save a snapshot of the current chain state

  • repeat N times (where N is set as a command-line arg):
    • load chain state (all trades are opened, none are closed)

    • close the trades in a random order

    • invariance checks

# Invariance checks (these should be True): # We are checking that the pool ends up in the same sate regardless of close transaction order - the following state values should equal in all checks:

  • effective share reserves

  • present value

  • shorts outstanding

  • withdrawal shares proceeds

  • lp share price

  • long exposure

  • bond reserves

  • lp total supply

  • longs outstanding

Classes

Args

Command line arguments for the invariant checker.

Functions

main([argv])

Primary entrypoint.

fuzz_path_independence(num_trades, num_paths_checked, ...)

Does fuzzy invariant checks for opening and closing longs and shorts.

namespace_to_args(→ Args)

Converts argprase.Namespace to Args.

parse_arguments(→ Args)

Parses input arguments.

invariant_check(→ None)

Check the pool state invariants and throws an assertion exception if fails.

Module Contents

agent0.hyperfuzz.unit_fuzz.fuzz_path_independence.main(argv: Sequence[str] | None = None)

Primary entrypoint.

Parameters:

argv (Sequence[str]) – The argv values returned from argparser.

agent0.hyperfuzz.unit_fuzz.fuzz_path_independence.fuzz_path_independence(num_trades: int, num_paths_checked: int, lp_share_price_epsilon: float, effective_share_reserves_epsilon: float, present_value_epsilon: float, chain_config: agent0.core.hyperdrive.interactive.LocalChain.Config, steth: bool = False, pause_on_fail: bool = False)

Does fuzzy invariant checks for opening and closing longs and shorts.

Parameters:
  • num_trades (int) – Number of trades to perform during the fuzz tests.

  • num_paths_checked (int) – Number of paths (order of operations for opening/closing) to perform.

  • lp_share_price_epsilon (float) – The allowed error for LP share price equality tests.

  • effective_share_reserves_epsilon (float) – The allowed error for effective share reserves equality tests.

  • present_value_epsilon (float) – The allowed error for present value equality tests.

  • chain_config (LocalChain.Config, optional) – Configuration options for the local chain.

  • steth (bool) – Whether to use steth instead of erc4626

  • pause_on_fail (bool) – Whether to pause on failure.

class agent0.hyperfuzz.unit_fuzz.fuzz_path_independence.Args

Bases: NamedTuple

Command line arguments for the invariant checker.

num_trades: int
num_paths_checked: int
lp_share_price_epsilon: float
effective_share_reserves_epsilon: float
present_value_epsilon: float
chain_config: agent0.core.hyperdrive.interactive.LocalChain.Config
agent0.hyperfuzz.unit_fuzz.fuzz_path_independence.namespace_to_args(namespace: argparse.Namespace) Args

Converts argprase.Namespace to Args.

Parameters:

namespace (argparse.Namespace) – Object for storing arg attributes.

Returns:

Formatted arguments

Return type:

Args

agent0.hyperfuzz.unit_fuzz.fuzz_path_independence.parse_arguments(argv: Sequence[str] | None = None) Args

Parses input arguments.

Parameters:

argv (Sequence[str]) – The argv values returned from argparser.

Returns:

Formatted arguments

Return type:

Args

agent0.hyperfuzz.unit_fuzz.fuzz_path_independence.invariant_check(check_data: dict[str, Any], check_epsilon: dict[str, Any], interactive_hyperdrive: agent0.core.hyperdrive.interactive.LocalHyperdrive) None

Check the pool state invariants and throws an assertion exception if fails.

Parameters:
  • check_data (dict[str, Any]) – The trade data to check.

  • check_epsilon (dict[str, Any]) – The expected epsilon for each invariants check.

  • interactive_hyperdrive (InteractiveHyperdrive) – An instantiated InteractiveHyperdrive object.