If a contract A is given an address of another contract B, can it duplicate B and produce B' that has the same code?
Asked
Active
Viewed 1,266 times
2 Answers
2
EDIT: Most of the contract code can be copied, but the constructor code is not actually stored on the blockchain, hence cannot be duplicatd. See comments below for a fuller explanation by Tjaden Hess.
ronme
- 1,035
- 1
- 9
- 18
0
No it can't,if you are using normal solidity a contract could call functions from other contracts, but it cannot read(parse) the other contracts in order to cloning the code. the question why it will be useful to do so? if you want to upgrade the previous code look at this discussion : Upgradeable smart contracts
Badr Bellaj
- 18,780
- 4
- 58
- 75
-
actually looking at the docs, it seems a contract could read another contract's code, just not using Solidity but assembly instructions. http://solidity.readthedocs.io/en/latest/control-structures.html#example Am I getting this wrong? – ronme Oct 21 '16 at 20:16
-
-
Doublethat has a constructor which puts the valueuint a = 2into storage. Then thedouble(uint b){return a+b}function is called. If you don't have the constructor or storage, there would be no way based on just the code to know what this function does. It will just return 0. But barring this type of example, it is certainly possible to just insert some opcodes – Tjaden Hess Oct 22 '16 at 04:55