hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

[hardhat-ethers] Error when configured gas is an unsafe integer

Open fvictorio opened this issue 3 years ago • 2 comments

Reproduction steps:

  1. Create a sample project
  2. Modify the hardhat network config to have gas: 1e16
  3. Run hh test

This produces this error:

     Error: overflow (fault="overflow", operation="BigNumber.from", value=10000000000000000, code=NUMERIC_FAULT, version=bignumber/5.4.1)
      at Logger.makeError (node_modules/@ethersproject/logger/src.ts/index.ts:213:28)
      at Logger.throwError (node_modules/@ethersproject/logger/src.ts/index.ts:225:20)
      at throwFault (node_modules/@ethersproject/bignumber/src.ts/bignumber.ts:358:19)
      at Function.BigNumber.from (node_modules/@ethersproject/bignumber/src.ts/bignumber.ts:249:17)
      at addGasToAbiMethodsIfNecessary (node_modules/@nomiclabs/hardhat-ethers/src/internal/helpers.ts:325:30)
      at getContractFactoryByAbiAndBytecode (node_modules/@nomiclabs/hardhat-ethers/src/internal/helpers.ts:254:27)
      at Context.<anonymous> (test/sample-test.js:5:21)

The problematic line is this one:

https://github.com/nomiclabs/hardhat/blob/403c495539c92df4dc505c81a930a4fa54f6ce68/packages/hardhat-ethers/src/internal/helpers.ts#L325

Two possible solutions:

  1. Change this line so that an unsafe integer doesn't cause an error. This might be as simple as converting the number to a string.
  2. Change the config validation to check that numbers like these are safe. Also, accept strings so that unsafe integers can be used.

Rejecting unsafe integers would be a breaking change, or a bug fix, YMMV.

fvictorio avatar Aug 06 '21 11:08 fvictorio

setting gas in Hardhat config to something like 9e6 would fix the issue for me. Though, I am not sure why MAX_SAFE_INTEGER is rejected by BigNumber.

ylv-io avatar Aug 08 '21 13:08 ylv-io

This issue was marked as stale because it didn't have any activity in the last 30 days. If you think it's still relevant, please leave a comment indicating so. Otherwise, it will be closed in 7 days.

github-actions[bot] avatar Aug 03 '22 08:08 github-actions[bot]