Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create2 code works on remix but don't work on hardhat #5791

Open
ddomeke opened this issue Sep 28, 2024 · 4 comments
Open

create2 code works on remix but don't work on hardhat #5791

ddomeke opened this issue Sep 28, 2024 · 4 comments
Assignees
Labels
status:needs-more-info There's not enough information to start working on this issue

Comments

@ddomeke
Copy link

ddomeke commented Sep 28, 2024

Version of Hardhat

2.22.12

What happened?

    assembly {
        // Prepare the contract creation code for the clone
        mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
        mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
        instance := create2(0, 0x09, 0x37, salt)
    }
    // Revert if the clone operation failed
    if (instance == address(0))
        revert CloneOpCancelled("Creation Failed");
    
    // Call the initialization function of the newly cloned contract
    (bool success, ) = instance.call(initData);

Minimal reproduction steps

this code works on remix ide on polygon mainnet. but when I use it on polygon mainnet fork for testing it gives initialization fail error. I use another version of assembly code, it passes initialization but could not generate abi correctly.

        let pointer := mload(0x40)
    
        // mstore 32 bytes at the start of free memory 
        mstore(pointer, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)

        // overwrite the trailing 0s above with implementation contract's address in bytes
        mstore(add(pointer, 0x14), implementation)
        
        // store 32 bytes to memory starting at "clone" + 40 bytes
        mstore(add(pointer, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
  
        instance := create2(0, pointer, 0x37, salt) 

Search terms

create2 on hardhat

@ddomeke
Copy link
Author

ddomeke commented Oct 8, 2024

Does anyone have any information on this subject?

@kanej
Copy link
Member

kanej commented Oct 21, 2024

To clarify, your issue here is that you can run the code on Polygon mainnet (via remix), but when you run the Solidity code against a forked version of Polygon mainnet you are getting a Hardhat error?

Could you provide the error you are seeing? This could potentially be an issue in our underlying runtime (EDR) during forking.

@kanej kanej added status:needs-more-info There's not enough information to start working on this issue and removed status:triaging labels Oct 21, 2024
@ddomeke
Copy link
Author

ddomeke commented Oct 22, 2024 via email

@ddomeke
Copy link
Author

ddomeke commented Oct 31, 2024

Hi John,
This issue can be related with lsb and msb. create2 can not set implementation address correctly into the bytecode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:needs-more-info There's not enough information to start working on this issue
Projects
Status: Backlog
Development

No branches or pull requests

3 participants