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

Dokzai issue 1654 #2172

Merged
merged 6 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion slither/solc_parsing/yul/parse_yul.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ def parse_yul_function_call(root: YulScope, node: YulNode, ast: Dict) -> Optiona
def _check_for_state_variable_name(root: YulScope, potential_name: str) -> Optional[Identifier]:
root_function = root.function
if isinstance(root_function, FunctionContract):
var = root_function.contract.get_state_variable_from_name(potential_name)
var = root_function.contract_declarer.get_state_variable_from_name(potential_name)
if var:
return Identifier(var)
return None
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/slithir/test_data/assembly_storage_slot.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
contract YYY {
mapping(address => uint256) private _counters;
function _getPackedBucketGlobalState(uint256 bucketId) internal view returns (uint256 packedGlobalState) {
assembly {
mstore(0x0, bucketId)
mstore(0x20, _counters.slot)
let slot := keccak256(0x0, 0x40)
packedGlobalState := sload(slot)
}
}
}


contract XXX is YYY {
function getPackedBucketGlobalState(uint256 bucketId) external {
_getPackedBucketGlobalState(bucketId);
}
}
40 changes: 40 additions & 0 deletions tests/unit/slithir/test_yul_parser_assembly_slot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from pathlib import Path
from slither import Slither

from slither.core.expressions import CallExpression
from slither.core.expressions.identifier import Identifier
from slither.core.expressions.literal import Literal
from slither.core.variables.state_variable import StateVariable
from slither.core.variables.local_variable import LocalVariable


TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data"


def test_yul_parser_assembly_slot(solc_binary_path) -> None:
# mstore(0x0, bucketId)
# mstore(0x20, _counters.slot)
data = {"0x0": "bucketId", "0x20": "_counters"}

solc_path = solc_binary_path("0.8.18")
slither = Slither(Path(TEST_DATA_DIR, "assembly_storage_slot.sol").as_posix(), solc=solc_path)

contract = slither.get_contract_from_name("XXX")[0]
func = contract.get_function_from_full_name("getPackedBucketGlobalState(uint256)")
calls = [
node.expression
for node in func.all_nodes()
if node.expression and "mstore" in str(node.expression)
]

for call in calls:
assert isinstance(call, CallExpression)
memory_location = call.arguments[0]
value = call.arguments[1]
assert isinstance(memory_location, Literal)
assert isinstance(value, Identifier)
assert value.value.name == data[memory_location.value]
if value.value.name == "_counters":
assert isinstance(value.value, StateVariable)
elif value.value.name == "bucketId":
assert isinstance(value.value, LocalVariable)