Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Enum value when fuzzing #6623

Open
2 tasks done
ScreamingHawk opened this issue Dec 19, 2023 · 2 comments
Open
2 tasks done

Invalid Enum value when fuzzing #6623

ScreamingHawk opened this issue Dec 19, 2023 · 2 comments
Labels
A-testing Area: testing C-forge Command: forge Cmd-forge-test Command: forge test P-low Priority: low T-bug Type: bug

Comments

@ScreamingHawk
Copy link

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.

@ScreamingHawk ScreamingHawk added the T-bug Type: bug label Dec 19, 2023
@gakonst gakonst added this to Foundry Dec 19, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry Dec 19, 2023
@mds1
Copy link
Collaborator

mds1 commented Dec 20, 2023

Solidity's output does not return the max length of the enum, so the fuzzer can't know the max value to use. As a workaround for now you should pass a uint8, bound it, then cast to your enum. See #871 for more info

I'll leave this issue open as the tracking issue better enum support as discussed in #871

@parseb parseb mentioned this issue Feb 8, 2024
2 tasks
@JacobHomanics
Copy link

Solidity's output does not return the max length of the enum, so the fuzzer can't know the max value to use. As a workaround for now you should pass a uint8, bound it, then cast to your enum. See #871 for more info

I'll leave this issue open as the tracking issue better enum support as discussed in #871

What if the fuzz test has a struct parameter containing an enum? See my comment on #871 for more clarity to the problem.

@zerosnacks zerosnacks added the A-testing Area: testing label Jun 28, 2024
@zerosnacks zerosnacks added Cmd-forge-test Command: forge test C-forge Command: forge labels Jul 8, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@grandizzy grandizzy added the P-low Priority: low label Oct 24, 2024
@grandizzy grandizzy removed this from the v1.0.0 milestone Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testing Area: testing C-forge Command: forge Cmd-forge-test Command: forge test P-low Priority: low T-bug Type: bug
Projects
Status: Todo
Development

No branches or pull requests

5 participants