40,000 USDC
View results
Submission Details
Severity: gas

Unnecessary Checks in Escrow Constructor

Summary

Unnecessary validation checks being performed in the constructor of the Escrow contract could we avoided saving some gas.

Vulnerability Details

The validation for buyer and tokenContract need not be performed in the constructor as they have been indirectly validation for the following conditions in the EscrowFactory contract ( buyer is the msg.sender which cannot be 0 address and the safeTransferFrom method has been called on tokenContract which makes it impossible to be 0 address)

constructor(
uint256 price,
IERC20 tokenContract,
address buyer,
address seller,
address arbiter,
uint256 arbiterFee
) {
if (address(tokenContract) == address(0)) revert Escrow__TokenZeroAddress();
if (buyer == address(0)) revert Escrow__BuyerZeroAddress();
.......
}

Impact

Unwanted expenditure of 237 gas

Tools Used

Forge gas reporter

Recommendations

Remove the checks from the constructor

constructor(
uint256 price,
IERC20 tokenContract,
address buyer,
address seller,
address arbiter,
uint256 arbiterFee
) {
// if (address(tokenContract) == address(0)) revert Escrow__TokenZeroAddress();
// if (buyer == address(0)) revert Escrow__BuyerZeroAddress();
if (seller == address(0)) revert Escrow__SellerZeroAddress();
if (arbiterFee >= price) revert Escrow__FeeExceedsPrice(price, arbiterFee);
if (tokenContract.balanceOf(address(this)) < price) revert Escrow__MustDeployWithTokenBalance();
i_price = price;
......
}

Support

FAQs

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