Skip to content
PenyuOnCore
Menu
  • Home
  • Core Ecosystem Analysis
  • Personal Finance & Investing
  • Make Money Online
  • Bitcoin
  • About Us
Menu
max code size exceeded error explained: the 24,576-byte EIP-170 contract size limit, enforced on Core mainnet

Max Code Size Exceeded Error: What It Means and How to Fix It

Posted on November 18, 2026

If a deployment fails with max code size exceeded, or the Solidity compiler warns that your “contract code size is X bytes and exceeds 24576 bytes”, your contract’s deployed bytecode is too big for the EVM to store.

Quick answer: EVM chains reject any contract whose runtime bytecode is larger than 24,576 bytes (EIP-170). Shanghai-era chains also cap the creation code (initcode) at 49,152 bytes (EIP-3860). To fix it, turn on the optimizer with a low runs value, try viaIR, replace revert strings with custom errors, and if it’s still too big, move code into external libraries or separate contracts. We tested Core mainnet on 18 November 2026: it enforces the limit to the exact byte.

What “max code size exceeded” means

EIP-170 set MAX_CODE_SIZE to 0x6000 (24,576 bytes) in Ethereum’s Spurious Dragon hard fork. If a contract’s constructor returns more runtime code than that, contract creation fails. That’s why the compiler warning mentions Spurious Dragon. The limit applies to the runtime bytecode that is stored on-chain, not to your source file or the constructor.

EIP-3860 (activated in Shanghai) added a second limit: the initcode you send in a deployment transaction can’t be larger than 2 * MAX_CODE_SIZE, which is 49,152 bytes. Initcode includes the constructor logic, the runtime code it returns, and any ABI-encoded constructor arguments.

The error text comes from Geth-based clients. In go-ethereum’s core/vm/errors.go you’ll find ErrMaxCodeSizeExceeded = errors.New("max code size exceeded") and ErrMaxInitCodeSizeExceeded = errors.New("max initcode size exceeded"). The limits live in params/protocol_params.go as MaxCodeSize = 24576 and MaxInitCodeSize = 2 * MaxCodeSize. Core’s client is a Geth fork, and the core-chain source contains the same error strings and the same 24,576 constant.

The compiler warning

Solidity warns you before you deploy. Compiling our oversized test contract with solc 0.8.38 and no optimizer printed:

Warning: Contract code size is 28696 bytes and exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable on Mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries.

It’s only a warning, so the build succeeds. The failure comes later, when the node simulates or executes the deployment.

Does Core enforce the 24,576-byte limit? (Tested result)

Yes. On 18 November 2026 we sent read-only eth_estimateGas and eth_call requests to https://rpc.coredao.org (chain ID 1116, block ~40,566,970) from an address with zero balance. Nothing was signed or broadcast. The initcode 0x61XXXX5ff3 (PUSH2 size, PUSH0, RETURN) simply returns that many zero bytes as the contract’s runtime code:

curl -s -X POST https://rpc.coredao.org -H 'content-type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"eth_estimateGas","params":[{"from":"0x5a17e57000000000000000000000000000000c0d","data":"0x6160015ff3"}]}'

# 24,576 bytes (0x6160005ff3): {"result":"0x4c7b84"}   (5,012,356 gas, success)
# 24,577 bytes (0x6160015ff3): {"error":{"code":-32000,"message":"max code size exceeded"}}

We also tested the initcode limit by sending 49,152 and 49,153 bytes of initcode. The first estimated fine. The second failed with failed with 20000000 gas: max initcode size exceeded: code size 49153 limit 49152 (from eth_call: err: max initcode size exceeded: code size 49153 limit 49152 (supplied gas 20000000)). So Core behaves like Ethereum on both limits.

Local Anvil (Foundry 1.9.0) enforces the same boundaries but words them differently: EVM error CreateContractSizeLimit for 24,577 bytes of runtime code and max initcode size exceeded for 49,153 bytes of initcode. If you see either message, it’s the same problem.

Bar chart: the same Solidity contract measured with forge build --sizes against the 24,576-byte EIP-170 limit, shrinking from 28,696 bytes to 8,335 bytes with optimizer, via-IR and custom errors

How to fix the max code size exceeded error

Work through these in order. The first three are config or style changes. The rest are architecture changes.

1. Measure your contract sizes

In Foundry, run forge build --sizes (see the forge build reference). It prints runtime and initcode sizes with the remaining margin, and exits with an error when a contract is over the limit:

forge build --sizes
# Error: some contracts exceed the runtime size limit (EIP-170: 24576 bytes)

In Hardhat, install hardhat-contract-sizer (published as @solidstate/hardhat-contract-sizer from v3, hardhat-contract-sizer for older versions) and run npx hardhat size-contracts. Its strict option makes the task fail when a contract is too large.

2. Enable the optimizer with a low runs value

The Solidity optimizer docs describe runs as a trade-off: “1” produces short but more expensive-to-run code, while larger values produce longer, more gas-efficient code. In Hardhat:

