1

I am getting this error when trying to deploy my smart contract using zkSync but on a different chain (Polygon Mumbai):

CompilerError: Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables.
   --> @matterlabs/zksync-contracts/l2/system-contracts/BootloaderUtilities.sol:103:34:
    |
103 |             uint256 listLength = encodedNonce.length +
    |                                  ^^^^^^^^^^^^

Error HH600: Compilation failed

This are all my files:

hardhat.config.ts

import "@matterlabs/hardhat-zksync-deploy";
import "@matterlabs/hardhat-zksync-solc";
const { pk } = require('./.secrets.json');

module.exports = {
  zksolc: {
    version: "1.3.1",
    compilerSource: "binary",
    settings: {},
  },
  defaultNetwork: "zkSyncTestnet",
  networks: {
    zkSyncTestnet: {
      url: "https://zksync2-testnet.zksync.dev",
      ethNetwork: "goerli", // Can also be the RPC URL of the network (e.g. `https://goerli.infura.io/v3/<API_KEY>`)
      zksync: true,
      accounts: [pk]
    },
    mumbai: {
      url: "https://matic-mumbai.chainstacklabs.com/",
      chainId: 80001,
      gasPrice: "auto",
      accounts: [pk],
      zksync: false
    }
  },
  solidity: {
    version: "0.8.17",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
    },
  },
};

Greeter.sol

//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

contract Greeter {
    string private greeting;

    constructor(string memory _greeting) {
        greeting = _greeting;
    }

    function greet() public view returns (string memory) {
        return greeting;
    }

    function setGreeting(string memory _greeting) public {
        greeting = _greeting;
    }
}

deploy.ts

import { Wallet } from "zksync-web3";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
import { pk } from "../.secrets.json";

// An example of a deploy script that will deploy and call a simple contract.
export default async function (hre: HardhatRuntimeEnvironment) {
  console.log(`Running deploy script for the Greeter contract`);

  // Initialize the wallet.
  const wallet = new Wallet(pk);

  // Create deployer object and load the artifact of the contract you want to deploy.
  const deployer = new Deployer(hre, wallet);
  const artifact = await deployer.loadArtifact("Greeter");

  // Estimate contract deployment fee
  const greeting = "Hi there!";
  //const deploymentFee = await deployer.estimateDeployFee(artifact, [greeting]);

  const greeterContract = await deployer.deploy(artifact, [greeting]);

  //obtain the Constructor Arguments
  console.log("constructor args:" + greeterContract.interface.encodeDeploy([greeting]));

  // Show the contract info.
  const contractAddress = greeterContract.address;
  console.log(`${artifact.contractName} was deployed to ${contractAddress}`);
}

1 Answer 1

1

At some point there was a bug in v1.3.1 so try deleting all the compilers from the cache folder in /Users/<YOUR USERNAME>/Library/Caches/hardhat-nodejs/compilers-v2/zksolc/ and try again. It will download the corresponding compiler automatically.

Also, make sure you're using the latest versions of the hardhat plugins (hardhat-zksync-solc and hardhat-zksync-deploy) and the compiler.

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.