Double division by BASE #210
Labels
bug
Warden finding
G (Gas Optimization)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
pauliax
Vulnerability details
Impact
This double division by BASE can be eliminated to improve precision and reduce gas costs:
uint256 tokensNeeded = basketAsERC20.totalSupply() * pendingWeights[i] * newRatio / BASE / BASE;
Recommended Mitigation Steps
if you introduce a constant variable, e.g.:
uint256 private constant BASE_2X = BASE * 2;
uint256 tokensNeeded = basketAsERC20.totalSupply() * pendingWeights[i] * newRatio / BASE_2X;
The text was updated successfully, but these errors were encountered: