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

[CRASH REPORT] fuzz invariant -- close short after maturity result is not as expected #698

Closed dpaiton closed 9 months ago

dpaiton commented 11 months ago

Crash Report

https://app.rollbar.com/a/delv/fix/item/FirstProject/38/occurrence/385515525734#detail

Same test as https://github.com/delvtech/hyperdrive/issues/697 but looking at the shorts instead of longs

Description

Test: fuzz_long_short_maturity_values.py

Expected Behavior

The trades should have matured from advancing time and an expected amount should have been returned.

actual_base_amount = close_trade_event.base_amount

`interest_accrued = expected_base_amount = ( open_trade_event.bond_amount * (closing_share_price / open_share_price + flat_fee_percent)

Actual Behavior

The expected and actual returned amounts do not match.

count       13.000000
mean      5933.461538
std       4760.426200
min        192.000000
25%       1670.000000
50%       5789.000000
75%       9998.000000
max      14437.000000
Name: additional_info.invariance_check:short_base_amount_difference_in_wei, dtype: float64

Steps to Reproduce

Run the fuzz test

Screenshots or Error Messages

image

Logs or Stack Traces

fuzz_long_short_maturity_values2023_12_12_18_44_49_Z.json

jalextowle commented 11 months ago

We also see this in our foundry tests, so I think that this calculation is legitimately off. @jrhea Made calculateShortProceeds more accurate in #685, so we should try this again after landing v0.4.0 to see if the situation has improved.

slundqui commented 10 months ago

Relevant crash report for v0.4.0 fuzz_long_short_maturity_values2024_01_10_20_11_34_Z.json

slundqui commented 10 months ago

Relevant crash report for v0.5.1 fuzz_long_short_maturity_values2024_01_19_21_25_56_611326_UTC.json

slundqui commented 9 months ago

Determined the difference here is due to the variable rate. Solved by added an epsilon of 1e9 wei in the fuzz test for mature shorts.