pcaversaccio / createx

Factory smart contract to make easier and safer usage of the `CREATE` and `CREATE2` EVM opcodes as well as of `CREATE3`-based (i.e. without an initcode factor) contract creations.

Home Page:https://createx.rocks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

⚡️ Gas Reports Summary for `CreateX`

pcaversaccio opened this issue · comments

Context

Gas reports for CreateX:

forge test --gas-report

I get the impression that the forge gas reports are not so reliable in profiling the gas costs for CreateX (some numbers are just blatantly wrong).

Summary Runtime Costs

image

Source.

My personal opinion is that we should not use a via_ir = true configuration due to the following reasons:

  • Deployment costs should not matter (via_ir wins here),
  • The new pipeline doesn't offer any huge gas savings (I always use the default optimiser steps dhfoDgvulfnTUtnIf),
  • Block explorer verification will be easier by not using via_ir since otherwise you must upload a standard JSON input file as Etherscan and Blockscout don't allow in the UI to configure the optimiser settings.

➛ My personal opinion is to choose optimizer_runs = 6_942_000 since optimizer_runs = 10_000_000 doesn't offer any additional significant gas savings & because of the meme factor 😄.

Option 1

Configuration:

  • optimizer = true
  • optimizer_runs = 6_942_000
  • via_ir = false
| src/CreateX.sol:CreateX contract                                    |                 |                     |                     |                     |         |
|---------------------------------------------------------------------|-----------------|---------------------|---------------------|---------------------|---------|
| Deployment Cost                                                     | Deployment Size |                     |                     |                     |         |
| 2370524                                                             | 12054           |                     |                     |                     |         |
| Function Name                                                       | min             | avg                 | median              | max                 | # calls |
| computeCreate2Address(bytes32,bytes32)                              | 559             | 559                 | 559                 | 559                 | 1       |
| computeCreate2Address(bytes32,bytes32,address)                      | 580             | 580                 | 580                 | 580                 | 37      |
| computeCreate3Address(bytes32)                                      | 551             | 551                 | 551                 | 551                 | 1       |
| computeCreate3Address(bytes32,address)                              | 648             | 648                 | 648                 | 648                 | 13      |
| computeCreateAddress(address,uint256)                               | 582             | 907                 | 918                 | 1011                | 9       |
| computeCreateAddress(uint256)                                       | 539             | 739                 | 739                 | 940                 | 2       |
| deployCreate                                                        | 32866           | 4468696730258534196 | 4468696730258690252 | 8937393460516723417 | 4       |
| deployCreate2(bytes)                                                | 34455           | 1787478692103751147 | 672889              | 8937393460516702614 | 5       |
| deployCreate2(bytes32,bytes)                                        | 34228           | 2234348365129359616 | 353432              | 8937393460516697372 | 4       |
| deployCreate2AndInit(bytes,bytes,(uint256,uint256))                 | 35063           | 893739346052220707  | 683843              | 8937393460516689843 | 10      |
| deployCreate2AndInit(bytes,bytes,(uint256,uint256),address)         | 35154           | 893739346052222859  | 683936              | 8937393460516689730 | 10      |
| deployCreate2AndInit(bytes32,bytes,bytes,(uint256,uint256))         | 1883            | 1117174182564938042 | 681904              | 8937393460516721268 | 8       |
| deployCreate2AndInit(bytes32,bytes,bytes,(uint256,uint256),address) | 2787            | 1489565576753136221 | 685888              | 8937393460516690343 | 6       |
| deployCreate2Clone(address,bytes)                                   | 48537           | 1787478692103388783 | 74846               | 8937393460516690542 | 5       |
| deployCreate2Clone(bytes32,address,bytes)                           | 48413           | 1787478692103389766 | 77011               | 8937393460516692031 | 5       |
| deployCreate3(bytes)                                                | 77062           | 3790412405130131143 | 724440              | 8937393460516392418 | 7       |
| deployCreate3(bytes32,bytes)                                        | 1254            | 4433785037053310919 | 4398873343848424821 | 8937393460516392781 | 4       |
| deployCreate3AndInit(bytes,bytes,(uint256,uint256))                 | 45706           | 1477928345684875189 | 735349              | 8937393460516361104 | 12      |
| deployCreate3AndInit(bytes,bytes,(uint256,uint256),address)         | 45664           | 1477928345684879200 | 735462              | 8937393460516361934 | 12      |
| deployCreate3AndInit(bytes32,bytes,bytes,(uint256,uint256))         | 2712            | 2533591449744862282 | 732319              | 8937393460516362238 | 7       |
| deployCreate3AndInit(bytes32,bytes,bytes,(uint256,uint256),address) | 2787            | 2412080621446464731 | 732329              | 8937393460516362773 | 11      |
| deployCreateAndInit(bytes,bytes,(uint256,uint256))                  | 33399           | 1117174182564945483 | 679699              | 8937393460516702624 | 8       |
| deployCreateAndInit(bytes,bytes,(uint256,uint256),address)          | 33602           | 1489565576753248846 | 684813              | 8937393460516702481 | 6       |
| deployCreateClone                                                   | 53260           | 2979131153505611705 | 75423               | 8937393460516706433 | 3       |

