Skip to content

Latest commit

 

History

History
27 lines (15 loc) · 1.34 KB

File metadata and controls

27 lines (15 loc) · 1.34 KB

contract-compilation-code

When we compile a contract, it's typically split up into:

  1. Contract Creation Code
  2. RunTime Code
  3. Metadata (Optional)

We can find the different sections inside the bytecode by looking to see what sections are unreachable. A good way to start is by looking at the RETURN (F3 opcode). Another opcode we can look at is the CODECOPY (39 opcode).

The solidity compiler adds an INVALID (FE opcode) opcode between these three sections to make them easier to locate.

Example:

0x6080604052348015600e575f80fd5b5060a58061001b5f395ff3fe6080604052348015600e575f80fd5b50600436106030575f3560e01c8063cdfead2e146034578063e026c017146045575b5f80fd5b6043603f3660046059565b5f55565b005b5f5460405190815260200160405180910390f35b5f602082840312156068575f80fd5b503591905056fea26469706673582212203c3af38923feca7980db1c48c560b3b78628481d265a59e1ef576264e3cf37d164736f6c63430008140033

Contract Creation Code:

0x6080604052348015600e575f80fd5b5060a58061001b5f395ff3fe

Runtime Code:

6080604052348015600e575f80fd5b50600436106030575f3560e01c8063cdfead2e146034578063e026c017146045575b5f80fd5b6043603f3660046059565b5f55565b005b5f5460405190815260200160405180910390f35b5f602082840312156068575f80fd5b503591905056fea26469706673582212203c3af38923fe

Metadata:

ca7980db1c48c560b3b78628481d265a59e1ef576264e3cf37d164736f6c63430008140033