8

I'm new to Solidity and it's my first try to write a smart contract using Openzeppelin, Pancakeswap and BEP20 libraries basically to make a BEP-20 token.

When i try to deploy the smart contract, i get the following error : "invalid opcode: opcode 0x5f not defined" and in my case i know that the OpCode must begin with 0x608.... I found that others had the same issue, but i still can't found the errors in my code.

It would be great if someone can help me.

Thanks :)

5 Answers 5

20

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/

1
  • 1
    Oh, you're right. It's working. Thank you :D
    – Mohammed
    Commented May 15, 2023 at 19:22
6

0x5f is the PUSH0 opcode which Solidity 0.8.20 started generating:

This compiler switches the default target EVM version to Shanghai, which means that the generated bytecode will include PUSH0 opcodes. Be sure to select the appropriate EVM version in case you intend to deploy on a chain other than mainnet like L2 chains that may not yet support PUSH0, otherwise, deployment of your contracts will fail.

For deploying to other chains (that do not support 0x5f), you can select the EVM version as follows: solc --evm-version <VERSION> contract.sol

https://docs.soliditylang.org/en/v0.8.20/using-the-compiler.html#setting-the-evm-version-to-target lists other EVM versions like paris, london, berlin.

Alternatively, as suggested by @Zartaj, use an older compiler version.

4

Instead of going back to an older version of Solidity compiler, in hardhat to prevent use of PUSH0 you can try setting evmVersion to a previous version (e.g. paris, which is the one before shanghai) whilst still using the latest compiler version (0.8.21 currently):

solidity: {
    compilers: [
      {
        version: `0.8.21`,
        settings: {
          optimizer: {
            enabled: true,
            runs: 15000
          },
          evmVersion: `paris`
        }
      },
    ],
  },

Polygon announced last week that they’ve just implemented PUSH0 on their zkEVM blockchain. I’ve tested the testnet and it works. zkEVM mainnet will work from 2023-09-10: Polygon zkEVM: Dragon Fruit Upgrade (with New Opcode) Coming to Mainnet Beta

I also tested 140 blockchains today and only found these ones (16%) that support PUSH0 currently:

  • auroraTestnet
  • edgeware
  • edgewareTestnet
  • gnosis
  • chiado
  • goerli
  • mainnet
  • moonbaseAlpha
  • moonbeam
  • moonriver
  • polygonZkEvmTestnet
  • pulsechain
  • pulsechainV4
  • sapphire
  • sapphireTestnet
  • scrollSepolia
  • sepolia
  • syscoin
  • syscoinTestnet
  • taikoTestnetSepolia

Hopefully the many other blockchains will follow, as developers want to be able to use the latest version.

0

I had same error. This is how I fixed it. To fix this error make sure solidity version is less that 0.8.20. I used 0.8.19 both in .sol file and package.json For specific version in package.json use command

npm install [email protected]

After that I re-generate .abi and .bin file using below commands.

if you using npm:

npx solcjs --bin --abi --include-path node_modules/ --base-path . FileName.sol

if you using yarn:

yarn solcjs --bin --abi --include-path node_modules/ --base-path . FileName.sol
0

I was faced with this issue, because ERC721URIStorage.sol from openzeppelin requires solidity 0.8.20+, but truffle build don't work with 0.8.20 by default. So you need set evmVersion as @SKYBITDEV3 mentioned 👌

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.