Option 2

Configuration:

  • optimizer = true
  • optimizer_runs = 10_000_000
  • via_ir = false
| src/CreateX.sol:CreateX contract                                    |                 |                     |                     |                     |         |
|---------------------------------------------------------------------|-----------------|---------------------|---------------------|---------------------|---------|
| Deployment Cost                                                     | Deployment Size |                     |                     |                     |         |
| 2370524                                                             | 12054           |                     |                     |                     |         |
| Function Name                                                       | min             | avg                 | median              | max                 | # calls |
| computeCreate2Address(bytes32,bytes32)                              | 559             | 559                 | 559                 | 559                 | 1       |
| computeCreate2Address(bytes32,bytes32,address)                      | 580             | 580                 | 580                 | 580                 | 43      |
| computeCreate3Address(bytes32)                                      | 551             | 551                 | 551                 | 551                 | 1       |
| computeCreate3Address(bytes32,address)                              | 648             | 648                 | 648                 | 648                 | 17      |
| computeCreateAddress(address,uint256)                               | 582             | 908                 | 964                 | 1011                | 9       |
| computeCreateAddress(uint256)                                       | 539             | 763                 | 763                 | 987                 | 2       |
| deployCreate                                                        | 32866           | 4468696730258534060 | 4468696730258690281 | 8937393460516722812 | 4       |
| deployCreate2(bytes)                                                | 34455           | 1787478692103749828 | 672889              | 8937393460516696018 | 5       |
| deployCreate2(bytes32,bytes)                                        | 2101            | 3574957384206698057 | 34248               | 8937393460516722935 | 5       |
| deployCreate2AndInit(bytes,bytes,(uint256,uint256))                 | 35063           | 893739346052218787  | 683843              | 8937393460516690742 | 10      |
| deployCreate2AndInit(bytes,bytes,(uint256,uint256),address)         | 35154           | 893739346052223528  | 683936              | 8937393460516689718 | 10      |
| deployCreate2AndInit(bytes32,bytes,bytes,(uint256,uint256))         | 34138           | 1276770494359928442 | 683559              | 8937393460516691677 | 7       |
| deployCreate2AndInit(bytes32,bytes,bytes,(uint256,uint256),address) | 1961            | 1489565576753130647 | 685878              | 8937393460516689238 | 6       |
| deployCreate2Clone(address,bytes)                                   | 55145           | 2234348365129223652 | 74846               | 8937393460516689771 | 4       |
| deployCreate2Clone(bytes32,address,bytes)                           | 1367            | 1489565576752828240 | 75322               | 8937393460516692169 | 6       |
| deployCreate3(bytes)                                                | 77062           | 3790412405130131095 | 724440              | 8937393460516392256 | 7       |
| deployCreate3(bytes32,bytes)                                        | 76801           | 4422147805985031721 | 4398873343848423992 | 8937393460516392754 | 6       |
| deployCreate3AndInit(bytes,bytes,(uint256,uint256))                 | 45553           | 1477928345684875038 | 735349              | 8937393460516361197 | 12      |
| deployCreate3AndInit(bytes,bytes,(uint256,uint256),address)         | 77746           | 1612285468019864591 | 735462              | 8937393460516361028 | 11      |
| deployCreate3AndInit(bytes32,bytes,bytes,(uint256,uint256))         | 2699            | 1773514014821628288 | 734785              | 8937393460516364250 | 10      |
| deployCreate3AndInit(bytes32,bytes,bytes,(uint256,uint256),address) | 1961            | 993043717835569402  | 734413              | 8937393460516361887 | 9       |
| deployCreateAndInit(bytes,bytes,(uint256,uint256))                  | 33399           | 2234348365129531318 | 684741              | 8937393460516721014 | 8       |
| deployCreateAndInit(bytes,bytes,(uint256,uint256),address)          | 33602           | 1489565576753250245 | 684813              | 8937393460516704174 | 6       |
| deployCreateClone                                                   | 46560           | 1489565576752829119 | 49949               | 8937393460516706274 | 6       |

