Skip to content

Invalid Enum value when fuzzing #6623

Open
@ScreamingHawk

Description

@ScreamingHawk

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (73fb616 2023-12-19T00:16:21.131413571Z)

What command(s) is the bug in?

forge test

Operating System

Windows

Describe the bug

When fuzzing an array of enums, forge supplies a value out of range.

Example:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.18;

import "forge-std/Test.sol";

contract ForgeFail is Test {

    enum EnumVal {
        VAL_0,
        VAL_1,
        VAL_2
    }

    function testForgeFail(EnumVal[] memory vals) external {
      // No content. Still fails
    }
}

Output:

Running 1 test for test/ForgeFail.t.sol:ForgeFail
[FAIL. Reason: EvmError: Revert; counterexample: calldata=0x98a2e150000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003 args=[[3]]] testForgeFail(uint8[]) (runs: 2, μ: 647, ~: 647)
Traces:
  [643] ForgeFail::testForgeFail([3])
    └─ ← EvmError: Revert

Test result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 5.63ms

Ran 1 test suites: 0 tests passed, 1 failed, 0 skipped (1 total tests)

Failing tests:
Encountered 1 failing test in test/sample/endorser/ForgeFail.t.sol:ForgeFail
[FAIL. Reason: EvmError: Revert; counterexample: calldata=0x98a2e150000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003 args=[[3]]] testForgeFail(uint8[]) (runs: 2, μ: 647, ~: 647)

Encountered a total of 1 failing tests, 0 tests succeeded

The argument 3 is outside the bounds of EnumVal.

Note: I am running forge on WSL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions