gas-optimizations
gas-optimizations copied to clipboard
Payable constructor
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.