Option 3

Configuration:

  • optimizer = true
  • optimizer_runs = 6_942_000
  • via_ir = true

☠️💀
image

| src/CreateX.sol:CreateX contract                                    |                 |                     |                     |                     |         |
|---------------------------------------------------------------------|-----------------|---------------------|---------------------|---------------------|---------|
| Deployment Cost                                                     | Deployment Size |                     |                     |                     |         |
| 1860013                                                             | 9428            |                     |                     |                     |         |
| Function Name                                                       | min             | avg                 | median              | max                 | # calls |
| computeCreate2Address(bytes32,bytes32)                              | 623             | 623                 | 623                 | 623                 | 1       |
| computeCreate2Address(bytes32,bytes32,address)                      | 770             | 770                 | 770                 | 770                 | 42      |
| computeCreate3Address(bytes32)                                      | 571             | 571                 | 571                 | 571                 | 1       |
| computeCreate3Address(bytes32,address)                              | 607             | 607                 | 607                 | 607                 | 15      |
| computeCreateAddress(address,uint256)                               | 500             | 833                 | 840                 | 956                 | 9       |
| computeCreateAddress(uint256)                                       | 350             | 520                 | 520                 | 690                 | 2       |
| deployCreate                                                        | 32838           | 2234348365129382625 | 393851              | 8937393460516709962 | 4       |
| deployCreate2(bytes)                                                | 34256           | 1787478692103800627 | 757523              | 8937393460516696311 | 5       |
| deployCreate2(bytes32,bytes)                                        | 33336           | 4468696730258552594 | 4468696730258727279 | 8937393460516722482 | 4       |
| deployCreate2AndInit(bytes,bytes,(uint256,uint256))                 | 35056           | 744782788376911022  | 767015              | 8937393460516689916 | 12      |
| deployCreate2AndInit(bytes,bytes,(uint256,uint256),address)         | 35178           | 812490314592995098  | 768254              | 8937393460516690131 | 11      |
| deployCreate2AndInit(bytes32,bytes,bytes,(uint256,uint256))         | 2239            | 1117174182564976152 | 767692              | 8937393460516690333 | 8       |
| deployCreate2AndInit(bytes32,bytes,bytes,(uint256,uint256),address) | 35033           | 1489565576753306014 | 771309              | 8937393460516690212 | 6       |
| deployCreate2Clone(address,bytes)                                   | 54904           | 2234348365129223361 | 74491               | 8937393460516689558 | 4       |
| deployCreate2Clone(bytes32,address,bytes)                           | 53945           | 2234348365129224383 | 76584               | 8937393460516690422 | 4       |
| deployCreate3(bytes)                                                | 76910           | 3790412405130160460 | 799837              | 8937393460516371615 | 7       |
| deployCreate3(bytes32,bytes)                                        | 77005           | 4422147805985053801 | 4398873343848462424 | 8937393460516372836 | 6       |
| deployCreate3AndInit(bytes,bytes,(uint256,uint256))                 | 77401           | 1612285468019912131 | 810018              | 8937393460516341162 | 11      |
| deployCreate3AndInit(bytes,bytes,(uint256,uint256),address)         | 45644           | 1477928345684928134 | 810408              | 8937393460516341280 | 12      |
| deployCreate3AndInit(bytes32,bytes,bytes,(uint256,uint256))         | 1780            | 2216892518526867853 | 808577              | 8937393460516342214 | 8       |
| deployCreate3AndInit(bytes32,bytes,bytes,(uint256,uint256),address) | 2239            | 1612285468019698086 | 809416              | 8937393460516341585 | 11      |
| deployCreateAndInit(bytes,bytes,(uint256,uint256))                  | 33532           | 1489565576753305759 | 768900              | 8937393460516702944 | 6       |
| deployCreateAndInit(bytes,bytes,(uint256,uint256),address)          | 33611           | 1117174182564986586 | 760989              | 8937393460516703673 | 8       |
| deployCreateClone                                                   | 53326           | 2979131153505611625 | 75391               | 8937393460516706158 | 3       |

