Skip to content

Add assume cheatcode to restrict fuzzing inputs #74

Open
@bbyalcinkaya

Description

@bbyalcinkaya

Description:

Currently, when writing fuzz tests in Komet, we manually enforce input assumptions using early returns in the test code:

if !assumption(input) {
    return true;
}

This approach is:

  • Error-prone, as it relies on developers to remember to negate the assumption and write early returns manually.
  • Not elegant, reducing the readability and expressiveness of tests.
  • Incorrect for statistics, because inputs that violate the assumption are still counted toward the total number of examples. For instance, if the fuzzer is configured to run 100 tests but 30 inputs are discarded due to assumptions, only 70 effective tests are run.

Proposal

Introduce a new assume cheatcode that allows developers to express input assumptions declaratively. During fuzzing:

  • When an input violates the assumption, execution should immediately terminate, and the input should be discarded.
  • The discarded input should not count toward the configured number of fuzzing iterations.
  • The fuzzer should continue generating inputs until it runs the desired number of test cases that satisfy the assumptions.

Example usage (conceptual):

assume(x > 0 && x < 100);

This would ensure the test only runs when x is in the specified range, and otherwise the input is skipped without counting toward the total.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions