Unable to deploy from Remix - invalid opcode: PUSH0

Contracts that I have successfully deployed, to the mumbai testnet, from Remix will no longer deploy. However it does deploy on VM. Even if I import a basic ERC-1155 from the wizard it will no longer deploy instead receive this warning "Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Returned error: {"jsonrpc":"2.0","error":"invalid opcode: PUSH0","id":8474518844492607}"

:1234: Code to reproduce

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts@5.0.0/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts@5.0.0/access/Ownable.sol";

contract MyToken is ERC1155, Ownable {
    constructor(address initialOwner) ERC1155("") Ownable(msg.sender) {}

    function setURI(string memory newuri) public onlyOwner {
        _setURI(newuri);
    }

    function mint(address account, uint256 id, uint256 amount, bytes memory data)
        public
        onlyOwner
    {
        _mint(account, id, amount, data);
    }

    function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
        public
        onlyOwner
    {
        _mintBatch(to, ids, amounts, data);
    }
}

:computer: Environment

Remix

This is because solidity 0.8.20 introduces the PUSH0(0x5f) opcode which is only supported on ETH mainnet and not on any other chains. That's why other chains can't find the PUSH0(0x5f) opcode and throw this error.

Consider using 0.8.19 for other chains.

This should solve your problem.

If you want to learn more about PUSH0 opcode you can check this small article which explains it pretty well. https://www.zaryabs.com/push0-opcode/

but the openzepplin contracts uses solidity v 0.8.20 now how would one take care of that ?

You can also choose a different EVM version, other than shanghai.

2 Likes

Indeed this is caused because of the PUSH0 opcode. It comes from EIP-3855 and was included in the Shanghai upgrade.

Consider that not all chains support PUSH0 at the moment, so compiling using the Shanghai EVM version will error for those chains. The workaround is specifying an older EVM version (eg. Paris) so that the compilation doesn't produce bytecode including the PUSH0 instruction. This can be done in the following menu in Remix (compiler -> advanced configuration):

Captura de pantalla 2023-10-10 a la(s) 8.35.17

The option default is usually the latest (Shanghai). Just select Paris and you'd be fine.

1 Like