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

Conversation

webthethird
Copy link
Contributor

Extends #1699, adding more utilities to slither.utils.upgradeability, specifically related to finding a proxy's implementation address storage slot.

in `slither.utils.upgradeability`
 cut down on branches and nested blocks
 by adding an `is_function_modified` helper function
…ame state variable(s) as a new/modified function
when finding functions tainted by `new_modified_function_vars`
when finding functions tainted by `new_modified_functions`
when finding modified functions
when finding modified functions
like `get_proxy_implementation_slot(proxy: Contract)`
out of `get_proxy_implementation_slot`
since either one could be more useful.
@webthethird
Copy link
Contributor Author

I'm not sure why Test slither-read-storage is failing here, since this PR doesn't touch it. I checked the test details, here's what it says:

Run pytest tests/test_read_storage.py
bash: cannot set terminal process group (669): Inappropriate ioctl for device
bash: no job control in this shell
============================= test session starts ==============================
platform linux -- Python 3.8.16, pytest-[7](https://github.com/crytic/slither/actions/runs/4418537918/jobs/7745793871#step:7:8).2.2, pluggy-1.0.0
rootdir: /home/runner/work/slither/slither
plugins: cov-4.0.0, web3-6.0.0, xdist-3.2.1
collected 0 items / 1 error

==================================== ERRORS ====================================
_________________ ERROR collecting tests/test_read_storage.py __________________
slither/tools/read_storage/read_storage.py:9: in <module>
    from eth_abi import decode_single, encode_abi
E   ImportError: cannot import name 'decode_single' from 'eth_abi' (/opt/hostedtoolcache/Python/3.[8](https://github.com/crytic/slither/actions/runs/4418537918/jobs/7745793871#step:7:9).16/x64/lib/python3.8/site-packages/eth_abi/__init__.py)

During handling of the above exception, another exception occurred:
tests/test_read_storage.py:13: in <module>
    from slither.tools.read_storage import SlitherReadStorage
slither/tools/read_storage/__init__.py:1: in <module>
    from .read_storage import SlitherReadStorage
slither/tools/read_storage/read_storage.py:1[9](https://github.com/crytic/slither/actions/runs/4418537918/jobs/7745793871#step:7:10): in <module>
    sys.exit(-1)
E   SystemExit: -1
------------------------------- Captured stdout --------------------------------
ERROR: in order to use slither-read-storage, you need to install web3
$ pip3 install web3 --user

=========================== short test summary info ============================
ERROR tests/test_read_storage.py - SystemExit: -1
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.61s ===============================
Error: Process completed with exit code 2.

Seems unrelated to me, though I was hoping the problem would go away when I merged dev into this PR.

@elopez
Copy link
Member

elopez commented Mar 14, 2023

I think that is being tracked in #1710

Due to the non-deterministic order of `Function.all_nodes()`
i.e., `delegatecall(gas(), sload(0x3608...), 0, calldatasize(), 0, 0)`
where the slot is not defined as a bytes32 constant
but rather is hardcoded in the fallback.
@webthethird webthethird requested review from montyly and removed request for elopez, smonicas and 0xalpharush March 17, 2023 18:41
@montyly
Copy link
Member

montyly commented Mar 23, 2023

Outside of the conflict with dev, is this ready for another review?

…lity-utils

# Conflicts:
#	slither/tools/upgradeability/checks/variables_order.py
@webthethird
Copy link
Contributor Author

Outside of the conflict with dev, is this ready for another review?

I believe so

Copy link
Member

@montyly montyly left a comment

Choose a reason for hiding this comment

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

This looks good. Only minor comment to address, and we can merge it

slither/utils/upgradeability.py Outdated Show resolved Hide resolved
slither/utils/upgradeability.py Outdated Show resolved Hide resolved
slither/utils/upgradeability.py Show resolved Hide resolved
@webthethird
Copy link
Contributor Author

@montyly I believe I've addressed the minor changes



# pylint: disable=too-many-branches
def encode_ir_for_compare(ir: Union[Operation, Variable]) -> str:
Copy link
Member

Choose a reason for hiding this comment

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

It's great that we have added the types, because this does not sound right :)

Should we split this function in two?

  • encore_ir_for_compare
  • encore_variable_for_compare

Note that we probably have the same issue in the slither-similar code, but that should be fixed in another PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we split this function in two?

Done!

@montyly
Copy link
Member

montyly commented Mar 28, 2023

@0xalpharush : should I merge this, or do you want to take a stab at the tests architecture first?

@@ -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!

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this test to slither/tests/unit/utils/ and put the tests folder and its files under slither/tests/unit/testdata/?

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

@0xalpharush
Copy link
Contributor

@montyly I think we should merge dev into this branch so that the tests are run in CI

@webthethird
Copy link
Contributor Author

I think we should merge dev into this branch so that the tests are run in CI

Done, done and done!

@montyly montyly merged commit 8b2fd9a into crytic:dev Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants