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

Address 0 checks can be done in assembly

Summary

If statements that check if an address value is equal to zero can be done using assembly instead to save the user some gas.

Vulnerability Details

4 instances of if statements that check the value of an address to ensure it's not zero can be done using assembly to save the user some gas instead of utilising standard solidity. Both the zero check and the revert with the custom error can be completed in this.

The identified instances (included in the relevant links) can be seen below:

Escrow.sol:constructor() Line 40

if (address(tokenContract) == address(0)) revert Escrow__TokenZeroAddress();

Escrow.sol:constructor() Line 41

if (buyer == address(0)) revert Escrow__BuyerZeroAddress();

Escrow.sol:constructor() Line 42

if (seller == address(0)) revert Escrow__SellerZeroAddress();

Escrow.sol:constructor() Line 103

if (i_arbiter == address(0)) revert Escrow__DisputeRequiresArbiter();

Impact

The cost of the functionality is higher than it needs to be for the end user and chain.

Tools Used

  • VS Code

  • Foundry

  • Manual reading

Recommendations

For each instance, change the if statement and revert to use assembly. An example of how this can be achieved can be seen below:

// check if token contract address is 0
if iszero(_tokenAddr) {
mstore(0x00, <selector>) // add selector for `Escrow__TokenZeroAddress()`.
revert(0x1c, 0x04)
}

Support

FAQs

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