Different formulas to calculate tokenAmount #37
Labels
1 (Low Risk)
Assets are not at risk. State handling, function incorrect as to spec, issues with comments
bug
Something isn't working
Handle
gpersoon
Vulnerability details
Impact
The function joinPool() and calcTokensForAmount() both calculate the tokenAmount , taking in account the entryFee.
However both use a different formula.
The result of the formulas is the same as far as I can see.
However for maintenance purposes it is better to use the same formula.
Note1: exitPool() and calcTokensForAmountExit() do use the same formula.
Note2: When using the same formula it is easier to optimize for gas, for example to take "_amount.add(feeAmount)" outside of the for loop.
Proof of Concept
https://github.com/code-423n4/2021-12-amun/blob/cf890dedf2e43ec787e8e5df65726316fda134a1/contracts/basket/contracts/facets/Basket/BasketFacet.sol#L143-L185
https://github.com/code-423n4/2021-12-amun/blob/cf890dedf2e43ec787e8e5df65726316fda134a1/contracts/basket/contracts/facets/Basket/BasketFacet.sol#L332-L362
Tools Used
Recommended Mitigation Steps
In function calcTokensForAmount() use the same formula to calculate tokenAmount as in joinPool()
The text was updated successfully, but these errors were encountered: