crytic / crytic/slither

[Bug-Candidate]: False positive uses timestamp for array length comparison

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

Description

### Describe the issue:

A Check: ```timestamp``` gets triggered when comparing to struct array length. I assume that it gets triggered because my struct has a block.timestamp assigned to a property inside the struct...

### Code example to reproduce the issue:

Inside my contract:

struct Post {
uint256 id;
uint256 timeCreated; // block.timestamp will be assigned here on creation
address contributor;
uint256 distributedSocialTokens;
}

Post[] public posts;

function _createPost() internal {
posts.push(Post(posts.length, block.timestamp, msg.sender, 0));
}

function _likePost(uint256 postIdx) internal onlyMember {
require(postIdx < posts.length, "Post does not exist");
/* ... */
}

### Version:

0.8.3

### Relevant log output:

```shell
AFeed._likePost(uint256) (contracts/feeds/AFeed.sol#58-93) uses timestamp for comparisons
Dangerous comparisons:
- require(bool,string)(postIdx < posts.length,Post does not exist)(contracts/feeds/AFeed.sol#59)
Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#block-timestamp
```

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.