# Governance ProviderError: max code size exceeded

**URL:** <https://forum.openzeppelin.com/t/governance-providererror-max-code-size-exceeded/25963>\
**Category:** Smart Contracts\
**Tags:** etherscan-verify\
**Created:** [March 10, 2022, 12:51pm UTC](https://forum.openzeppelin.com/t/governance-providererror-max-code-size-exceeded/25963 "2022-03-10T12:51:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maksim\_Gushchyn](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/maksim_gushchyn/32/13769_2.png) [@Maksim\_Gushchyn](https://forum.openzeppelin.com/u/Maksim_Gushchyn)\
**Post date:** [March 10, 2022, 12:51pm UTC](https://forum.openzeppelin.com/t/governance-providererror-max-code-size-exceeded/25963/1 "2022-03-10T12:51:54Z")

</div>

Hi, i am trying to deploy a contract [https://wizard.openzeppelin.com/#governor](https://wizard.openzeppelin.com/#governor) with upgradeability UUPS in **mumbai testnet**.

My contract (Governor.sol):

```auto
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts-upgradeable/governance/GovernorUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorSettingsUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorCountingSimpleUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesQuorumFractionUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorTimelockControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

/// @custom:security-contact security@plush.family
contract Governor is Initializable, GovernorUpgradeable, GovernorSettingsUpgradeable, GovernorCountingSimpleUpgradeable, GovernorVotesUpgradeable, GovernorVotesQuorumFractionUpgradeable, GovernorTimelockControlUpgradeable, OwnableUpgradeable, UUPSUpgradeable {
    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() initializer {}

    function initialize(IVotesUpgradeable _token, TimelockControllerUpgradeable _timelock)
    initializer public
    {
        __Governor_init("Governor");
        __GovernorSettings_init(1 /* 1 block */, 19636 /* 3 days */, 0);
        __GovernorCountingSimple_init();
        __GovernorVotes_init(_token);
        __GovernorVotesQuorumFraction_init(1);
        __GovernorTimelockControl_init(_timelock);
        __Ownable_init();
        __UUPSUpgradeable_init();
    }

    function _authorizeUpgrade(address newImplementation)
    internal
    onlyOwner
    override
    {}

    // The following functions are overrides required by Solidity.

    function votingDelay()
    public
    view
    override(IGovernorUpgradeable, GovernorSettingsUpgradeable)
    returns (uint256)
    {
        return super.votingDelay();
    }

    function votingPeriod()
    public
    view
    override(IGovernorUpgradeable, GovernorSettingsUpgradeable)
    returns (uint256)
    {
        return super.votingPeriod();
    }

    function quorum(uint256 blockNumber)
    public
    view
    override(IGovernorUpgradeable, GovernorVotesQuorumFractionUpgradeable)
    returns (uint256)
    {
        return super.quorum(blockNumber);
    }

    function getVotes(address account, uint256 blockNumber)
    public
    view
    override(IGovernorUpgradeable, GovernorVotesUpgradeable)
    returns (uint256)
    {
        return super.getVotes(account, blockNumber);
    }

    function state(uint256 proposalId)
    public
    view
    override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
    returns (ProposalState)
    {
        return super.state(proposalId);
    }

    function propose(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, string memory description)
    public
    override(GovernorUpgradeable, IGovernorUpgradeable)
    returns (uint256)
    {
        return super.propose(targets, values, calldatas, description);
    }

    function proposalThreshold()
    public
    view
    override(GovernorUpgradeable, GovernorSettingsUpgradeable)
    returns (uint256)
    {
        return super.proposalThreshold();
    }

    function _execute(uint256 proposalId, address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
    internal
    override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
    {
        super._execute(proposalId, targets, values, calldatas, descriptionHash);
    }

    function _cancel(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
    internal
    override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
    returns (uint256)
    {
        return super._cancel(targets, values, calldatas, descriptionHash);
    }

    function _executor()
    internal
    view
    override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
    returns (address)
    {
        return super._executor();
    }

    function supportsInterface(bytes4 interfaceId)
    public
    view
    override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
    returns (bool)
    {
        return super.supportsInterface(interfaceId);
    }
}

```

My ts hardhat(deploy):

```auto
const { ethers, upgrades } = require("hardhat");
import * as args from "../../arguments/plushCoinWalletsArgs";

require('@openzeppelin/hardhat-upgrades');

async function main() {
    const Governor = await ethers.getContractFactory("Governor");
    const governor = await upgrades.deployProxy(Governor);
    await governor.deployed();

    console.log('Governor -> deployed to address:', governor.address);

    if (process.env.NETWORK != 'local') {
        console.log('Waiting 1m before verify contract\n');
        await new Promise(function (resolve) {
            setTimeout(resolve, 60000);
        });
        console.log('Verifying...\n');

        await ethers.run('verify:verify', {
            address: governor.address,
            contract: 'contracts/Governor.sol:Governor'
        });
    }
}
main()
    .then(() => process.exit(0))
    .catch((error) => {
        console.error(error);
        process.exit(1);
    });

```

And i get this error:

```auto
Compiling 1 file with 0.8.9
Warning: Contract code size 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.
  --> contracts/Governor.sol:15:1:
   |
15 | contract Governor is Init ... nableUpgradeable, UUPSUpgradeable {
   | ^ (Relevant source part starts here and spans across multiple lines).

Solidity compilation finished successfully
ProviderError: max code size exceeded
    at HttpProvider.request (WorkFolder/plushNew/node_modules/hardhat/src/internal/core/providers/http.ts:49:19)
    at LocalAccountsProvider.request (WorkFolder/plushNew/node_modules/hardhat/src/internal/core/providers/accounts.ts:188:34)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async EthersProviderWrapper.send (WorkFolder/plushNew/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)

```

Tell me what am I doing wrong? After all, I take the standard code from your constructor...

---

<div class="post-metadata">

**Author:** ![TtheBC01](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/tthebc01/32/14174_2.png) [@TtheBC01](https://forum.openzeppelin.com/u/TtheBC01)\
**Post date:** [March 10, 2022, 8:47pm UTC](https://forum.openzeppelin.com/t/governance-providererror-max-code-size-exceeded/25963/2 "2022-03-10T20:47:23Z")

</div>

@Maksim_Gushchyn, are you using the solidity compiler optimizer? Enabling optimization can make a big difference in the size of your programs. [Here's an example](https://github.com/GoHypernet/hypernet-protocol/blob/dev/packages/contracts/hardhat.config.js#L31) of how to turn that on in Hardhat from one of my projects.

---

<div class="post-metadata">

**Author:** ![Maksim\_Gushchyn](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/maksim_gushchyn/32/13769_2.png) [@Maksim\_Gushchyn](https://forum.openzeppelin.com/u/Maksim_Gushchyn)\
**Post date:** [March 11, 2022, 7:16am UTC](https://forum.openzeppelin.com/t/governance-providererror-max-code-size-exceeded/25963/3 "2022-03-11T07:16:06Z")

</div>

Yes sure.

```auto
settings: {
      optimizer: {
        enabled: true,
        runs: 1,
      },
    },

```

I tried with different values but it doesn't help. I used to have 200, but after reading a lot of articles, I put **"runs: 1"** , but it does not help, the error remains...

 ![image](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/7/741d8cec710c8d1404233023a8ac164c64c0d5fd.png)

---

<div class="post-metadata">

**Author:** ![Maksim\_Gushchyn](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/maksim_gushchyn/32/13769_2.png) [@Maksim\_Gushchyn](https://forum.openzeppelin.com/u/Maksim_Gushchyn)\
**Post date:** [March 11, 2022, 8:03am UTC](https://forum.openzeppelin.com/t/governance-providererror-max-code-size-exceeded/25963/4 "2022-03-11T08:03:39Z")

</div>

I just tried truffle, same problem

---

<div class="post-metadata">

**Author:** ![TtheBC01](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/tthebc01/32/14174_2.png) [@TtheBC01](https://forum.openzeppelin.com/u/TtheBC01)\
**Post date:** [March 11, 2022, 11:44pm UTC](https://forum.openzeppelin.com/t/governance-providererror-max-code-size-exceeded/25963/5 "2022-03-11T23:44:20Z")

</div>

I just copied your contract from above into a new hardhat project and the size of the compiled contract for me came out to 15.3KB.

[Here is a link to a minimal git repo](https://github.com/TtheBC01/OZ-Governor-Hardhat-Example) to reproduce what I got.

---

<div class="post-metadata">

**Author:** ![Maksim\_Gushchyn](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/maksim_gushchyn/32/13769_2.png) [@Maksim\_Gushchyn](https://forum.openzeppelin.com/u/Maksim_Gushchyn)\
**Post date:** [March 12, 2022, 9:50am UTC](https://forum.openzeppelin.com/t/governance-providererror-max-code-size-exceeded/25963/6 "2022-03-12T09:50:19Z")

</div>

```auto
solidity: {
    compilers: [
      {
        version: '0.8.9',
      },
      {
        version: '0.8.4',
      },
      {
        version: '0.8.2',
      },
      {
        version: '0.6.6',
      },
      {
        version: '0.6.2',
      },
      {
        version: '0.6.0',
      },
    ],
    overrides: {
      'contracts/PlushCoin.sol': {
        version: '0.8.9',
      },
      'contracts/PlushCoreToken.sol': {
        version: '0.8.9',
      },
      'contracts/PlushForest.sol': {
        version: '0.8.9',
      },
      'contracts/PlushGetTree.sol': {
        version: '0.8.9',
      },
      'contracts/PlushGetCoreToken.sol': {
        version: '0.8.9',
      },
      'contracts/PlushCoinPolygon.sol': {
        version: '0.6.6',
      },
      'contracts/PlushCoinPolygonProxy.sol': {
        version: '0.6.6',
      },
    },
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
    },
    contractSizer: {
      alphaSort: true,
      runOnCompile: true,
      disambiguatePaths: false,
    },
  },

```

if i use Multiple Solidity versions - 27 kb  
if i use:

```auto
solidity: {
    version: '0.8.4',
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
    },
    contractSizer: {
      alphaSort: true,
      runOnCompile: true,
      disambiguatePaths: false,
    },
  },

```

all good - 15.3 kb but i have problem with others contracts: how can i fixed that?

---

<div class="post-metadata">

**Author:** ![Maksim\_Gushchyn](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/maksim_gushchyn/32/13769_2.png) [@Maksim\_Gushchyn](https://forum.openzeppelin.com/u/Maksim_Gushchyn)\
**Post date:** [March 12, 2022, 10:04am UTC](https://forum.openzeppelin.com/t/governance-providererror-max-code-size-exceeded/25963/7 "2022-03-12T10:04:49Z")

</div>

so i fixed that!

```auto
{
        version: "0.6.7",
        settings: {},
      },

```

i need to register the optimizer everywhere! Thank you!!!

---

<div class="post-metadata">

**Author:** ![Subhajit](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/subhajit/32/11866_2.png) [@Subhajit](https://forum.openzeppelin.com/u/Subhajit)\
**Post date:** [May 8, 2022, 12:31pm UTC](https://forum.openzeppelin.com/t/governance-providererror-max-code-size-exceeded/25963/8 "2022-05-08T12:31:45Z")

</div>

> [@Maksim\_Gushchyn](#):
>
> `compilers`

for example your compiler setting should look like this .

solidity: {

```
compilers: [

  {

    version: "0.8.13",

    settings: {

      optimizer: {

        enabled: true,

        runs: 200,

      },

    },

  },

  {

    version: "0.8.9",

    settings: {

      optimizer: {

        enabled: true,

        runs: 200,

      },

    },

  },

  {

    version: "0.8.4",

    settings: {

      optimizer: {

        enabled: true,

        runs: 200,

      },

    },

  },

  {

    version: "0.8.2",

    settings: {

      optimizer: {

        enabled: true,

        runs: 200,

      },

    },

  },

  {

    version: "0.6.6",

    settings: {

      optimizer: {

        enabled: true,

        runs: 200,

      },

    },

  },

  {

    version: "0.6.2",

    settings: {

      optimizer: {

        enabled: true,

        runs: 200,

      },

    },

  },

  {

    version: "0.6.0",

    settings: {

      optimizer: {

        enabled: true,

        runs: 200,

      },

    },

  },

],

```

},

And It takes time to deploy the Governance contract.
