Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
daejunpark committed Sep 11, 2024
1 parent 36ecb35 commit eb28518
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
9 changes: 4 additions & 5 deletions src/halmos/calldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import re
from collections.abc import Callable
from dataclasses import dataclass, field
from dataclasses import dataclass
from functools import reduce

from z3 import (
Expand Down Expand Up @@ -126,7 +126,8 @@ def get_dyn_sizes(self, name: str, typ: Type) -> tuple[list[int], BitVecRef]:
sizes = (
list(range(self.args.loop + 1))
if isinstance(typ, DynamicArrayType)
else [0, 32, 1024, 65] # bytes/string sizes # 65 is ECDSA signature size
# typ is bytes or string
else [0, 32, 1024, 65] # 65 is ECDSA signature size
)
if self.args.debug:
print(
Expand Down Expand Up @@ -194,9 +195,7 @@ def encode(self, name: str, typ: Type) -> EncodingResult:
items = [self.encode(f"{name}[{i}]", typ.base) for i in range(max(sizes))]
encoded = self.encode_tuple(items)
# generalized encoding for multiple sizes
return EncodingResult(
[size_var] + encoded.data, 32 + encoded.size, False
)
return EncodingResult([size_var] + encoded.data, 32 + encoded.size, False)

if isinstance(typ, BaseType):
new_symbol = f"p_{name}_{typ.typ}_{self.new_symbol_id():>02}"
Expand Down
26 changes: 14 additions & 12 deletions src/halmos/cheatcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
from .assertions import assert_cheatcode_handler
from .bytevec import ByteVec
from .calldata import (
DynamicArrayType,
DynamicParam,
FunctionInfo,
find_abi,
mk_calldata,
Expand Down Expand Up @@ -232,10 +230,13 @@ def create_calldata_contract(ex, arg, sevm, stack, step_id):

def create_calldata_contract_bool(ex, arg, sevm, stack, step_id):
contract_name = name_of(extract_string_argument(arg, 0))
include_view_functions = bool(int_of(
extract_bytes(arg, 4+32, 32), "symbolic boolean flag for SVM.createCalldata()"
))
return create_calldata_generic(ex, arg, sevm, stack, step_id, contract_name, include_view_functions=include_view_functions)
include_view = int_of(
extract_bytes(arg, 4 + 32 * 1, 32),
"symbolic boolean flag for SVM.createCalldata()",
)
return create_calldata_generic(
ex, arg, sevm, stack, step_id, contract_name, include_view=bool(include_view)
)


def create_calldata_file_contract(ex, arg, sevm, stack, step_id):
Expand All @@ -249,16 +250,17 @@ def create_calldata_file_contract(ex, arg, sevm, stack, step_id):
def create_calldata_file_contract_bool(ex, arg, sevm, stack, step_id):
filename = name_of(extract_string_argument(arg, 0))
contract_name = name_of(extract_string_argument(arg, 1))
include_view_functions = bool(int_of(
extract_bytes(arg, 4+32*2, 32), "symbolic boolean flag for SVM.createCalldata()"
))
include_view = int_of(
extract_bytes(arg, 4 + 32 * 2, 32),
"symbolic boolean flag for SVM.createCalldata()",
)
return create_calldata_generic(
ex, arg, sevm, stack, step_id, contract_name, filename, include_view_functions
ex, arg, sevm, stack, step_id, contract_name, filename, bool(include_view)
)


def create_calldata_generic(
ex, arg, sevm, stack, step_id, contract_name, filename=None, include_view_functions=False
ex, arg, sevm, stack, step_id, contract_name, filename=None, include_view=False
):
"""
Generate arbitrary symbolic calldata for the given contract.
Expand All @@ -280,7 +282,7 @@ def create_calldata_generic(
funselector = methodIdentifiers[funsig]
funinfo = FunctionInfo(funname, funsig, funselector)

if not include_view_functions:
if not include_view:
fun_abi = find_abi(abi, funinfo)
if fun_abi["stateMutability"] in ["pure", "view"]:
continue
Expand Down
2 changes: 1 addition & 1 deletion src/halmos/sevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
Xor,
ZeroExt,
eq,
is_eq,
is_false,
is_true,
sat,
simplify,
unsat,
is_eq,
)
from z3.z3util import is_expr_var

Expand Down

0 comments on commit eb28518

Please sign in to comment.