12

Given the compiled bytecode on the blockchain, is there a way to detect which compiler version is being used in order to verify source matches bytecode without having to bruteforce all available compiler versions / outputs?

7

No, as there is no difference in the output of the bytecode from the simple contract Test {} plugged into Browser-solidity when using different recent versions of the Solidity compiler.

There is some information on how http://etherchain.org checks the contract source code against the contract bytecode at How can I verify that a contract on the blockchain matches the source code? including the note that:

the match you should check is the compiled bytecode against the data of the contract creation tx

This is because the bytecode is executed by the contract creation transaction includes some contract initialisation code.


(Interesting) The question How can I verify that a contract on the blockchain matches the source code? has an answer by @mKoeppelmann with a link to EtherScrape that tries matching contract source code to bytecode using some pattern matching technique, but this site does not seem up-to-date.



Some Details

There are two different bytecodes generated by the Solidity compiler:

  • Bytecode is the bytecode executed by the transaction that inserts the contract into the blockchain and includes some contract initialisation instructions.
  • Runtime bytecode is the contract code that is inserted into the blockchain.

The following Solidity output was generated from the simple contract Test {} plugged into Browser-solidity for different versions of Solidity, and there is no difference in the output, implying that there is no compiler version information encoded in the bytecode:

  • Solidity version: 0.3.2-dd4300d5/.-Emscripten/clang/Interpreter (latest version available on the website):

    • Bytecode: 6060604052600a8060106000396000f360606040526008565b00
    • Runtime bytecode: 60606040526008565b00
    • Optcodes: PUSH1 0x60 PUSH1 0x40 MSTORE PUSH1 0xA DUP1 PUSH1 0x10 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN PUSH1 0x60 PUSH1 0x40 MSTORE PUSH1 0x8 JUMP JUMPDEST STOP
  • Solidity version: 0.3.0-11d67369/.-Emscripten/clang/Interpreter linked to libethereum-:

    • Bytecode: 6060604052600a8060106000396000f360606040526008565b00
    • Runtime bytecode: 60606040526008565b00
    • Optcodes: PUSH1 0x60 PUSH1 0x40 MSTORE PUSH1 0xA DUP1 PUSH1 0x10 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN PUSH1 0x60 PUSH1 0x40 MSTORE PUSH1 0x8 JUMP JUMPDEST STOP
  • Solidity version: 0.2.2-ef92f566/.-Emscripten/clang/int linked to libethereum-:

    • Bytecode: 6060604052600a8060106000396000f360606040526008565b00
    • Runtime bytecode: 60606040526008565b00
    • Optcodes: PUSH1 0x60 PUSH1 0x40 MSTORE PUSH1 0xA DUP1 PUSH1 0x10 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN PUSH1 0x60 PUSH1 0x40 MSTORE PUSH1 0x8 JUMP JUMPDEST STOP
  • Solidity version: 0.1.6-c881d103/.-Emscripten/clang/int linked to libethereum-1.1.0-c61302f2/.-Emscripten/clang/int:

    • Bytecode: 6060604052600a8060106000396000f360606040526008565b00
    • Runtime bytecode: 60606040526008565b00
    • Optcodes: PUSH1 0x60 PUSH1 0x40 MSTORE PUSH1 0xA DUP1 PUSH1 0x10 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN PUSH1 0x60 PUSH1 0x40 MSTORE PUSH1 0x8 JUMP JUMPDEST STOP
  • Solidity version: 0.3.2-0/Release-Linux/g++/Interpreter on my computer:

    • Bytecode: 6060604052600a8060106000396000f360606040526008565b00
    • Runtime bytecode: 60606040526008565b00
    • Optcodes: PUSH1 0x60 PUSH1 0x40 MSTORE PUSH1 0xA DUP1 PUSH1 0x10 PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN PUSH1 0x60 PUSH1 0x40 MSTORE PUSH1 0x8 JUMP JUMPDEST STOP
  • While reading your answer, there is a question that came into my mine. Is possible to reproduce the Bytecode from the Runtime bytecode? – berrytchaks Nov 17 '17 at 19:54

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.