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

1 stars 0 forks source link

Double division by BASE #210

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

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;

GalloDaSballo commented 2 years ago

Agree with the gas cost reduction as the value of BASE_2X will be inlined in the bytecode Can't confirm on the precision as you're still dividing by the same value