Improve slither-check-upgradability + add travis unit tests

pull/194/head
Josselin 6 years ago
parent cdda518e12
commit ea24e614be
  1. 12
      scripts/travis_test_upgradability.sh
  2. 49
      tests/check-upgradability/contract_initialization.sol
  3. 13
      tests/check-upgradability/test_5.txt
  4. 1
      utils/upgradability/__main__.py
  5. 4
      utils/upgradability/check_initialization.py

@ -44,7 +44,19 @@ then
exit -1
fi
slither-check-upgradability "$DIR_TESTS/proxy.sol" Proxy "$DIR_TESTS/contract_initialization.sol" Contract_no_bug --solc solc-0.5.0 > test_5.txt 2>&1
DIFF=$(diff test_5.txt "$DIR_TESTS/test_5.txt")
if [ "$DIFF" != "" ]
then
echo "slither-check-upgradability failed"
cat test_5.txt
cat "$DIR_TESTS/test_5.txt"
exit -1
fi
rm test_1.txt
rm test_2.txt
rm test_3.txt
rm test_4.txt
rm test_5.txt

@ -0,0 +1,49 @@
contract Initializable{
address destination;
modifier initializer(){
_;
}
}
contract Contract_no_bug is Initializable{
function initialize() public initializer{
}
}
contract Contract_lack_to_call_modifier is Initializable{
function initialize() public {
}
}
contract Contract_not_called_super_init is Contract_no_bug{
function initialize() public initializer{
}
}
contract Contract_no_bug_inherits is Contract_no_bug{
function initialize() public initializer{
Contract_no_bug.initialize();
}
}
contract Contract_double_call is Contract_no_bug, Contract_no_bug_inherits{
function initialize() public initializer{
Contract_no_bug_inherits.initialize();
Contract_no_bug.initialize();
}
}

@ -0,0 +1,13 @@
INFO:CheckInitialization:Contract_lack_to_call_modifier.initialize does not call initializer
INFO:CheckInitialization:Missing call to Contract_no_bug.initialize in Contract_not_called_super_init
INFO:CheckInitialization:Contract_no_bug.initialize() is called multiple time in Contract_double_call
INFO:CheckInitialization:Check the deployement script to ensure that these functions are called:
Contract_no_bug needs to be initialized by initialize()
Contract_lack_to_call_modifier needs to be initialized by initialize()
Contract_not_called_super_init needs to be initialized by initialize()
Contract_no_bug_inherits needs to be initialized by initialize()
Contract_double_call needs to be initialized by initialize()

INFO:CompareFunctions:No function id collision found
INFO:VariablesOrder:Variable in the proxy: destination address
INFO:VariablesOrder:No error found (variables ordering proxy <-> implementation)

@ -49,7 +49,6 @@ def main():
check_initialization(v1)
if not args.new_version:
compare_function_ids(v1, v1_name, proxy, proxy_name)
compare_variables_order_proxy(v1, v1_name, proxy, proxy_name)

@ -11,7 +11,7 @@ class MultipleInitTarget(Exception):
pass
def _get_initialize_functions(contract):
return [f for father in contract.inheritance for f in father.functions_not_inherited if f.name == 'initialize']
return [f for father in contract.inheritance + [contract] for f in father.functions_not_inherited if f.name == 'initialize']
def _get_all_internal_calls(function):
all_ir = function.all_slithir_operations()
@ -61,7 +61,7 @@ def check_initialization(s):
for f in missing_calls:
logger.info(red(f'Missing call to {f.contract.name}.{f.name} in {contract.name}'))
missing_call = True
double_calls = [f for f in all_init_functions_called if all_init_functions_called.count(f) > 1]
double_calls = list(set([f for f in all_init_functions_called if all_init_functions_called.count(f) > 1]))
for f in double_calls:
logger.info(red(f'{f.contract.name + "." + f.full_name} is called multiple time in {contract.name}'))
double_calls_found = True

Loading…
Cancel
Save