[Bug]: Missing quotes in case mapping key passed as a string
- Dominant language
- Python
- Stars
- 6.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the issue:
We are using Slither Python API to analyze the expression of each node of function in a contract within Slither object.
The issue I need help with is that Slither expression does not differentiate between the following cases (in Solidity):
mapping(string => uint256) stringGeneBuckets;
```
//case # 1
stringGeneBuckets["myvariable"] = _geneId;
```
```
//case # 2
myvariable = "someStringValue"
stringGeneBuckets[myvariable] = _geneId;
```
For both cases mentioned above, the node.expression returned is `stringGeneBuckets[myvariable] = _geneId`, in the first case shouldn't it be `stringGeneBuckets["myvariable"] = _geneId`?
### Code example to reproduce the issue:
pragma solidity ^0.8.0;
contract GeneMapping {
// Mapping from a string to a uint256 value
mapping(string => uint256) public stringGeneBuckets;
function setGeneId(string memory _myvariable, uint256 _geneId) public {
stringGeneBuckets["myvariable"] = _geneId;
stringGeneBuckets[_myvariable] = _geneId;
}
// Function to retrieve a value from the mapping for a given key
function getGeneId(string memory key) public view returns (uint256) {
return stringGeneBuckets[key];
}
}
### Version:
0.9.6
### Relevant log output:
_No response_
Contributor guide
Research direction
Start by reproducing the contract example through Slither's Python API and inspect how node.expression represents the two mapping assignments. Trace the expression handling for string literals versus identifiers; done means the literal key remains distinguishable from the variable key in the returned expression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, solidity
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100