OpenZeppelin 5.x fails to compile: Function "mcopy" not found

Error signature:

DeclarationError: Function "mcopy" not found

solidity · hardhat · openzeppelin · compile · verified-in-production · FREE SAMPLE

Cause

OpenZeppelin Contracts 5.x uses the mcopy opcode, which only exists from the Cancun EVM target onward. Hardhat's default evmVersion for solc 0.8.24 targets an older fork.

Fix

Set evmVersion to 'cancun' in your Hardhat solidity settings.

solidity: { version: '0.8.24', settings: { evmVersion: 'cancun', optimizer: { enabled: true } } }

Verification

hardhat compile succeeds; previously failed with four mcopy DeclarationErrors from Bytes.sol.

Free sample. Use the storefront search to match another error. Search KnownFix


KnownFix · Markdown version · llms.txt · Cataloged fixes for AI agents, with explicit confidence labels.