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

Switch to stable Black #2536

Merged
merged 2 commits into from
Mar 1, 2022
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
2 changes: 1 addition & 1 deletion examples/evm/mappingchallenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


class StopAtDepth(Detector):
""" This just aborts explorations that are too deep """
"""This just aborts explorations that are too deep"""

def will_run_callback(self, *args):
with self.manticore.locked_context("seen_rep", dict) as reps:
Expand Down
2 changes: 1 addition & 1 deletion examples/script/concolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def constraints_to_constraintset(constupl):


def input_from_cons(constupl, datas):
" solve bytes in |datas| based on "
"solve bytes in |datas| based on"

def make_chr(c):
try:
Expand Down
4 changes: 2 additions & 2 deletions examples/wasm/if_check/solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@


def getchar(state):
""" Symbolic `getchar` implementation. Returns an arbitrary single byte """
"""Symbolic `getchar` implementation. Returns an arbitrary single byte"""
res = state.new_symbolic_value(32, "getchar_res")
state.constrain(0 < res)
state.constrain(res < 256)
return [res]


class PrintRetPlugin(Plugin):
""" A plugin that looks for states that returned zero and solves for their inputs """
"""A plugin that looks for states that returned zero and solves for their inputs"""

def will_terminate_state_callback(self, state, *args):
retval = state.stack.peek()
Expand Down
2 changes: 1 addition & 1 deletion manticore/core/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def p_expression_or(p):


def p_expression_neg(p):
"expression : NEG expression "
"expression : NEG expression"
p[0] = ~p[1]


Expand Down
16 changes: 8 additions & 8 deletions manticore/core/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class DecorateAllMeta(type):
@staticmethod
def _if_enabled(f):
""" decorator used to guard callbacks """
"""decorator used to guard callbacks"""

@wraps(f)
def g(self, *args, **kwargs):
Expand All @@ -44,17 +44,17 @@ def __init__(self):
self._plugin_context_name = f"{classname}_context_{hex(hash(self))}"

def enable(self):
""" Enable all callbacks """
"""Enable all callbacks"""
with self.manticore.locked_context() as context:
context[self._enabled_key] = True

def disable(self):
""" Disable all callbacks """
"""Disable all callbacks"""
with self.manticore.locked_context() as context:
context[self._enabled_key] = False

def is_enabled(self):
""" True if callbacks are enabled """
"""True if callbacks are enabled"""
with self.manticore.locked_context() as context:
return context.get(self._enabled_key, True)

Expand Down Expand Up @@ -85,18 +85,18 @@ def locked_context(self, key=None, value_type=list):

@property
def context(self):
""" Convenient access to shared context """
"""Convenient access to shared context"""
plugin_context_name = self._plugin_context_name
if plugin_context_name not in self.manticore.context:
self.manticore.context[plugin_context_name] = {}
return self.manticore.context[plugin_context_name]

def on_register(self):
""" Called by parent manticore on registration """
"""Called by parent manticore on registration"""
pass

def on_unregister(self):
""" Called be parent manticore on un-registration """
"""Called be parent manticore on un-registration"""
pass

def generate_testcase(self, state, testcase, message):
Expand Down Expand Up @@ -332,7 +332,7 @@ def create_stats(self):
return ps

def save_profiling_data(self, stream=None):
""":param stream: an output stream to write the profiling data """
""":param stream: an output stream to write the profiling data"""
ps = self.get_profiling_data()
# XXX(yan): pstats does not support dumping to a file stream, only to a file
# name. Below is essentially the implementation of pstats.dump_stats() without
Expand Down
16 changes: 8 additions & 8 deletions manticore/core/smtlib/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def add(self, constraint) -> None:
self._constraints.append(constraint)

def _get_sid(self) -> int:
""" Returns a unique id. """
"""Returns a unique id."""
assert self._child is None
self._sid += 1
return self._sid
Expand Down Expand Up @@ -232,23 +232,23 @@ def to_string(self, replace_constants: bool = False) -> str:
return result

def _declare(self, var):
""" Declare the variable `var` """
"""Declare the variable `var`"""
if var.name in self._declarations:
raise ValueError("Variable already declared")
self._declarations[var.name] = var
return var

