delvtech / hyperdrive-rs

Rust SDK for the Hyperdrive AMM.
https://docs.rs/crate/hyperdrive-math/latest
Apache License 2.0
2 stars 0 forks source link

`fuzz_calculate_max_short` occasionally failing #121

Closed dpaiton closed 4 months ago

dpaiton commented 5 months ago
---- short::max::tests::fuzz_calculate_max_short stdout ----
thread 'short::max::tests::fuzz_calculate_max_short' panicked at crates/hyperdrive-math/src/short/max.rs:742:17:
expected (base=70430895.800062968817706189) < (budget=70964720.871387510943216964) * 0.001000000000000000 = 70964.720871387510943216

I posted about a similar error here but closed that issue in favor of this dedicated one.

wakamex commented 5 months ago

my testing shows a problem occurring with fixed rates above 300%:

Total tests: 17720 Both pass: 8496 Both fail: 8873 Mismatched: 351 Failure rate: 0.019808126410835215
Fuzzed over fixed rate from Some(FixedPoint(0.000385747703397417)) to Some(FixedPoint(399.625149689078101990))
Mismatched  fixed rate from Some(FixedPoint(3.131040290023483491)) to Some(FixedPoint(133.805637502892130607))

that's from wip draft pr #19

testing with

RUST_BACKTRACE=full HYPERDRIVE_FAST_FUZZ_RUNS=100000 HYPERDRIVE_ETHEREUM_URL=http://127.0.0.1:8547 LOCAL_DEVELOPMENT=true cargo test -vvv --package hyperdrive-math --release -- short::max::tests::fuzz_calculate_max_short_no_budget --exact --show-output --nocapture
wakamex commented 5 months ago

still get a 2% mismatch rate after #122 allows the test to run to the end

Total tests: 100,000 Both pass: 48,054 Both fail: 49,871 Mismatched: 2,075 Failure rate: 0.02075
wakamex commented 5 months ago

looks like Rust succeeds when Solidity doesn't:

Fixed rate: 9.258702584950471355
MISMATCHED: actual: Ok(Ok(FixedPoint(44767131.875921600404760400))) expected: Revert(Bytes(0x4e487b710000000000000000000000000000000000000000000000000000000000000011))
Rust: FixedPoint(44767131.875921600404760400) Solidity: Revert(Bytes(0x4e487b710000000000000000000000000000000000000000000000000000000000000011))
Fixed rate: 5.460357484762586677
MISMATCHED: actual: Ok(Ok(FixedPoint(835897164.703558754582240549))) expected: Revert(Bytes(0x4e487b710000000000000000000000000000000000000000000000000000000000000011))

this result is on 989ad42c89e4b9179331f8b879e376a356433bca