Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: State variables shadowed by a local variable are incorrectly set to the local variable #2058

Closed
Tiko7454 opened this issue Jul 19, 2023 · 2 comments
Labels
bug Something isn't working parsing

Comments

@Tiko7454
Copy link
Contributor

Describe the issue:

A state variable is used before it was shadowed. The dependency goes to the local variable instead of state variable

Code example to reproduce the issue:

// SPDX-License-Identifier: UNLICENSED

pragma solidity 0.8.7;

contract B {
    uint public x = 21;
    function a()  public {
        uint u = 2 * x;  // BUG
        uint x;
    }
}
> from slither import Slither
>
>
> a = Slither('b.sol').contracts[0].functions[0]
> buggy_node = a.nodes[1]
> print(buggy_node.variables_read[0].canonical_name)
>> B.a().x

Version:

0.9.3
(tested the freshest dev branch 3e39026)

Relevant log output:

No response

@Tiko7454 Tiko7454 added the bug-candidate Bugs reports that are not yet confirmed label Jul 19, 2023
@smonicas
Copy link
Contributor

The issue is in early expression parsing because x is found by this code as the local variable. Removing this code makes the example works however it will fail if the legacy ast is used and i'm not sure if there are other edge cases that require it.

# If not found, check for name
func_variables = function_parser.underlying_function.variables_as_dict
if var_name in func_variables:
return func_variables[var_name]

@smonicas smonicas added bug Something isn't working parsing and removed bug-candidate Bugs reports that are not yet confirmed labels Jul 19, 2023
@smonicas smonicas changed the title [Bug-Candidate]: False data dependency caused by shadowing afterwords [Bug]: State variables shadowed by a local variable are incorrectly set to the local variable Jul 19, 2023
@0xalpharush
Copy link
Contributor

Closed by #2121

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parsing
Projects
None yet
Development

No branches or pull requests

3 participants