gnosis / cow-dex-solver

Other
56 stars 31 forks source link

Runtime Panic in Slippage Computation #37

Open nlordell opened 2 years ago

nlordell commented 2 years ago

There appears to be a runtime panic introduced in the slippage computation:

2022-11-04T12:38:43.557Z ERROR cowdexsolver::tracing_helper: thread 'tokio-runtime-worker' panicked at 'denominator == 0', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/num-rational-0.4.0/src/lib.rs:132:13:
thread 'tokio-runtime-worker' panicked at 'denominator == 0', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/num-rational-0.4.0/src/lib.rs:132:13
stack backtrace:
   0: std::panicking::begin_panic
             at ./rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:616:12
   1: num_rational::Ratio<T>::reduce
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/num-rational-0.4.0/src/lib.rs:132:13
   2: num_rational::Ratio<T>::new
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/num-rational-0.4.0/src/lib.rs:105:9
   3: <num_rational::Ratio<T> as core::ops::arith::Div<T>>::div
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/num-rational-0.4.0/src/lib.rs:739:9
   4: <num_rational::Ratio<T> as core::ops::arith::Div<&T>>::div
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/num-rational-0.4.0/src/lib.rs:666:17
   5: cowdexsolver::slippage::SlippageCalculator::compute_inner
             at ./usr/src/cowdexsolver/src/slippage.rs:108:67
   6: cowdexsolver::slippage::SlippageCalculator::compute
             at ./usr/src/cowdexsolver/src/slippage.rs:78:36
   7: cowdexsolver::slippage::SlippageContext::relative
             at ./usr/src/cowdexsolver/src/slippage.rs:41:12
   8: cowdexsolver::solve::get_swaps_for_left_over_amounts::{{closure}}::{{closure}}::{{closure}}
             at ./usr/src/cowdexsolver/src/solve.rs:394:42
   9: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at ./rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/future/mod.rs:91:19
  10: <futures_util::future::maybe_done::MaybeDone<Fut> as core::future::future::Future>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.21/src/future/maybe_done.rs:95:38
  11: <futures_util::future::join_all::JoinAll<F> as core::future::future::Future>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.21/src/future/join_all.rs:143:24
  12: cowdexsolver::solve::get_swaps_for_left_over_amounts::{{closure}}
             at ./usr/src/cowdexsolver/src/solve.rs:407:48
  13: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at ./rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/future/mod.rs:91:19
  14: cowdexsolver::solve::solve::{{closure}}
             at ./usr/src/cowdexsolver/src/solve.rs:131:14
  15: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at ./rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/future/mod.rs:91:19
  16: cowdexsolver::api::solve::get_solve::{{closure}}::{{closure}}
             at ./usr/src/cowdexsolver/src/api/solve.rs:76:66
  17: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at ./rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/future/mod.rs:91:19
  18: <F as futures_core::future::TryFuture>::try_poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-core-0.3.21/src/future.rs:82:9
  19: <warp::filter::and_then::State<T,F> as core::future::future::Future>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.2/src/filter/and_then.rs:99:44
  20: <warp::filter::and_then::AndThenFuture<T,F> as core::future::future::Future>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.2/src/filter/and_then.rs:74:9
  21: <F as futures_core::future::TryFuture>::try_poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-core-0.3.21/src/future.rs:82:9
  22: <warp::filter::recover::RecoverFuture<T,F> as core::future::future::Future>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.2/src/filter/recover.rs:91:65
  23: <F as futures_core::future::TryFuture>::try_poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-core-0.3.21/src/future.rs:82:9
  24: <warp::filters::cors::internal::WrappedFuture<F> as core::future::future::Future>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.2/src/filters/cors.rs:578:26
  25: <futures_util::future::either::Either<A,B> as core::future::future::Future>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.21/src/future/either.rs:90:33
  26: <F as futures_core::future::TryFuture>::try_poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-core-0.3.21/src/future.rs:82:9
  27: <warp::filter::service::FilteredFuture<F> as core::future::future::Future>::poll::{{closure}}
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.2/src/filter/service.rs:128:40
  28: scoped_tls::ScopedKey<T>::set
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137:9
  29: warp::route::set
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.2/src/route.rs:16:5
  30: <warp::filter::service::FilteredFuture<F> as core::future::future::Future>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.2/src/filter/service.rs:128:15
  31: <hyper::proto::h1::dispatch::Server<S,hyper::body::body::Body> as hyper::proto::h1::dispatch::Dispatch>::poll_msg
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.19/src/proto/h1/dispatch.rs:491:35
  32: hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_write
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.19/src/proto/h1/dispatch.rs:297:43
  33: hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_loop
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.19/src/proto/h1/dispatch.rs:161:21
  34: hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_inner
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.19/src/proto/h1/dispatch.rs:137:16
  35: hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_catch
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.19/src/proto/h1/dispatch.rs:120:28
  36: <hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T> as core::future::future::Future>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.19/src/proto/h1/dispatch.rs:424:9
  37: <hyper::server::conn::ProtoServer<T,B,S,E> as core::future::future::Future>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.19/src/server/conn.rs:952:47
  38: <hyper::server::conn::upgrades::UpgradeableConnection<I,S,E> as core::future::future::Future>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.19/src/server/conn.rs:1012:30
  39: <hyper::server::server::new_svc::NewSvcTask<I,N,S,E,W> as core::future::future::Future>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-0.14.19/src/server/server.rs:728:36
  40: tokio::runtime::task::core::CoreStage<T>::poll::{{closure}}
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/core.rs:165:17
  41: tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/loom/std/unsafe_cell.rs:14:9
  42: tokio::runtime::task::core::CoreStage<T>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/core.rs:155:13
  43: tokio::runtime::task::harness::poll_future::{{closure}}
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/harness.rs:470:19
  44: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at ./rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panic/unwind_safe.rs:271:9
  45: std::panicking::try::do_call
             at ./rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:492:40
  46: std::panicking::try
             at ./rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:456:19
  47: std::panic::catch_unwind
             at ./rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panic.rs:137:14
  48: tokio::runtime::task::harness::poll_future
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/harness.rs:458:18
  49: tokio::runtime::task::harness::Harness<T,S>::poll_inner
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/harness.rs:104:27
  50: tokio::runtime::task::harness::Harness<T,S>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/harness.rs:57:15
  51: tokio::runtime::task::raw::RawTask::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/raw.rs:84:18
  52: tokio::runtime::task::LocalNotified<S>::run
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/mod.rs:376:9
  53: tokio::runtime::thread_pool::worker::Context::run_task::{{closure}}
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/thread_pool/worker.rs:458:21
  54: tokio::coop::with_budget::{{closure}}
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/coop.rs:102:9
  55: std::thread::local::LocalKey<T>::try_with
             at ./rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/thread/local.rs:445:16
  56: std::thread::local::LocalKey<T>::with
             at ./rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/thread/local.rs:421:9
  57: tokio::coop::with_budget
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/coop.rs:95:5
  58: tokio::coop::budget
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/coop.rs:72:5
  59: tokio::runtime::thread_pool::worker::Context::run_task
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/thread_pool/worker.rs:434:9
  60: tokio::runtime::thread_pool::worker::Context::run
  61: tokio::runtime::thread_pool::worker::run::{{closure}}
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/thread_pool/worker.rs:386:17
  62: tokio::macros::scoped_tls::ScopedKey<T>::set
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/macros/scoped_tls.rs:61:9
  63: tokio::runtime::thread_pool::worker::run
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/thread_pool/worker.rs:383:5
  64: tokio::runtime::thread_pool::worker::Launch::launch::{{closure}}
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/thread_pool/worker.rs:362:45
  65: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/blocking/task.rs:42:21
  66: tokio::runtime::task::core::CoreStage<T>::poll::{{closure}}
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/core.rs:165:17
  67: tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/loom/std/unsafe_cell.rs:14:9
  68: tokio::runtime::task::core::CoreStage<T>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/core.rs:155:13
  69: tokio::runtime::task::harness::poll_future::{{closure}}
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/harness.rs:470:19
  70: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at ./rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panic/unwind_safe.rs:271:9
  71: std::panicking::try::do_call
             at ./rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:492:40
  72: std::panicking::try
             at ./rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:456:19
  73: std::panic::catch_unwind
             at ./rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panic.rs:137:14
  74: tokio::runtime::task::harness::poll_future
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/harness.rs:458:18
  75: tokio::runtime::task::harness::Harness<T,S>::poll_inner
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/harness.rs:104:27
  76: tokio::runtime::task::harness::Harness<T,S>::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/harness.rs:57:15
  77: tokio::runtime::task::raw::RawTask::poll
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/raw.rs:84:18
  78: tokio::runtime::task::UnownedTask<S>::run
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/task/mod.rs:413:9
  79: tokio::runtime::blocking::pool::Task::run
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/blocking/pool.rs:91:9
  80: tokio::runtime::blocking::pool::Inner::run
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/blocking/pool.rs:325:17
  81: tokio::runtime::blocking::pool::Spawner::spawn_thread::{{closure}}
             at ./root/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/blocking/pool.rs:300:13
nlordell commented 2 years ago

Seems to be caused by a 0-amount being passed into the slippage calculator.