Some of the checks in the constructor of the Escrow Contract are unreachable:
40: if (address(tokenContract) == address(0)) revert Escrow__TokenZeroAddress();
can never be reached because there would already have been a revert in the EscrowFactory Contract since tokens from this address are already transferred.
41: if (buyer == address(0)) revert Escrow__BuyerZeroAddress();
cannot be reached because buyer in EscrowFactory is always passed as msg.sender
, and msg.sender
cannot be the zero address.
Move all the checks to the EscrowFactory Contract, as it also saves gas when all the checks are performed before deploying a new Escrow Contract.
The buyer address does not need to be checked as it is always msg.sender.
Please note: The custom errors needed for the checks must be copied from IEscrow.sol to IEscrowFactory.sol.
Required error messages from IEscrow.sol:
Gas saving when attempting to deploy a new Escrow Contract with the seller's address as the zero address.
src/EscrowFactory.sol:EscrowFactory contract | |||||
---|---|---|---|---|---|
Function Name | min | avg | median | max | # calls |
newEscrow | 76396 | 76396 | 76396 | 76396 | 1 |
src/EscrowFactory.sol:EscrowFactory contract | |||||
---|---|---|---|---|---|
Function Name | min | avg | median | max | # calls |
newEscrow | 410 | 410 | 410 | 410 | 1 |
In this scenario, 75986 gas could be saved. Similar amounts of gas can be saved if other checks revert since the checks are performed before executing the code to deploy the Escrow Contracts.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.