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

Update pre-commit hooks, replace black with black compatible ruff-format #1892

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@
# pre-commit autoupdate
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-toml
- id: check-yaml
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1
rev: v0.9.1
hooks:
# lint & attempt to correct failures
- id: ruff
args: [--fix, --show-fixes]
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
# compatible replacement for black
- id: ruff-format
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.8.0-1
rev: v3.10.0-2
hooks:
- id: shfmt
args: [--write, --indent, '4']
Expand All @@ -38,7 +37,7 @@ repos:
- id: pretty-format-toml
args: [--autofix]
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.1
rev: 0.31.0
hooks:
- id: check-circle-ci
- id: check-github-workflows
Expand Down
5 changes: 3 additions & 2 deletions myth
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""mythril.py: Bug hunting on the Ethereum blockchain
http://www.github.com/ConsenSys/mythril
"""
http://www.github.com/ConsenSys/mythril
"""

from sys import exit

import mythril.interfaces.cli
Expand Down
2 changes: 1 addition & 1 deletion mythril/analysis/module/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Mythril Detection Modules
"""Mythril Detection Modules

This module includes an definition of the DetectionModule interface.
DetectionModules implement different analysis rules to find weaknesses and vulnerabilities.
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 @@ -63,7 +63,6 @@ def get_detection_modules(
result = self._modules[:]

if white_list:

# Sanity check

available_names = [type(module).__name__ for module in result]
Expand Down
2 changes: 0 additions & 2 deletions mythril/analysis/module/modules/dependence_on_origin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def _analyze_state(self, state: GlobalState) -> List[Issue]:
# We're in JUMPI prehook

for annotation in state.mstate.stack[-2].annotations:

if isinstance(annotation, TxOriginAnnotation):
constraints = copy(state.world_state.constraints)

Expand Down Expand Up @@ -103,7 +102,6 @@ def _analyze_state(self, state: GlobalState) -> List[Issue]:
issues.append(issue)

else:

# In ORIGIN posthook

state.mstate.stack[-1].annotate(TxOriginAnnotation())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,13 @@ def _analyze_state(self, state: GlobalState) -> List[Issue]:
issues = []

if is_prehook():

opcode = state.get_current_instruction()["opcode"]

if opcode == "JUMPI":

# Look for predictable state variables in jump condition

for annotation in state.mstate.stack[-2].annotations:

if isinstance(annotation, PredictableValueAnnotation):

constraints = state.world_state.constraints
try:
transaction_sequence = solver.get_transaction_sequence(
Expand Down Expand Up @@ -137,7 +133,6 @@ def _analyze_state(self, state: GlobalState) -> List[Issue]:
issues.append(issue)

elif opcode == "BLOCKHASH":

param = state.mstate.stack[-1]

constraint = [
Expand All @@ -151,7 +146,6 @@ def _analyze_state(self, state: GlobalState) -> List[Issue]:
# Why the second constraint? Because without it Z3 returns a solution where param overflows.

try:

solver.get_model(
state.world_state.constraints + constraint # type: ignore
)
Expand Down
7 changes: 0 additions & 7 deletions mythril/analysis/module/modules/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ def _get_title(_type):

@staticmethod
def _handle_sstore(state: GlobalState) -> None:

stack = state.mstate.stack
value = stack[-2]

Expand All @@ -214,7 +213,6 @@ def _handle_sstore(state: GlobalState) -> None:

@staticmethod
def _handle_jumpi(state):

stack = state.mstate.stack
value = stack[-2]

Expand All @@ -226,7 +224,6 @@ def _handle_jumpi(state):

@staticmethod
def _handle_call(state):

stack = state.mstate.stack
value = stack[-3]

Expand All @@ -250,7 +247,6 @@ def _handle_return(state: GlobalState) -> None:
state_annotation = _get_overflowunderflow_state_annotation(state)

for element in state.mstate.memory[offset : offset + length]:

if not isinstance(element, Expression):
continue

Expand All @@ -259,11 +255,9 @@ def _handle_return(state: GlobalState) -> None:
state_annotation.overflowing_state_annotations.add(annotation)

def _handle_transaction_end(self, state: GlobalState) -> List[Issue]:

state_annotation = _get_overflowunderflow_state_annotation(state)
issues = []
for annotation in state_annotation.overflowing_state_annotations:

ostate = annotation.overflowing_state

if ostate in self._ostates_unsatisfiable:
Expand All @@ -289,7 +283,6 @@ def _handle_transaction_end(self, state: GlobalState) -> List[Issue]:
)

try:

constraints = state.world_state.constraints + [annotation.constraint]
transaction_sequence = solver.get_transaction_sequence(
state, constraints
Expand Down
1 change: 0 additions & 1 deletion mythril/analysis/module/modules/multiple_sends.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def _analyze_state(self, state: GlobalState):
call_offsets.append(state.get_current_instruction()["address"])

else: # RETURN or STOP

for offset in call_offsets[1:]:
try:
transaction_sequence = get_transaction_sequence(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def __copy__(self):
def get_issue(
self, global_state: GlobalState, detector: DetectionModule
) -> Optional[PotentialIssue]:

if not self.state_change_states:
return None
constraints = Constraints()
Expand Down Expand Up @@ -146,7 +145,6 @@ def _add_external_call(global_state: GlobalState) -> None:
pass

def _analyze_state(self, global_state: GlobalState) -> List[PotentialIssue]:

if global_state.environment.active_function_name == "constructor":
return []

Expand Down
1 change: 0 additions & 1 deletion mythril/analysis/module/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def get_detection_module_hooks(
"""
hook_dict: Mapping[str, List[Callable]] = defaultdict(list)
for module in modules:

