crytic / crytic/slither

[Bug]: Functions declared in inline assembly blocks can be conflated

Open
#2,100 0 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:

This happens in the case where there are functions:
1. In the same contract.
2. With the same name (say `f`).
3. Each `f` declares an inline function with the same name (say `g`), within the same-indexed assembly block (ie, each in the first, second, or third etc... block).

The `g` functions end up being conflated in `[f for contract in compilation_unit.contracts for f in contract.functions_and_modifiers]`; that is, only one of those functions end up being there.

### Code example to reproduce the issue:

```solidity
pragma solidity ^0.8.0;

contract Test {
function f(bytes32 p0) internal pure {
assembly {
function g(w) {
let length := 0
}
g(p0)
}
}
function f(bytes32 p0, bytes32 p1) internal pure {
assembly {
function g(w, x) {
let length := 0
}
g(p0, p1)
}
}
}
```
Note that the parameters of `f` will necessarily be different, and the parameters of `g` don't matter. Also, the `canonical_name` of both `g` functions is `Test.f.asm_0.g()`.

A larger example is the [`safeconsole` library in forge-std](https://github.com/foundry-rs/forge-std/blob/fe9d28aafbbadcfeff06bc662a8cab0c5486a69f/src/safeconsole.sol), involving some `log` and `writeString` functions.

### Version:

0.9.6

### 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.