Submitted by oakcobalt, also found by 0xAlix2, Daniel526, Lambda, and Tigerfrake
A user cannot claim rewards or close_position, due to vulnerable division by zero handling in the claim -> calculate_rewards flow.
In calculate_rewards, a users reward per farm per epoch is based on the user_share (user_weight/contract_weights); contract_weights can be zero.
The main vulnerability is division by zero handling is not done at the site of division; i.e., no check on contract_weights is non-zero before using it as a denominator in checked_mul_floor. (Flows: claim -> calculate_rewards).
/contracts/farm-manager/src/farm/commands.rs#L205
Current contract attempts to handle this at the source; clear the users LAST_CLAIMED_EPOCH when a user closes a position. This is also vulnerable because when the user has active positions in other lp-denoms, LAST_CLAIMED_EPOCH cannot be cleared for the user. Back in calcualte_rewards, this means the epoch iteration will still start at (LAST_CLAIMED_EPOCH + 1) which includes the epoch where contract_weights is zero. (Flows: close_position -> reconcile_user_state).
/contracts/farm-manager/src/position/helpers.rs#L215
Users rewards will be locked and unclaimable. Since pending rewards have to be claimed before close_position, users cannot close any positions without penalty.
Suppose a user has two positions: position1 (lp_denom1) and position2(lp_denom2).
Coded PoC:
In contracts/farm-manager/tests/integration.rs, add test_query_rewards_divide_by_zero_cause_rewards_locked and run cargo test test_query_rewards_divide_by_zero_cause_rewards_locked.
Consider handling division by zero in calculate_rewards directly by skip the epoch iteration when contract_weights is 0.
jvr0x (MANTRA) confirmed
