Merge pull request #2329 from crytic/dev-constant-yul

Track storage variables read/written in assembly
pull/2341/head
alpharush 9 months ago committed by GitHub
commit 754d64d7f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 16
      slither/core/cfg/node.py
  2. 9
      tests/e2e/detectors/test_data/constable-states/0.8.0/const_state_variables.sol
  3. BIN
      tests/e2e/detectors/test_data/constable-states/0.8.0/const_state_variables.sol-0.8.0.zip

@ -11,6 +11,7 @@ from slither.core.declarations.solidity_variables import (
SolidityFunction, SolidityFunction,
) )
from slither.core.expressions.expression import Expression 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.solidity_types import ElementaryType
from slither.core.source_mapping.source_mapping import SourceMapping from slither.core.source_mapping.source_mapping import SourceMapping
from slither.core.variables.local_variable import LocalVariable 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 # TODO: consider removing dependancy of solidity_call to internal_call
self._solidity_calls.append(ir.function) self._solidity_calls.append(ir.function)
self._internal_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): if isinstance(ir, LowLevelCall):
assert isinstance(ir.destination, (Variable, SolidityVariable)) assert isinstance(ir.destination, (Variable, SolidityVariable))
self._low_level_calls.append((ir.destination, str(ir.function_name.value))) self._low_level_calls.append((ir.destination, str(ir.function_name.value)))

@ -66,7 +66,7 @@ contract Good {
uint immutable should_be_immutable_3 = 10 + block.number; uint immutable should_be_immutable_3 = 10 + block.number;
B immutable should_be_immutable_4 = new B(); B immutable should_be_immutable_4 = new B();
uint immutable should_be_immutable_5; uint immutable should_be_immutable_5;
uint blobBaseFee;
constructor(uint b) { constructor(uint b) {
should_be_immutable_5 = b; should_be_immutable_5 = b;
} }
@ -74,5 +74,10 @@ contract Good {
function getNumber() public returns(uint){ function getNumber() public returns(uint){
return block.number; return block.number;
} }
function updateBlobBaseFee(uint _blobBaseFee) public {
assembly {
sstore(blobBaseFee.slot, _blobBaseFee)
}
}
} }
Loading…
Cancel
Save