1

It seems redeploying a contract using bytecode on the blockchain is not possible (even assuming the ABI is known). The reason for this assumption is that the compiled code includes instructions for initialization including any constructor actions, however, the return data on contract initialization written to the block does not include constructor instructions. If it is possible to reconstruct and redeploy with information already extant on the chain, I would love to see how this is possible.

[In a side note: recent versions of the compiler provide "runtime bytecode" which allows one to check the validity of source code. This code should match contract code deployed to the block.]

1
  • You can create an instance of the contract if you know the address and then interact with it. Oct 6, 2018 at 19:53

1 Answer 1

2

You can do that.

Everything on the blockchain is deterministic and immutable. Therefore, a contract cannot exist on the blockchain without a corresponding transaction that deployed it. This transaction will include the constructor arguments and constructor code. This transaction is the first contract transaction shown on Etherscan.io, labeled "contract creation".

You would be able to redeploy an exact replica by sending a raw transaction with the exact same data payload. Context is important in many constructors, e.g. owner = msg.sender. Even if you don't know what all the code does, you would be the msg.sender in this case and you might get desirable effects, e.g. you own the new contract. You could even manipulate the constructor arguments to create a similar deployed contract with different constructor arguments.

It won't be especially easy to decode the payload without source code but it's a matter of degree of difficulty. A tool like this can help you decipher the bytecode. https://ethervm.io/decompile.

Hope it helps.

1
  • 1
    Thanks, I see what you mean. The send code(payload) is stored as well as the return code. The challenge lies in decoding the payload and determining where the constructor code inserts and what it should consist of. Oct 8, 2018 at 20:54

Your Answer

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

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