From 25d79fa6990f4a93e107af33bbae4fb3d4ce4384 Mon Sep 17 00:00:00 2001 From: alpo Date: Sat, 29 Jun 2024 13:00:57 -0700 Subject: [PATCH] add defense in depth check to swap steps --- contracts/sumtree-orderbook/src/order.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contracts/sumtree-orderbook/src/order.rs b/contracts/sumtree-orderbook/src/order.rs index 03f958e..8f616de 100644 --- a/contracts/sumtree-orderbook/src/order.rs +++ b/contracts/sumtree-orderbook/src/order.rs @@ -557,6 +557,14 @@ pub(crate) fn run_market_order_internal( tick_price, RoundingDirection::Up, )?; + + ensure!( + !input_filled.is_zero(), + ContractError::InvalidSwap { + error: "Input amount for a given swap step cannot be zero".to_string() + } + ); + order.quantity = order .quantity // Safe conversions as amount filled should never be larger than order quantity which is upper bounded by Uint128::MAX