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

slither-read-storage: Handle unstructured storage #1752

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
636d055
Handle conversion from hex string to int
webthethird Mar 13, 2023
7311ca0
Get constant storage slots,
webthethird Mar 13, 2023
f53d725
Determine value type stored in constant slot
webthethird Mar 13, 2023
200f2cc
Include constant slots in `get_storage_layout()`
webthethird Mar 13, 2023
ea0146c
Black format
webthethird Mar 13, 2023
dabe318
Call `get_constant_storage_slots` in `main`
webthethird Mar 13, 2023
4db313b
Handle keccak256 in bytes32 constant declaration
webthethird Mar 15, 2023
1fa25cc
Add test for unstructured storage support
webthethird Mar 15, 2023
340a022
Merge remote-tracking branch 'crytic/slither/dev' into dev-read-stora…
webthethird Mar 15, 2023
0dd6321
Merge `get_constant_storage_slots` into `get_all_storage_variables`
webthethird Mar 15, 2023
8dfe072
Handle storage slot hardcoded in fallback
webthethird Mar 15, 2023
7c8f14e
Handle storage slot hardcoded in fallback
webthethird Mar 15, 2023
90df442
Compact `get_all_storage_variables`
webthethird Mar 15, 2023
ea72130
Black
webthethird Mar 15, 2023
c8d7420
Use Literal.value instead of string casting
webthethird Mar 15, 2023
6b0f49a
Use `Contract.get_functions_reading_from_variable`,
webthethird Mar 15, 2023
285a6ba
Get Literal from expression
webthethird Mar 15, 2023
3e3dc68
Always check fallback function
webthethird Mar 15, 2023
c45287e
Merge remote-tracking branch 'crytic/slither/dev' into dev-read-stora…
webthethird Mar 15, 2023
c8a89ae
Modularize pytest fixtures used by both `test_read_storage`
webthethird Mar 15, 2023
f26ba13
pylint
webthethird Mar 15, 2023
9ad84ce
Merge remote-tracking branch 'crytic/slither/dev' into dev-read-stora…
webthethird Mar 16, 2023
4d80741
Change `isConnected` to `is_connected`
webthethird Mar 16, 2023
5434188
pylint: remove unused import
webthethird Mar 16, 2023
9f44726
Apply suggestions from code review
webthethird Mar 22, 2023
cac3427
Move fixtures into conftest.py
webthethird Mar 22, 2023
42698f2
Revert using `contracts_derived`
webthethird Mar 22, 2023
67aa471
pylint disable too-few-public-methods
webthethird Mar 22, 2023
f09aa2d
pylint
webthethird Mar 22, 2023
40bf399
Only handle sload from Literal
webthethird Mar 22, 2023
9ae6c2d
Black
webthethird Mar 22, 2023
b173082
Change default value of `func` to lambda expression
webthethird Mar 23, 2023
d5054c5
Minor fix
webthethird Mar 23, 2023
4c36d1b
Fixes in `find_hardcoded_slot_in_fallback`
webthethird Mar 23, 2023
ef5d05b
fold constant of hash expressions
0xalpharush Mar 23, 2023
faf54a9
handle exception
0xalpharush Mar 23, 2023
854f878
Add a few unhappy paths to unstructured_storage-0.8.10.sol
webthethird Mar 23, 2023
5220e50
Clean up and comment `find_hardcoded_slot_in_fallback`
webthethird Mar 24, 2023
3244433
Merge remote-tracking branch 'crytic/slither/fold-hash-expressions' i…
webthethird Mar 24, 2023
f8d94e8
Make exp parsing more robust, use ConstantFolding
webthethird Mar 24, 2023
6117abd
Add more "unhappy path" tests for unstructured storage
webthethird Mar 24, 2023
8dd932a
Black and pylint
webthethird Mar 24, 2023
0bf27ff
Black and pylint
webthethird Mar 24, 2023
4828a04
Revert moving import to top-level
webthethird Mar 24, 2023
0b2ddbc
Black again...
webthethird Mar 24, 2023
73cb16b
Remove print statements
webthethird Mar 24, 2023
16d50d3
Update test contract and expected result
webthethird Mar 24, 2023
260db9b
Use constant folding for cases like `BEACON_SLOT = `
webthethird Mar 24, 2023
a1b359d
Infer storage type from `sstore`
webthethird Mar 24, 2023
b3f7160
Pylint
webthethird Mar 24, 2023
35c9c00
Format
webthethird Mar 24, 2023
7bab369
Minor refactoring
webthethird Mar 24, 2023
77ad16b
Add comments
webthethird Mar 24, 2023
d2924ff
Merge into new tests dir structure
webthethird Mar 29, 2023
b7e1f3e
Add unstructured storage test to test_read_storage.py
webthethird Mar 29, 2023
ee3df3c
Pylint
webthethird Mar 29, 2023
fa6f7b6
Merge remote-tracking branch 'crytic/slither/dev' into dev-read-stora…
webthethird Mar 31, 2023
2cd62cb
Update setup.py
webthethird Apr 4, 2023
bd95810
Undo renamed directory
webthethird Apr 4, 2023
5649f66
Black/pylint
webthethird Apr 4, 2023
117bfbe
Put unstructured storage handling behind a flag,
webthethird Apr 13, 2023
1ffe92d
Handle `NotConstant` exception
webthethird Apr 13, 2023
0a19bce
Use assertion for precondition
webthethird Apr 13, 2023
a28c3ca
Better handling of `sload` from hardcoded slot
webthethird Apr 13, 2023
f14dbcc
Black
webthethird Apr 13, 2023
ca7eac0
Assume `sload` type is address iff found in fallback
webthethird Apr 13, 2023
d9ce126
Put self._constant_storage_slots behind flag
webthethird Apr 17, 2023
677849d
Handle NotConstant exception
webthethird Apr 17, 2023
0adecf6
Better bytes to string conversion
webthethird Apr 17, 2023
906fa8c
Black
webthethird Apr 17, 2023
04d7b67
Merge remote-tracking branch 'crytic/slither/dev' into dev-read-stora…
webthethird Apr 26, 2023
02e7466
Pylint after merge
webthethird Apr 26, 2023
bb58ea2
Disable too-many-locals in test_constant_folding.py
webthethird Apr 26, 2023
34e3902
Add missing solc_binary_path
webthethird Apr 26, 2023
846e2af
Add missing solc_binary_path
webthethird Apr 26, 2023
d2dad0f
Format comments, fix typo
webthethird Apr 27, 2023
132bf89
Merge branch 'dev' into dev-read-storage-unstructured
webthethird May 19, 2023
a7fdd4b
Merge branch 'dev' into dev-read-storage-unstructured
webthethird May 25, 2023
01722f6
Merge branch 'dev' into dev-read-storage-unstructured
webthethird Jun 8, 2023
abb7622
Update test_unstructured_storage
webthethird Jun 8, 2023
1fe9f25
Merge branch 'dev' into dev-read-storage-unstructured
webthethird Jun 9, 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
17 changes: 11 additions & 6 deletions slither/printers/guidance/echidna.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from slither.slithir.operations.binary import Binary
from slither.slithir.variables import Constant
from slither.utils.output import Output
from slither.visitors.expression.constants_folding import ConstantFolding
from slither.visitors.expression.constants_folding import ConstantFolding, NotConstant


