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

1 stars 0 forks source link

Gas in `Cvx3CrvOracle.sol:min()`: Non-strict inequalities are cheaper than strict ones #68

Closed code423n4 closed 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: Cvx3CrvOracle.sol
55:     function min(uint256 a, uint256 b) internal pure returns (uint256) {
56:         return a < b ? a : b; //@audit-info <= is less expensive and would give the same result
57:     }

Tools Used

VS Code

Recommended Mitigation Steps

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

iamsahu commented 2 years ago

From readme:

Screenshot 2022-02-01 at 9 10 32 AM
GalloDaSballo commented 2 years ago

Improvement is valid, this should save 3 gas. As per the sponsors requirements I'll mark invalid