Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upgradeability utils #1757

Merged
merged 56 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
d04fc9e
Start `slither.utils.upgradeability`
webthethird Feb 27, 2023
ec537e5
Merge remote-tracking branch 'crytic/slither/dev' into dev-compare-up…
webthethird Feb 27, 2023
f08d2af
Implement `compare(v1: Contract, v2: Contract)`
webthethird Feb 27, 2023
ebd2201
Pylint
webthethird Feb 27, 2023
04c71c2
Add return statement (whoops!)
webthethird Feb 28, 2023
6b0124c
Merge remote-tracking branch 'crytic/slither/dev' into dev-compare-up…
webthethird Feb 28, 2023
5b361e8
Also consider an unmodified function tainted if it reads/writes the s…
webthethird Feb 28, 2023
6b9d21a
Make pylint happy (reduce branches)
webthethird Feb 28, 2023
3757601
Avoid duplicates, constants and immutables
webthethird Feb 28, 2023
770ca81
Avoid constructor
webthethird Feb 28, 2023
596b4d0
Avoid `slitherConstructorConstantVariables()`
webthethird Feb 28, 2023
480ee60
Avoid `slitherConstructorConstantVariables()`
webthethird Feb 28, 2023
37554ec
Bump to re-run CI tests
webthethird Mar 11, 2023
f1947bb
Add additional upgradeability utils
webthethird Mar 12, 2023
8181fae
Add docstrings
webthethird Mar 12, 2023
4c57168
Separate `get_proxy_implementation_var`
webthethird Mar 12, 2023
09128ab
pylint
webthethird Mar 14, 2023
a6d49d5
Merge remote-tracking branch 'crytic/slither/dev' into dev-upgradeabi…
webthethird Mar 14, 2023
3655708
Redesign `utils.upgradeability.is_function_modified`
webthethird Mar 14, 2023
c195a15
Handle `sload` from slot in `delegatecall` args
webthethird Mar 14, 2023
ccb98d8
Merge remote-tracking branch 'crytic/slither/dev' into dev-upgradeabi…
webthethird Mar 16, 2023
317af45
Minor bug fixes
webthethird Mar 16, 2023
9f4be7d
Include variables touched by tainted functions
webthethird Mar 16, 2023
6ff59f9
Copy/paste and tweak `encode_ir` to compare ir
webthethird Mar 16, 2023
701c8f3
Add test for slither.utils.upgradeability.compare
webthethird Mar 16, 2023
a035d27
pylint
webthethird Mar 16, 2023
c5b5463
Rename shadowed var
webthethird Mar 16, 2023
5622230
Return six lists instead of dictionary of lists
webthethird Mar 17, 2023
c159f56
Rewrite test for `utils.upgradeability`
webthethird Mar 17, 2023
a6f6fc0
Use `.state_variables_ordered` and `.is_constructor_variables`
webthethird Mar 17, 2023
af6727c
Add `Contract.fallback_function` and `.receive_function` properties
webthethird Mar 17, 2023
26f80cf
Use `Contract.fallback_function`
webthethird Mar 17, 2023
1a54d0d
Handle hardcoded slot sloaded in delegatecall
webthethird Mar 17, 2023
24dad03
Document when a newly created variable can be returned
webthethird Mar 17, 2023
9a9acbe
Comment when a newly created variable can be returned
webthethird Mar 17, 2023
f148bbc
Also search `parent_func.returns` in `find_delegate_from_name`
webthethird Mar 17, 2023
722a343
Remove unused TEST_upgrade_diff.json
webthethird Mar 17, 2023
fc1b94c
Handle named variable declared in assembly
webthethird Mar 17, 2023
cbbcb8c
pylint and black
webthethird Mar 17, 2023
bff30a3
Update upgradeability util tests
webthethird Mar 17, 2023
574afbe
Add `get_missing_vars` to util, use it in `compare`
webthethird Mar 17, 2023
f216817
Use `get_missing_vars` in MissingVariable detector
webthethird Mar 17, 2023
1588334
Fix `compare` return signature
webthethird Mar 17, 2023
0e708e6
Handle sload from integer slot, i.e., `sload(0)`
webthethird Mar 17, 2023
9192fef
Comment out ZosProxy test for now
webthethird Mar 17, 2023
72c6d78
Add SynthProxy.sol to test_upgradeability_util.py test
webthethird Mar 17, 2023
a292d8d
Merge remote-tracking branch 'crytic/slither/dev' into dev-upgradeabi…
webthethird Mar 23, 2023
78e2ea3
Add types to function signatures
webthethird Mar 24, 2023
c094818
Pylint
webthethird Mar 24, 2023
0ac4c01
Black
webthethird Mar 24, 2023
2695243
Create separate `encore_var_for_compare`
webthethird Mar 25, 2023
47c92f8
Fix ir encoding in comparison
webthethird Mar 27, 2023
ac88e8c
Merge remote-tracking branch 'crytic/slither/dev' into dev-upgradeabi…
webthethird Mar 28, 2023
be0e405
Move upgradeability util test files
webthethird Mar 28, 2023
8731a92
Add Path import
webthethird Mar 28, 2023
5703b9d
Add test for `Contract.fallback_function`
webthethird Mar 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions slither/core/declarations/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def __init__(self, compilation_unit: "SlitherCompilationUnit", scope: "FileScope
self._signatures: Optional[List[str]] = None
self._signatures_declared: Optional[List[str]] = None

self._fallback_function: Optional["FunctionContract"] = None
self._receive_function: Optional["FunctionContract"] = None

self._is_upgradeable: Optional[bool] = None
self._is_upgradeable_proxy: Optional[bool] = None
self._upgradeable_version: Optional[str] = None
Expand Down Expand Up @@ -663,6 +666,24 @@ def functions_and_modifiers_declared(self) -> List["Function"]:
"""
return self.functions_declared + self.modifiers_declared # type: ignore

@property
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test case under slither/tests/unit/core to ensure that it works for examples like #1331 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

def fallback_function(self) -> Optional["FunctionContract"]:
if self._fallback_function is None:
for f in self.functions:
if f.is_fallback:
self._fallback_function = f
break
return self._fallback_function

@property
def receive_function(self) -> Optional["FunctionContract"]:
if self._receive_function is None:
for f in self.functions:
if f.is_receive:
self._receive_function = f
break
return self._receive_function

def available_elements_from_inheritances(
self,
elements: Dict[str, "Function"],
Expand Down
23 changes: 6 additions & 17 deletions slither/tools/upgradeability/checks/variables_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
AbstractCheck,
CHECK_INFO,
)
from slither.utils.upgradeability import get_missing_vars
from slither.utils.output import Output


Expand Down Expand Up @@ -55,25 +56,13 @@ def _check(self) -> List[Output]:
contract2 = self.contract_v2

assert contract2

order1 = [
variable
for variable in contract1.state_variables_ordered
if not (variable.is_constant or variable.is_immutable)
]
order2 = [
variable
for variable in contract2.state_variables_ordered
if not (variable.is_constant or variable.is_immutable)
]
missing = get_missing_vars(contract1, contract2)

results = []
for idx, _ in enumerate(order1):
variable1 = order1[idx]
if len(order2) <= idx:
info: CHECK_INFO = ["Variable missing in ", contract2, ": ", variable1, "\n"]
json = self.generate_result(info)
results.append(json)
for variable1 in missing:
info: CHECK_INFO = ["Variable missing in ", contract2, ": ", variable1, "\n"]
json = self.generate_result(info)
results.append(json)

return results

Expand Down
Loading