How is it possible to decompile a smart contract bytecode?
Etherscan has an option to decompile bytecode of smart contracts that are not verified/source code is not public. How can they possibly do that and how reliable is the result? https://rinkeby.etherscan.io/bytecode-decompiler
To post an answer, please !
1 answer
52 views
Really great question! Tl;dr decompiling bytecode just means parsing it to a more human readable format. Bytecode is basically machine-readable source code - it's not meant to necessarily be impossible to read or reverse engineer - ultimately, the computers executing the smart contract code need to be able to understand what it's telling them to do! So bytecode describes all the functions written on a smart contract in a way that machines can read them, and that humans can also technically decode - it's just very, very difficult for us to read! So what decompilers do is basically they have a computer parse all the code and then translate it back into a more human readable format. However, this isn't exactly ideal or anything close to having the real source code - decompiled bytecode loses all the comments written in the original source code to describe all the functions, and doesn't exactly write the code the way it was originally written - it just converts it to a standard decompiled format. Smart contracts on Ethereum actually retain a lot more of their function and variable naming than other decompilers would be able to decipher in other situations, so it's actually still pretty surprisingly readable - you can see an example of a decompiled bytecode contract using the Panoramix decompiler that Etherscan relies compared with its original source code here: https://oko.palkeo.com/0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/code/ And you can see all the function names and most of the variable names are preserved, with a few exceptions. The code is also surprisingly readable, though not nearly as readable as the original source code, which you can clearly see in the side by side comparison! Hope that helps! You can read more about how decompilers work from the great Wikipedia article on them: https://en.wikipedia.org/wiki/Decompiler
Not the answer you're looking for? Browse other questions tagged #Smart Contracts or ask your own question.