From a27bff86e5143430fb97ba15530d02a66ce0782b Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 29 Sep 2025 01:09:51 +0200 Subject: [PATCH] feat: Add validation for non-zero total deposit in add_liquidity --- contracts/pool-templates/base/SwapTemplateBase.vy | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/contracts/pool-templates/base/SwapTemplateBase.vy b/contracts/pool-templates/base/SwapTemplateBase.vy index d1d4f1e2..77aedfdd 100644 --- a/contracts/pool-templates/base/SwapTemplateBase.vy +++ b/contracts/pool-templates/base/SwapTemplateBase.vy @@ -290,7 +290,11 @@ def calc_token_amount(_amounts: uint256[N_COINS], _is_deposit: bool) -> uint256: diff = D0 - D1 return diff * token_amount / D0 - +# Adds liquidity to the pool by depositing specified amounts of tokens. +# Calculates the new invariant (D) after deposit, applies fees based on the difference +# between ideal and actual balances, and mints LP tokens proportional to the change in D. +# Includes non-reentrant protection to prevent reentrancy attacks and ensures minimum +# mint amount to protect against slippage. @external @nonreentrant('lock') def add_liquidity(_amounts: uint256[N_COINS], _min_mint_amount: uint256) -> uint256: @@ -302,6 +306,12 @@ def add_liquidity(_amounts: uint256[N_COINS], _min_mint_amount: uint256) -> uint """ assert not self.is_killed # dev: is killed + # Ensure at least one amount is non-zero to prevent invalid deposits + total_amount: uint256 = 0 + for i in range(N_COINS): + total_amount += _amounts[i] + assert total_amount > 0, "Total deposit amount must be greater than zero" + amp: uint256 = self._A() old_balances: uint256[N_COINS] = self.balances