0

How can I redeploy a different smart contract on the same address after selfdestruct()?

I know that with CREATE2 I can place a smart contract on a specific address. But after I remove the source code from that address through selfdestruct() how can I redeploy a different smart contract on that same address?

OrionN
  • 23
  • 4

1 Answers1

2

If the contract was deployed using CREATE opcode (the normal contract deployment), then it's impossible. Because the address is calculated based on the deployer's nonce new_address is derived from keccak256(sender, nonce). And your deployer nonce is always increasing.

If the contract was deployed using CREATE2 opcode in EIP-1014 then YES, it's possible because the contract address is deterministic: new_address is derived from keccak256(0xFF, sender, salt, bytecode). You can take a look at how to use CREATE2 in very details from openzeppelin

About CREATE2, although the address is computed using hash of the bytecode, there was an interesting method to deploy arbitrary bytecode on the same address with this Metamorphosis Smart Contracts pattern

minhhn2910
  • 1,740
  • 4
  • 14
  • But so when you see a contract that was "Reinit" on Etherscan, does it mean it has the same bytecode, or do people brute-force their way into finding a salt that gives the same address for a given new bytecode? – Mouradif Feb 09 '24 at 16:21