Submitted by sirhashalot
The setPerTokenWalletCap() function in WhitelistPeriodManager.sol contains a comment stating:
Even if the manual step of calling the getMaxCommunityLpPositon() function is properly performed, it is possible for a user to add liquidity to increase the maxLp value in between when the getMaxCommunityLpPositon() function is called and when the setPerTokenWalletCap() function is called. Because this process is manual, this doesnt need to be bot frontrunning in the same block as when the setPerTokenWalletCap() function is called, but can be cause by poor timing of an innocent unknowing user adding liquidity to the protocol. If this condition occurs, the liquidity provider will have provided more liquidity than the perTokenWalletCap limit, breaking the assumptions for this variable and leading to some denial of service conditions.
This edge situation can impact the setTotalCap() function and the perTokenTotalCap[_token] state variable as well, but the perTokenWalletCap[_token] value would have to be reduced before the perTokenTotalCap[_token] value is reduced. The impact to setTotalCap() follows the same execution path but adds the additional step of calling the setTotalCap() function at the end of the process.
This edge situation can impact the setTotalCap() function and the perTokenTotalCap[_token] state variable as well, but the perTokenWalletCap[_token] value would have to be reduced before the perTokenTotalCap[_token] value is reduced. The impact to setTotalCap() follows the same execution path but adds the additional step of calling the setTotalCap() function at the end of the process.
A programmatic solution is the only way to avoid these edge case scenarios, though it will increase gas consumption. To convert the manual calling of getMaxCommunityLpPositon(_token) to a programmatic solution, add the following require statement next to the existing require statement of the setPerTokenWalletCap() function:
require(_perTokenWalletCap <= getMaxCommunityLpPositon(_token), "ERR_PWC_GT_MCLP");
ankurdubey521 (Biconomy) acknowledged
pauliax (judge) commented:
