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

Gas: XDEFIDistribution.sol's withdrawAmount substraction can be unchecked #49

Open
code423n4 opened this issue Jan 5, 2022 · 2 comments
Labels
bug Something isn't working G (Gas Optimization) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) 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

Dravee

Vulnerability details

Impact

Waste of gas due to unnecessary underflow checks

Proof of Concept

On XDEFIDistribution.sol:120 and XDEFIDistribution.sol:175, you can find the following substraction:
uint256 withdrawAmount = amountUnlocked_ - lockAmount_;

However, as the Solidity version is 0.8.10, default overflow and underflow checks are made, which cost some gas.

You can save this gas with the unchecked keyword to bypass these checks as 5 lines above (L115 and L170), a require statement already checks that lockAmount_ <= amountUnlocked_.

Therefore, no underflow is possible.

Tools Used

VS Code

Recommended Mitigation Steps

Use the "unchecked" keyword

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jan 5, 2022
code423n4 added a commit that referenced this issue Jan 5, 2022
@deluca-mike deluca-mike added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Jan 5, 2022
@deluca-mike
Copy link
Collaborator

Yep, while I originally did not want to messy the code with unchecked math, enough people have mentioned it, and I've now down enough analysis to just go ahead and do it.

@deluca-mike
Copy link
Collaborator

deluca-mike commented Jan 14, 2022

In release candidate contacts, done in _relock.

@deluca-mike deluca-mike added the resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) label Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) 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

2 participants