I'm aware since Spurious Dragon there's a size limit for the contracts, I cloned this repository to test it locally and learn about how everything works, but I can't deploy some contracts due to the size being larger than the limit.

I'm using hardhat and my deploy script looks something like this:

async function main() {       
const Comptroller = await ethers.getContractFactory('Comptroller');
        const comptroller = await Comptroller.deploy();
        console.log("comptroller deployed to:", comptroller.address);
.then(() => process.exit(0))
.catch((error) => {

This is on my hardhat.config:

    module.exports = {
      solidity: "0.5.16",
      settings: {
        optimizer: {
          enabled: true,
          runs: 20
  networks: {
    testnet: {
      url: secret.url,
      gasPrice: 20000000000,
      accounts: [secret.key]

This is what I'm using to deploy:

npx hardhat --network testnet run scripts/deploy1.js 

I'm getting the error from the deployment that the size of the contracts is too large, so how can they have deployed the same code that is exceeding the size and I'm not able to deploy it?

  • What's the exact error message?
    – Ismael
    Dec 4, 2021 at 20:28
  • ProviderError: max code size exceeded at HttpProvider.request at LocalAccountsProvider.request at processTicksAndRejections at EthersProviderWrapper.send Dec 4, 2021 at 22:31
  • Have you tried after change the solidity version?
    – Victor
    Dec 4, 2021 at 23:57
  • I tried and got some deployed but others still didn't deploy. I'm curious why would a solidity change affect this? Dec 5, 2021 at 12:48
  • @SamuelVillegas The repo uses eth-saddle to manage compilation and deployment. If I'm reading the config file correctly they enable in ganache allowUnlimitedContractSize to support arbitrary large contracts.
    – Ismael
    Dec 5, 2021 at 23:18

2 Answers 2


Optimizer is supposed to help your large code achieve maximum efficiency so it runs and can be deployed. Increasing the runs value from 20 to 500 may work.

  • 6
    By increasing runs, you are telling the optimizer that the functions on the contract are going to be called very often, so the optimizer will try and make functions cheaper to call, even if this means it has to inline/repeat some code… resulting in a larger contract with higher one-time initial deployment gas cost. So what the OP wants to be doing here is the opposite, to lower runs, to encourage the optimizer to save on initial deployment gas — in order to lower this cost, the optimizer will try and make the contract bytecode smaller, which might bring it back below the limit.
    – dwardu
    May 31, 2022 at 23:24
  • 2
    Thank you for this, I finally understand what the optimizer really does and how it does it. This would've probably taken me a longer time to figure out
    – Akay Udeh
    Jun 1, 2022 at 11:18

I came across same problem once, this setting below worked for me

settings: {
      optimizer: {
        enabled: true,
        runs: 200,
        details: { yul: false },
  • This was perfect for me! Can you point me towards some documentation for the details? It's difficult to find advanced optimizer settings for this.
    – nikojpapa
    Sep 29, 2023 at 18:55

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.