Stack Exchange Network
Stack Exchange network consists of 181 Q&A communities including
Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
The best answers are voted up and rise to the top
4 years, 8 months ago
I am wondering, what is the purpose of the
EXTCODECOPY bytecode instruction? I don't see any advantage in copying the code of another contract in memory.
I am a little bit confused, because of the existence of other instructions, such as
DELEGATECALL that really "use" the code of another contract
Oct 1, 2018 at 7:37
1,854 1 1 gold badge 10 10 silver badges 31 31 bronze badges
It is used to check and compare a contract's bytecode, similar to comparing a known hash of a download file to confirm its legitimacy. The best description of why it is useful (and suggestions as to how to make it better), can be seen
here in EIP 1052.
Many contracts need to perform checks on a contract's bytecode, but do not necessarily need the bytecode itself. For instance, a contract may want to check if another contract's bytecode is one of a set of permitted implementations, or it may perform analyses on code and whitelist any contract with matching bytecode if the analysis passes.
Oct 1, 2018 at 23:38
Shane Fontaine Shane Fontaine
17.2k 17 17 gold badges 50 50 silver badges 81 81 bronze badges
An unconventional of
EXTCODECOPY is to use a deployed contract as the "storage" of another contract, as is is done by this library:
The rationale is that writing/reading data in the contract code region can become cheaper than writing/reading data in the storage region.
Cheaper storage reads (vs SLOAD) after 32 bytes
Cheaper storage writes (vs SSTORE) after 32 bytes (auto-gen key)
Cheaper storage writes (vs SSTORE) after 96 bytes (custom key)
blog post from Zefram Lou has additional information about it.
Jan 1, 2022 at 22:54
159 1 1 silver badge 5 5 bronze badges
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our
Accept all cookies
Necessary cookies only