solidity: {
  version: "0.8.24",
  settings: {
    optimizer: { enabled: true, runs: 1 },
    viaIR: true
  }
}

In Foundry’s foundry.toml:

[profile.default]
optimizer = true
optimizer_runs = 1
via_ir = true

3. Try viaIR

The IR-based code generator can produce smaller bytecode, though compile times are longer. In our test, the same contract dropped from 18,056 bytes (optimizer, runs=200) to 14,935 bytes with via-IR enabled. Test your full suite afterwards. Results vary by contract.

4. Replace revert strings with custom errors

Every require(cond, "long message") stores the string in your bytecode. Custom errors store only a 4-byte selector plus arguments:

error TooSmall(uint256 op);

// before
require(a > 5, "BigContract: value a is too small for operation number 5");

// after
if (a <= 5) revert TooSmall(5);

That change alone took our unoptimized test contract from 28,696 to 19,279 bytes. With the optimizer and via-IR as well, it reached 8,335 bytes.

5. Remove unused code and needless public getters

Every public state variable generates a getter function, and every function adds dispatcher code. Make variables internal or private when nobody needs to read them on-chain. Delete dead functions, debug helpers and duplicated modifiers. Large modifiers are copied into every function that uses them, so moving their body into an internal function can help.

6. Move logic into libraries with external functions

According to the Solidity docs on libraries, internal library functions are copied into the calling contract at compile time, so they don’t save space. public or external library functions live in a separately deployed library and are called with DELEGATECALL. Your contract only holds the call. You’ll need to deploy and link the library, and each call costs a bit more gas.

7. Split the contract, use a proxy, or use a Diamond

If the logic is simply too large, split it into several contracts that call each other. Upgradeable proxies also help, because the proxy is tiny and the implementation only needs to fit by itself. For very large systems, the Diamond standard (ERC-2535) routes calls to multiple “facet” contracts, which the EIP describes as having “virtually no size limit”. It adds complexity and audit surface, so use it only if you really need it.

Why allowUnlimitedContractSize only works locally

Hardhat’s network config has allowUnlimitedContractSize, which Hardhat’s docs describe as disabling “the contract size limit imposed by EIP 170” (default false). Anvil has --code-size-limit and --disable-code-size-limit. We confirmed that Anvil with --disable-code-size-limit accepted both 24,577 bytes of runtime code and 49,153 bytes of initcode. These flags only change your local simulator. Real networks such as Core mainnet run their own consensus rules, and your deployment will still fail there. Use the flags for tests and gas profiling, not as a fix.

Quick reference

FixEffortOur test result
Optimizer, runs=200Config only28,696 → 18,056 bytes
Optimizer, runs=1Config only28,696 → 17,388 bytes
viaIR + runs=200Config + retest28,696 → 14,935 bytes
Custom errors + optimizer + viaIRCode changes28,696 → 8,335 bytes
Libraries, split contracts, DiamondArchitectureNot measured

Once the size is under the limit, deploy as usual with our Hardhat guide for Core or Foundry guide for Core. Keep the same optimizer and viaIR settings when you verify the contract on Core Scan, or the bytecode won’t match.

FAQ

Is the limit on source code or bytecode?

Bytecode. EIP-170 limits the runtime code returned by the constructor. EIP-3860 limits the initcode in the deployment transaction. Comments and source length don’t matter.

Why does the error show up during gas estimation?

Wallets and tools call eth_estimateGas before sending. The node runs the deployment in simulation, hits the size check and returns the error before you sign. That’s also why it can look like a gas problem (see our “gas required exceeds allowance” guide for that one).

Will the 24,576-byte limit ever be raised?

There is a proposal. EIP-7954 would raise the limits to 65,536 bytes (runtime) and 131,072 bytes (initcode), and go-ethereum already has constants for it under the planned “Amsterdam” fork. It was not active on Core mainnet in our 18 November 2026 test, so design for 24,576 bytes until your target chain announces otherwise.

Does a lower runs value cost users more gas?

It can. Low runs optimize for deployment size, so function calls may cost slightly more. Measure both before choosing.

Disclaimer: This article is for educational purposes only and is not financial or investment advice. Test results reflect our own checks on 18 November 2026. Clients and network rules change, so run your own tests on a testnet before deploying to mainnet.

Recent Posts

  • Spring Payout After Shutdown: How to Get Your Remaining Teespring Balance (2026)
  • Max Code Size Exceeded Error: What It Means and How to Fix It
  • Invalid Opcode PUSH0 Error: What It Means and How to Fix It
  • Can You Have Two Stocks and Shares ISAs in the Same Tax Year? (2026/27 Rules)
  • Fourthwall Payout Schedule: When Creators Get Paid (2026)
Subscription form is not available at the moment
  • Altcoin News
  • Bitcoin
  • Core Ecosystem Analysis
  • DeFi
  • Free Crypto Signals
  • Make Money Online
  • Personal Finance & Investing
  • Token Analysis
  • About Us
  • Contact
  • Privacy Policy
  • Disclaimer
©2026 PenyuOnCore | Design: Newspaperly WordPress Theme