The newEscrow
function could be optimized to fail earlier on invalid inputs, saving users on gas costs in the event of a failed transaction.
The newEscrow
function in the EscrowFactory contract could be optimized to perform input validation earlier.
The following require
statements could be checked earlier in the function:
- require(address(tokenContract) != address(0), "EscrowFactory: tokenContract must not be the zero address");
- require(seller != address(0), "EscrowFactory: seller must not be the zero address");
- require(arbiterFee < price, "EscrowFactory: arbiterFee must be less than price");
Currently, these checks are performed after several other operations, which means users will spend unnecessary gas when these conditions are not met.
Comparing the gas costs of failed transactions with and without the proposed changes shows a significant difference.
Without changes

With changes

Manual analysis, Foundry
To avoid unnecessary gas costs for users, it is recommended to perform input validation earlier in the newEscrow
function:
While this change will slightly increase the gas cost for successful transactions, it will have a much greater impact on reducing gas costs for failed transactions, benefiting the codebase as a whole.
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.