agent0.hyperfuzz.system_fuzz ============================ .. py:module:: agent0.hyperfuzz.system_fuzz .. autoapi-nested-parse:: System level fuzz bots. .. !! processed by numpydoc !! Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/agent0/hyperfuzz/system_fuzz/invariant_checks/index /autoapi/agent0/hyperfuzz/system_fuzz/run_fuzz_bots/index Functions --------- .. autoapisummary:: agent0.hyperfuzz.system_fuzz.run_invariant_checks agent0.hyperfuzz.system_fuzz.generate_fuzz_hyperdrive_config agent0.hyperfuzz.system_fuzz.run_fuzz_bots Package Contents ---------------- .. py:function:: run_invariant_checks(check_block_data: web3.types.BlockData, interface: agent0.ethpy.hyperdrive.HyperdriveReadInterface, log_to_rollbar: bool = True, rollbar_log_level_threshold: int | None = None, rollbar_log_filter_func: Callable[[Exception], bool] | None = None, pool_name: str | None = None, lp_share_price_test: bool | None = None, crash_report_additional_info: dict[str, Any] | None = None, log_anvil_state_dump: bool = False, pending_pool_state: agent0.ethpy.hyperdrive.state.pool_state.PoolState | None = None, check_price_spike: bool = True) -> list[agent0.hyperfuzz.FuzzAssertionException] Run the invariant checks. # Invariance checks (these should be True): - hyperdrive base & eth balances are zero - the expected total shares equals the hyperdrive balance in the vault contract - the pool has more than the minimum share reserves - the system is solvent, i.e. (share reserves - long exposure in shares - min share reserves) > 0 - present value is greater than idle shares - the lp share price doesn't exceed an amount from block to block - check negative interest on yield source - Warn if a trade causes a large rate spike; which is a precursor to an attack :param check_block_data: The current block to be tested. :type check_block_data: BlockData :param interface: An instantiated HyperdriveReadInterface object constructed using the script arguments. :type interface: HyperdriveReadInterface :param log_to_rollbar: If True, log to rollbar if any invariant check fails. :type log_to_rollbar: bool :param rollbar_log_level_threshold: Threshold for logging to rollbar. :type rollbar_log_level_threshold: int | None, optional :param rollbar_log_filter_func: A function that filters exceptions to log to rollbar. The function should return `True` for exceptions that should be filtered from rollbar logging. Defaults to logging all exceptions. :type rollbar_log_filter_func: Callable[[Exception], bool] | None :param pool_name: The name of the pool for crash reporting information. :type pool_name: str | None :param lp_share_price_test: If True, only test the lp share price. If False, skips the lp share price test. If None (default), runs all tests. :type lp_share_price_test: bool | None, optional :param crash_report_additional_info: Additional information to include in the crash report. :type crash_report_additional_info: dict[str, Any] | None :param log_anvil_state_dump: If True, log anvil state dump on crash. :type log_anvil_state_dump: bool :param pending_pool_state: The pool state for the pending block. If None, assumes the block is ticking in the background and will maintain the pending block itself. :type pending_pool_state: BlockData | None, optional :param check_price_spike: If True, check price spike :type check_price_spike: bool :returns: A list of FuzzAssertionExceptions, one for each failed invariant check. :rtype: list[FuzzAssertionException] .. !! processed by numpydoc !! .. py:function:: generate_fuzz_hyperdrive_config(rng: numpy.random.Generator, lp_share_price_test: bool, steth: bool) -> agent0.LocalHyperdrive.Config Fuzz over hyperdrive config. :param rng: Random number generator. :type rng: np.random.Generator :param lp_share_price_test: If True, uses lp share price test fuzz parameters. :type lp_share_price_test: bool :param steth: If True, uses steth instead of erc4626 :type steth: bool :returns: Fuzzed hyperdrive config. :rtype: LocalHyperdrive.Config .. !! processed by numpydoc !! .. py:function:: run_fuzz_bots(chain: agent0.Chain, hyperdrive_pools: agent0.Hyperdrive | Sequence[agent0.Hyperdrive], check_invariance: bool, num_random_agents: int | None = None, num_random_hold_agents: int | None = None, agents: Sequence[agent0.core.hyperdrive.interactive.hyperdrive_agent.HyperdriveAgent] | None = None, base_budget_per_bot: fixedpointmath.FixedPoint | None = None, eth_budget_per_bot: fixedpointmath.FixedPoint | None = None, slippage_tolerance: fixedpointmath.FixedPoint | None = None, raise_error_on_crash: bool = False, raise_error_on_failed_invariance_checks: bool = False, ignore_raise_error_func: Callable[[Exception], bool] | None = None, minimum_avg_agent_base: fixedpointmath.FixedPoint | None = None, minimum_avg_agent_eth: fixedpointmath.FixedPoint | None = None, log_to_rollbar: bool = True, run_async: bool = False, random_advance_time: bool = False, random_variable_rate: bool = False, num_iterations: int | None = None, lp_share_price_test: bool = False, whale_accounts: dict[eth_typing.ChecksumAddress, eth_typing.ChecksumAddress] | None = None, accrue_interest_func: Callable[[agent0.ethpy.hyperdrive.HyperdriveReadWriteInterface, fixedpointmath.FixedPoint, int], None] | None = None, accrue_interest_rate: fixedpointmath.FixedPoint | None = None) -> Sequence[agent0.core.hyperdrive.interactive.hyperdrive_agent.HyperdriveAgent] Runs fuzz bots on a hyperdrive pool. :param chain: The chain to run the bots on. :type chain: Chain :param hyperdrive_pools: The hyperdrive pool(s) to run the bots on. :type hyperdrive_pools: Hyperdrive | Sequence[Hyperdrive] :param check_invariance: If True, will run invariance checks after each set of trades. :type check_invariance: bool :param agents: The agents making trades. If None, will create random agents. :type agents: Sequence[HyperdriveAgent] | None, optional :param num_random_agents: The number of random agents to create. Defaults to 2. :type num_random_agents: int | None, optional :param num_random_hold_agents: The number of random agents to create. Defaults to 2. :type num_random_hold_agents: int | None, optional :param base_budget_per_bot: The base budget per bot. Defaults to 10_000_000 :type base_budget_per_bot: FixedPoint | None, optional :param eth_budget_per_bot: The ETH budget per bot. Defaults to 1_000 :type eth_budget_per_bot: FixedPoint | None, optional :param slippage_tolerance: The slippage tolerance. Defaults to 1% slippage :type slippage_tolerance: FixedPoint | None, optional :param raise_error_on_crash: If True, will exit the process if a bot crashes. Defaults to False. :type raise_error_on_crash: bool, optional :param raise_error_on_failed_invariance_checks: If True, will exit the process if the pool fails an invariance check. Defaults to False. :type raise_error_on_failed_invariance_checks: bool, optional :param ignore_raise_error_func: A function that determines if an exception should be ignored when raising error on crash. The function takes an exception as an an argument and returns True if the exception should be ignored. Defaults to raising all errors. :type ignore_raise_error_func: Callable[[Exception], bool] | None, optional :param minimum_avg_agent_base: The minimum average agent base. Will refund bots if average agent base drops below this. Defaults to 1/10 of base_budget_per_bot :type minimum_avg_agent_base: FixedPoint | None, optional :param minimum_avg_agent_eth: The minimum average agent eth. Will refund bots if average agent base drops below this. Defaults to 1/10 of eth_budget_per_bot :type minimum_avg_agent_eth: FixedPoint | None, optional :param log_to_rollbar: If True, log errors rollbar. Defaults to True. :type log_to_rollbar: bool, optional :param run_async: If True, will run the bots asynchronously. Defaults to False. :type run_async: bool, optional :param random_advance_time: If True, will advance the time randomly between sets of trades. Defaults to False. :type random_advance_time: bool, optional :param random_variable_rate: If True, will randomly change the rate between sets of trades. Defaults to False. :type random_variable_rate: bool, optional :param num_iterations: The number of iterations to run. Defaults to None (infinite) :type num_iterations: int | None, optional :param lp_share_price_test: If True, will test the LP share price. Defaults to False. :type lp_share_price_test: bool, optional :param whale_accounts: A mapping between token -> whale addresses to use to fund the fuzz agent. If the token is not in the mapping, fuzzing will attempt to call `mint` on the token contract. Defaults to an empty mapping. :type whale_accounts: dict[ChecksumAddress, ChecksumAddress] | None, optional :param accrue_interest_func: A function that will accrue interest on the hyperdrive pool. This function will get called after advancing time, with the following signature: `accrue_interest_func(hyperdrive_interface, variable_rate, block_number_before_advance)`. :type accrue_interest_func: Callable[[HyperdriveReadWriteInterface, FixedPoint, int], None] | None, optional :param accrue_interest_rate: The variable rate to be passed into the accrue_interest_func. Note this value is only used when forking, as variable interest is handled by a mock yield source when simulating. If `random_variable_rate` is True, this value will be ignored. :type accrue_interest_rate: FixedPoint | None, optional :returns: The set of agents making trades. :rtype: Sequence[HyperdriveAgent] .. !! processed by numpydoc !!