Option 4

Configuration:

  • optimizer = true
  • optimizer_runs = 10_000_000
  • via_ir = true

☠️💀
image

| src/CreateX.sol:CreateX contract                                    |                 |                     |                     |                     |         |
|---------------------------------------------------------------------|-----------------|---------------------|---------------------|---------------------|---------|
| Deployment Cost                                                     | Deployment Size |                     |                     |                     |         |
| 1860013                                                             | 9428            |                     |                     |                     |         |
| Function Name                                                       | min             | avg                 | median              | max                 | # calls |
| computeCreate2Address(bytes32,bytes32)                              | 623             | 623                 | 623                 | 623                 | 1       |
| computeCreate2Address(bytes32,bytes32,address)                      | 770             | 770                 | 770                 | 770                 | 41      |
| computeCreate3Address(bytes32)                                      | 571             | 571                 | 571                 | 571                 | 1       |
| computeCreate3Address(bytes32,address)                              | 607             | 607                 | 607                 | 607                 | 15      |
| computeCreateAddress(address,uint256)                               | 500             | 816                 | 840                 | 955                 | 9       |
| computeCreateAddress(uint256)                                       | 350             | 520                 | 520                 | 690                 | 2       |
| deployCreate                                                        | 32838           | 2979131153505832505 | 754858              | 8937393460516709820 | 3       |
| deployCreate2(bytes)                                                | 34256           | 1787478692103800716 | 757523              | 8937393460516696759 | 5       |
| deployCreate2(bytes32,bytes)                                        | 2129            | 4468696730258363881 | 4468696730258365250 | 8937393460516722895 | 4       |
| deployCreate2AndInit(bytes,bytes,(uint256,uint256))                 | 35087           | 812490314592992551  | 768150              | 8937393460516690644 | 11      |
| deployCreate2AndInit(bytes,bytes,(uint256,uint256),address)         | 35276           | 893739346052291025  | 768254              | 8937393460516689488 | 10      |
| deployCreate2AndInit(bytes32,bytes,bytes,(uint256,uint256))         | 3118            | 1986087435670725602 | 767440              | 8937393460516720825 | 9       |
| deployCreate2AndInit(bytes32,bytes,bytes,(uint256,uint256),address) | 3062            | 993043717835623063  | 767371              | 8937393460516691473 | 9       |
| deployCreate2Clone(address,bytes)                                   | 48211           | 1489565576752831652 | 64697               | 8937393460516689582 | 6       |
| deployCreate2Clone(bytes32,address,bytes)                           | 47882           | 1787478692103389438 | 76506               | 8937393460516691581 | 5       |
| deployCreate3(bytes)                                                | 76910           | 4416329190450909174 | 4398873343848462089 | 8937393460516370947 | 8       |
| deployCreate3(bytes32,bytes)                                        | 76863           | 4422147805985053576 | 4398873343848462122 | 8937393460516371785 | 6       |
| deployCreate3AndInit(bytes,bytes,(uint256,uint256))                 | 70701           | 1612285468019911552 | 810018              | 8937393460516341258 | 11      |
| deployCreate3AndInit(bytes,bytes,(uint256,uint256),address)         | 77791           | 1612285468019917388 | 810408              | 8937393460516340412 | 11      |
| deployCreate3AndInit(bytes32,bytes,bytes,(uint256,uint256))         | 1780            | 812490314592701599  | 45081               | 8937393460516341757 | 11      |
| deployCreate3AndInit(bytes32,bytes,bytes,(uint256,uint256),address) | 3131            | 2216892518526881854 | 812739              | 8937393460516342081 | 8       |
| deployCreateAndInit(bytes,bytes,(uint256,uint256))                  | 33532           | 1489565576753304705 | 768900              | 8937393460516703320 | 6       |
| deployCreateAndInit(bytes,bytes,(uint256,uint256),address)          | 33599           | 1276770494359981812 | 765475              | 8937393460516704003 | 7       |
| deployCreateClone                                                   | 53326           | 2979131153505611556 | 75391               | 8937393460516705953 | 3       |

Final decision:

  • optimizer = true
  • optimizer_runs = 10_000_000
  • via_ir = false