Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double division by BASE #210

Open
code423n4 opened this issue Sep 22, 2021 · 1 comment
Open

Double division by BASE #210

code423n4 opened this issue Sep 22, 2021 · 1 comment
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")

Comments

@code423n4
Copy link
Contributor

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;

code423n4 added a commit that referenced this issue Sep 22, 2021
@frank-beard frank-beard added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Oct 19, 2021
@GalloDaSballo
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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")
Projects
None yet
Development

No branches or pull requests

3 participants