hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

opcode create always return zero address if no require check

Open JeremyX2022 opened this issue 6 months ago • 1 comments

Version of Hardhat

2.22.7

What happened?

    function func1(bytes memory code) public {
        address addr;
        assembly {
            addr := create(callvalue(), add(code, 0x20), mload(code))
        }
        emit Deployed(addr);
    }

    function func2(bytes memory code) public {
        address addr;
        assembly {
            addr := create(callvalue(), add(code, 0x20), mload(code))
        }
        require(addr != address(0));
        emit Deployed(addr);
    }

I'm using remix connected to a local hardhat node network. Providing any same creation code to these 2 functions, the results are different. func1 always results address(0) while the func2 is OK.

Minimal reproduction steps

Try this code:

0x6080604052348015600f57600080fd5b506102048061001f6000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063093c3b9a1461003b57806373c3b2f914610050575b600080fd5b61004e610049366004610115565b610063565b005b61004e61005e366004610115565b6100ba565b600081516020830134f090506001600160a01b03811661008257600080fd5b6040516001600160a01b038216907ff40fcec21964ffb566044d083b4073f29f7f7929110ea19e1b3ebe375d89055e90600090a25050565b600081516020830134f06040519091506001600160a01b038216907ff40fcec21964ffb566044d083b4073f29f7f7929110ea19e1b3ebe375d89055e90600090a25050565b634e487b7160e01b600052604160045260246000fd5b60006020828403121561012757600080fd5b813567ffffffffffffffff81111561013e57600080fd5b8201601f8101841361014f57600080fd5b803567ffffffffffffffff811115610169576101696100ff565b604051601f8201601f19908116603f0116810167ffffffffffffffff81118282101715610198576101986100ff565b6040528181528282016020018610156101b057600080fd5b8160208401602083013760009181016020019190915294935050505056fea2646970667358221220703335b27726056742f3a58f7417edd792336fc3ec97b5fe28a8c277c0bdf3ca64736f6c634300081a0033

Search terms

No response

JeremyX2022 avatar Aug 10 '24 06:08 JeremyX2022