Skip to content

Missing proxy bytecode in CREATE3 #2

@rollchad

Description

@rollchad

if let Ok(proxy) = unsafe { RawDeploy::new().salt(salt).deploy(creation_code, value) } {

    pub fn deploy(salt: B256, creation_code: &[u8], value: U256) -> Result<Address> {
        if let Ok(proxy) = unsafe { RawDeploy::new().salt(salt).deploy(creation_code, value) } {
            let deployed = Self::get_deployed(salt)?;

            RawCall::new_static()
                .gas(evm::gas_left())
                .call(proxy, creation_code)
                .map(|ret| sol_data::Address::decode_single(ret.as_slice(), false).unwrap())
                .map_err(|_| CREATE3Error::InitilizationFailed(InitilizationFailed {}))?;

            Ok(deployed)
        } else {
            Err(CREATE3Error::DeploymentFailed(DeploymentFailed {}))
        }
    }

Your code uses creation_code for the proxy. I believe that you should deploy the proxy code in the first call. Here Solmate's implementation

    bytes internal constant PROXY_BYTECODE = hex"67_36_3d_3d_37_36_3d_34_f0_3d_52_60_08_60_18_f3";

    bytes32 internal constant PROXY_BYTECODE_HASH = keccak256(PROXY_BYTECODE);

    function deploy(
        bytes32 salt,
        bytes memory creationCode,
        uint256 value
    ) internal returns (address deployed) {
        bytes memory proxyChildBytecode = PROXY_BYTECODE;

        address proxy;
        assembly {
            // Deploy a new contract with our pre-made bytecode via CREATE2.
            // We start 32 bytes into the code to avoid copying the byte length.
            proxy := create2(0, add(proxyChildBytecode, 32), mload(proxyChildBytecode), salt)
        }
        require(proxy != address(0), "DEPLOYMENT_FAILED");

        deployed = getDeployed(salt);
        (bool success, ) = proxy.call{value: value}(creationCode);
        require(success && deployed.code.length != 0, "INITIALIZATION_FAILED");
    }

https://github.com/transmissions11/solmate/blob/c93f7716c9909175d45f6ef80a34a650e2d24e56/src/utils/CREATE3.sol#L49

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions