gas-optimizations icon indicating copy to clipboard operation
gas-optimizations copied to clipboard

Payable constructor

Open pcaversaccio opened this issue 2 years ago • 1 comments

The payable modifier can also help to reduce deployment costs. You can cut out 10 opcodes in the creation-time EVM bytecode if you declare a constructor payable. The following opcodes are cut out:

  • CALLVALUE
  • DUP1
  • ISZERO
  • PUSH2
  • JUMPI
  • PUSH1
  • DUP1
  • REVERT
  • JUMPDEST
  • POP

In Solidity, this chunk of assembly would mean the following:

if(msg.value != 0) revert();

I've compiled further gas optimisation tricks here.

pcaversaccio avatar Jul 03 '22 10:07 pcaversaccio