Johannes Zweng
2 min readMar 2, 2019

--

Regarding question 14 (“Once a smart contract on the Ethereum blockchain is deployed, it can never be changed again.”):

Since 2 days ago the Constantinople upgrade was activated on Ethereum this is no longer completly true.

With Constantinople an additional OP-Code for deploying contracts(CREATE2) was activated which uses a different scheme for address derivation (i.e. the algorithm how the address of the newly created contract is determined).

Before Constantinople the address and the nonce of the contract creator have been used in the address derivation, therefore it was impossible to deploy two times to the same address (as the nonce would have been increased at the time of the second deployment).

The new CREATE2 no longer uses the nonce and therefore allows to derive the same address for contract deployment independent of the creator’s current nonce. In short: CREATE2 allows you to deploy a contract to the same address several times.

Address derivation for CREATE2 (note that there is no nonce in there):

keccak256( 0xFF , sender_address , salt , keccak256( contract_init_code) )

So, if you design a contract which includes the possibility of self-destruction one could deploy this contract to an address, self-destruct it, and deploy a contract to the same address again later in time.

But wait, the init_code of the deployed contract affects the generated address: this looks like it’s not possible to deploy different code to the same address (as different init_code would produce a different address).

But this is not the case. Ethereum contract deployment works like this: not the init_code is the code that gets installed at the contract address, but the code which is returned by the init_code.The init_code gets executed during the deployment transaction and whatever it returns gets installed as code at the contract address.

Thus it’s possible to write static init_code (so it will derive always the same address) which returns different code at each deployment (i.e. by reading code from a state variable of another contract, or returning different code based on external circumstances, like block number, etc... you get the picture).

And voilà: now you can construct a setup which allows you to deploy a contract on the Ethereum blockchain which can have completely different code at a later point in time (really different code, not just different state) on the same address.

Back to question 14: Most contracts cannot be changed after they have been deployed, but it’s not impossible to create contracts which can be changed. :-)

--

--

No responses yet