def get_declared_variables(self):
""" Returns the variable expressions of this constraint set """
"""Returns the variable expressions of this constraint set"""
return self._declarations.values()

def get_variable(self, name):
""" Returns the variable declared under name or None if it does not exists """
"""Returns the variable declared under name or None if it does not exists"""
return self._declarations.get(name)

@property
def declarations(self):
""" Returns the variable expressions of this constraint set """
"""Returns the variable expressions of this constraint set"""
declarations = GetDeclarations()
for a in self.constraints:
try:
Expand Down Expand Up @@ -279,11 +279,11 @@ def __iter__(self):
return iter(self.constraints)

def __str__(self):
""" Returns a smtlib representation of the current state """
"""Returns a smtlib representation of the current state"""
return self.to_string()

def _make_unique_name(self, name="VAR"):
""" Makes a unique variable name"""
"""Makes a unique variable name"""
# the while loop is necessary because appending the result of _get_sid()
# is not guaranteed to make a unique name on the first try; a colliding
# name could have been added previously
Expand All @@ -292,7 +292,7 @@ def _make_unique_name(self, name="VAR"):
return name

def is_declared(self, expression_var) -> bool:
""" True if expression_var is declared in this constraint set """
"""True if expression_var is declared in this constraint set"""
if not isinstance(expression_var, Variable):
raise ValueError(f"Expression must be a Variable (not a {type(expression_var)})")
return any(expression_var is x for x in self.get_declared_variables())
Expand Down
2 changes: 1 addition & 1 deletion manticore/core/smtlib/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ class Array(Expression, abstract=True):
def __init__(self, *, index_bits: int, index_max: Optional[int], value_bits: int, **kwargs):
assert index_bits in (32, 64, 256)
assert value_bits in (8, 16, 32, 64, 256)
assert index_max is None or index_max >= 0 and index_max < 2 ** index_bits
assert index_max is None or index_max >= 0 and index_max < 2**index_bits
self._index_bits = index_bits
self._index_max = index_max
self._value_bits = value_bits
Expand Down
10 changes: 5 additions & 5 deletions manticore/core/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def join(self):


class WorkerThread(Worker):
""" A worker thread """
"""A worker thread"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -237,7 +237,7 @@ def join(self):


class WorkerProcess(Worker):
""" A worker process """
"""A worker process"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -278,21 +278,21 @@ def start(self, target: typing.Optional[typing.Callable] = None):


class DumpTCPHandler(socketserver.BaseRequestHandler):
""" TCP Handler that calls the `dump` method bound to the server """
"""TCP Handler that calls the `dump` method bound to the server"""

def handle(self):
self.request.sendall(self.server.dump())


class ReusableTCPServer(socketserver.TCPServer):
""" Custom socket server that gracefully allows the address to be reused """
"""Custom socket server that gracefully allows the address to be reused"""

allow_reuse_address = True
dump: typing.Optional[typing.Callable] = None


