In Remix and Ropsten, the bytecode of a contract is different

Viewed 387

The contract which I compile in Remix and depoly on Ropsten.

pragma solidity ^0.5.11;

contract Deployer {
    constructor() public {
        bytes memory bytecode = hex'61000061000061000061000061006161000301610000619789f100';
        assembly {
            return (add(bytecode, 0x20), mload(bytecode))
        }
    }
}

Its bytecode in Remix is

{
    "linkReferences": {},
    "object": "6080604052348015600f57600080fd5b5060606040518060400160405280601b81526020017f61000061000061000061000061006161000301610000619789f10000000000008152509050805160208201f3fe",
    "opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH1 0xF JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x60 PUSH1 0x40 MLOAD DUP1 PUSH1 0x40 ADD PUSH1 0x40 MSTORE DUP1 PUSH1 0x1B DUP2 MSTORE PUSH1 0x20 ADD PUSH32 0x61000061000061000061000061006161000301610000619789F1000000000000 DUP2 MSTORE POP SWAP1 POP DUP1 MLOAD PUSH1 0x20 DUP3 ADD RETURN INVALID ",
    "sourceMap": "28:241:0:-;;;53:213;8:9:-1;5:2;;;30:1;27;20:12;5:2;53:213:0;85:21;:83;;;;;;;;;;;;;;;;;;;238:8;232:15;225:4;215:8;211:19;203:45"
}

Its runtime bytecode is

{
    "linkReferences": {},
    "object": "6080604052600080fdfea265627a7a7231582046db7afc80e31555b0d8a4dd3357ac5c36930b00fef8a32c2746b725244550ae64736f6c63430005110032",
    "opcodes": "PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x0 DUP1 REVERT INVALID LOG2 PUSH6 0x627A7A723158 KECCAK256 CHAINID 0xDB PUSH27 0xFC80E31555B0D8A4DD3357AC5C36930B00FEF8A32C2746B7252445 POP 0xAE PUSH5 0x736F6C6343 STOP SDIV GT STOP ORIGIN ",
    "sourceMap": "28:241:0:-;;;;;"
}

But when I deploy it to the Ropsten:https://ropsten.etherscan.io/address/0xCE1e482Bb5600f7DE9d316bcd30fb53cBAd4DcBe#code

Its bytecode is

0x61000061000061000061000061006161000301610000619789f100

I want to know what is the reason for this situation.

1 Answers

The Remix bytecode export contains the bytecode variable definition and assembly block without the constructor being executed - just the actual definitions compiled to bytecode.


Constructor usually returns the contract instance (including its parent contracts and imported libraries). But in this case, the assembly block forces the EVM to not return the contract instance, but to return the value of the bytecode variable from the constructor.

Then the deployment process continues as usual - the EVM stores the constructor return value (usually the contract instance, now the bytecode) into the contract storage.

Related