crytic / crytic/slither

`references` for virtual functions are filled incorrectly

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

Description

### Describe the issue:

Suppose that we have a contract `A` defined in `A.sol` that has a virtual function `f` and a (normal) function `g` that uses `f`.
Additionally, there is a contract `B` inheriting from `A` and overriding `f`.

Then, `references` list for `B.f` contains a code from `A.sol` (the line where `f` is referenced in `g`).

Here is the code fragment that updates `references` list:
https://github.com/crytic/slither/blob/3383e39823a088fc00c6a2563ba23ac202b29c39/slither/solc_parsing/expressions/expression_parsing.py#L465-L467

In this case, `identifier.source_mapping` will reference a fragment of `g` function from `A.sol` and `references` list will be updated incorrectly.

### Code example to reproduce the issue:

```solidity
// content of A.sol:
pragma solidity 0.7.6;

contract A
{
function f() internal virtual {}

function g() internal
{
f();
}
}

//content of B.sol:
pragma solidity 0.7.6;

import "./A.sol";

contract B is A
{
function f() internal override {} // this function will have A.sol#9 in `references`
}
```

### Version:

`0.9.2`

### Relevant log output:

_No response_

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.