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 · 0 comments
Open

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

ddomeke opened this issue Sep 28, 2024 · 0 comments
Assignees

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

2 participants