Skip to content

Commit 3f1ad3f

Browse files
dbastnorhh
andauthored
Update pre-commit hooks, replace black with compatible ruff-format (#1892)
The [Ruff Formatter](https://docs.astral.sh/ruff/formatter/) is an extremely fast Python code formatter designed as a drop-in replacement for Black. This leads to some adjustments as ruff already contains 2025 black style updates, see astral-sh/ruff#13371 Co-authored-by: Nikhil Parasaram <[email protected]>
1 parent 764f1d9 commit 3f1ad3f

34 files changed

+16
-70
lines changed

.pre-commit-config.yaml

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@
66
# pre-commit autoupdate
77
repos:
88
- repo: https://github.com/pre-commit/pre-commit-hooks
9-
rev: v4.6.0
9+
rev: v5.0.0
1010
hooks:
1111
- id: check-toml
1212
- id: check-yaml
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.6.1
14+
rev: v0.9.1
1515
hooks:
16+
# lint & attempt to correct failures
1617
- id: ruff
1718
args: [--fix, --show-fixes]
18-
- repo: https://github.com/psf/black
19-
rev: 24.8.0
20-
hooks:
21-
- id: black
19+
# compatible replacement for black
20+
- id: ruff-format
2221
- repo: https://github.com/scop/pre-commit-shfmt
23-
rev: v3.8.0-1
22+
rev: v3.10.0-2
2423
hooks:
2524
- id: shfmt
2625
args: [--write, --indent, '4']
@@ -38,7 +37,7 @@ repos:
3837
- id: pretty-format-toml
3938
args: [--autofix]
4039
- repo: https://github.com/python-jsonschema/check-jsonschema
41-
rev: 0.29.1
40+
rev: 0.31.0
4241
hooks:
4342
- id: check-circle-ci
4443
- id: check-github-workflows

myth

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
"""mythril.py: Bug hunting on the Ethereum blockchain
4-
http://www.github.com/ConsenSys/mythril
5-
"""
4+
http://www.github.com/ConsenSys/mythril
5+
"""
6+
67
from sys import exit
78

89
import mythril.interfaces.cli

mythril/analysis/module/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Mythril Detection Modules
1+
"""Mythril Detection Modules
22
33
This module includes an definition of the DetectionModule interface.
44
DetectionModules implement different analysis rules to find weaknesses and vulnerabilities.

mythril/analysis/module/loader.py

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def get_detection_modules(
6363
result = self._modules[:]
6464

6565
if white_list:
66-
6766
# Sanity check
6867

6968
available_names = [type(module).__name__ for module in result]

mythril/analysis/module/modules/dependence_on_origin.py

-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def _analyze_state(self, state: GlobalState) -> List[Issue]:
5656
# We're in JUMPI prehook
5757

5858
for annotation in state.mstate.stack[-2].annotations:
59-
6059
if isinstance(annotation, TxOriginAnnotation):
6160
constraints = copy(state.world_state.constraints)
6261

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

105104
else:
106-
107105
# In ORIGIN posthook
108106

109107
state.mstate.stack[-1].annotate(TxOriginAnnotation())

mythril/analysis/module/modules/dependence_on_predictable_vars.py

-6
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,13 @@ def _analyze_state(self, state: GlobalState) -> List[Issue]:
6666
issues = []
6767

6868
if is_prehook():
69-
7069
opcode = state.get_current_instruction()["opcode"]
7170

7271
if opcode == "JUMPI":
73-
7472
# Look for predictable state variables in jump condition
7573

7674
for annotation in state.mstate.stack[-2].annotations:
77-
7875
if isinstance(annotation, PredictableValueAnnotation):
79-
8076
constraints = state.world_state.constraints
8177
try:
8278
transaction_sequence = solver.get_transaction_sequence(
@@ -137,7 +133,6 @@ def _analyze_state(self, state: GlobalState) -> List[Issue]:
137133
issues.append(issue)
138134

139135
elif opcode == "BLOCKHASH":
140-
141136
param = state.mstate.stack[-1]
142137

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

153148
try:
154-
155149
solver.get_model(
156150
state.world_state.constraints + constraint # type: ignore
157151
)

mythril/analysis/module/modules/integer.py

-7
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ def _get_title(_type):
200200

201201
@staticmethod
202202
def _handle_sstore(state: GlobalState) -> None:
203-
204203
stack = state.mstate.stack
205204
value = stack[-2]
206205

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

215214
@staticmethod
216215
def _handle_jumpi(state):
217-
218216
stack = state.mstate.stack
219217
value = stack[-2]
220218

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

227225
@staticmethod
228226
def _handle_call(state):
229-
230227
stack = state.mstate.stack
231228
value = stack[-3]
232229

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

252249
for element in state.mstate.memory[offset : offset + length]:
253-
254250
if not isinstance(element, Expression):
255251
continue
256252

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

261257
def _handle_transaction_end(self, state: GlobalState) -> List[Issue]:
262-
263258
state_annotation = _get_overflowunderflow_state_annotation(state)
264259
issues = []
265260
for annotation in state_annotation.overflowing_state_annotations:
266-
267261
ostate = annotation.overflowing_state
268262

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

291285
try:
292-
293286
constraints = state.world_state.constraints + [annotation.constraint]
294287
transaction_sequence = solver.get_transaction_sequence(
295288
state, constraints

mythril/analysis/module/modules/multiple_sends.py

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def _analyze_state(self, state: GlobalState):
6363
call_offsets.append(state.get_current_instruction()["address"])
6464

6565
else: # RETURN or STOP
66-
6766
for offset in call_offsets[1:]:
6867
try:
6968
transaction_sequence = get_transaction_sequence(

mythril/analysis/module/modules/state_change_external_calls.py

-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def __copy__(self):
4242
def get_issue(
4343
self, global_state: GlobalState, detector: DetectionModule
4444
) -> Optional[PotentialIssue]:
45-
4645
if not self.state_change_states:
4746
return None
4847
constraints = Constraints()
@@ -146,7 +145,6 @@ def _add_external_call(global_state: GlobalState) -> None:
146145
pass
147146

148147
def _analyze_state(self, global_state: GlobalState) -> List[PotentialIssue]:
149-
150148
if global_state.environment.active_function_name == "constructor":
151149
return []
152150

mythril/analysis/module/util.py

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def get_detection_module_hooks(
2121
"""
2222
hook_dict: Mapping[str, List[Callable]] = defaultdict(list)
2323
for module in modules:
24-
2524
hooks = module.pre_hooks if hook_type == "pre" else module.post_hooks
2625

2726
for op_code in map(lambda x: x.upper(), hooks):

mythril/analysis/report.py

-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ def as_swc_standard_format(self):
344344
_issues = []
345345

346346
for _, issue in self.issues.items():
347-
348347
idx = self.source.get_source_index(issue.bytecode_hash)
349348
try:
350349
title = SWC_TO_TITLE[issue.swc_id]

mythril/analysis/symbolic.py

-3
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,14 @@ def __init__(
252252
self.calls: List[Call] = []
253253

254254
for key in self.nodes:
255-
256255
state_index = 0
257256

258257
for state in self.nodes[key].states:
259-
260258
instruction = state.get_current_instruction()
261259

262260
op = instruction["opcode"]
263261

264262
if op in ("CALL", "CALLCODE", "DELEGATECALL", "STATICCALL"):
265-
266263
stack = state.mstate.stack
267264

268265
if op in ("CALL", "CALLCODE"):

mythril/analysis/traceexplore.py

-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def get_serializable_statespace(statespace):
6868
i += 1
6969

7070
for node_key in statespace.nodes:
71-
7271
node = statespace.nodes[node_key]
7372

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

141140
for edge in statespace.edges:
142-
143141
if edge.condition is None:
144142
label = ""
145143
else:
146-
147144
try:
148145
label = str(simplify(edge.condition)).replace("\n", "")
149146
except Z3Exception:

mythril/ethereum/evmcontract.py

-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def matches_expression(self, expression):
9090
tokens = re.split(r"\s+(and|or|not)\s+", expression, re.IGNORECASE)
9191

9292
for token in tokens:
93-
9493
if token in ("and", "or", "not"):
9594
str_eval += " " + token + " "
9695
continue
@@ -108,7 +107,6 @@ def matches_expression(self, expression):
108107
m = re.match(r"^func#([a-zA-Z0-9\s_,(\\)\[\]]+)#$", token)
109108

110109
if m:
111-
112110
sign_hash = "0x" + sha3(m.group(1))[:4].hex()
113111
str_eval += '"' + sign_hash + '" in self.disassembly.func_hashes'
114112

mythril/interfaces/cli.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33
"""mythril.py: Bug hunting on the Ethereum blockchain
44
5-
http://www.github.com/ConsenSys/mythril
5+
http://www.github.com/ConsenSys/mythril
66
"""
77

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

842842
elif args.statespace_json:
843-
844843
if not analyzer.contracts:
845844
exit_with_error(
846845
args.outform, "input files do not contain any valid contracts"

mythril/laser/ethereum/call.py

-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ def native_call(
202202
memory_out_offset: Union[int, Expression],
203203
memory_out_size: Union[int, Expression],
204204
) -> Optional[List[GlobalState]]:
205-
206205
if isinstance(callee_address, BitVec) or not (
207206
0 < int(callee_address, 16) <= PRECOMPILE_COUNT
208207
):

mythril/laser/ethereum/cheat_code.py

-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,5 @@ def handle_cheat_codes(
3939
memory_out_offset: Union[int, Expression],
4040
memory_out_size: Union[int, Expression],
4141
):
42-
4342
insert_ret_val(global_state)
4443
pass

mythril/laser/ethereum/instructions.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1237,8 +1237,7 @@ def _code_copy_helper(
12371237

12381238
global_state.mstate.memory[concrete_memory_offset + i] = int(
12391239
code[
1240-
2
1241-
* (concrete_code_offset + i) : 2
1240+
2 * (concrete_code_offset + i) : 2
12421241
* (concrete_code_offset + i + 1)
12431242
],
12441243
16,

mythril/laser/ethereum/strategy/extensions/bounded_loops.py

-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ def get_strategic_global_state(self) -> GlobalState:
108108
"""
109109

110110
while True:
111-
112111
state = self.super_strategy.get_strategic_global_state()
113112

114113
annotations = cast(

mythril/laser/ethereum/svm.py

-2
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ def exec(self, create=False, track_gas=False) -> Optional[List[GlobalState]]:
334334
hook()
335335

336336
for global_state in self.strategy:
337-
338337
if create and self._check_create_termination():
339338
log.debug("Hit create timeout, returning.")
340339
return final_states + [global_state] if track_gas else None
@@ -499,7 +498,6 @@ def execute_state(
499498

500499
new_global_states = []
501500
else:
502-
503501
# First execute the post hook for the transaction ending instruction
504502
self._execute_post_hook(op_code, [end_signal.global_state])
505503

mythril/laser/plugin/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Laser plugins
1+
"""Laser plugins
22
33
This module contains everything to do with laser plugins
44

mythril/laser/plugin/plugins/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Plugin implementations
1+
"""Plugin implementations
22
33
This module contains the implementation of some features
44

mythril/laser/plugin/plugins/dependency_pruner.py

-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def get_dependency_annotation(state: GlobalState) -> DependencyAnnotation:
3030
)
3131

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

174173
for location in storage_write_cache:
175174
for dependency in dependencies:
176-
177175
# Is there a known read operation along this path that matches a write in the previous transaction?
178176

179177
try:
@@ -319,7 +317,6 @@ def _check_basic_block(address: int, annotation: DependencyAnnotation):
319317

320318
@symbolic_vm.laser_hook("add_world_state")
321319
def world_state_filter_hook(state: GlobalState):
322-
323320
if isinstance(state.current_transaction, ContractCreationTransaction):
324321
# Reset iteration variable
325322
self.iteration = 0

mythril/laser/plugin/plugins/mutation_pruner.py

-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def staticcall_mutator_hook(global_state: GlobalState):
6060

6161
@symbolic_vm.laser_hook("add_world_state")
6262
def world_state_filter_hook(global_state: GlobalState):
63-
6463
if isinstance(
6564
global_state.current_transaction, ContractCreationTransaction
6665
):
@@ -74,7 +73,6 @@ def world_state_filter_hook(global_state: GlobalState):
7473
callvalue = global_state.environment.callvalue
7574

7675
try:
77-
7876
constraints = global_state.world_state.constraints + [
7977
UGT(callvalue, symbol_factory.BitVecVal(0, 256))
8078
]

mythril/laser/plugin/plugins/summary/annotations.py

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def __init__(
3232
self.code = code
3333

3434
def __copy__(self):
35-
3635
annotation = SummaryTrackingAnnotation(
3736
entry=self.entry,
3837
storage_pairs=deepcopy(self.storage_pairs),

0 commit comments

Comments
 (0)