20,000 USDC
View results
Submission Details
Severity: gas
Valid

Using assembly helper function for checking address(0) can reduce gas.

Summary

Using assembly helper function for checking address(0) can reduce gas.

Vulnerability Details

Using assembly helper function for checking address(0) can reduce gas.
The below pattern will help reduce gas. You can use your own custom error.

error ZeroAddress();

function assembly_notZero(address toCheck) public pure returns(bool success) {
  assembly {
     if iszero(toCheck) {
  	      let ptr := mload(0x40)
  	      mstore(ptr, 0xd92e233d00000000000000000000000000000000000000000000000000000000) // selector for 
                                                                                          // `ZeroAddress()`.                       

  	      revert(ptr, 0x4)
  	  }
   }
 return true;
}

Impact

can cost more gas

Tools Used

Manual review

Recommendations

Using assembly helper function for checking address(0) can reduce gas.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.