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

[WIP] Tool slither-format: automatic code improvements #238

Merged
merged 117 commits into from Oct 2, 2019

Conversation

@rajeevgopalakrishna
Copy link
Contributor

@rajeevgopalakrishna rajeevgopalakrishna commented May 10, 2019

This PR (depends on #237 and #236 and replaces PR #235 which was created against a stale dev branch by mistake) addresses #150 to add a new utility tool slither-format which uses slither detectors to identify code patterns of concern (w.r.t security, readability and optimisation) and automatically fix those code patterns with suggested changes.

The current list of detectors used to detect and fix include: unused-state, solc-version, pragma, naming-convention, external-function, constable-states and constant-function.

Detectors highlight names, context and source-mapping of code constructs which are then used by slither-format to programmatically locate those constructs in the Solidity files and then replace them with changes based on best practices. Lexical analysis for identification of such constructs is confined to the smallest possible region to avoid conflicts with similarly named constructs (with potentially different types or signatures) in other scopes, functions or contracts within the same file (because of shadowing, overloading etc.).

Done: Framework and basic functionality. Unit testing.
WIP: More real-world testing and bug-fixes. More tool options.
Known bugs:

  1. naming-convention formatting doesn't work on NatSpec comments, e.g. @param.
  2. Variables used as indices on LHS (e.g. _to in balances[_to] = 100) don't get reported from Slither in variables that are read and hence are not formatted in naming-convention.
    3. Bugs potentially from incorrectly reported source mappings, which might be related to #218.
…es on slither parsing/core and detectors. Single commit because of checking out utils/slither_format from dev-slither-format into this branch.
…ant_function passes.
…o variable types. test_unused_state_vars passes.
…ame instead of the earlier expression name. test_solc_version passes. Removes patch_file check for now. Need to change verbose output to JSON format and include patch_file then.
…stead of the earlier expression name. test_pragma passes. Removes patch_file check for now. Need to change verbose output to JSON format and include patch_file then.
…nal_function passes.
@rajeevgopalakrishna rajeevgopalakrishna force-pushed the dev-slither-format-tool-only-new branch 2 times, most recently from 86568a6 to ced9498 May 13, 2019
…SON output field updates. Removed the use of event.full_name to simply use name instead (so PR #236 not required). naming-convention tests pass (except the index variable test which is expected to fail); run_all_tests passes except that one. Testing requires checking out slither core/parsing changes from dev-slither-changes-for-slither-format-new.
…_event/var_declaration, which will be removed from slither.
…ts instead of raw source text.
@rajeevgopalakrishna rajeevgopalakrishna requested a review from montyly May 15, 2019
@montyly
Copy link
Member

@montyly montyly commented May 16, 2019

Few recommendations:

@rajeevgopalakrishna rajeevgopalakrishna force-pushed the dev-slither-format-tool-only-new branch from 800f375 to 2e93076 May 17, 2019
@montyly montyly force-pushed the dev-slither-format-tool-only-new branch from 63fd179 to 99e7b81 Sep 11, 2019
montyly added 16 commits Sep 12, 2019
 - move to slither.formatters.x
 - add _format in abstract detector
 - simplify slither-format tool
Add slither flag --generate-patches: generate patches and add them to the json
Change string / bytes in create_patch functions
Remove slither-format --skip-patch-generation flag
@montyly montyly merged commit 5992ba1 into dev Oct 2, 2019
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
license/cla Contributor License Agreement is signed.
Details
@montyly montyly deleted the dev-slither-format-tool-only-new branch Oct 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.