INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Push an image to a remote registry. | def push(self, image_id, service_name, tag=None, namespace=None, url=None, username=None, password=None,
repository_prefix=None, **kwargs):
"""
Push an image to a remote registry.
"""
auth_config = {
'username': username,
'password': password
... |
If username and password are provided, authenticate with the registry.
Otherwise, check the config file for existing authentication data. | def login(self, username, password, email, url, config_path):
"""
If username and password are provided, authenticate with the registry.
Otherwise, check the config file for existing authentication data.
"""
if username and password:
try:
self.client.l... |
Update the config file with the authorization. | def _update_config_file(username, password, email, url, config_path):
"""Update the config file with the authorization."""
try:
# read the existing config
config = json.load(open(config_path, "r"))
except ValueError:
config = dict()
if not config.get(... |
Retrieve from the config file the current authentication for a given URL, and
return the username, password | def _get_registry_auth(registry_url, config_path):
"""
Retrieve from the config file the current authentication for a given URL, and
return the username, password
"""
username = None
password = None
try:
docker_config = json.load(open(config_path))
... |
Set default values for options. | def initialize_options(self):
"""Set default values for options."""
# Each user option must be listed here with their default value.
self.debug = False
self.ignore_errors = False
self.distros = ''
self.conductor_provider = 'ansible' |
Run command. | def run(self):
"""Run command."""
from container.cli import LOGGING
from logging import config
from container import core
if self.debug:
LOGGING['loggers']['container']['level'] = 'DEBUG'
config.dictConfig(LOGGING)
core.hostcmd_prebake(self.distros, de... |
Create a new role with initial files from templates.
:param role_name: Name of the role
:param role_path: Full path to the role
:param project_name: Name of the project, or the base path name.
:param description: One line description of the role.
:return: None | def create_role_from_templates(role_name=None, role_path=None,
project_name=None, description=None):
"""
Create a new role with initial files from templates.
:param role_name: Name of the role
:param role_path: Full path to the role
:param project_name: Name of the pro... |
Given a role definition from a service's list of roles, returns the file path to the role | def resolve_role_to_path(role):
"""
Given a role definition from a service's list of roles, returns the file path to the role
"""
loader = DataLoader()
try:
variable_manager = VariableManager(loader=loader)
except TypeError:
# If Ansible prior to ansible/ansible@8f97aef1a365
... |
Given a role definition from a service's list of roles, returns a hexdigest based on the role definition,
the role contents, and the hexdigest of each dependency | def get_role_fingerprint(role, service_name, config_vars):
"""
Given a role definition from a service's list of roles, returns a hexdigest based on the role definition,
the role contents, and the hexdigest of each dependency
"""
def hash_file(hash_obj, file_path):
blocksize = 64 * 1024
... |
Returns decorator for backoff and retry triggered by predicate.
Args:
wait_gen: A generator yielding successive wait times in
seconds.
predicate: A function which when called on the return value of
the target function will trigger backoff when considered
truthily... | def on_predicate(wait_gen,
predicate=operator.not_,
max_tries=None,
max_time=None,
jitter=full_jitter,
on_success=None,
on_backoff=None,
on_giveup=None,
logger='backoff',
... |
Returns decorator for backoff and retry triggered by exception.
Args:
wait_gen: A generator yielding successive wait times in
seconds.
exception: An exception type (or tuple of types) which triggers
backoff.
max_tries: The maximum number of attempts to make before gi... | def on_exception(wait_gen,
exception,
max_tries=None,
max_time=None,
jitter=full_jitter,
giveup=lambda e: False,
on_success=None,
on_backoff=None,
on_giveup=None,
logg... |
Generator for exponential decay.
Args:
base: The mathematical base of the exponentiation operation
factor: Factor to multiply the exponentation by.
max_value: The maximum value to yield. Once the value in the
true exponential sequence exceeds this, the value
of max... | def expo(base=2, factor=1, max_value=None):
"""Generator for exponential decay.
Args:
base: The mathematical base of the exponentiation operation
factor: Factor to multiply the exponentation by.
max_value: The maximum value to yield. Once the value in the
true exponential s... |
Generator for fibonaccial decay.
Args:
max_value: The maximum value to yield. Once the value in the
true fibonacci sequence exceeds this, the value
of max_value will forever after be yielded. | def fibo(max_value=None):
"""Generator for fibonaccial decay.
Args:
max_value: The maximum value to yield. Once the value in the
true fibonacci sequence exceeds this, the value
of max_value will forever after be yielded.
"""
a = 1
b = 1
while True:
if m... |
Generator for constant intervals.
Args:
interval: A constant value to yield or an iterable of such values. | def constant(interval=1):
"""Generator for constant intervals.
Args:
interval: A constant value to yield or an iterable of such values.
"""
try:
itr = iter(interval)
except TypeError:
itr = itertools.repeat(interval)
for val in itr:
yield val |
Check if the node reads tx.origin and doesn't read msg.sender
Avoid the FP due to (msg.sender == tx.origin)
Returns:
(bool) | def _contains_incorrect_tx_origin_use(node):
"""
Check if the node reads tx.origin and doesn't read msg.sender
Avoid the FP due to (msg.sender == tx.origin)
Returns:
(bool)
"""
solidity_var_read = node.solidity_variables_read
if solidity_var_... |
Detect incorrect ERC20 interface
Returns:
list(str) : list of incorrect function signatures | def detect_incorrect_erc20_interface(contract):
""" Detect incorrect ERC20 interface
Returns:
list(str) : list of incorrect function signatures
"""
functions = [f for f in contract.functions if f.contract == contract and \
IncorrectERC20InterfaceDetectio... |
Detect incorrect erc20 interface
Returns:
dict: [contrat name] = set(str) events | def _detect(self):
""" Detect incorrect erc20 interface
Returns:
dict: [contrat name] = set(str) events
"""
results = []
for c in self.contracts:
functions = IncorrectERC20InterfaceDetection.detect_incorrect_erc20_interface(c)
if functions:
... |
Detects if functions, access modifiers, events, state variables, and local variables are named after
reserved keywords. Any such definitions are returned in a list.
Returns:
list of tuple: (type, contract name, definition) | def detect_shadowing_definitions(self, contract):
""" Detects if functions, access modifiers, events, state variables, and local variables are named after
reserved keywords. Any such definitions are returned in a list.
Returns:
list of tuple: (type, contract name, definition)"""
... |
Detect shadowing local variables
Recursively visit the calls
Returns:
list: {'vuln', 'filename,'contract','func', 'shadow'} | def _detect(self):
""" Detect shadowing local variables
Recursively visit the calls
Returns:
list: {'vuln', 'filename,'contract','func', 'shadow'}
"""
results = []
for contract in self.contracts:
shadows = self.detect_shadowing_definitions(contr... |
:param detector_class: Class inheriting from `AbstractDetector`. | def register_detector(self, detector_class):
"""
:param detector_class: Class inheriting from `AbstractDetector`.
"""
self._check_common_things('detector', detector_class, AbstractDetector, self._detectors)
instance = detector_class(self, logger_detector)
self._detectors... |
:param printer_class: Class inheriting from `AbstractPrinter`. | def register_printer(self, printer_class):
"""
:param printer_class: Class inheriting from `AbstractPrinter`.
"""
self._check_common_things('printer', printer_class, AbstractPrinter, self._printers)
instance = printer_class(self, logger_printer)
self._printers.append(ins... |
:return: List of registered detectors results. | def run_detectors(self):
"""
:return: List of registered detectors results.
"""
self.load_previous_results()
results = [d.detect() for d in self._detectors]
self.write_results_to_hide()
return results |
Detect state variables that could be const | def _detect(self):
""" Detect state variables that could be const
"""
results = []
all_info = ''
all_variables = [c.state_variables for c in self.slither.contracts]
all_variables = set([item for sublist in all_variables for item in sublist])
all_non_constant_elem... |
_filename is not used
Args:
_filename(string) | def output(self, _filename):
"""
_filename is not used
Args:
_filename(string)
"""
for contract in self.slither.contracts_derived:
txt = "\nContract %s"%contract.name
table = PrettyTable(["Function",
... |
Detect if the function is suicidal
Detect the public functions calling suicide/selfdestruct without protection
Returns:
(bool): True if the function is suicidal | def detect_suicidal_func(func):
""" Detect if the function is suicidal
Detect the public functions calling suicide/selfdestruct without protection
Returns:
(bool): True if the function is suicidal
"""
if func.is_constructor:
return False
if func... |
Detect the suicidal functions | def _detect(self):
""" Detect the suicidal functions
"""
results = []
for c in self.contracts:
functions = self.detect_suicidal(c)
for func in functions:
txt = "{}.{} ({}) allows anyone to destruct the contract\n"
info = txt.format... |
Naive implementation of Cooper, Harvey, Kennedy algo
See 'A Simple,Fast Dominance Algorithm'
Compute strict domniators | def compute_dominators(nodes):
'''
Naive implementation of Cooper, Harvey, Kennedy algo
See 'A Simple,Fast Dominance Algorithm'
Compute strict domniators
'''
changed = True
for n in nodes:
n.dominators = set(nodes)
while changed:
changed = False
fo... |
Naive implementation of Cooper, Harvey, Kennedy algo
See 'A Simple,Fast Dominance Algorithm'
Compute dominance frontier | def compute_dominance_frontier(nodes):
'''
Naive implementation of Cooper, Harvey, Kennedy algo
See 'A Simple,Fast Dominance Algorithm'
Compute dominance frontier
'''
for node in nodes:
if len(node.fathers) >= 2:
for father in node.fathers:
runner... |
_filename is not used
Args:
_filename(string) | def output(self, _filename):
"""
_filename is not used
Args:
_filename(string)
"""
for contract in self.slither.contracts_derived:
txt = "\nContract %s"%contract.name
table = PrettyTable(["Function",
... |
Return the nodes where the return value of a call is unused
Args:
f (Function)
Returns:
list(Node) | def detect_unused_return_values(self, f):
"""
Return the nodes where the return value of a call is unused
Args:
f (Function)
Returns:
list(Node)
"""
values_returned = []
nodes_origin = {}
for n in f.nodes:
for ir in ... |
Detect high level calls which return a value that are never used | def _detect(self):
""" Detect high level calls which return a value that are never used
"""
results = []
for c in self.slither.contracts:
for f in c.functions + c.modifiers:
if f.contract != c:
continue
unused_return = self.... |
Check if the code is complex
Heuristic, the code is complex if:
- One function has a cyclomatic complexity > 7
Args:
contract | def is_complex_code(self, contract):
"""
Check if the code is complex
Heuristic, the code is complex if:
- One function has a cyclomatic complexity > 7
Args:
contract
"""
is_complex = self._is_complex_code(contract)
result = r... |
_filename is not used
Args:
_filename(string) | def output(self, _filename):
"""
_filename is not used
Args:
_filename(string)
"""
txt = "Analyze of {}\n".format(self.slither.filename)
txt += self.get_detectors_result()
for contract in self.slither.contracts_derived:
txt += "\nC... |
Obtain a string that describes variable shadowing for the given variable. None if no shadowing exists.
:param var: The variable to collect shadowing information for.
:param contract: The contract in which this variable is being analyzed.
:return: Returns a string describing variable shadowing fo... | def _get_indirect_shadowing_information(contract):
"""
Obtain a string that describes variable shadowing for the given variable. None if no shadowing exists.
:param var: The variable to collect shadowing information for.
:param contract: The contract in which this variable is being analy... |
Build summary using HTML | def _summary(self, contract):
"""
Build summary using HTML
"""
ret = ''
# Add arrows (number them if there is more than one path so we know order of declaration for inheritance).
if len(contract.immediate_inheritance) == 1:
ret += '%s -> %s;\n' % (contrac... |
Output the graph in filename
Args:
filename(string) | def output(self, filename):
"""
Output the graph in filename
Args:
filename(string)
"""
if filename == '':
filename = 'contracts.dot'
if not filename.endswith('.dot'):
filename += ".dot"
info = 'Inheritance Graph: ' ... |
_filename is not used
Args:
_filename(string) | def output(self, _filename):
"""
_filename is not used
Args:
_filename(string)
"""
txt = ""
for c in self.contracts:
(name, _inheritance, _var, func_summaries, _modif_summaries) = c.get_summary()
txt += blue("\n+ Contract %... |
Return the size in bits
Return None if the size is not known
Returns:
int | def size(self):
'''
Return the size in bits
Return None if the size is not known
Returns:
int
'''
t = self._type
if t.startswith('uint'):
return int(t[len('uint'):])
if t.startswith('int'):
return int(t[len('int'... |
Detects if local variables in a given function/modifier are named after built-in symbols.
Any such items are returned in a list.
Returns:
list of tuple: (type, definition, local variable parent) | def detect_builtin_shadowing_locals(self, function_or_modifier):
""" Detects if local variables in a given function/modifier are named after built-in symbols.
Any such items are returned in a list.
Returns:
list of tuple: (type, definition, local variable parent)"""
res... |
Detects if functions, access modifiers, events, state variables, or local variables are named after built-in
symbols. Any such definitions are returned in a list.
Returns:
list of tuple: (type, definition, [local variable parent]) | def detect_builtin_shadowing_definitions(self, contract):
""" Detects if functions, access modifiers, events, state variables, or local variables are named after built-in
symbols. Any such definitions are returned in a list.
Returns:
list of tuple: (type, definition, [local vari... |
Detect shadowing of built-in symbols
Recursively visit the calls
Returns:
list: {'vuln', 'filename,'contract','func', 'shadow'} | def _detect(self):
""" Detect shadowing of built-in symbols
Recursively visit the calls
Returns:
list: {'vuln', 'filename,'contract','func', 'shadow'}
"""
results = []
for contract in self.contracts:
shadows = self.detect_builtin_shadowing_defin... |
_filename is not used
Args:
_filename(string) | def output(self, _filename):
"""
_filename is not used
Args:
_filename(string)
"""
txt = ''
for contract in self.slither.contracts_derived:
txt += '\n{}:\n'.format(contract.name)
table = PrettyTable(['Name', 'ID'])
... |
_filename is not used
Args:
_filename(string) | def output(self, _filename):
"""
_filename is not used
Args:
_filename(string)
"""
for c in self.contracts:
(name, inheritance, var, func_summaries, modif_summaries) = c.get_summary()
txt = "\nContract %s"%name
txt += '... |
Return the function id of the given signature
Args:
sig (str)
Return:
(int) | def get_function_id(sig):
''''
Return the function id of the given signature
Args:
sig (str)
Return:
(int)
'''
s = sha3.keccak_256()
s.update(sig.encode('utf-8'))
return int("0x" + s.hexdigest()[:8], 16) |
Output the graph in filename
Args:
filename(string) | def output(self, filename):
"""
Output the graph in filename
Args:
filename(string)
"""
if not filename.endswith('.dot'):
filename += '.dot'
if filename == ".dot":
filename = "all_contracts.dot"
with open(filename,... |
_filename is not used
Args:
_filename(string) | def output(self, _filename):
"""
_filename is not used
Args:
_filename(string)
"""
txt = ""
for contract in self.contracts:
print('Contract {}'.format(contract.name))
for function in contract.functions:
if f... |
Detects and obtains functions which are indirectly shadowed via multiple inheritance by C3 linearization
properties, despite not directly inheriting from each other.
:param contract: The contract to check for potential C3 linearization shadowing within.
:return: A list of list of tuples: (contract, functio... | def detect_c3_function_shadowing(contract):
"""
Detects and obtains functions which are indirectly shadowed via multiple inheritance by C3 linearization
properties, despite not directly inheriting from each other.
:param contract: The contract to check for potential C3 linearization shadowing within.
... |
Detects and obtains functions which are shadowed immediately by the provided ancestor contract.
:param contract: The ancestor contract which we check for function shadowing within.
:return: A list of tuples (overshadowing_function, overshadowed_immediate_base_contract, overshadowed_function)
-overshadowing_... | def detect_direct_function_shadowing(contract):
"""
Detects and obtains functions which are shadowed immediately by the provided ancestor contract.
:param contract: The ancestor contract which we check for function shadowing within.
:return: A list of tuples (overshadowing_function, overshadowed_immedia... |
Detects all overshadowing and overshadowed functions in the provided contracts.
:param contracts: The contracts to detect shadowing within.
:param direct_shadowing: Include results from direct inheritance/inheritance ancestry.
:param indirect_shadowing: Include results from indirect inheritance collisions a... | def detect_function_shadowing(contracts, direct_shadowing=True, indirect_shadowing=True):
"""
Detects all overshadowing and overshadowed functions in the provided contracts.
:param contracts: The contracts to detect shadowing within.
:param direct_shadowing: Include results from direct inheritance/inher... |
Detects all overshadowing and overshadowed state variables in the provided contracts.
:param contracts: The contracts to detect shadowing within.
:return: Returns a set of tuples (overshadowing_contract, overshadowing_state_var, overshadowed_contract,
overshadowed_state_var).
The contract-variable pair'... | def detect_state_variable_shadowing(contracts):
"""
Detects all overshadowing and overshadowed state variables in the provided contracts.
:param contracts: The contracts to detect shadowing within.
:return: Returns a set of tuples (overshadowing_contract, overshadowing_state_var, overshadowed_contract,
... |
Detects pragma statements that allow for outdated solc versions.
:return: Returns the relevant JSON data for the findings. | def _detect(self):
"""
Detects pragma statements that allow for outdated solc versions.
:return: Returns the relevant JSON data for the findings.
"""
# Detect all version related pragmas and check if they are disallowed.
results = []
pragma = self.slither.pragma_d... |
Analyze event variable attributes
:param attributes: The event variable attributes to parse.
:return: None | def _analyze_variable_attributes(self, attributes):
"""
Analyze event variable attributes
:param attributes: The event variable attributes to parse.
:return: None
"""
# Check for the indexed attribute
if 'indexed' in attributes:
self._indexed = attrib... |
Args:
contract (Contract)
Returns:
list((Function), (list (Node))) | def detect_dangerous_timestamp(self, contract):
"""
Args:
contract (Contract)
Returns:
list((Function), (list (Node)))
"""
ret = []
for f in [f for f in contract.functions if f.contract == contract]:
nodes = self.timestamp(f)
... |
Return true if the variable is located in storage
See https://solidity.readthedocs.io/en/v0.4.24/types.html?highlight=storage%20location#data-location
Returns:
(bool) | def is_storage(self):
"""
Return true if the variable is located in storage
See https://solidity.readthedocs.io/en/v0.4.24/types.html?highlight=storage%20location#data-location
Returns:
(bool)
"""
if self.location == 'memory':
return False
... |
Detect uninitialized state variables
Recursively visit the calls
Returns:
dict: [contract name] = set(state variable uninitialized) | def _detect(self):
""" Detect uninitialized state variables
Recursively visit the calls
Returns:
dict: [contract name] = set(state variable uninitialized)
"""
results = []
for c in self.slither.contracts_derived:
ret = self.detect_uninitialized(c)... |
Detect shadowing
Recursively visit the calls
Returns:
list: {'vuln', 'filename,'contract','func', 'shadow'} | def _detect(self):
""" Detect shadowing
Recursively visit the calls
Returns:
list: {'vuln', 'filename,'contract','func', 'shadow'}
"""
results = []
for c in self.contracts:
shadowing = self.detect_shadowing(c)
if shadowing:
... |
Return the function signature
Returns:
(str, list(str)): name, list parameters type | def signature(self):
''' Return the function signature
Returns:
(str, list(str)): name, list parameters type
'''
return self.name, [str(x.type) for x in self.elems] |
Returns a list of InternallCall, SolidityCall
calls made in a function
Returns:
(list): List of all InternallCall, SolidityCall | def detect_functions_called(contract):
""" Returns a list of InternallCall, SolidityCall
calls made in a function
Returns:
(list): List of all InternallCall, SolidityCall
"""
result = []
# Obtain all functions reachable by this contract.
for func... |
Checks if a contract contains a dynamic call either in a direct definition, or through inheritance.
Returns:
(boolean): True if this contract contains a dynamic call (including through inheritance). | def _contains_internal_dynamic_call(contract):
"""
Checks if a contract contains a dynamic call either in a direct definition, or through inheritance.
Returns:
(boolean): True if this contract contains a dynamic call (including through inheritance).
"""
for func in c... |
Obtains the base function definition for the provided function. This could be used to obtain the original
definition of a function, if the provided function is an override.
Returns:
(function): Returns the base-most function of a provided function. (The original definition). | def get_base_most_function(function):
"""
Obtains the base function definition for the provided function. This could be used to obtain the original
definition of a function, if the provided function is an override.
Returns:
(function): Returns the base-most function of a pro... |
Obtains all function definitions given a base-most function. This includes the provided function, plus any
overrides of that function.
Returns:
(list): Returns any the provided function and any overriding functions defined for it. | def get_all_function_definitions(base_most_function):
"""
Obtains all function definitions given a base-most function. This includes the provided function, plus any
overrides of that function.
Returns:
(list): Returns any the provided function and any overriding functions de... |
_filename is not used
Args:
_filename(string) | def output(self, _filename):
"""
_filename is not used
Args:
_filename(string)
"""
txt = ''
for c in self.contracts:
txt += "\nContract %s\n"%c.name
table = PrettyTable(['Variable', 'Dependencies'])
for v in c.s... |
Detect the cyclomatic complexity of the contract functions
shouldn't be greater than 7 | def detect_complex_func(func):
"""Detect the cyclomatic complexity of the contract functions
shouldn't be greater than 7
"""
result = []
code_complexity = compute_cyclomatic_complexity(func)
if code_complexity > ComplexFunction.MAX_CYCLOMATIC_COMPLEXITY:
r... |
_filename is not used
Args:
_filename(string) | def output(self, original_filename):
"""
_filename is not used
Args:
_filename(string)
"""
for contract in self.contracts:
for function in contract.functions + contract.modifiers:
filename = "{}-{}-{}.dot".format(original_filen... |
Detect unused state variables | def _detect(self):
""" Detect unused state variables
"""
results = []
for c in self.slither.contracts_derived:
unusedVars = self.detect_unused(c)
if unusedVars:
info = ''
for var in unusedVars:
info += "{}.{} ({}... |
Detect uninitialized local variables
Recursively visit the calls
Returns:
dict: [contract name] = set(local variable uninitialized) | def _detect(self):
""" Detect uninitialized local variables
Recursively visit the calls
Returns:
dict: [contract name] = set(local variable uninitialized)
"""
results = []
self.results = []
self.visited_all_paths = {}
for contract in self.sl... |
Detect un-indexed ERC20 event parameters in a given contract.
:param contract: The contract to check ERC20 events for un-indexed parameters in.
:return: A list of tuple(event, parameter) of parameters which should be indexed. | def detect_erc20_unindexed_event_params(contract):
"""
Detect un-indexed ERC20 event parameters in a given contract.
:param contract: The contract to check ERC20 events for un-indexed parameters in.
:return: A list of tuple(event, parameter) of parameters which should be indexed.
... |
Detect un-indexed ERC20 event parameters in all contracts. | def _detect(self):
"""
Detect un-indexed ERC20 event parameters in all contracts.
"""
results = []
for c in self.contracts:
unindexed_params = self.detect_erc20_unindexed_event_params(c)
if unindexed_params:
info = "{} ({}) does not mark im... |
Transform slithIR vars to SSA (TemporaryVariable, ReferenceVariable, TupleVariable) | def transform_slithir_vars_to_ssa(function):
"""
Transform slithIR vars to SSA (TemporaryVariable, ReferenceVariable, TupleVariable)
"""
variables = []
for node in function.nodes:
for ir in node.irs_ssa:
if isinstance(ir, OperationWithLValue) and not ir.lvalue in variables:
... |
Add SSA version of the IR
Args:
function
all_state_variables_instances | def add_ssa_ir(function, all_state_variables_instances):
'''
Add SSA version of the IR
Args:
function
all_state_variables_instances
'''
if not function.is_implemented:
return
init_definition = dict()
for v in function.parameters:
if v.name:
i... |
Args:
ir (Operation)
local_variables_instances(dict(str -> LocalVariable))
state_variables_instances(dict(str -> StateVariable))
temporary_variables_instances(dict(int -> Variable))
reference_variables_instances(dict(int -> Variable))
Note: temporary and reference can be ind... | def copy_ir(ir, *instances):
'''
Args:
ir (Operation)
local_variables_instances(dict(str -> LocalVariable))
state_variables_instances(dict(str -> StateVariable))
temporary_variables_instances(dict(int -> Variable))
reference_variables_instances(dict(int -> Variable))
... |
Obtains a list of representing this function and any base definitions
:param function: The function to obtain all definitions at and beneath.
:return: Returns a list composed of the provided function definition and any base definitions. | def all_function_definitions(function):
"""
Obtains a list of representing this function and any base definitions
:param function: The function to obtain all definitions at and beneath.
:return: Returns a list composed of the provided function definition and any base definitions.
"""
return [fun... |
Obtains all functions which can lead to any of the target functions being called.
:param target_functions: The functions we are interested in reaching.
:return: Returns a list of all functions which can reach any of the target_functions. | def find_target_paths(target_functions):
"""
Obtains all functions which can lead to any of the target functions being called.
:param target_functions: The functions we are interested in reaching.
:return: Returns a list of all functions which can reach any of the target_functions.
"""
# Create ... |
Detect arbitrary send
Args:
contract (Contract)
Returns:
list((Function), (list (Node))) | def detect_arbitrary_send(self, contract):
"""
Detect arbitrary send
Args:
contract (Contract)
Returns:
list((Function), (list (Node)))
"""
ret = []
for f in [f for f in contract.functions if f.contract == contract]:
nodes =... |
Resolves a function instance, given a contract name and function.
:param contract_name: The name of the contract the function is declared in.
:param function_name: The name of the function to resolve.
:return: Returns the resolved function, raises an exception otherwise. | def resolve_function(slither, contract_name, function_name):
"""
Resolves a function instance, given a contract name and function.
:param contract_name: The name of the contract the function is declared in.
:param function_name: The name of the function to resolve.
:return: Returns the resolved func... |
Resolves the provided function descriptors.
:param functions: A list of tuples (contract_name, function_name) or str (of form "ContractName.FunctionName")
to resolve into function objects.
:return: Returns a list of resolved functions. | def resolve_functions(slither, functions):
"""
Resolves the provided function descriptors.
:param functions: A list of tuples (contract_name, function_name) or str (of form "ContractName.FunctionName")
to resolve into function objects.
:return: Returns a list of resolved functions.
"""
# Cre... |
list(Contract): List of contracts that are derived and not inherited. | def contracts_derived(self):
"""list(Contract): List of contracts that are derived and not inherited."""
inheritance = (x.inheritance for x in self.contracts)
inheritance = [item for sublist in inheritance for item in sublist]
return [c for c in self._contracts.values() if c not in inher... |
Return a contract from a name
Args:
contract_name (str): name of the contract
Returns:
Contract | def get_contract_from_name(self, contract_name):
"""
Return a contract from a name
Args:
contract_name (str): name of the contract
Returns:
Contract
"""
return next((c for c in self.contracts if c.name == contract_name), None) |
Export all the functions to dot files | def print_functions(self, d):
"""
Export all the functions to dot files
"""
for c in self.contracts:
for f in c.functions:
f.cfg_to_dot(os.path.join(d, '{}.{}.dot'.format(c.name, f.name))) |
Check if the result is valid
A result is invalid if:
- All its source paths belong to the source path filtered
- Or a similar result was reported and saved during a previous run | def valid_result(self, r):
'''
Check if the result is valid
A result is invalid if:
- All its source paths belong to the source path filtered
- Or a similar result was reported and saved during a previous run
'''
source_mapping_elements = [... |
Output the inheritance relation
_filename is not used
Args:
_filename(string) | def output(self, filename):
"""
Output the inheritance relation
_filename is not used
Args:
_filename(string)
"""
info = 'Inheritance\n'
if not self.contracts:
return
info += blue('Child_Contract -> ') + green('Im... |
Args:
variable (Variable)
source (Variable)
context (Contract|Function)
only_unprotected (bool): True only unprotected function are considered
Returns:
bool | def is_dependent(variable, source, context, only_unprotected=False):
'''
Args:
variable (Variable)
source (Variable)
context (Contract|Function)
only_unprotected (bool): True only unprotected function are considered
Returns:
bool
'''
assert isinstance(context,... |
Args:
variable (Variable)
taint (Variable)
context (Contract|Function)
only_unprotected (bool): True only unprotected function are considered
Returns:
bool | def is_dependent_ssa(variable, source, context, only_unprotected=False):
'''
Args:
variable (Variable)
taint (Variable)
context (Contract|Function)
only_unprotected (bool): True only unprotected function are considered
Returns:
bool
'''
assert isinstance(conte... |
Args:
variable
context (Contract|Function)
only_unprotected (bool): True only unprotected function are considered
Returns:
bool | def is_tainted(variable, context, only_unprotected=False, ignore_generic_taint=False):
'''
Args:
variable
context (Contract|Function)
only_unprotected (bool): True only unprotected function are considered
Returns:
bool
'''
assert isinstance(context, (Contract, Fun... |
Args:
variable
context (Contract|Function)
only_unprotected (bool): True only unprotected function are considered
Returns:
bool | def is_tainted_ssa(variable, context, only_unprotected=False, ignore_generic_taint=False):
'''
Args:
variable
context (Contract|Function)
only_unprotected (bool): True only unprotected function are considered
Returns:
bool
'''
assert isinstance(context, (Contract, Fun... |
Args:
variable
context (Contract|Function)
only_unprotected (bool): True only unprotected function are considered
Returns:
list(Variable) | def get_dependencies(variable, context, only_unprotected=False):
'''
Args:
variable
context (Contract|Function)
only_unprotected (bool): True only unprotected function are considered
Returns:
list(Variable)
'''
assert isinstance(context, (Contract, Function))
asse... |
Detect uninitialized storage variables
Recursively visit the calls
Returns:
dict: [contract name] = set(storage variable uninitialized) | def _detect(self):
""" Detect uninitialized storage variables
Recursively visit the calls
Returns:
dict: [contract name] = set(storage variable uninitialized)
"""
results = []
self.results = []
self.visited_all_paths = {}
for contract in sel... |
Detect if the node contains a call that can
be used to re-entrance
Consider as valid target:
- low level call
- high level call
Do not consider Send/Transfer as there is not enough gas | def _can_callback(self, irs):
"""
Detect if the node contains a call that can
be used to re-entrance
Consider as valid target:
- low level call
- high level call
Do not consider Send/Transfer as there is not enough gas
"""
... |
Detect if the node can send eth | def _can_send_eth(irs):
"""
Detect if the node can send eth
"""
for ir in irs:
if isinstance(ir, (HighLevelCall, LowLevelCall, Transfer, Send)):
if ir.call_value:
return True
return False |
Check if the node is a condtional node where
there is an external call checked
Heuristic:
- The call is a IF node
- It contains a, external call
- The condition is the negation (!)
This will work only on naive implementation | def _filter_if(self, node):
"""
Check if the node is a condtional node where
there is an external call checked
Heuristic:
- The call is a IF node
- It contains a, external call
- The condition is the negation (!)
Th... |
Explore the CFG and look for re-entrancy
Heuristic: There is a re-entrancy if a state variable is written
after an external call
node.context will contains the external calls executed
It contains the calls executed in father nodes
if node.context... | def _explore(self, node, visited, skip_father=None):
"""
Explore the CFG and look for re-entrancy
Heuristic: There is a re-entrancy if a state variable is written
after an external call
node.context will contains the external calls executed
... |
Return:
Node | def _parse_block(self, block, node):
'''
Return:
Node
'''
assert block[self.get_key()] == 'Block'
if self.is_compact_ast:
statements = block['statements']
else:
statements = block[self.get_children('children')]
for statement i... |
Can occur on:
if(..){
return
}
else{
return
}
Iterate until a fix point to remove the ENDIF node
creates on the following pattern
if(){
return
}
else if(){
... | def _remove_alone_endif(self):
"""
Can occur on:
if(..){
return
}
else{
return
}
Iterate until a fix point to remove the ENDIF node
creates on the following pattern
if(){
... |
Check if the node is a IF node
Returns:
bool: True if the node is a conditional node (IF or IFLOOP) | def contains_if(self, include_loop=True):
"""
Check if the node is a IF node
Returns:
bool: True if the node is a conditional node (IF or IFLOOP)
"""
if include_loop:
return self.type in [NodeType.IF, NodeType.IFLOOP]
return self.type == NodeTy... |
_filename is not used
Args:
_filename(string) | def output(self, _filename):
"""
_filename is not used
Args:
_filename(string)
"""
for contract in self.contracts:
txt = "\nContract %s\n"%contract.name
table = PrettyTable(["Function", "State variables written", "Conditions on msg... |
Check if the node is a conditional node
A conditional node is either a IF or a require/assert or a RETURN bool
Returns:
bool: True if the node is a conditional node | def is_conditional(self, include_loop=True):
"""
Check if the node is a conditional node
A conditional node is either a IF or a require/assert or a RETURN bool
Returns:
bool: True if the node is a conditional node
"""
if self.contains_if(include_loop) ... |
Remove the father node. Do nothing if the node is not a father
Args:
fathers: list of fathers to add | def remove_father(self, father):
""" Remove the father node. Do nothing if the node is not a father
Args:
fathers: list of fathers to add
"""
self._fathers = [x for x in self._fathers if x.node_id != father.node_id] |
Remove the son node. Do nothing if the node is not a son
Args:
fathers: list of fathers to add | def remove_son(self, son):
""" Remove the son node. Do nothing if the node is not a son
Args:
fathers: list of fathers to add
"""
self._sons = [x for x in self._sons if x.node_id != son.node_id] |
Detects if an expression makes use of any deprecated standards.
Returns:
list of tuple: (detecting_signature, original_text, recommended_text) | def detect_deprecation_in_expression(self, expression):
""" Detects if an expression makes use of any deprecated standards.
Returns:
list of tuple: (detecting_signature, original_text, recommended_text)"""
# Perform analysis on this expression
export = ExportValues(expressio... |
Detects if a node makes use of any deprecated standards.
Returns:
list of tuple: (detecting_signature, original_text, recommended_text) | def detect_deprecated_references_in_node(self, node):
""" Detects if a node makes use of any deprecated standards.
Returns:
list of tuple: (detecting_signature, original_text, recommended_text)"""
# Define our results list
results = []
# If this node has an expressi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.