Merge pull request #1535 from webthethird/slither/dev-upgradeability-complex-datatype

slither-check-upgradeability: support complex datatypes
pull/1661/head
Feist Josselin 2 years ago committed by GitHub
commit 1d52aeaf5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      scripts/ci_test_upgradability.sh
  2. 14
      slither/core/declarations/structure.py
  3. 4
      slither/core/solidity_types/user_defined_type.py
  4. 8
      tests/check-upgradeability/contractV1_struct.sol
  5. 8
      tests/check-upgradeability/contractV2_struct.sol
  6. 8
      tests/check-upgradeability/contractV2_struct_bug.sol
  7. 7
      tests/check-upgradeability/test_12.txt
  8. 12
      tests/check-upgradeability/test_13.txt

@ -155,6 +155,32 @@ then
exit 255 exit 255
fi fi
slither-check-upgradeability "$DIR_TESTS/contractV1_struct.sol" ContractV1 --new-contract-filename "$DIR_TESTS/contractV2_struct.sol" --new-contract-name ContractV2 > test_12.txt 2>&1
DIFF=$(diff test_12.txt "$DIR_TESTS/test_12.txt")
if [ "$DIFF" != "" ]
then
echo "slither-check-upgradeability 12 failed"
cat test_12.txt
echo ""
cat "$DIR_TESTS/test_12.txt"
echo ""
echo "$DIFF"
exit 255
fi
slither-check-upgradeability "$DIR_TESTS/contractV1_struct.sol" ContractV1 --new-contract-filename "$DIR_TESTS/contractV2_struct_bug.sol" --new-contract-name ContractV2 > test_13.txt 2>&1
DIFF=$(diff test_13.txt "$DIR_TESTS/test_13.txt")
if [ "$DIFF" != "" ]
then
echo "slither-check-upgradeability 13 failed"
cat test_13.txt
echo ""
cat "$DIR_TESTS/test_13.txt"
echo ""
echo "$DIFF"
exit 255
fi
rm test_1.txt rm test_1.txt
rm test_2.txt rm test_2.txt
rm test_3.txt rm test_3.txt
@ -166,3 +192,5 @@ rm test_8.txt
rm test_9.txt rm test_9.txt
rm test_10.txt rm test_10.txt
rm test_11.txt rm test_11.txt
rm test_12.txt
rm test_13.txt

@ -51,3 +51,17 @@ class Structure(SourceMapping):
def __str__(self) -> str: def __str__(self) -> str:
return self.name return self.name
def __eq__(self, other) -> bool:
if not isinstance(other, Structure):
return False
if len(self.elems) != len(other.elems):
return False
for idx, elem in enumerate(self.elems_ordered):
other_elem = other.elems_ordered[idx]
if str(other_elem.type) != str(elem.type) or other_elem.name != elem.name:
return False
return self.name == other.name
def __hash__(self):
return hash(self.name)

@ -72,8 +72,12 @@ class UserDefinedType(Type):
return str(type_used.name) return str(type_used.name)
def __eq__(self, other): def __eq__(self, other):
from slither.core.declarations.contract import Contract
if not isinstance(other, UserDefinedType): if not isinstance(other, UserDefinedType):
return False return False
if isinstance(self.type, Contract) and isinstance(other.type, Contract):
return self.type == other.type.name
return self.type == other.type return self.type == other.type
def __hash__(self): def __hash__(self):

@ -0,0 +1,8 @@
contract ContractV1{
struct Foo {
uint256 bar;
address baz;
}
address destination;
Foo foo;
}

@ -0,0 +1,8 @@
contract ContractV2{
struct Foo {
uint256 bar;
address baz;
}
address destination;
Foo foo;
}

@ -0,0 +1,8 @@
contract ContractV2{
struct Foo {
uint8 bar;
address baz;
}
address destination;
Foo foo;
}

@ -0,0 +1,7 @@
INFO:Slither:
Initializable contract not found, the contract does not follow a standard initalization schema.
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initializable-is-missing
INFO:Slither:
Initializable contract not found, the contract does not follow a standard initalization schema.
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initializable-is-missing
INFO:Slither:2 findings, 21 detectors run

@ -0,0 +1,12 @@
INFO:Slither:
Initializable contract not found, the contract does not follow a standard initalization schema.
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initializable-is-missing
INFO:Slither:
Different variables between ContractV1 (tests/check-upgradeability/contractV1_struct.sol#1-8) and ContractV2 (tests/check-upgradeability/contractV2_struct_bug.sol#1-8)
ContractV1.foo (tests/check-upgradeability/contractV1_struct.sol#7)
ContractV2.foo (tests/check-upgradeability/contractV2_struct_bug.sol#7)
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#incorrect-variables-with-the-v2
INFO:Slither:
Initializable contract not found, the contract does not follow a standard initalization schema.
Reference: https://github.com/crytic/slither/wiki/Upgradeability-Checks#initializable-is-missing
INFO:Slither:3 findings, 21 detectors run
Loading…
Cancel
Save