1

the wallet A deploy a contract using CREATE(wallet,nonce) to the X address.

the contract at X can be self-destruct.

Is it possible for the same wallet A to deploy to the X address a new contract using CREATE2(wallet,salt,bytecode) ?

Thank you by advance

2
  • interesting question, though I wouldn't rely on this feature because they want to delete it in the future: eips.ethereum.org/EIPS/eip-4758
    – Nulik
    Commented Dec 21, 2022 at 15:13
  • a brief look at the sources tells that it is possible to recreate selfdestructed state object , well, at least there is no check for history of what happened in the past with this address
    – Nulik
    Commented Dec 21, 2022 at 15:14

2 Answers 2

0

Looks like you actually can.

I put this code in remix:


contract target{
    uint public myUint;

    constructor() {
        myUint = 1;
    }

    function destroy() external {
        selfdestruct(payable(address(0)));
    }
}


contract Example {

    function deploy(uint _salt) public returns(address newContract) {

        bytes memory bytecode = type(target).creationCode;
        assembly {
            newContract := create2(0, add(bytecode, 32), mload(bytecode), _salt)
        }
    }
}

And I can deploy a target contract with the deploy() function (contract is at address 0x733C8B6...). I can call the myUint to check that it's = 1. Then I can call destroy() of the target contract and check that myUint = 0 since the contract was destroyed. From there, I can call the deploy() function again and the newly created contract will also be at address 0x733C8B6!.

Try it yourself. Hope this helps!

0

It's not possible. Read: https://eips.ethereum.org/EIPS/eip-1014. The formula for contract address with CREATE2 is prefixed with 0xff on purpose to avoid collisions with CREATE. The formula for address with CREATE is derived from RLP encoding of address and nonce and the first byte in RLP encoding signifies length, which is at most 52 bytes for address + nonce. However, 0xff implies petabytes of data, which is clearly impossible.

Your Answer

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

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