From d592e76dea61bea5c65c77b1fef968e023ddf109 Mon Sep 17 00:00:00 2001 From: Simone Date: Tue, 20 Feb 2024 19:46:09 +0100 Subject: [PATCH] Track storage variables read/written in assembly --- slither/core/cfg/node.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/slither/core/cfg/node.py b/slither/core/cfg/node.py index 9b53b0db9..87d0e16a2 100644 --- a/slither/core/cfg/node.py +++ b/slither/core/cfg/node.py @@ -11,6 +11,7 @@ from slither.core.declarations.solidity_variables import ( SolidityFunction, ) from slither.core.expressions.expression import Expression +from slither.core.expressions import CallExpression, Identifier, AssignmentOperation from slither.core.solidity_types import ElementaryType from slither.core.source_mapping.source_mapping import SourceMapping from slither.core.variables.local_variable import LocalVariable @@ -898,6 +899,21 @@ class Node(SourceMapping): # pylint: disable=too-many-public-methods # TODO: consider removing dependancy of solidity_call to internal_call self._solidity_calls.append(ir.function) self._internal_calls.append(ir.function) + if ( + isinstance(ir, SolidityCall) + and ir.function == SolidityFunction("sstore(uint256,uint256)") + and isinstance(ir.node.expression, CallExpression) + and isinstance(ir.node.expression.arguments[0], Identifier) + ): + self._vars_written.append(ir.arguments[0]) + if ( + isinstance(ir, SolidityCall) + and ir.function == SolidityFunction("sload(uint256)") + and isinstance(ir.node.expression, AssignmentOperation) + and isinstance(ir.node.expression.expression_right, CallExpression) + and isinstance(ir.node.expression.expression_right.arguments[0], Identifier) + ): + self._vars_read.append(ir.arguments[0]) if isinstance(ir, LowLevelCall): assert isinstance(ir.destination, (Variable, SolidityVariable)) self._low_level_calls.append((ir.destination, str(ir.function_name.value)))