pcaversaccio / create2deployer

Helper smart contract to make easier and safer usage of the `CREATE2` EVM opcode.
MIT License
286 stars 42 forks source link

Feature Request: Add Further Testnet Deployments #101

Closed dinesh11515 closed 1 year ago

dinesh11515 commented 1 year ago

Ser love this create2Deployer contract i am building a product using your create3Developer we in did need of zkSync Era chains too can you pls deploy this too as soon possible

pcaversaccio commented 1 year ago

@dinesh11515 thanks for the request. Can you please fund the deployer address 0x554282Cf65b42fc8fddc6041eb24ce5E8A0632Ad with enough funds on the chains you need and I will deploy it accordingly.

dinesh11515 commented 1 year ago

Need ZkSync,Mantle,FVM, Scroll testnets I have sent the testnet tokens to that address @pcaversaccio

pcaversaccio commented 1 year ago

Thanks - I will look into those. Actually I don't know yet how to deploy on zksync since they don't follow the usual RLP scheme used by EVMs: https://era.zksync.io/docs/dev/building-on-zksync/contracts/contract-deployment.html#differences-in-create-behaviour

For the ease of supporting account abstraction, for each account, we split the nonce into two parts: the deployment nonce and the transaction nonce. The deployment nonce is the number of contracts the account has deployed with CREATE opcode, while the transaction nonce is used for replay attack protection for the transactions.

This means that while for smart contracts the nonce on zkSync behaves the same way as on Ethereum, for EOAs calculating the address of the deployed contract is not as straightforward. On Ethereum, it can be safely calculated as hash(RLP[address, nonce]), while on zkSync it is recommended to wait until the contract is deployed and catch the ContractDeployed event emitted by ContractDeployer with the address of the newly deployed contract. All of this is done in the background by the SDK.

I simulated the deployment using the zksync hardhat tools and the deployment from my EOA would lead to an incorrect Create2Deployer address. I asked in their discord for help but I can be that it's not possible to deploy it right now.

pcaversaccio commented 1 year ago

https://github.com/pcaversaccio/create2deployer/commit/1eb0b3545382c18cd1ae459fa9aaafece8d2b93e added Mantle and Filecoin. What Scroll testnet did you send the tokens? I couldn't figure it out.

pcaversaccio commented 1 year ago

Ok after a zksync deep-dive, I must inform you that I won't be able to deploy my Create2Deployer there on the address 0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2. Let me elaborate the reason why it won't work:

If you deploy a contract, the zksync system contracts invoke the function create under the hood. This function in turn calls a function createAccount which calls the function getNewAddressCreate. This function looks like the following:

    /// @notice Calculates the address of a deployed contract via create
    /// @param _sender The account that deploys the contract.
    /// @param _senderNonce The deploy nonce of the sender's account.
    function getNewAddressCreate(
        address _sender,
        uint256 _senderNonce
    ) public pure override returns (address newAddress) {
        // No collision is possible with the Ethereum's CREATE, since
        // the prefix begins with 0x63....
        bytes32 hash = keccak256(
            bytes.concat(CREATE_PREFIX, bytes32(uint256(uint160(_sender))), bytes32(_senderNonce))
        );

        newAddress = address(uint160(uint256(hash)));
    }

The issue here is now the CREATE_PREFIX with value 0x63bae3a9951d38e8a3fbb7b70909afc1200610fc5bc55ade242f815974674f23. This will lead to a different derived address than you would expect on any "normal" EVM chain.

The only remaining thing I can do for you is to deploy to the Scroll network if you tell me which test network you sent the tokens to.

pcaversaccio commented 1 year ago

Completed via https://github.com/pcaversaccio/create2deployer/commit/3ccdac4a4ab9aafcf82f1a35cca70036e5969549. For zkSync you will need to find another solution.