agent0.hyperfuzz.system_fuzz.invariant_checks

Runs invariant checks against a hyperdrive pool.

Attributes

LP_SHARE_PRICE_EPSILON

TOTAL_SHARES_EPSILON

NEGATIVE_INTEREST_ATOL

NEGATIVE_INTEREST_RTOL

PRESENT_VALUE_EPSILON

EZETH_NEG_INTEREST_TIME_DELTA

Classes

InvariantCheckResults

Results from an invariant check.

Functions

run_invariant_checks(...)

Run the invariant checks.

Module Contents

agent0.hyperfuzz.system_fuzz.invariant_checks.LP_SHARE_PRICE_EPSILON = 0.0001
agent0.hyperfuzz.system_fuzz.invariant_checks.TOTAL_SHARES_EPSILON = 1e-09
agent0.hyperfuzz.system_fuzz.invariant_checks.NEGATIVE_INTEREST_ATOL
agent0.hyperfuzz.system_fuzz.invariant_checks.NEGATIVE_INTEREST_RTOL
agent0.hyperfuzz.system_fuzz.invariant_checks.PRESENT_VALUE_EPSILON
agent0.hyperfuzz.system_fuzz.invariant_checks.EZETH_NEG_INTEREST_TIME_DELTA = 43200
agent0.hyperfuzz.system_fuzz.invariant_checks.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

Parameters:
  • check_block_data (BlockData) – The current block to be tested.

  • interface (HyperdriveReadInterface) – An instantiated HyperdriveReadInterface object constructed using the script arguments.

  • log_to_rollbar (bool) – If True, log to rollbar if any invariant check fails.

  • rollbar_log_level_threshold (int | None, optional) – Threshold for logging to rollbar.

  • rollbar_log_filter_func (Callable[[Exception], bool] | None) – 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.

  • pool_name (str | None) – The name of the pool for crash reporting information.

  • lp_share_price_test (bool | None, optional) – If True, only test the lp share price. If False, skips the lp share price test. If None (default), runs all tests.

  • crash_report_additional_info (dict[str, Any] | None) – Additional information to include in the crash report.

  • log_anvil_state_dump (bool) – If True, log anvil state dump on crash.

  • pending_pool_state (BlockData | None, optional) – The pool state for the pending block. If None, assumes the block is ticking in the background and will maintain the pending block itself.

  • check_price_spike (bool) – If True, check price spike

Returns:

A list of FuzzAssertionExceptions, one for each failed invariant check.

Return type:

list[FuzzAssertionException]

class agent0.hyperfuzz.system_fuzz.invariant_checks.InvariantCheckResults

Bases: NamedTuple

Results from an invariant check.

failed: bool
exception_message: str | None
exception_data: dict[str, Any]
log_level: int | None