hooks = module.pre_hooks if hook_type == "pre" else module.post_hooks

for op_code in map(lambda x: x.upper(), hooks):
Expand Down
1 change: 0 additions & 1 deletion mythril/analysis/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ def as_swc_standard_format(self):
_issues = []

for _, issue in self.issues.items():

idx = self.source.get_source_index(issue.bytecode_hash)
try:
title = SWC_TO_TITLE[issue.swc_id]
Expand Down
3 changes: 0 additions & 3 deletions mythril/analysis/symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,14 @@ def __init__(
self.calls: List[Call] = []

for key in self.nodes:

state_index = 0

for state in self.nodes[key].states:

instruction = state.get_current_instruction()

op = instruction["opcode"]

if op in ("CALL", "CALLCODE", "DELEGATECALL", "STATICCALL"):

stack = state.mstate.stack

if op in ("CALL", "CALLCODE"):
Expand Down
3 changes: 0 additions & 3 deletions mythril/analysis/traceexplore.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def get_serializable_statespace(statespace):
i += 1

for node_key in statespace.nodes:

node = statespace.nodes[node_key]

code = node.get_cfg_dict()["code"]
Expand Down Expand Up @@ -139,11 +138,9 @@ def get_state_accounts(node_state):
nodes.append(s_node)

for edge in statespace.edges:

if edge.condition is None:
label = ""
else:

try:
label = str(simplify(edge.condition)).replace("\n", "")
except Z3Exception:
Expand Down
2 changes: 0 additions & 2 deletions mythril/ethereum/evmcontract.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def matches_expression(self, expression):
tokens = re.split(r"\s+(and|or|not)\s+", expression, re.IGNORECASE)

for token in tokens:

if token in ("and", "or", "not"):
str_eval += " " + token + " "
continue
Expand All @@ -108,7 +107,6 @@ def matches_expression(self, expression):
m = re.match(r"^func#([a-zA-Z0-9\s_,(\\)\[\]]+)#$", token)

if m:

sign_hash = "0x" + sha3(m.group(1))[:4].hex()
str_eval += '"' + sign_hash + '" in self.disassembly.func_hashes'

Expand Down
3 changes: 1 addition & 2 deletions mythril/interfaces/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""mythril.py: Bug hunting on the Ethereum blockchain

http://www.github.com/ConsenSys/mythril
http://www.github.com/ConsenSys/mythril
"""

import argparse
Expand Down Expand Up @@ -840,7 +840,6 @@ def execute_command(
exit_with_error(args.outform, "Error saving graph: " + str(e))

elif args.statespace_json:

if not analyzer.contracts:
exit_with_error(
args.outform, "input files do not contain any valid contracts"
Expand Down
1 change: 0 additions & 1 deletion mythril/laser/ethereum/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def native_call(
memory_out_offset: Union[int, Expression],
memory_out_size: Union[int, Expression],
) -> Optional[List[GlobalState]]:

if isinstance(callee_address, BitVec) or not (
0 < int(callee_address, 16) <= PRECOMPILE_COUNT
):
Expand Down
1 change: 0 additions & 1 deletion mythril/laser/ethereum/cheat_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@ def handle_cheat_codes(
memory_out_offset: Union[int, Expression],
memory_out_size: Union[int, Expression],
):

insert_ret_val(global_state)
pass
3 changes: 1 addition & 2 deletions mythril/laser/ethereum/instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,8 +1237,7 @@ def _code_copy_helper(

global_state.mstate.memory[concrete_memory_offset + i] = int(
code[
2
* (concrete_code_offset + i) : 2
2 * (concrete_code_offset + i) : 2
* (concrete_code_offset + i + 1)
],
16,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def get_strategic_global_state(self) -> GlobalState:
"""

while True:

state = self.super_strategy.get_strategic_global_state()

annotations = cast(
Expand Down
2 changes: 0 additions & 2 deletions mythril/laser/ethereum/svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ def exec(self, create=False, track_gas=False) -> Optional[List[GlobalState]]:
hook()

for global_state in self.strategy:

if create and self._check_create_termination():
log.debug("Hit create timeout, returning.")
return final_states + [global_state] if track_gas else None
Expand Down Expand Up @@ -499,7 +498,6 @@ def execute_state(

new_global_states = []
else:

# First execute the post hook for the transaction ending instruction
self._execute_post_hook(op_code, [end_signal.global_state])

Expand Down
2 changes: 1 addition & 1 deletion mythril/laser/plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Laser plugins
"""Laser plugins

This module contains everything to do with laser plugins

Expand Down
2 changes: 1 addition & 1 deletion mythril/laser/plugin/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Plugin implementations
"""Plugin implementations

This module contains the implementation of some features

Expand Down
3 changes: 0 additions & 3 deletions mythril/laser/plugin/plugins/dependency_pruner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def get_dependency_annotation(state: GlobalState) -> DependencyAnnotation:
)

if len(annotations) == 0:

"""FIXME: Hack for carrying over state annotations from the STOP and RETURN states of
the previous states. The states are pushed on a stack in the world state annotation
and popped off the stack in the subsequent iteration. This might break if any
Expand Down Expand Up @@ -173,7 +172,6 @@ def wanna_execute(self, address: int, annotation: DependencyAnnotation) -> bool:

for location in storage_write_cache:
for dependency in dependencies:

# Is there a known read operation along this path that matches a write in the previous transaction?

try:
Expand Down Expand Up @@ -319,7 +317,6 @@ def _check_basic_block(address: int, annotation: DependencyAnnotation):

@symbolic_vm.laser_hook("add_world_state")
def world_state_filter_hook(state: GlobalState):

if isinstance(state.current_transaction, ContractCreationTransaction):
# Reset iteration variable
self.iteration = 0
Expand Down
2 changes: 0 additions & 2 deletions mythril/laser/plugin/plugins/mutation_pruner.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def staticcall_mutator_hook(global_state: GlobalState):

@symbolic_vm.laser_hook("add_world_state")
def world_state_filter_hook(global_state: GlobalState):

if isinstance(
global_state.current_transaction, ContractCreationTransaction
):
Expand All @@ -74,7 +73,6 @@ def world_state_filter_hook(global_state: GlobalState):
callvalue = global_state.environment.callvalue

try:

constraints = global_state.world_state.constraints + [
UGT(callvalue, symbol_factory.BitVecVal(0, 256))
]
Expand Down
1 change: 0 additions & 1 deletion mythril/laser/plugin/plugins/summary/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def __init__(
self.code = code

def __copy__(self):

annotation = SummaryTrackingAnnotation(
entry=self.entry,
storage_pairs=deepcopy(self.storage_pairs),
Expand Down
Loading
Loading