2

Since solidity 0.8.0, we can now specify the salt for contract creation using new keyword

Using 'new'

bytes32 _salt = bytes32("0x4");
address addr = address(new DummyContract{salt: _salt}());

I am getting different addresses for the same salt used in create2 which calculates address as:

address = first 20 bytes of keccak256(0xff + address(this) + s + keccak256(mem[p…(p+n))) s = big-endian 256-bit value

using 'create2'

address addr;    
bytes memory bytecode = type(DummyContract).creationCode;
    assembly {
        addr := create2(0, add(bytecode, 0x20), mload(bytecode), 4)
        if iszero(extcodesize(addr)) {
            revert(0, 0)
        }
    }

Am I missing something here ?

1 Answer 1

2

"0x4" is interpreted as a string, so the two salts are different.

bytes32("0x4") != 4

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.