def _get_name(f: Union[Function, Variable]) -> str:
Expand Down Expand Up @@ -178,11 +178,16 @@ def _extract_constants_from_irs( # pylint: disable=too-many-branches,too-many-n
all_cst_used_in_binary[str(ir.type)].append(
ConstantValue(str(r.value), str(r.type))
)
if isinstance(ir.variable_left, Constant) and isinstance(ir.variable_right, Constant):
if ir.lvalue:
type_ = ir.lvalue.type
cst = ConstantFolding(ir.expression, type_).result()
all_cst_used.append(ConstantValue(str(cst.value), str(type_)))
if isinstance(ir.variable_left, Constant) or isinstance(
ir.variable_right, Constant
):
if ir.lvalue:
try:
type_ = ir.lvalue.type
cst = ConstantFolding(ir.expression, type_).result()
all_cst_used.append(ConstantValue(str(cst.value), str(type_)))
except NotConstant:
pass
if isinstance(ir, TypeConversion):
if isinstance(ir.variable, Constant):
if isinstance(ir.type, TypeAlias):
Expand Down
2 changes: 2 additions & 0 deletions slither/solc_parsing/expressions/expression_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ def parse_expression(expression: Dict, caller_context: CallerContextExpression)
type_candidate = ElementaryType("uint256")
else:
type_candidate = ElementaryType("string")
elif type_candidate.startswith("rational_const "):
type_candidate = ElementaryType("uint256")
elif type_candidate.startswith("int_const "):
type_candidate = ElementaryType("uint256")
elif type_candidate.startswith("bool"):
Expand Down
7 changes: 7 additions & 0 deletions slither/tools/read_storage/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ def parse_args() -> argparse.Namespace:
default="latest",
)

parser.add_argument(
"--unstructured",
action="store_true",
help="Include unstructured storage slots",
)

cryticparser.init(parser)

return parser.parse_args()
Expand Down Expand Up @@ -133,6 +139,7 @@ def main() -> None:
rpc_info = RpcInfo(args.rpc_url, block)

srs = SlitherReadStorage(contracts, args.max_depth, rpc_info)
srs.unstructured = bool(args.unstructured)
# Remove target prefix e.g. rinkeby:0x0 -> 0x0.
address = target[target.find(":") + 1 :]
# Default to implementation address unless a storage address is given.
Expand Down
Loading