I'm just going through the first few opcodes on this contract: https://etherscan.io/address/0xab7c74abc0c4d48d1bdad5dcb26153fc8780f83e#code.

Which are (according to the opcodes view):

PUSH1 0x60
PUSH1 0x40
MSTORE
CALLDATASIZE
ISZERO
PUSH2 0x00f8

Based on What OPCODES are available for the Ethereum EVM?, I would expect the bytecode to be 0x6060604052156100f8....

But the bytecode is: 0x60606040526002610108..., which I'm reading as

0x60 0x60      ;; PUSH1 0x60 
0x60 0x40      ;; PUSH1 0x40
0x52           ;; MSTORE
0x60 0x02      ;; PUSH1 0x02???
0x61 0x01 x08  ;; PUSH2 0x01 0x08???

What am I doing wrong?

up vote 3 down vote accepted

There's a difference between the "Contract Creation Code" (which includes the constructor at the front) and the deployed bytecode. The "Bytecodes view" is showing you the full contract creation code with the constructor at the front; the "Opcodes view" is showing you only the actual deployed contract code. The constructor is only run once at contract deployment time in order to create and set up the deployed code; it doesn't appear in the deployed bytecode at all. This is not obvious from the Etherscan user interface! The actually deployed code starts at byte 0x01bf as far as I can tell (big constructor).

You can verify this by accessing the actual deployed bytecode with web3.eth.getCode('0xab7c74abc0c4d48d1bdad5dcb26153fc8780f83e'); the output of which you'll find matches the Opcodes view on Etherscan.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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