Skip to content

solidity test aborts with ERR_STRING_TOO_LONG when a build-info output exceeds Node's max string length #8341

Description

@anaPerezGhiglia

Version of Hardhat

3.5.1 and 3.6.0

What happened?

The Solidity test runner reads each build-info *.output.json into a single Node string via bytesToUtf8String + JSON.parse in two places, and both crash when the output is larger than V8's String::kMaxLength (~512 MiB, 0x1fffffe8). The whole test run aborts before a single test is started.

The triggers are fast byte scans, so the work behind the gate is invisible to users:

  1. Inline-config collector (solidity-test/inline-config/index.ts:152-158, in collectRawOverrides) — runs whenever forge-config: or hardhat-config: bytes are present in the build info.
  2. EIP-712 type collector (solidity-test/eip712/index.ts:57-66, in collectEip712CanonicalTypes) — runs whenever test.solidity.eip712Types.include is set and the build info contains struct (which is true for nearly every real Solidity project).

Stack traces

Call site 1:

RangeError: Cannot create a string longer than 0x1fffffe8 characters
    at TextDecoder.decode (node:internal/encoding:447:16)
    at bytesToUtf8String (.../hardhat-utils/src/bytes.ts:59:28)
    at collectRawOverrides (.../solidity-test/inline-config/index.ts:157:7)
    at getTestFunctionOverrides (.../solidity-test/inline-config/index.ts:55:27)
    at runSolidityTests (.../solidity-test/task-action.ts:234:33)
  code: 'ERR_STRING_TOO_LONG'

Call site 2 (after patching the first):

RangeError: Cannot create a string longer than 0x1fffffe8 characters
    at TextDecoder.decode (node:internal/encoding:447:16)
    at bytesToUtf8String (.../hardhat-utils/src/bytes.ts:59:28)
    at collectEip712CanonicalTypes (.../solidity-test/eip712/index.ts:65:21)
  code: 'ERR_STRING_TOO_LONG'

Minimal reproduction steps

Real project

git clone https://github.com/aave/aave-v4.git
cd aave-v4 && git checkout hh3-migration-v2  # @ ed2ab8d
yarn install --ignore-scripts
npx hardhat compile        # succeeds — produces a 698 MiB build-info output
npx hardhat test solidity  # crashes with ERR_STRING_TOO_LONG

Expected vs actual

Expected Actual
npx hardhat test solidity on a project with a >512 MiB build-info output Inline-config / EIP-712 metadata extracted; tests run ERR_STRING_TOO_LONG thrown from collectRawOverrides or collectEip712CanonicalTypes; whole run aborts before any test starts

Environment

  • Hardhat: reproduces on 3.5.1 and 3.6.0 (latest at the time of writing)
  • EDR: @nomicfoundation/edr@0.12.0-next.33 (unchanged across both Hardhat versions)
  • Node.js: v22.x
  • OS: Linux 6.10
  • Repro project's build-info output: 731_669_005 bytes (~698 MiB) for the default profile

Layer

Pure Hardhat (test-runner plugin). Failure happens entirely inside the solidity-test task-action before EDR is invoked.

Search terms

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions