crytic / crytic/slither

[Bug]: Incorrect SSA form with break

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

Description

### Describe the issue:

The SSA form returns `s_3` and `p_3` instead of `s_2` and `p_2` which are correctly returned if the break is removed.

### Code example to reproduce the issue:

```solidity
contract T {
function a(uint n) public returns(uint,uint){
uint s = 0;
uint p = 0;

for (uint i; i < n; i++) {
s += i;
p *= i;
if (i == 3) { break; }
}
return (s, p);
}
}
```

### Version:

0.10.3

### Relevant log output:

```shell
Function T.a(uint256)
Expression: s = 0
IRs:
s_1(uint256) := 0(uint256)
Expression: p = 0
IRs:
p_1(uint256) := 0(uint256)
Expression: i < n
IRs:
s_2(uint256) := ϕ(['s_3', 's_1'])
p_2(uint256) := ϕ(['p_1', 'p_3'])
i_1(uint256) := ϕ(['i_0', 'i_2'])
TMP_0(bool) = i_1 < n_1
CONDITION TMP_0
Expression: s += i
IRs:
s_3(uint256) = s_2 (c)+ i_1
Expression: p *= i
IRs:
p_3(uint256) = p_2 (c)* i_1
Expression: i == 3
IRs:
TMP_1(bool) = i_1 == 3
CONDITION TMP_1
Expression: i ++
IRs:
TMP_2(uint256) := i_1(uint256)
i_2(uint256) = i_1 (c)+ 1
Expression: (s,p)
IRs:
RETURN s_3,p_3
```

Contributor guide

Open the contributing guide

Research direction

Start with the supplied Solidity contract and compare the SSA output with and without the break statement. Trace how loop exits and variable versions are represented, then verify that the return expression uses s_2 and p_2 for the break path and add coverage for this reproducer if the project’s existing tests support it.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, solidity
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.