3

Deployed: https://rinkeby.etherscan.io/address/0x121e370ae349425d0d744f6db43c2f43e777f972#code

pragma solidity 0.8.3;

contract Test {
    uint256 public a;
    constructor (uint256 _a) public {
        a = _a;
    }
}

contract DeployTest {
    function deploy(bytes32 _salt, uint256 param) public {
        new Test{salt: _salt}(param);
    }
}

Transaction 1

Transaction 2

I was expecting that the new deployment will override the old one?


I was looking at this article: https://hackernoon.com/using-ethereums-create2-nw2137q7

In Solidity assembly, create2() takes 4 parameters: 1: The amount of wei to send to the new contract as msg.value. This is 0 for this example. 2–3: The location of the bytecode in memory 4: The salt — that we will calculate in step 3. We leave this as a parameter so it can we provided after we have calculated it.

I'm not using assembly. I'm using Solidity code and constructor parameters.

I will do some more experiments but maybe you'll know - can I override the existing contract if I use the same salt but different constructor parameters?

4

No it's impossible to override an existing contract in Ethereum. From EIP-684:

If a contract creation is attempted, due to either a creation transaction or the CREATE (or future CREATE2) opcode, and the destination address already has either nonzero nonce, or nonempty code, then the creation throws immediately, with exactly the same behavior as would arise if the first byte in the init code were an invalid opcode. This applies retroactively starting from genesis.

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.