wise-foundation / lending-audit

5 stars 4 forks source link

[WSH-05C] Non-Standard Revert Patterns #68

Open vm06007 opened 11 months ago

vm06007 commented 11 months ago

WSH-05C: Non-Standard Revert Patterns

Type Severity Location
Gas Optimization WiseSecurityHelper.sol:L845-L847, L849, L922-L924, L926-L928, L930

Description:

The referenced functions will evaluate a condition, return early in such a case and otherwise revert.

Example:

function checkOwnerPosition(
    uint256 _nftId,
    address _caller
)
    public
    view
{
    if (POSITION_NFTS.reserved(_caller) == _nftId) {
        return;
    }

    if (POSITION_NFTS.ownerOf(_nftId) == _caller) {
        return;
    }

    revert NotOwner();
}

Recommendation:

We advise the functions to inverse their if conditions and revert in their case, reducing the bytecode signature as well as common-case gas cost of the functions.

vm06007 commented 11 months ago

Team decided not to address this information, as it is not a security concern and a matter of style preference. Team finds this optimization not worth the effort amount of gas/bytecode it allows to save is extremely negligeble and would like to maintain code with using strict comparison such as == instead of != without using require (if statement is cheaper)