code-423n4 / 2022-01-yield-findings

1 stars 0 forks source link

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

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

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.

iamsahu commented 2 years ago

18 #83 #125

alcueca commented 2 years ago

Taking as main

GalloDaSballo commented 2 years ago

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

In an if statement != will cost more gas

devtooligan commented 2 years ago

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