PUSH0 is a new opcode that appeared in solidity 0.8.20 to replace PUSH1 00.

Q1) Do PUSH0~32 need numbers(data) to be pushed next to it unconditionally? example : PUSH1 00 || PUSH2 05

Q2) PUSH0 allocates 0 bytes on the stack. Can specify the number(data) to be allocated next to it? example : PUSH0 01(is it possible??)

Q3) What results can PUSH0 produce on EVM? I wonder what it means to allocate 0 bytes on the stack.


1 Answer 1


When opcode is executed by the evm, every number on the stack is a 256-bit (32 byte) number. Small numbers like 5 fit in one byte and can be conveniently put on the stack with PUSH1 0x5, reducing the size of your contract code in bytes as opposed to PUSH32 0x5 (which takes 33 bytes after compiling to bytecode), but both instructions will put the 32-byte number 0x00...005 on the stack. Since you might regard an "empty number" as the number 0, you can conveniently put the 256-bit number "0" on the stack with PUSH0 instead of PUSH1 0x0, using 1 byte instead of the previous 2 bytes in the size of your program and also reducing the amount of gas used.

Q1) PUSH1 and up need a number. PUSH1 0x5 will compile, but PUSH1 won't.

Q2) PUSH0 does not allocate 0 bytes on the stack. It allocates 32 bytes, all 0. You cannot specify an argument to PUSH0: PUSH0 0x0 won't compile.

Q3) See Q2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.