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

EVM Engineering: semgrep rule for require messages #12774

Open
3 tasks
smartcontracts opened this issue Nov 1, 2024 · 4 comments
Open
3 tasks

EVM Engineering: semgrep rule for require messages #12774

smartcontracts opened this issue Nov 1, 2024 · 4 comments

Comments

@smartcontracts
Copy link
Contributor

We're moving most of the codebase to custom error messages but there will still be plenty of places like scripts and tests where require gets used instead.

@jsvisa has a nice PR open (#12702) that does some of the work to make sure that all instances of require have a corresponding error message.

We should have a semgrep rule that enforces this condition so that we don't end up adding new require statements that don't have messages.

Tasks for this issue are:

  • Add semgrep rule that enforces the format require(..., $MSG)
  • Add tests for the semgrep rule
  • Apply semgrep rule to all files and fix any open instances

When adding the semgrep rule, something along the lines of the following should work:

  - id: sol-style-enforce-require-msg
    languages: [solidity]
    severity: ERROR
    message: Require statement must have an error message
    patterns:
      - pattern: require($ERR);
      - pattern-not: require($ERR, $MSG);

Tests for the semgrep rule should be added in semgrep/sol-rules.t.sol.

For the sake of keeping PRs clean, I generally recommend creating the rule + tests in one PR while excluding files/folders where the rule is violated so that no changes to the contracts are actually required. Afterwards, a second PR can remove the exclusions and fix all of the violations.

@jsvisa
Copy link
Contributor

jsvisa commented Nov 1, 2024

Sounds good to me, I'll take this one

@smartcontracts
Copy link
Contributor Author

smartcontracts commented Nov 1, 2024

Awesome, thank you!

@ControlCplusControlV
Copy link
Contributor

I mentioned it in the design-doc for custom errors, but do we actually just want a semgrep rule to blanket outlaw require and then use assertEq and assert in tests/scripts

@smartcontracts
Copy link
Contributor Author

I mentioned it in the design-doc for custom errors, but do we actually just want a semgrep rule to blanket outlaw require and then use assertEq and assert in tests/scripts

Yes

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

No branches or pull requests

3 participants