8

I have been digging a bit deeper into the Ethereum bytecode with the specific goal to do contract verification from the source code.

I noticed, while doing some tests, that the initial bytes of the Ethereum contract has changed somewhere between 0.4.21 and 0.4.22.

Normally, a contract would always start with:

6060604052 

PUSH1 0x60 PUSH1 0x40 MSTORE

But starting at 0.4.22 and onward, they seem to start with:

6080604052 

PUSH1 0x80 PUSH1 0x40 MSTORE

What is the significance of this change, and where can I find documentation about this change?

1 Answer 1

4

The contract prologue instructions changed to provide an additional slot at 0x60, which should always hold the value 0. The documentation states that:

The zero slot is used as initial value for dynamic memory arrays and should never be written to (the free memory pointer points to 0x80 initially).

FYI I checked several contracts with JEB Decompiler, and it seems they agree with you: contracts with the old prologue (0x60 bytes) are detected as generated by Solidity <= 0.4.21, whereas contracts with the new prologue are detected as >= 0.4.22.

3
  • Very cool reference to the documentation. I also see that the sentence you quote was added to the docs specifically on 0.4.22. Last question I would have is "Why did this change?" Commented Dec 5, 2018 at 1:25
  • Most likely, for optimization purposes: if the compiler knows that the memory word at offset 0x60 is always 0, it can use that to optimize memory-array write operations during initialization or reset. My guess is that (some) constructs like "PUSH 0 / PUSH offset / MSTORE" (used to initialize [offset] to 0) can then be avoided. We would need to see that in code though. If you compile a non-trivial contract making use of memory arrays with a recent version of Solidity, you should be able to see how [0x60] is being used. Commented Dec 5, 2018 at 17:33
  • 1
    the documentation url format was updated, here are the links to 0.4.21 and 0.4.22. docs.soliditylang.org/en/v0.4.21/miscellaneous.html docs.soliditylang.org/en/v0.4.22/miscellaneous.html Commented Feb 12, 2022 at 20:53

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.