_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q226100
get_account_balance
train
def get_account_balance(address, token_type, hostport=None, proxy=None): """ Get the balance of an account for a particular token Returns an int """ assert proxy or hostport, 'Need proxy or hostport' if proxy is None: proxy = connect_hostport(hostport) balance_schema = { 'ty...
python
{ "resource": "" }
q226101
get_name_DID
train
def get_name_DID(name, proxy=None, hostport=None): """ Get the DID for a name or subdomain Return the DID string on success Return None if not found """ assert proxy or hostport, 'Need proxy or hostport' if proxy is None: proxy = connect_hostport(hostport) did_schema = { ...
python
{ "resource": "" }
q226102
get_JWT
train
def get_JWT(url, address=None): """ Given a URL, fetch and decode the JWT it points to. If address is given, then authenticate the JWT with the address. Return None if we could not fetch it, or unable to authenticate it. NOTE: the URL must be usable by the requests library """ jwt_txt = No...
python
{ "resource": "" }
q226103
decode_name_zonefile
train
def decode_name_zonefile(name, zonefile_txt): """ Decode a zone file for a name. Must be either a well-formed DNS zone file, or a legacy Onename profile. Return None on error """ user_zonefile = None try: # by default, it's a zonefile-formatted text file user_zonefile_defaul...
python
{ "resource": "" }
q226104
BlockstackAPIEndpointHandler._send_headers
train
def _send_headers(self, status_code=200, content_type='application/json', more_headers={}): """ Generate and reply headers """ self.send_response(status_code) self.send_header('content-type', content_type) self.send_header('Access-Control-Allow-Origin', '*') # CORS ...
python
{ "resource": "" }
q226105
BlockstackAPIEndpointHandler._reply_json
train
def _reply_json(self, json_payload, status_code=200): """ Return a JSON-serializable data structure """ self._send_headers(status_code=status_code) json_str = json.dumps(json_payload) self.wfile.write(json_str)
python
{ "resource": "" }
q226106
BlockstackAPIEndpointHandler._read_json
train
def _read_json(self, schema=None, maxlen=JSONRPC_MAX_SIZE): """ Read a JSON payload from the requester Return the parsed payload on success Return None on error """ # JSON post? request_type = self.headers.get('content-type', None) client_address_str = "{}...
python
{ "resource": "" }
q226107
BlockstackAPIEndpointHandler.parse_qs
train
def parse_qs(self, qs): """ Parse query string, but enforce one instance of each variable. Return a dict with the variables on success Return None on parse error """ qs_state = urllib2.urlparse.parse_qs(qs) ret = {} for qs_var, qs_value_list in qs_state.it...
python
{ "resource": "" }
q226108
BlockstackAPIEndpointHandler.get_path_and_qs
train
def get_path_and_qs(self): """ Parse and obtain the path and query values. We don't care about fragments. Return {'path': ..., 'qs_values': ...} on success Return {'error': ...} on error """ path_parts = self.path.split("?", 1) if len(path_parts) > 1: ...
python
{ "resource": "" }
q226109
BlockstackAPIEndpointHandler.OPTIONS_preflight
train
def OPTIONS_preflight( self, path_info ): """ Give back CORS preflight check headers """ self.send_response(200) self.send_header('Access-Control-Allow-Origin', '*') # CORS self.send_header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE') self.send_hea...
python
{ "resource": "" }
q226110
BlockstackAPIEndpointHandler.GET_names_owned_by_address
train
def GET_names_owned_by_address( self, path_info, blockchain, address ): """ Get all names owned by an address Returns the list on success Return 404 on unsupported blockchain Return 502 on failure to get names for any non-specified reason """ if not check_address(...
python
{ "resource": "" }
q226111
BlockstackAPIEndpointHandler.GET_account_record
train
def GET_account_record(self, path_info, account_addr, token_type): """ Get the state of a particular token account Returns the account """ if not check_account_address(account_addr): return self._reply_json({'error': 'Invalid address'}, status_code=400) if no...
python
{ "resource": "" }
q226112
BlockstackAPIEndpointHandler.GET_names
train
def GET_names( self, path_info ): """ Get all names in existence If `all=true` is set, then include expired names. Returns the list on success Returns 400 on invalid arguments Returns 502 on failure to get names """ include_expired = False qs_val...
python
{ "resource": "" }
q226113
BlockstackAPIEndpointHandler.GET_name_history
train
def GET_name_history(self, path_info, name): """ Get the history of a name or subdomain. Requires 'page' in the query string return the history on success return 400 on invalid start_block or end_block return 502 on failure to query blockstack server """ i...
python
{ "resource": "" }
q226114
BlockstackAPIEndpointHandler.GET_name_zonefile_by_hash
train
def GET_name_zonefile_by_hash( self, path_info, name, zonefile_hash ): """ Get a historic zonefile for a name With `raw=1` on the query string, return the raw zone file Reply 200 with {'zonefile': zonefile} on success Reply 204 with {'error': ...} if the zone file is non-standar...
python
{ "resource": "" }
q226115
BlockstackAPIEndpointHandler.GET_namespaces
train
def GET_namespaces( self, path_info ): """ Get the list of all namespaces Reply all existing namespaces Reply 502 if we can't reach the server for whatever reason """ qs_values = path_info['qs_values'] offset = qs_values.get('offset', None) count = qs_valu...
python
{ "resource": "" }
q226116
BlockstackAPIEndpointHandler.GET_namespace_info
train
def GET_namespace_info( self, path_info, namespace_id ): """ Look up a namespace's info Reply information about a namespace Reply 404 if the namespace doesn't exist Reply 502 for any error in talking to the blocksatck server """ if not check_namespace(namespace_id...
python
{ "resource": "" }
q226117
BlockstackAPIEndpointHandler.GET_namespace_num_names
train
def GET_namespace_num_names(self, path_info, namespace_id): """ Get the number of names in a namespace Reply the number on success Reply 404 if the namespace does not exist Reply 502 on failure to talk to the blockstack server """ if not check_namespace(namespace_...
python
{ "resource": "" }
q226118
BlockstackAPIEndpointHandler.GET_namespace_names
train
def GET_namespace_names( self, path_info, namespace_id ): """ Get the list of names in a namespace Reply the list of names in a namespace Reply 404 if the namespace doesn't exist Reply 502 for any error in talking to the blockstack server """ if not check_namespac...
python
{ "resource": "" }
q226119
BlockstackAPIEndpointHandler.GET_blockchain_ops
train
def GET_blockchain_ops( self, path_info, blockchain_name, blockheight ): """ Get the name's historic name operations Reply the list of nameops at the given block height Reply 404 for blockchains other than those supported Reply 502 for any error we have in talking to the blocksta...
python
{ "resource": "" }
q226120
BlockstackAPIEndpointHandler.GET_blockchain_name_record
train
def GET_blockchain_name_record( self, path_info, blockchain_name, name ): """ Get the name's blockchain record in full Reply the raw blockchain record on success Reply 404 if the name is not found Reply 502 if we have an error talking to the server """ if not chec...
python
{ "resource": "" }
q226121
BlockstackAPIEndpointHandler._get_balance
train
def _get_balance( self, get_address, min_confs ): """ Works only in test mode! Get the confirmed balance for an address """ bitcoind_opts = get_bitcoin_opts() bitcoind_host = bitcoind_opts['bitcoind_server'] bitcoind_port = bitcoind_opts['bitcoind_port'] b...
python
{ "resource": "" }
q226122
BlockstackAPIEndpoint.bind
train
def bind(self): """ Bind to our port """ log.debug("Set SO_REUSADDR") self.socket.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1 ) # we want daemon threads, so we join on abrupt shutdown (applies if multithreaded) self.daemon_threads = True ...
python
{ "resource": "" }
q226123
BlockstackAPIEndpoint.overloaded
train
def overloaded(self, client_addr): """ Deflect if we have too many inbound requests """ overloaded_txt = 'HTTP/1.0 429 Too Many Requests\r\nServer: BaseHTTP/0.3 Python/2.7.14+\r\nContent-type: text/plain\r\nContent-length: 17\r\n\r\nToo many requests' if BLOCKSTACK_TEST: ...
python
{ "resource": "" }
q226124
to_bytes
train
def to_bytes(obj, encoding='utf-8', errors=None, nonstring='simplerepr'): """Make sure that a string is a byte string :arg obj: An object to make sure is a byte string. In most cases this will be either a text string or a byte string. However, with ``nonstring='simplerepr'``, this can be used...
python
{ "resource": "" }
q226125
to_text
train
def to_text(obj, encoding='utf-8', errors=None, nonstring='simplerepr'): """Make sure that a string is a text string :arg obj: An object to make sure is a text string. In most cases this will be either a text string or a byte string. However, with ``nonstring='simplerepr'``, this can be used ...
python
{ "resource": "" }
q226126
push_images
train
def push_images(base_path, image_namespace, engine_obj, config, **kwargs): """ Pushes images to a Docker registry. Returns dict containing attributes used to push images. """ config_path = kwargs.get('config_path', engine_obj.auth_config_path) username = kwargs.get('username') password = kwargs.get('pas...
python
{ "resource": "" }
q226127
remove_existing_container
train
def remove_existing_container(engine_obj, service_name, remove_volumes=False): """ Remove a container for an existing service. Handy for removing an existing conductor. """ conductor_container_id = engine_obj.get_container_id_for_service(service_name) if engine_obj.service_is_running(service_name): ...
python
{ "resource": "" }
q226128
resolve_push_to
train
def resolve_push_to(push_to, default_url, default_namespace): ''' Given a push-to value, return the registry and namespace. :param push_to: string: User supplied --push-to value. :param default_url: string: Container engine's default_index value (e.g. docker.io). :return: tuple: registry_url, names...
python
{ "resource": "" }
q226129
conductorcmd_push
train
def conductorcmd_push(engine_name, project_name, services, **kwargs): """ Push images to a registry """ username = kwargs.pop('username') password = kwargs.pop('password') email = kwargs.pop('email') url = kwargs.pop('url') namespace = kwargs.pop('namespace') tag = kwargs.pop('tag') conf...
python
{ "resource": "" }
q226130
Deploy.get_route_templates
train
def get_route_templates(self): """ Generate Openshift route templates or playbook tasks. Each port on a service definition found in container.yml represents an externally exposed port. """ def _get_published_ports(service_config): result = [] for port in s...
python
{ "resource": "" }
q226131
DockerfileParser.preparse_iter
train
def preparse_iter(self): """ Comments can be anywhere. So break apart the Dockerfile into significant lines and any comments that precede them. And if a line is a carryover from the previous via an escaped-newline, bring the directive with it. """ to_yield = {} la...
python
{ "resource": "" }
q226132
Engine.run_container
train
def run_container(self, image_id, service_name, **kwargs): """Run a particular container. The kwargs argument contains individual parameter overrides from the service definition.""" run_kwargs = self.run_kwargs_for_service(service_name) run_kwargs.update(kwargs, relax=True) logge...
python
{ "resource": "" }
q226133
Engine.push
train
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 ...
python
{ "resource": "" }
q226134
Engine.login
train
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...
python
{ "resource": "" }
q226135
Engine._update_config_file
train
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(...
python
{ "resource": "" }
q226136
Engine._get_registry_auth
train
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)) ...
python
{ "resource": "" }
q226137
resolve_role_to_path
train
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 ...
python
{ "resource": "" }
q226138
get_role_fingerprint
train
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 ...
python
{ "resource": "" }
q226139
on_predicate
train
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', ...
python
{ "resource": "" }
q226140
expo
train
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...
python
{ "resource": "" }
q226141
fibo
train
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...
python
{ "resource": "" }
q226142
constant
train
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
python
{ "resource": "" }
q226143
IncorrectERC20InterfaceDetection.detect_incorrect_erc20_interface
train
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...
python
{ "resource": "" }
q226144
IncorrectERC20InterfaceDetection._detect
train
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: ...
python
{ "resource": "" }
q226145
LocalShadowing.detect_shadowing_definitions
train
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)""" ...
python
{ "resource": "" }
q226146
LocalShadowing._detect
train
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...
python
{ "resource": "" }
q226147
ConstCandidateStateVars._detect
train
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...
python
{ "resource": "" }
q226148
Suicidal.detect_suicidal_func
train
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...
python
{ "resource": "" }
q226149
Suicidal._detect
train
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...
python
{ "resource": "" }
q226150
UnusedReturnValues._detect
train
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....
python
{ "resource": "" }
q226151
PrinterInheritanceGraph._summary
train
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...
python
{ "resource": "" }
q226152
BuiltinSymbolShadowing.detect_builtin_shadowing_definitions
train
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...
python
{ "resource": "" }
q226153
BuiltinSymbolShadowing._detect
train
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...
python
{ "resource": "" }
q226154
detect_c3_function_shadowing
train
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. ...
python
{ "resource": "" }
q226155
UninitializedStateVarsDetection._detect
train
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)...
python
{ "resource": "" }
q226156
ExternalFunction.detect_functions_called
train
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...
python
{ "resource": "" }
q226157
ExternalFunction._contains_internal_dynamic_call
train
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...
python
{ "resource": "" }
q226158
ExternalFunction.get_base_most_function
train
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...
python
{ "resource": "" }
q226159
ExternalFunction.get_all_function_definitions
train
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...
python
{ "resource": "" }
q226160
ComplexFunction.detect_complex_func
train
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...
python
{ "resource": "" }
q226161
UnusedStateVars._detect
train
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 += "{}.{} ({}...
python
{ "resource": "" }
q226162
UninitializedLocalVars._detect
train
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...
python
{ "resource": "" }
q226163
UnindexedERC20EventParameters._detect
train
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...
python
{ "resource": "" }
q226164
Slither.print_functions
train
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)))
python
{ "resource": "" }
q226165
PrinterInheritance.output
train
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...
python
{ "resource": "" }
q226166
UninitializedStorageVars._detect
train
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...
python
{ "resource": "" }
q226167
Reentrancy._can_callback
train
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 """ ...
python
{ "resource": "" }
q226168
Reentrancy._can_send_eth
train
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
python
{ "resource": "" }
q226169
Node.remove_father
train
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]
python
{ "resource": "" }
q226170
Node.remove_son
train
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]
python
{ "resource": "" }
q226171
DeprecatedStandards.detect_deprecated_references_in_node
train
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...
python
{ "resource": "" }
q226172
DeprecatedStandards.detect_deprecated_references_in_contract
train
def detect_deprecated_references_in_contract(self, contract): """ Detects the usage of any deprecated built-in symbols. Returns: list of tuple: (state_variable | node, (detecting_signature, original_text, recommended_text))""" results = [] for state_variable in contract.var...
python
{ "resource": "" }
q226173
process
train
def process(filename, args, detector_classes, printer_classes): """ The core high-level code for running Slither static analysis. Returns: list(result), int: Result list and number of contracts analyzed """ ast = '--ast-compact-json' if args.legacy_ast: ast = '--ast-json' ar...
python
{ "resource": "" }
q226174
ConstantFunctions._detect
train
def _detect(self): """ Detect the constant function changing the state Recursively visit the calls Returns: list: {'vuln', 'filename,'contract','func','#varsWritten'} """ results = [] for c in self.contracts: for f in c.functions: ...
python
{ "resource": "" }
q226175
Contract.constructor
train
def constructor(self): ''' Return the contract's immediate constructor. If there is no immediate constructor, returns the first constructor executed, following the c3 linearization Return None if there is no constructor. ''' cst = self.constructor_...
python
{ "resource": "" }
q226176
Contract.get_functions_reading_from_variable
train
def get_functions_reading_from_variable(self, variable): ''' Return the functions reading the variable ''' return [f for f in self.functions if f.is_reading(variable)]
python
{ "resource": "" }
q226177
Contract.get_functions_writing_to_variable
train
def get_functions_writing_to_variable(self, variable): ''' Return the functions writting the variable ''' return [f for f in self.functions if f.is_writing(variable)]
python
{ "resource": "" }
q226178
Contract.get_source_var_declaration
train
def get_source_var_declaration(self, var): """ Return the source mapping where the variable is declared Args: var (str): variable name Returns: (dict): sourceMapping """ return next((x.source_mapping for x in self.variables if x.name == var))
python
{ "resource": "" }
q226179
Contract.get_source_event_declaration
train
def get_source_event_declaration(self, event): """ Return the source mapping where the event is declared Args: event (str): event name Returns: (dict): sourceMapping """ return next((x.source_mapping for x in self.events if x.name == event))
python
{ "resource": "" }
q226180
Contract.get_summary
train
def get_summary(self): """ Return the function summary Returns: (str, list, list, list, list): (name, inheritance, variables, fuction summaries, modifier summaries) """ func_summaries = [f.get_summary() for f in self.functions] modif_summaries = [f.get_summary() for ...
python
{ "resource": "" }
q226181
Contract.is_erc20
train
def is_erc20(self): """ Check if the contract is an erc20 token Note: it does not check for correct return values Returns: bool """ full_names = [f.full_name for f in self.functions] return 'transfer(address,uint256)' in full_names and\ ...
python
{ "resource": "" }
q226182
integrate_value_gas
train
def integrate_value_gas(result): ''' Integrate value and gas temporary arguments to call instruction ''' was_changed = True calls = [] while was_changed: # We loop until we do not find any call to value or gas was_changed = False # Find all the assignments ...
python
{ "resource": "" }
q226183
propagate_type_and_convert_call
train
def propagate_type_and_convert_call(result, node): ''' Propagate the types variables and convert tmp call to real call operation ''' calls_value = {} calls_gas = {} call_data = [] idx = 0 # use of while len() as result can be modified during the iteration while idx < len(result...
python
{ "resource": "" }
q226184
convert_to_push
train
def convert_to_push(ir, node): """ Convert a call to a PUSH operaiton The funciton assume to receive a correct IR The checks must be done by the caller May necessitate to create an intermediate operation (InitArray) Necessitate to return the lenght (see push documentation) As a result, the...
python
{ "resource": "" }
q226185
get_type
train
def get_type(t): """ Convert a type to a str If the instance is a Contract, return 'address' instead """ if isinstance(t, UserDefinedType): if isinstance(t.type, Contract): return 'address' return str(t)
python
{ "resource": "" }
q226186
find_references_origin
train
def find_references_origin(irs): """ Make lvalue of each Index, Member operation points to the left variable """ for ir in irs: if isinstance(ir, (Index, Member)): ir.lvalue.points_to = ir.variable_left
python
{ "resource": "" }
q226187
apply_ir_heuristics
train
def apply_ir_heuristics(irs, node): """ Apply a set of heuristic to improve slithIR """ irs = integrate_value_gas(irs) irs = propagate_type_and_convert_call(irs, node) irs = remove_unused(irs) find_references_origin(irs) return irs
python
{ "resource": "" }
q226188
Function.return_type
train
def return_type(self): """ Return the list of return type If no return, return None """ returns = self.returns if returns: return [r.type for r in returns] return None
python
{ "resource": "" }
q226189
Function.all_solidity_variables_read
train
def all_solidity_variables_read(self): """ recursive version of solidity_read """ if self._all_solidity_variables_read is None: self._all_solidity_variables_read = self._explore_functions( lambda x: x.solidity_variables_read) return self._all_solidity_variable...
python
{ "resource": "" }
q226190
Function.all_state_variables_written
train
def all_state_variables_written(self): """ recursive version of variables_written """ if self._all_state_variables_written is None: self._all_state_variables_written = self._explore_functions( lambda x: x.state_variables_written) return self._all_state_variabl...
python
{ "resource": "" }
q226191
Function.all_internal_calls
train
def all_internal_calls(self): """ recursive version of internal_calls """ if self._all_internals_calls is None: self._all_internals_calls = self._explore_functions(lambda x: x.internal_calls) return self._all_internals_calls
python
{ "resource": "" }
q226192
Function.all_low_level_calls
train
def all_low_level_calls(self): """ recursive version of low_level calls """ if self._all_low_level_calls is None: self._all_low_level_calls = self._explore_functions(lambda x: x.low_level_calls) return self._all_low_level_calls
python
{ "resource": "" }
q226193
Function.all_high_level_calls
train
def all_high_level_calls(self): """ recursive version of high_level calls """ if self._all_high_level_calls is None: self._all_high_level_calls = self._explore_functions(lambda x: x.high_level_calls) return self._all_high_level_calls
python
{ "resource": "" }
q226194
Function.all_library_calls
train
def all_library_calls(self): """ recursive version of library calls """ if self._all_library_calls is None: self._all_library_calls = self._explore_functions(lambda x: x.library_calls) return self._all_library_calls
python
{ "resource": "" }
q226195
Function.all_conditional_state_variables_read
train
def all_conditional_state_variables_read(self, include_loop=True): """ Return the state variable used in a condition Over approximate and also return index access It won't work if the variable is assigned to a temp variable """ if include_loop: if...
python
{ "resource": "" }
q226196
Function.all_conditional_solidity_variables_read
train
def all_conditional_solidity_variables_read(self, include_loop=True): """ Return the Soldiity variables directly used in a condtion Use of the IR to filter index access Assumption: the solidity vars are used directly in the conditional node It won't work if the v...
python
{ "resource": "" }
q226197
Function.all_solidity_variables_used_as_args
train
def all_solidity_variables_used_as_args(self): """ Return the Soldiity variables directly used in a call Use of the IR to filter index access Used to catch check(msg.sender) """ if self._all_solidity_variables_used_as_args is None: self._all_solid...
python
{ "resource": "" }
q226198
Function.is_protected
train
def is_protected(self): """ Determine if the function is protected using a check on msg.sender Only detects if msg.sender is directly used in a condition For example, it wont work for: address a = msg.sender require(a == owner) Returns...
python
{ "resource": "" }
q226199
SoltraEdge.auth_string
train
def auth_string(self): ''' Authenticate based on username and token which is base64-encoded ''' username_token = '{username}:{token}'.format(username=self.username, token=self.token) b64encoded_string = b64encode(username_token) auth_string = 'Token {b64}'.format(b64=b64...
python
{ "resource": "" }