Member-only story
Solidity Tutorial: All About Code
Understanding the structure and behaviour of a smart contract’s bytecode
Part 5 of the “All About Data Locations” subseries.
This article focuses on the last data locations of the EVM that are accessible in Solidity: the bytecode of a smart contract.
We will look at most aspects of a contract’s bytecode at the architecture level. This includes some detailed explanations of “where the bytecode of a smart contract is stored” and the difference between creation and runtime code.
We will also demystify the bytecode that runs when we deploy a smart contract to understand how that works when we deploy a smart contract with no constructor
. This will help us understand how (and why) the EVM returns the runtime code of a smart contract to save it in Ethereum’s world state under the smart contract’s address.
We will finally look at some security caveats around the isContract()
function from the OpenZeppelin library that directly relate to the EXTCODESIZE
opcode.
Table of Contents
Basics of Code
Layout of Code
Where Is the Code of a Smart Contract Stored?
Creation vs Runtime Code
How Contract (Runtime) Code Is Generated
The Caveats of isContract() and EXTCODESIZE
Accessing Contract Code in Solidity