Extend property `is_dynamic()` to Variable classes
- Dominant language
- Python
- Stars
- 6.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the desired feature
The new `is_dynamic()` property for types is a great idea. However, only basing this property off of type information leads to incorrect conclusions if you check a slither Variable's `type` and want to know whether the variable itself is static or dynamic.
Below is a contract defining the functionality. Currently, all of these variables `types` would return dynamic.
```js
contract DynamicOrStatic {
bytes a; // dynamic
bytes constant b = hex"00"; // static
uint[] c; // dynamic
uint[3] d; // static
uint[3][] e; // dynamic
bytes f = bytes(hex"22"); // typecast literal -> static
bytes g = getBytes(); // func lookup -> uses literal -> logic concludes static
function getBytes() pure public returns (bytes memory) {
return bytes(hex"22");
}
}
```
Having this logic available on a per-variable basis would be amazing for detectors and printers.
Here is a case where a detector using `is_dynamic()` on Slither `Variable`s could be utilized, but would not work currently with `is_dynamic` on the types alone:
```js
pragma solidity ^0.8.13;
contract encodePackedCollision {
//detect collision. (dynamic_args > 1)
function bad(bytes calldata username, bytes calldata salt) pure external {
abi.encodePacked(username, salt);
}
function good(bytes calldata username) pure external {
abi.encodePacked(username, bytes(hex"22"), getBytes());
}
function getBytes() pure public returns (bytes memory) {
return bytes(hex"22");
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.