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: > 0 is less efficient than != 0 for unsigned integers #57

Open
code423n4 opened this issue Jan 29, 2022 · 4 comments
Open

Gas: > 0 is less efficient than != 0 for unsigned integers #57

code423n4 opened this issue Jan 29, 2022 · 4 comments
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Handle

Dravee

Vulnerability details

Impact

!= 0 costs less gas compared to > 0 for unsigned integers in require statements with the optimizer enabled (6 gas)

Proof of Concept

> 0 is used in the following location(s):

ConvexStakingWrapper.sol:165:        if (_supply > 0 && d_cvxreward > 0) {
ConvexStakingWrapper.sol:182:                    if (receiveable > 0) {
ConvexStakingWrapper.sol:221:        if (_supply > 0 && (bal - rewardRemaining) > 0) {
ConvexStakingWrapper.sol:237:                    if (receiveable > 0) {
ConvexStakingWrapper.sol:325:            if (supply > 0) {
ConvexYieldWrapper.sol:128:        require(amount_ > 0, "No convex token to wrap");
ConvexYieldWrapper.sol:142:        require(amount_ > 0, "No wrapped convex token");

Tools Used

VS Code

Recommended Mitigation Steps

Change > 0 with != 0.

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jan 29, 2022
code423n4 added a commit that referenced this issue Jan 29, 2022
@iamsahu iamsahu added the duplicate This issue or pull request already exists label Feb 1, 2022
@iamsahu
Copy link
Collaborator

iamsahu commented Feb 1, 2022

#18 #83 #125

@alcueca
Copy link
Collaborator

alcueca commented Feb 2, 2022

Taking as main

@GalloDaSballo
Copy link
Collaborator

Note that the finding is valid only when using the check for a require

In an if statement != will cost more gas

@devtooligan
Copy link
Collaborator

@GalloDaSballo
Try as I might, I could not confirm any gas difference between !=0 and >0 with if statements :/

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)
Projects
None yet
Development

No branches or pull requests

5 participants