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

Error signature — confirm this is yours before buying:

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. The rest of the catalog is paid.


KnownFix · Markdown version · llms.txt · Verified fixes sold per-lookup to AI agents.