Skip to content

Commit

Permalink
Run black + ruff via pre-commit, fix findings to reduce requirements.…
Browse files Browse the repository at this point in the history
…txt (#1865)

* Run black via pre-commit + Github Action workflow, update black

* Apply black via pre-commit

* Enable ruff + rulset "F" via pre-commit

* Apply ruff via pre-commit

* Manual lint fixes

* Apply review comments

---------

Co-authored-by: Nikhil Parasaram <[email protected]>
  • Loading branch information
dbast and norhh authored Aug 7, 2024
1 parent a710ca2 commit 25de4e7
Show file tree
Hide file tree
Showing 124 changed files with 268 additions and 291 deletions.
6 changes: 0 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ jobs:
paths:
- .tox/py*
- /root/.cache/pip/wheels/
# TODO: Remove all --break-system-packages here in and mythril-ci image
- run:
name: Black style check
command: |
pip3 install --user black==22.3.0 --break-system-packages
python3 -m black --check /home/mythril/

- run:
background: true
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
push:
branches:
- master
- develop
tags:
- '*'
pull_request:

name: pre-commit

concurrency:
# Concurrency group that uses the workflow name and PR number if available
# or commit SHA as a fallback. If a new build is triggered under that
# concurrency group while a previous build is running it will be canceled.
# Repeated pushes to a PR will cancel all previous builds, while multiple
# merges to a branch will not cancel.
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- uses: pre-commit/[email protected]
30 changes: 29 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# Apply to all files without commiting:
# pre-commit run --all-files
# Update this file:
# pre-commit autoupdate
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-toml
- id: check-yaml
- repo: https://github.com/psf/black
rev: 21.12b0
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.6
hooks:
- id: ruff
args: [--fix, --show-fixes]
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.14.0
hooks:
- id: pretty-format-toml
args: [--autofix]
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.1
hooks:
- id: check-circle-ci
- id: check-github-workflows
- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
2 changes: 2 additions & 0 deletions mypy-stubs/z3/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ class AstRef(Z3PPObject):
def __init__(self, ast: Ast, ctx: Context) -> None:
self.ast: Ast = ...
self.ctx: Context = ...

@overload
def __init__(self, ast: Ast) -> None:
self.ast: Ast = ...
self.ctx: Context = ...

def ctx_ref(self) -> ContextObj: ...
def as_ast(self) -> Ast: ...
def children(self) -> List[AstRef]: ...
Expand Down
1 change: 0 additions & 1 deletion myth
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ import mythril.interfaces.cli
if __name__ == "__main__":
mythril.interfaces.cli.main()
exit()

2 changes: 1 addition & 1 deletion mythril/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging

# Accept mythril.VERSION to get mythril's current version number
from .__version__ import __version__ as VERSION # NOQA
from .__version__ import __version__ as VERSION
from mythril.plugin.loader import MythrilPluginLoader

log = logging.getLogger(__name__)
1 change: 1 addition & 0 deletions mythril/analysis/call_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This module provides helper functions for the analysis modules to deal with
call functionality."""

from typing import Union

from mythril.analysis.ops import VarType, Call, get_variable
Expand Down
2 changes: 1 addition & 1 deletion mythril/analysis/issue_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from mythril.analysis.report import Issue
from mythril.laser.ethereum.state.annotation import StateAnnotation
from mythril.laser.smt import Bool
from mythril.laser.smt import SMTBool as Bool
from copy import deepcopy


Expand Down
1 change: 1 addition & 0 deletions mythril/analysis/module/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This module includes an definition of the DetectionModule interface.
DetectionModules implement different analysis rules to find weaknesses and vulnerabilities.
"""

import logging
from typing import List, Set, Optional, Tuple

Expand Down
1 change: 0 additions & 1 deletion mythril/analysis/module/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from mythril.analysis.module.modules.user_assertions import UserAssertions
from mythril.analysis.module.modules.unexpected_ether import UnexpectedEther

from mythril.analysis.module.base import EntryPoint

from mythril.exceptions import DetectorNotFoundError

Expand Down
3 changes: 1 addition & 2 deletions mythril/analysis/module/modules/arbitrary_jump.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""This module contains the detection code for Arbitrary jumps."""
import logging

from mythril.exceptions import UnsatError
import logging

from mythril.analysis.solver import get_transaction_sequence, UnsatError
from mythril.analysis.issue_annotation import IssueAnnotation
Expand Down
1 change: 1 addition & 0 deletions mythril/analysis/module/modules/arbitrary_write.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module contains the detection code for arbitrary storage write."""

import logging
from mythril.analysis.module.base import DetectionModule, EntryPoint
from mythril.analysis.potential_issues import (
Expand Down
3 changes: 2 additions & 1 deletion mythril/analysis/module/modules/delegatecall.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module contains the detection code for insecure delegate call usage."""

import logging
from typing import List

Expand All @@ -14,7 +15,7 @@
from mythril.analysis.module.base import DetectionModule, EntryPoint
from mythril.exceptions import UnsatError
from mythril.laser.ethereum.state.global_state import GlobalState
from mythril.laser.smt import symbol_factory, UGT, Bool
from mythril.laser.smt import symbol_factory, UGT

log = logging.getLogger(__name__)

Expand Down
1 change: 1 addition & 0 deletions mythril/analysis/module/modules/dependence_on_origin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This module contains the detection code for predictable variable
dependence."""

import logging
from copy import copy
from mythril.analysis.issue_annotation import IssueAnnotation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This module contains the detection code for predictable variable
dependence."""

import logging

from mythril.analysis.issue_annotation import IssueAnnotation
Expand Down
1 change: 1 addition & 0 deletions mythril/analysis/module/modules/ether_thief.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This module contains the detection code for unauthorized ether
withdrawal."""

import logging
from copy import copy

Expand Down
1 change: 1 addition & 0 deletions mythril/analysis/module/modules/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module contains the detection code for reachable exceptions."""

import logging

from typing import cast, List, Optional
Expand Down
2 changes: 1 addition & 1 deletion mythril/analysis/module/modules/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
symbol_factory,
Not,
Expression,
Bool,
SMTBool as Bool,
And,
)

Expand Down
1 change: 1 addition & 0 deletions mythril/analysis/module/modules/multiple_sends.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This module contains the detection code to find multiple sends occurring in
a single transaction."""

from copy import copy
from typing import cast, List
from mythril.analysis.issue_annotation import IssueAnnotation
Expand Down
1 change: 1 addition & 0 deletions mythril/analysis/module/modules/requirements_violation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module contains the detection code for requirement violations in a call"""

import logging

from mythril.analysis import solver
Expand Down
1 change: 0 additions & 1 deletion mythril/analysis/module/modules/suicide.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
ContractCreationTransaction,
)
import logging
from mythril.laser.ethereum.function_managers import keccak_function_manager


log = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from mythril.analysis.swc_data import TX_ORDER_DEPENDENCE
from mythril.laser.ethereum.transaction.symbolic import ACTORS
from mythril.analysis.module.base import DetectionModule
from mythril.laser.smt import Or, Bool
from mythril.laser.smt import Or, SMTBool as Bool
from mythril.laser.ethereum.state.global_state import GlobalState
from mythril.exceptions import UnsatError
import logging
Expand Down
1 change: 1 addition & 0 deletions mythril/analysis/module/modules/unchecked_retval.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This module contains detection code to find occurrences of calls whose
return value remains unchecked."""

from copy import copy
from typing import cast, List

Expand Down
1 change: 1 addition & 0 deletions mythril/analysis/module/modules/unexpected_ether.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module contains the detection code for unexpected ether balance."""

from mythril.analysis.report import Issue
from mythril.analysis.issue_annotation import IssueAnnotation
from mythril.analysis.swc_data import UNEXPECTED_ETHER_BALANCE
Expand Down
1 change: 1 addition & 0 deletions mythril/analysis/ops.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This module contains various helper methods for dealing with EVM
operations."""

from enum import Enum

from mythril.laser.ethereum import util
Expand Down
4 changes: 2 additions & 2 deletions mythril/analysis/report.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""This module provides classes that make up an issue report."""
import base64

import logging
import re
import json
Expand Down Expand Up @@ -242,7 +242,7 @@ def resolve_input(data, function_name):
for item in decoded_output
)
return decoded_output
except Exception as e:
except Exception:
return None


Expand Down
7 changes: 3 additions & 4 deletions mythril/analysis/symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from mythril.laser.ethereum.strategy.extensions.bounded_loops import (
BoundedLoopsStrategy,
)
from mythril.laser.plugin.plugins.state_merge.state_merge_plugin import StateMergePlugin
from mythril.laser.smt import symbol_factory, BitVec
from mythril.support.support_args import args
from typing import Union, List, Type, Optional
Expand Down Expand Up @@ -206,9 +205,9 @@ def __init__(
dynamic_loader=dynloader,
contract_name=contract.name,
balances=world_state.balances,
concrete_storage=True
if (dynloader is not None and dynloader.active)
else False,
concrete_storage=(
True if (dynloader is not None and dynloader.active) else False
),
) # concrete_storage can get overridden by global args

if dynloader is not None:
Expand Down
1 change: 1 addition & 0 deletions mythril/analysis/traceexplore.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This module provides a function to convert a state space into a set of state
nodes and transition edges."""

from z3 import Z3Exception
from mythril.laser.smt import simplify
from mythril.laser.ethereum.svm import NodeFlags
Expand Down
9 changes: 2 additions & 7 deletions mythril/concolic/concolic_execution.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import json
import binascii

from datetime import datetime, timedelta
from datetime import datetime
from typing import Dict, List, Any
from copy import deepcopy

from mythril.concolic.concrete_data import ConcreteData
from mythril.concolic.find_trace import concrete_execution
from mythril.disassembler.disassembly import Disassembly
from mythril.laser.ethereum.strategy.concolic import ConcolicStrategy
from mythril.laser.ethereum.svm import LaserEVM
from mythril.laser.ethereum.state.world_state import WorldState
from mythril.laser.ethereum.state.account import Account
from mythril.laser.ethereum.transaction.symbolic import execute_transaction
from mythril.laser.ethereum.transaction.transaction_models import tx_id_manager
from mythril.laser.smt import Expression, BitVec, symbol_factory
from mythril.laser.smt import symbol_factory
from mythril.laser.ethereum.time_handler import time_handler
from mythril.support.support_args import args

Expand Down
6 changes: 2 additions & 4 deletions mythril/concolic/find_trace.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import json
import binascii

from copy import deepcopy
from datetime import datetime
from typing import Dict, List, Tuple
from typing import List, Tuple

from mythril.concolic.concrete_data import ConcreteData

Expand All @@ -15,9 +14,8 @@
from mythril.laser.plugin.plugins import TraceFinderBuilder
from mythril.laser.ethereum.transaction.concolic import execute_transaction
from mythril.laser.plugin.loader import LaserPluginLoader
from mythril.laser.smt import Expression, BitVec, symbol_factory
from mythril.laser.smt import symbol_factory
from mythril.laser.ethereum.transaction.transaction_models import tx_id_manager
from mythril.plugin.discovery import PluginDiscovery
from mythril.support.support_args import args


Expand Down
1 change: 1 addition & 0 deletions mythril/disassembler/disassembly.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module contains the class used to represent disassembly code."""

from mythril.ethereum import util
from mythril.disassembler import asm
from mythril.support.signatures import SignatureDB
Expand Down
1 change: 1 addition & 0 deletions mythril/ethereum/evmcontract.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This module contains the class representing EVM contracts, aka Smart
Contracts."""

import re
import logging
import persistent
Expand Down
1 change: 1 addition & 0 deletions mythril/ethereum/interface/rpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This code is adapted from: https://github.com/ConsenSys/ethjsonrpc
"""

import json
import logging

Expand Down
1 change: 1 addition & 0 deletions mythril/ethereum/interface/rpc/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This file contains constants used used by the Ethereum JSON RPC
interface."""

BLOCK_TAG_EARLIEST = "earliest"
BLOCK_TAG_LATEST = "latest"
BLOCK_TAG_PENDING = "pending"
Expand Down
1 change: 1 addition & 0 deletions mythril/ethereum/interface/rpc/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This module contains various utility functions regarding the RPC data format
and validation."""

from .constants import BLOCK_TAGS


Expand Down
Loading

0 comments on commit 25de4e7

Please sign in to comment.