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

Add enums to echidna printer's list of constants #1665

Merged
merged 1 commit into from
Feb 21, 2023

Conversation

samalws
Copy link

@samalws samalws commented Feb 15, 2023

Fixes crytic/echidna#918.

This PR makes the echidna printer count enum values as uint256 constants, including them in the "constants_used" list so that echidna is aware of them. Currently, when a function has enum arguments, echidna will try all numbers, not privileging in-range enum values over out-of-range values.

Example:

contract Example {
  bool flag = false;
  function setFlag(ExampleEnum a, ExampleEnum b, ExampleEnum c) public {
    if (a == ExampleEnum.E28 && b == ExampleEnum.E29 && c == ExampleEnum.E30)
      flag = true;
  }
  function echidna_flag() public view returns (bool) {
    return !flag;
  }
  enum ExampleEnum {
    E0,
    E1,
    // ...
    E30
  }
}

Before this PR, echidna takes a very long time to break the contract (didn't break it in 500000 iterations when I ran it). Afterwards, it breaks the contract nearly instantly.

I chose to make enum values be considered uint256 constants rather than uint8 constants since some versions of solidity allow for enums with more than 256 values.

@montyly montyly merged commit 9779380 into crytic:dev Feb 21, 2023
@montyly
Copy link
Member

montyly commented Feb 21, 2023

great idea, thanks @samalws

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants