Hardhat Deploy ProviderError: stack-underflow

Hi,

I want to deploy a simple counter:

// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.20;

contract Counter {
    uint public count;

    function inc() external {
        count += 1;
    }

    function get() external view returns (uint) {
        return count;
    }
}

Hardhat deploy script:

async function main() {
    const [deployer] = await ethers.getSigners();
  
    console.log("Deploying contracts with the account:", deployer.address);
  
    const counter = await ethers.deployContract("Counter");
  
    console.log("Counter address:", await counter.getAddress());
  }
  
  main()
    .then(() => process.exit(0))
    .catch((error) => {
      console.error(error);
      process.exit(1);
    });

hardhat.config.js is set to compiler verion 0.8.20.

During deploy i receive following error: ProviderError: stack-underflow

This only happens with solidity version above ^0.8.19, any ideas ?

Yes, this is because Solc Version 0.8.20 has switched the default target EVM version to Shanghai:

IMPORTANT NOTE: This compiler switches the default target EVM version to Shanghai, which means that the generated bytecode will include PUSH0 opcodes. Be sure to select the appropriate EVM version in case you intend to deploy on a chain other than mainnet like L2 chains that may not yet support PUSH0, otherwise deployment of your contracts will fail.

And the default target EVM version is set to Shanghai only starting from HardHat Version 2.14.0:

This release sets Shanghai as the default hardfork used by the Hardhat Network.

So you must choose either one of the following options:

  • Solc < 0.8.20 and HardHat < 2.14.0
  • Solc >= 0.8.20 and HardHat >= 2.14.0
1 Like

Thank you for the clarification.

1 Like

In hardhat 2.17.3, the default EVM version reverted back to paris.

I've written an issue about this at https://github.com/NomicFoundation/hardhat/issues/4391