40,000 USDC
View results
Submission Details
Severity: gas

Make the Escrow constructor payable

Summary

Making constructors payable saves gas on deployment.

Vulnerability Details

Upon contract deployment, if the constructor is not payable, additional opcodes are generated to check if any ETH has been sent in the call, and revert if true. Having a payable constructor results in this check not being performed, thereby saving on deployment size and cost. Since the Escrow contract will be deployed many times, it is worth having this optimization.

After making the Escrow constructor payable, there was a gas saving of 15 gas on each test, and a total reduction of 405 gas across all tests. In addition, deployment size reduced by 6 bytes whereas deployment cost fell by 95 gas. This means a saving of ~100 gas on each Escrow deployment.

Impact

Gas

Tools Used

Forge, Foundry Toolkit (gas report, gas snapshots)

Recommendation

Make Escrow constructor payable.

Support

FAQs

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