delvtech / hyperdrive

An automated market maker for fixed and variable yield with on-demand terms.
Apache License 2.0
33 stars 4 forks source link

bug: crash when share_price < 1 [elfpy_crash_2] #412

Closed wakamex closed 1 year ago

wakamex commented 1 year ago

hyperdrive commit: 661b4181b990da0ccf01d44ca8a7fb5d8352b2be elf-simulations commit: ed7ed8497570a2007f27dc9dd5e4c250568f5dc0

# initial crash
Block number: 19.0, Block time: 2023-07-03 14:01:37, Trades without crashing: 5, base_fee: 0.098468686
agent_0x1bF032 has Eth=26.0 Base=49,747
    rade CLOSE_LONG
 => closeLong(_maturityTime=1719878400, _bondAmount=0.000000000000000001, _minOutput=0, _destination=0x1bF0326E53EC6d86d97a1e5330d2c00DEF11B9da, _asUnderlying=True)
Txn failed in unexpected way on attempt 1 of 2: Arithmetic operation underflowed or overflowed outside of an unchecked block.
Failed to execute CLOSE_LONG: Arithmetic operation underflowed or overflowed outside of an unchecked block.
 => Amount: 380292066725979348024
 => Agent: 0x1bF0326E53EC6d86d97a1e5330d2c00DEF11B9da
 => Pool: {'shareReserves': 99866386834097123072338, 'bondReserves': 296271126865413883832970, 'lpTotalSupply': 100230897860422790988272, 'sharePrice': 998265350777803153, 'longsOutstanding': 0, 'longAverageMaturityTime': 0, 'shortsOutstanding': 385811450946370469888, 'shortAverageMaturityTime': 1719878400000000000000000000, 'shortBaseVolume': 366194883487218406230, 'withdrawalSharesReadyToWithdraw': 0, 'withdrawalSharesProceeds': 0}
Crashed with error: Arithmetic operation underflowed or overflowed outside of an unchecked block.

# replicated crash
Block number: 20.0, Block time: 2023-07-03 14:01:38, Trades without crashing: 0, base_fee: 0.086160101
agent_0x1bF032 has Eth=26.0 Base=49,747
    rade CLOSE_LONG
 => closeLong(_maturityTime=1719878400, _bondAmount=0.000000000000000001, _minOutput=0, _destination=0x1bF0326E53EC6d86d97a1e5330d2c00DEF11B9da, _asUnderlying=True)
Txn failed in unexpected way on attempt 1 of 2: Arithmetic operation underflowed or overflowed outside of an unchecked block.
Failed to execute CLOSE_LONG: Arithmetic operation underflowed or overflowed outside of an unchecked block.
 => Amount: 380292066725979348024
 => Agent: 0x1bF0326E53EC6d86d97a1e5330d2c00DEF11B9da
 => Pool: {'shareReserves': 99866386834097123072338, 'bondReserves': 296271126865413883832970, 'lpTotalSupply': 100230897860422790988272, 'sharePrice': 998352717961164229, 'longsOutstanding': 0, 'longAverageMaturityTime': 0, 'shortsOutstanding': 385811450946370469888, 'shortAverageMaturityTime': 1719878400000000000000000000, 'shortBaseVolume': 366194883487218406230, 'withdrawalSharesReadyToWithdraw': 0, 'withdrawalSharesProceeds': 0}
Crashed with error: Arithmetic operation underflowed or overflowed outside of an unchecked block.

replication steps:

wakamex commented 1 year ago

got some more prints. this tells me it's crashing on burn.

=== HyperdriveLong: closeLong ===
HyperdriveLong: closeLong: _maturityTime 1719964800
HyperdriveLong: closeLong: _bondAmount 1
HyperdriveLong: closeLong: _minOutput 0
HyperdriveLong: closeLong: _destination 0x1bF0326E53EC6d86d97a1e5330d2c00DEF11B9da
HyperdriveLong: closeLong: _asUnderlying true
HyperdriveLong: closeLong: sharePrice 1000139434479340023
HyperdriveLong: closeLong: _bondAmount PRE-BURN  1
eth_getTransactionReceipt

    Transaction: 0x0ee7db1cf9b96b7ffb144a843c232d7d7820d25b59512d286dac379be8afd7fb
    Gas used: 54646
    Error: reverted with 'Arithmetic over/underflow'

    Block Number: 20
    Block Hash: 0x17b8b8ba8a6b45c26587ff97d22019b71b5e30498b22452eec1916d2acd91a83
    Block Time: "Tue, 04 Jul 2023 00:59:22 +0000"
wakamex commented 1 year ago

even more prints. this tells me it's trying to burn something that doesn't exist.

=== MultiToken: burn ===
MultiToken: burn: tokenID:  452312848583266388373324160190187140051835877600158453279131187532630627456
MultiToken: burn: from:  0x1bF0326E53EC6d86d97a1e5330d2c00DEF11B9da
MultiToken: burn: amount:  1
MultiToken: burn: next line: _balanceOf[tokenID][from] -= amount
MultiToken: burn: PRE-BURN  _balanceOf[tokenID][from] 0
wakamex commented 1 year ago

at this point thinking it's an error in the evm_bots code as the agent is trying to close a position with 0 size.

will verify this, then close this issue, if confirmed.

dpaiton commented 1 year ago

Hyperdrive team don't worry about this for now. I'm actively rewriting evm_bots so I'll revisit this bug once I'm done.

wakamex commented 1 year ago

this issue is likely caused by or related to this issue on the elf-sims side, which we should resolve first, before doing any more work on the solidity bug: https://github.com/delvtech/elf-simulations/issues/637

jalextowle commented 1 year ago

Closing because this isn't a Hyperdrive issue.