4

I extracted opcodes from an already existing and deployed smart contract and I would like to know if it is possible to deploy an exact copy of this contract from its opcodes?

My extracted opcodes looks like this :

0x0, push1, 0x80
0x2, push1, 0x40
0x4, mstore, 
0x5, push1, 0x4
0x7, calldatasize, 
0x8, lt, 
0x9, push2, 0x7f
0xc, jumpi, 
0xd, push1, 0x0
0xf, calldataload, 
0x10, push1, 0xe0
0x12, shr, 
0x13, dup1, 
...

I'm not looking for an alternative (e.g. deploying from bytecode or reverse engineering to source code) but really to deploy from these opcodes. Is that even possible? Or the lowest level possible is inline assembly with Yul?

I'm assuming there is no constructor in the source code. If I manage to deploy this code and send to it the right data (functions and parameters, let's say I have the ABI), will it behave exactly like the already deployed contract I got these opcodes from?

Thanks

  • I believe that from source-code to byte-code, the compiler "goes through" assembly-code. So this is simply a question of 'can we run solc with assembly code as input?'. To begin with, we need to know which version of solc this assembly code was generated with (i.e., what version of solc was used in the source code from which this assembly code was generated). – goodvibration Oct 9 at 10:29
0

Yes, it should be possible. But it is not as easy as it sounds. A contract is composed of two things runtime bytecode and internal state.

  • Runtime: It is not that hard to duplicate the runtime bytecode, with some EVM assembly knowledge. Perhaps someone has already done that in github.

  • State: On the other hand is more complicated since it depends on the contract's constructor. It is possible to trace a contract creation and obtain the transaction that executes the constructor.

The problem with deploying a contract like that is that you are blindly trusting the bytecodes. If it does something else like allowing a third party full access then your giving up the same priviledges into your instance.

| improve this answer | |

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.