hats-finance / Fenix-Finance-0x83dbe5aa378f3ce160ed084daf85f621289fb92f

0 stars 0 forks source link

`AlgebraEternalFarming.exitFarming` function doesn't correctly exits farming #11

Open hats-bug-reporter[bot] opened 9 months ago

hats-bug-reporter[bot] commented 9 months ago

Github username: -- Twitter username: -- Submission hash (on-chain): 0xde3519aab90d6649df40cd508d7a4d962f2a19076db56045f006771ed0df1282 Severity: medium

Description:

Description

AlgebraEternalFarming.exitFarming function is meant to exitFarmings for Algebra LP token, it dirst updates the position and distributes its entitled rewards, then it deletes the farm :

```javascript
delete farms[tokenId][incentiveId];
```

but farms is a nested mapping, so deleting it via delete will not remove the nested mapping inside it, and getFarms for this deleted farm will always return a result :

```javascript
mapping(uint256 tokenId => mapping(bytes32 incentiveId => Farm farm)) public override farms;
```

This will prevent the same token with incentive from entering farm again as the liquidity of the farm will not be set to zero upon exiiting

Code Snippet

AlgebraEternalFarming.exitFarming function

delete farms[tokenId][incentiveId];

Tool used

Manual Review

Recommendation

reset the farms mapping related to the deleted farm.

BohdanHrytsak commented 9 months ago

Thank you for the submission.

The exit of a token from one farming does not mean the exit from all farming

delete farms[tokenId][incentiveId];

Clears the Farm structure by tokenId and incentiveId, delete in this case is applied to the structure without attachments, which will lead to its clearing

You can also see that the cleaning is checked: https://github.com/hats-finance/Fenix-Finance-0x83dbe5aa378f3ce160ed084daf85f621289fb92f/blob/08d3a808b6c252d43fbbba869959c8231d0e5934/src/farming/test/unit/EternalFarms.spec.ts#L1661

Accordingly, as the structure is being cleaned, a second enter will be possible