pcaversaccio / createx

Factory smart contract to make easier and safer usage of the `CREATE` and `CREATE2` EVM opcodes as well as of `CREATE3`-based (i.e. without an initcode factor) contract creations.
https://createx.rocks
GNU Affero General Public License v3.0
342 stars 26 forks source link

💥 Discussion: Comments on Current Version #1

Closed mds1 closed 1 year ago

mds1 commented 1 year ago

Comments on the current version, which is commit bbbd299:

pcaversaccio commented 1 year ago

[ ] 1. Can't tell what the guard modifier is just from it's name, maybe something like preventCrossChainRedeploy but that's verbose.

Yeah, I agree. What about xchainRedeployGuard?

[ ] 7. deployCreate2(initCode): maybe include block.difficulty/prevrandao there also?

So your proposal would be like that (or should I keep block.timestamp)? I mean in any case it doesn't increase the entropy much, and is anyways still pseudo-randomly:

function deployCreate2(bytes memory initCode) public payable returns (address newContract) {
    return
        deployCreate2(
            keccak256(abi.encode(block.prevrandao, blockhash(block.number))),
            initCode
        );
}
mds1 commented 1 year ago

Yeah, I agree. What about xchainRedeployGuard?

works for me!

[ ] 7. deployCreate2(initCode): maybe include block.difficulty/prevrandao there also?

So your proposal would be like that (or should I keep block.timestamp)? I mean in any case it doesn't increase the entropy much, and is anyways still pseudo-randomly:

function deployCreate2(bytes memory initCode) public payable returns (address newContract) {
    return
        deployCreate2(
            keccak256(abi.encode(block.prevrandao, blockhash(block.number))),
            initCode
        );
}

I think ideally we should try to ensure the pseudo-random number is always unique, regardless of chain. For example on arbitrum block.prevrandao always returns a constant of 1, and blockhash is just a cryptographically insecure, pseudo-random hash for x, and it wouldn't surprise me if some chains just have a constant value there. Since this will be deployed on many chains, we might want to load up the pseudo-random salt with various params to ensure as much uniqueness as possible. All the block property opcodes are really cheap anyway, so maybe we do:

bytes32 salt = keccak256(
    abi.encode(
        blockhash(block.number),
        block.coinbase,
        block.number,
        block.timestamp,
        block.prevrandao,
        block.chainid,
        msg.sender
    )
);

I can see an argument where this feels like overkill, but it does only cost 32 gas to use all those opcodes (blockhash is 20 gas) so maybe this is the safest way to do it

pcaversaccio commented 1 year ago

works for me!

cool, will use xChainRedeployGuard

I think ideally we should try to ensure the pseudo-random number is always unique, regardless of chain. For example on arbitrum block.prevrandao always returns a constant of 1, and blockhash is just a cryptographically insecure, pseudo-random hash for x, and it wouldn't surprise me if some chains just have a constant value there. Since this will be deployed on many chains, we might want to load up the pseudo-random salt with various params to ensure as much uniqueness as possible. All the block property opcodes are really cheap anyway, so maybe we do:

bytes32 salt = keccak256(
    abi.encode(
        blockhash(block.number),
        block.coinbase,
        block.number,
        block.timestamp,
        block.prevrandao,
        block.chainid,
        msg.sender
    )
);

I can see an argument where this feels like overkill, but it does only cost 32 gas to use all those opcodes (blockhash is 20 gas) so maybe this is the safest way to do it

Ok, yeah better safe than sorry here indeed.

pcaversaccio commented 1 year ago

Missing methods:

  • [ ] 8.1 The create2 section is missing methods that have onlyMsgSender without guard. Sample use case: I want the same address on all chains, but don't want others to be able to deploy
  • [ ] 8.2 Similarly the create3 section is missing versions with only the guard no onlyMsgSender modifier. Sample use case: I want the same address on all chains and anyone should be able to deploy it
  • [ ] 8.3 We should make sure each deployment opcode (create/create2/create3) supports any combination of modifiers (none, guard, onlyMsgSender, both)