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

  • 2
    One use case I can think of is validating that the code of a smart contract can be trusted. – Henk Oct 1 '18 at 15:38
  • Do you mean, something like, "I copy the code in memory, compute the hash and check if it corresponds to the sha3 version I know?" – Briomkez Oct 1 '18 at 15:42
  • yes, something like that – Henk Oct 1 '18 at 16:53

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."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.