code-423n4 / 2021-09-defiprotocol-findings

1 stars 0 forks source link

tokensNeeded can potentially be 0 #101

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

itsmeSTYJ

Vulnerability details

Impact

If tokensNeeded is 0, it is possible to remove all the funds in the basket since no tokens are required to pass the balanceOf checks. The chances of this happening is very unlikely however it is better to be safe than sorry.

Recommended Mitigation Steps

Add a require statement to check that the numerator (basketAsERC20.totalSupply() * pendingWeights[i] * newRatio) is greater than or eq to the denominator (BASE * BASE). This will ensure that it can never round down i.e. tokensNeeded can never be 0.

GalloDaSballo commented 2 years ago

Agree with the finding, due to integer division the rounding can return a 0 there which can cause issues Given the low likelihood of this happening low severity is proper