NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.32k stars 1.42k forks source link

Block gas limits at or above MAX_SAFE_INTEGER #1469

Open fvictorio opened 3 years ago

fvictorio commented 3 years ago

We only accept numbers as values for blockGasLimit. There are two issues here.

The first one is related to big values. Setting the block gas limit to 0x2fffffffffffff throws this error when starting the node:

Error HH604: Error running JSON-RPC server: Assertion failed

We should either show a better error or, better still, validate that the number is safe. Besides, we should consider accepting string values for this setting.

The second error is a small one related to hardhat-ethers. Setting the block gas limit to 0x1fffffffffffff (which is the value of Number.MAX_SAFE_INTEGER) works and the node starts, but when you try to send a transaction, hardhat-ethers throws an error caused by this line:

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

The problem is that BigNumber.from throws for that specific value. I don't know if this is intended or an off-by-one error (see discussion: https://github.com/ethers-io/ethers.js/discussions/1582).

alcuadrado commented 3 years ago

I think I'll validate it for now. As accepting a string is a breaking change.

fvictorio commented 3 years ago

Why accepting a type that was previously rejected is a breaking change?

fvictorio commented 3 years ago

This is intended behavior from ethers so, yeah, we should validate it. I guess we should just try/catch the BigNumber.from and report the number as invalid if it fails.