Skip to content

Commit

Permalink
Fuzz fixes for lp share price, and another attempt to fix local fuzz …
Browse files Browse the repository at this point in the history
…bots from crashing (#1489)
  • Loading branch information
Sheng Lundquist authored May 23, 2024
1 parent b73e7fd commit 88157f3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/agent0/core/hyperdrive/interactive/local_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def cleanup(self):
# Runs cleanup on all deployed pools
try:
if self.anvil_process is not None:
self.anvil_process.kill()
self.anvil_process.terminate()
if self.anvil_process.stdout is not None:
self.anvil_process.stdout.close()
if self.anvil_process.stderr is not None:
Expand All @@ -137,7 +137,7 @@ def cleanup(self):

try:
if self.dashboard_subprocess is not None:
self.dashboard_subprocess.kill()
self.dashboard_subprocess.terminate()
if self.dashboard_subprocess.stdout is not None:
self.dashboard_subprocess.stdout.close()
if self.dashboard_subprocess.stderr is not None:
Expand Down
14 changes: 13 additions & 1 deletion src/agent0/hyperfuzz/system_fuzz/invariant_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,19 @@ def _check_lp_share_price(
current_lp_share_price = pool_state.pool_info.lp_share_price
test_tolerance = previous_lp_share_price * FixedPoint(str(normalized_test_epsilon))

if not isclose(previous_lp_share_price, current_lp_share_price, abs_tol=test_tolerance):
# Determine if the current checkpoint has been minted by looking at the checkpoint's vault share price.
current_checkpoint_minted = pool_state.checkpoint.vault_share_price > 0

# Check both directions if checkpoint has been minted.
if current_checkpoint_minted:
if not isclose(previous_lp_share_price, current_lp_share_price, abs_tol=test_tolerance):
failed = True
# Only check that the lp share price doesn't decrease by more than our tolerance if checkpoint hasn't been minted.
else:
if (previous_lp_share_price - current_lp_share_price) >= test_tolerance:
failed = True

if failed:
difference_in_wei = abs(previous_lp_share_price.scaled_value - current_lp_share_price.scaled_value)
exception_message = f"{previous_lp_share_price=} != {current_lp_share_price=}, {difference_in_wei=}"
exception_data["invariance_check:initial_lp_share_price"] = previous_lp_share_price
Expand Down
10 changes: 10 additions & 0 deletions src/agent0/hyperfuzz/system_fuzz/run_local_fuzz_bots.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from agent0 import LocalChain, LocalHyperdrive, PolicyZoo
from agent0.core.base.make_key import make_private_key
from agent0.core.hyperdrive.interactive.hyperdrive_agent import HyperdriveAgent
from agent0.ethpy.base import set_anvil_account_balance
from agent0.hyperfuzz.system_fuzz.invariant_checks import run_invariant_checks

ONE_HOUR_IN_SECONDS = 60 * 60
Expand Down Expand Up @@ -375,6 +376,15 @@ def run_local_fuzz_bots(
else:
_ = [agent.add_funds(base=base_budget_per_bot, eth=eth_budget_per_bot) for agent in agents]

# The deployer pays gas for advancing time
# We check the eth balance and refund if it runs low
deployer_account = hyperdrive_pool._deployed_hyperdrive.deploy_account # pylint: disable=protected-access
deployer_agent_eth = hyperdrive_pool.interface.get_eth_base_balances(deployer_account)[0]
if deployer_agent_eth < minimum_avg_agent_eth:
_ = set_anvil_account_balance(
hyperdrive_pool.interface.web3, deployer_account.address, eth_budget_per_bot.scaled_value
)

if random_advance_time:
# We only allow random advance time if the chain connected to the pool is a
# LocalChain object
Expand Down

0 comments on commit 88157f3

Please sign in to comment.