2

Why does Ethereum store bytecode on the blockchain and not the source code, what's the tradeoff?

As far as I know, a source code does not need as much storage.

2 Answers 2

1

Source code is for humans to read and write. Bytecode is for machines.

From Wikipedia:

In computing, source code is any collection of computer instructions, possibly with comments, written using a human-readable programming language, usually as plain text. ... The source code is often transformed by an assembler or compiler into binary machine code understood by the computer. The machine code might then be stored for execution at a later time.

That's exactly what's going on here.

Also consider that different versions of the Solidity compiler output different bytecode. It's easy to specify exactly what each piece of bytecode should do, but would be very hard to incorporate a human readable language into the EVM.

2
  • Would it be correct to say source code needs less storage space on the blockchain, but does not perform so well in terms of performance?
    – Ini
    Commented Mar 22, 2018 at 20:43
  • 1
    hmmm, I just checked source code and binary size of the greeter.sol example contract. I was surprised that source was larger... so it seems that in the case of solidity output, you are correct.
    – maurelian
    Commented Mar 23, 2018 at 20:02
0

You can write a smart contract in many languages like Solidity, Vyper, Yul, Mutan, Serpent, etc. They all have different syntaxes. That is why source code is compiled into the same standard bytecode for EVM.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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