code-423n4 / 2022-01-trader-joe-findings

2 stars 0 forks source link

Gas: Non-strict inequalities are cheaper than strict ones #178

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

Dravee

Vulnerability details

Impact

Strict inequalities add a check of non equality which costs around 3 gas.

Proof of Concept

The following should use an inclusive inequality to save gas:

File: RocketJoeStaking.sol
181:     function _safeRJoeTransfer(address _to, uint256 _amount) internal {
182:         uint256 rJoeBal = rJoe.balanceOf(address(this));
183:         if (_amount > rJoeBal) { //@audit should be >= to save gas
184:             rJoe.transfer(_to, rJoeBal);
185:         } else {
186:             rJoe.transfer(_to, _amount);
187:         }
188:     }

Tools Used

VS Code

Recommended Mitigation Steps

Use >= or <= instead of > and < when possible.