Static Analyzer for Solidity
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
slither/utils/upgradability/compare_function_ids.py

43 lines
1.6 KiB

'''
Check for functions collisions between a proxy and the implementation
More for information: https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357
'''
import logging
from slither import Slither
from slither.utils.function import get_function_id
from slither.utils.colors import red, green
logger = logging.getLogger("CompareFunctions")
logger.setLevel(logging.INFO)
def get_signatures(c):
functions = c.functions
functions = [f.full_name for f in functions if f.visibility in ['public', 'external'] and not f.is_constructor]
variables = c.state_variables
variables = [variable.name+ '()' for variable in variables if variable.visibility in ['public']]
return list(set(functions+variables))
def compare_function_ids(implem, implem_name, proxy, proxy_name):
implem_contract = implem.get_contract_from_name(implem_name)
proxy_contract = proxy.get_contract_from_name(proxy_name)
signatures_implem = get_signatures(implem_contract)
signatures_proxy = get_signatures(proxy_contract)
signatures_ids_implem = {get_function_id(s): s for s in signatures_implem}
signatures_ids_proxy = {get_function_id(s): s for s in signatures_proxy}
found = False
for (k, _) in signatures_ids_implem.items():
if k in signatures_ids_proxy:
found = True
logger.info(red('Function id collision found {} {}'.format(signatures_ids_implem[k],
signatures_ids_proxy[k])))
if not found:
logger.info(green('No function id collision found'))