crytic / crytic/slither

Improve cache-array-length detector

Open
#1,987 0 comments 0 reactions 0 assignees View on GitHub
false-positive
Dominant language
Python
Stars
6.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

One caveat is that internal function call, or storage pointer will lead to false positive. For example
```solidity
contract CacheArrayLength
{

uint[] public array;

function f() public
{

for (uint i = 0; i < array.length; i++)
{
change(array);
}
}

function change(uint[] storage array) internal{
array.pop();
}

}
```

With pointer aliases it can even be more difficult. Maybe we should:
- Disable the result if the array is given as an internal function call argument
- Disable the result if a storage pointer is created with the array

Most likely both case are uncommon (and could actually be bugs - for a separate detector?), so I am ok to merge this PR for this week's release if we don't have the time to include them. What do you think @0xalpharush ?

_Originally posted by @montyly in https://github.com/crytic/slither/issues/1694#issuecomment-1602266851_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.