Constructor argument gas estimation fallback in Hardhat v2.12.0
0 reputation · 03 Dec 2021, 18:32 UTC
0 reputation · 03 Dec 2021, 18:32 UTC
This examination targets Hardhat v2.12.0's handling of constructor arguments that surpass the ABI encoding threshold for inline values. When such arguments are present, the deployment transaction silently falls back to a gas estimate of 0, causing the transaction to revert with out of gas status and no embedded revert reason. The objective is to delineate this boundary condition and its impact on typical development cycles.
Observed behavior differs between Hardhat's default network and external chain forks, and updates to the Solidity compiler or Hardhat release can shift gas estimation heuristics. Additionally, the degree to which the underlying JSON-RPC provider makes the original EVM revert data available is inconsistent, leaving a compatibility gap that is not uniformly documented across deployment scenarios.
What mechanisms could Hardhat adopt to reliably surface the EVM's original revert reason when gas estimation defaults to zero? Should the framework standardize revert reason exposure across provider types for oversized constructor arguments? What adjustments should project configurations make when migrating between Hardhat network and forked environments with divergent gas estimation policies?
32275 reputation · 03 Dec 2021, 18:43 UTC
This occurs because Hardhat relies on the eth_estimateGas RPC-call before sending the transaction. If the constructor arguments are exceptionally large (e.g., massive arrays or complex structs), the underlying JSON-RPC provider may return zero or an error because it cannot simulate the execution cost of the oversized payload. Since the transaction is never actually "sent" with a valid gas limit, the Solidity logic—and its requirerequire statements—are never triggered.
To bypass the faulty estimation logic and surface the actual error, follow these steps in your deployment script:
gasLimit manually in your deploy function.const contract = await ethers.deployContract("MyContract", args, {
gasLimit: 5000000, // Set a sufficiently high limit manually
});
--force flag: If using the Hardhat-ignition, some versions allow forcing a deployment to skip the estimation phase, though this is less common in standard ethers-based scripts.The behavior varies significantly between the local Hardhat Network and forked environments. The local network is more permissive with simulation, whereas external chain forks (like Infura or Alchemy) have strict timeouts and resource limits on gas-call simulations. When migrating between these, you should:
hardhat.config.js specifically for the forked network to ensure consistency.debug_traceCall, which can sometimes provide more detail than standard estimation fails.For Hardhat to reliably surface revert reasons, it would need to implement a "dry-run" fallback: if eth_estimateGas fails, the framework could attempt to send the transaction with a high gas limit and then parse the data field of the reverted-transaction response. However, this would consume actual gas on live networks, which is undesirable for development workflows.
Diagnostic Question: Are you encountering this specifically when deploying to a mainnet fork, or does it also occur on the local Hardhat Network node?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.