Marking constructors as payable is one of the great ways to optimize contract deployments.
According to a post by pcaversaccio
on Openzeppelin Forum
Thanks to his approach, I have tried it and we saved a bunch of sweet deployment gas.
Here are the results that I've obtained from the Foundry gas snapshot:
Before adding payable constructor
test_EscrowFactoryDeploymentGas() (gas: 1752574)
After Adding Payable Constructor
test_EscrowFactoryDeploymentGas() (gas: 1752552)
1752574 - 1752552 = 22 units of gas
Before adding payable to the constructor :
Deployment Cost | Deployment Size |
---|---|
1863762 | 9139 |
Function Name | min | avg | median | max | # calls |
---|---|---|---|---|---|
run | 1757938 | 1757938 | 1757938 | 1757938 | 1 |
After adding payable // :
Deployment Cost | Deployment Size |
---|---|
1861362 | 9127 |
Function Name | min | avg | median | max | # calls |
---|---|---|---|---|---|
run | 1755538 | 1755538 | 1755538 | 1755538 | 1 |
We can see a sweet difference of 1757938-1755538 = 2400 gas units.
that is huge when the Ethereum Mainnet is in demand.
Foundry, Manual review, pcaversaccio's post
Add payable to the constructor of the Escrow contract.
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.