Improve slither-check-upgradability

pull/194/head
Josselin 6 years ago
parent 833e390707
commit f17d1dd9a7
  1. 2
      utils/upgradability/__main__.py
  2. 17
      utils/upgradability/compare_function_ids.py
  3. 2
      utils/upgradability/compare_variables_order.py

@ -56,7 +56,7 @@ def main():
if args.new_contract_name:
last_name = args.new_contract_name
compare_function_ids(last_version, proxy)
compare_function_ids(last_version, last_name, proxy, proxy_name)
compare_variables_order_proxy(last_version, last_name, proxy, proxy_name)
if args.new_version:

@ -11,20 +11,21 @@ from slither.utils.colors import red, green
logger = logging.getLogger("CompareFunctions")
logger.setLevel(logging.INFO)
def get_signatures(s):
functions = s.functions
functions = [f.full_name for f in functions if f.visibility in ['public', 'external']]
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 = [contract.state_variables for contract in s.contracts]
variables = [item for sublist in variables for item in sublist]
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, proxy):
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)
signatures_proxy = get_signatures(proxy)
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}

@ -69,7 +69,7 @@ def compare_variables_order_proxy(implem, implem_name, proxy, proxy_name):
found = False
for idx in range(0, len(order_proxy)):
(proxy_name, proxy_type) = order_proxy[idx]
if len(order_proxy) < idx:
if len(order_implem) <= idx:
logger.info(red('Extra variable in the proxy: {} {}'.format(proxy_name, proxy_type)))
continue
(implem_name, implem_type) = order_implem[idx]

Loading…
Cancel
Save