class LogCaptureWorker(DaemonThread):
""" Extended DaemonThread that runs a TCP server that dumps the captured logs """
"""Extended DaemonThread that runs a TCP server that dumps the captured logs"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion manticore/ethereum/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ABI:

@staticmethod
def _type_size(ty):
""" Calculate `static` type size """
"""Calculate `static` type size"""
if ty[0] in ("int", "uint", "bytesM", "function"):
return 32
elif ty[0] in ("tuple"):
Expand Down
4 changes: 2 additions & 2 deletions manticore/ethereum/manticore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,8 +1075,8 @@ def multi_tx_analysis(
args=None,
compile_args=None,
):
owner_account = self.create_account(balance=10 ** 10, name="owner", address=0x10000)
attacker_account = self.create_account(balance=10 ** 10, name="attacker", address=0x20000)
owner_account = self.create_account(balance=10**10, name="owner", address=0x10000)
attacker_account = self.create_account(balance=10**10, name="attacker", address=0x20000)
# Pretty print
logger.info("Starting symbolic create contract")

Expand Down
2 changes: 1 addition & 1 deletion manticore/ethereum/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def will_open_transaction_callback(self, state, tx):


class LoopDepthLimiter(Plugin):
""" This just aborts explorations that are too deep """
"""This just aborts explorations that are too deep"""

def __init__(self, loop_count_threshold=5, **kwargs):
super().__init__(**kwargs)
Expand Down
2 changes: 1 addition & 1 deletion manticore/ethereum/solidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(
abi,
warnings,
):
""" Contract metadata for Solidity-based contracts """
"""Contract metadata for Solidity-based contracts"""
self.name = name
if isinstance(source_code, bytes):
source_code = source_code.decode()
Expand Down
6 changes: 3 additions & 3 deletions manticore/ethereum/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ def manticore_verifier(
user_accounts = []
for n, address_i in enumerate(senders):
user_accounts.append(
m.create_account(balance=10 ** 10, address=address_i, name=f"sender_{n}")
m.create_account(balance=10**10, address=address_i, name=f"sender_{n}")
)
# the address used for deployment
owner_account = m.create_account(balance=10 ** 10, address=deployer, name="deployer")
owner_account = m.create_account(balance=10**10, address=deployer, name="deployer")
# the target contract account
contract_account = m.solidity_create_contract(
source_code,
Expand All @@ -162,7 +162,7 @@ def manticore_verifier(
name="contract_account",
)
# the address used for checking porperties
checker_account = m.create_account(balance=10 ** 10, address=psender, name="psender")
checker_account = m.create_account(balance=10**10, address=psender, name="psender")

print(f"# Owner account: 0x{int(owner_account):x}")
print(f"# Contract account: 0x{int(contract_account):x}")
Expand Down
2 changes: 1 addition & 1 deletion manticore/native/cpu/aarch64.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def write(self, register, value):
name = self._alias(register)
parent, size = self._table[name]
if isinstance(value, int):
assert value <= 2 ** size - 1
assert value <= 2**size - 1
else:
assert value.size == size

Expand Down
20 changes: 10 additions & 10 deletions manticore/native/cpu/abstractcpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _sig_is_varargs(sig: inspect.Signature) -> bool:


class CpuException(Exception):
""" Base cpu exception """
"""Base cpu exception"""


class DecodeException(CpuException):
Expand All @@ -66,11 +66,11 @@ class InstructionEmulationError(CpuException):


class DivideByZeroError(CpuException):
""" A division by zero """
"""A division by zero"""


class Interruption(CpuException):
""" A software interrupt. """
"""A software interrupt."""

def __init__(self, N):
super().__init__("CPU Software Interruption %08x" % N)
Expand Down Expand Up @@ -191,23 +191,23 @@ def type(self):

@property
def size(self):
""" Return bit size of operand """
"""Return bit size of operand"""
raise NotImplementedError

@property
def reg(self):
return self._reg_name(self.op.reg)

def address(self):
""" On a memory operand it returns the effective address """
"""On a memory operand it returns the effective address"""
raise NotImplementedError

def read(self):
""" It reads the operand value from the registers or memory """
"""It reads the operand value from the registers or memory"""
raise NotImplementedError

def write(self, value):
""" It writes the value of specific type to the registers or memory """
"""It writes the value of specific type to the registers or memory"""
raise NotImplementedError


Expand Down Expand Up @@ -252,12 +252,12 @@ def read(self, register):

@property
def all_registers(self):
""" Lists all possible register names (Including aliases) """
"""Lists all possible register names (Including aliases)"""
return tuple(self._aliases)

@property
def canonical_registers(self):
""" List the minimal most beautiful set of registers needed """
"""List the minimal most beautiful set of registers needed"""
raise NotImplementedError

def __contains__(self, register):
Expand Down Expand Up @@ -602,7 +602,7 @@ def last_executed_insn(self) -> Optional[Instruction]:
# Register access
@property
def regfile(self):
""" The RegisterFile of this cpu """
"""The RegisterFile of this cpu"""
return self._regfile

@property
Expand Down
2 changes: 1 addition & 1 deletion manticore/native/cpu/bitwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def SInt(value, width):
return Operators.ITEBV(
width,
Bit(value, width - 1) == 1,
GetNBits(value, width) - 2 ** width,
GetNBits(value, width) - 2**width,
GetNBits(value, width),
)

Expand Down
Loading