I am trying to analyse the bytecode of creating a contract and I can't figure out why there is a need for the
006 DUP1 opcode in the snippet below.
000 PUSH1 80 002 PUSH1 40 004 MSTORE 005 CALLVALUE 006 DUP1 007 ISZERO 008 PUSH2 0010 011 JUMPI 012 PUSH1 00 014 DUP1 015 REVERT 016 JUMPDEST 017 POP ...
My understanding is that before executing
011 JUMPI the stack will have three items:
0010 [result of 007 ISZERO] [value from 005 CALLVALUE]
011 JUMPI will take two items off the stack, leaving
[value from 005 CALLVALUE]. The next instruction set will be either:
012 PUSH1 00->
015 REVERT(this opcode takes two parameters, so it will take the original and duplicated
012 PUSH1 00; after that no more code will be executed)
017 POP(at this point
[value from 005 CALLVALUE]will be discarded) ->
It seems to me that in both cases the value is not used for anything, so
006 DUP1 can be safely removed from the generated bytecode. What am I missing?
This bytecode has been generated in Remix using the 0.6.4 compiler with optimization enabled.