ethereum-optimism / optimism-integration

[Optimism] Service Integration & Rapid Development
53 stars 21 forks source link

Deploy failed, and the code is 0x. #107

Open guanzhenxing opened 3 years ago

guanzhenxing commented 3 years ago

Hi, I want to deploy my contract to L2 network, but it failed. The message like this:

20210324091649

And my deploy code is

const deploy = async (factory, payload) => {
    console.log("Deploying with: ".blue, payload);
    const contract = await factory.deploy(...payload);
    return await _finish_and_check_deploy(
        contract,
        factory.provider || factory.signer.provider
    );

};
const _finish_and_check_deploy = async (contract, provider) => {
    const txHash = contract.deployTransaction.hash;
    console.log("Deployed in transaction: ".blue, txHash.green);

    await contract.deployTransaction.wait();
    console.log("Contract address: ".blue, contract.address.green);

    const txReceipt = await provider.getTransactionReceipt(txHash);
    console.log("Receipt: ", txReceipt);

    // Check if code is stored
    const code = await provider.getCode(contract.address);
    console.log("Code: ", code);

    assert(code.length > 2, "Contract NOT deployed (no code)".red);
    console.log("--------\n");
    return contract;
};

I don't understand why the deployment failed. The size of the contract is within the limits.I've tried making the contract a little smaller and it can be deployed successfully.

guanzhenxing commented 3 years ago

I found out that if the contract size is larger than 22,500Byte, the deployment will fail and if it is smaller than 22,500Byte, the deployment will be successful? Is it possible that the contract size limit is not 24KB?

tynes commented 3 years ago

Try pasting your bytecode into isByteCodeSafe to see if its passing the safetychecker - https://etherscan.io/address/0x3F4914B14cb75D83935E4b42Cc27B0BEE21b862c#readContract

The transaction may be running out of gas, also try upping the gas limit

guanzhenxing commented 3 years ago

It's true for safetychecker. And I try upping the gas limit to 8999999, also field.

K-Ho commented 3 years ago

@guanzhenxing - the deployment is probably running out of gas... There's currently not a great way around this other than taking logic out of the constructor or lowering your contract code size further.

guanzhenxing commented 3 years ago

@K-Ho Yes. I agree with you. But my question is, if the limit is 24KB in size, why does the contract fail even if it is less than 24KB in size? Is this a bug?