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]: slither.core.expressions.new_contract.NewContract object's contract_name field is not str #2424

Open
Tiko7454 opened this issue Apr 12, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Tiko7454
Copy link
Contributor

Describe the issue:

The contract name for the right expression C c = new C(); is not str

The way to get the actual contract name is to call newC.contract_name.type.name (is it the intended way?)

I think the bug is caused by the confusion between slither.core.expressions.new_contract.NewContract and slither.slithir.operations.new_contract.NewContract, both have an option contract_name but the first one is of type str, and the second is of type UserDefinedType.
I think the issue arouse in this commit

69ece6d#diff-fd01d1c9135cdceee138701706ce2947d135c9b32bf89253c5ca2f84a54979d9
new = NewContract(contract_type)

Code example to reproduce the issue:

contract C { }

contract D {
    function f() public {
        C c = new C();
    }
}

Version:

0.10.2

Relevant log output:

>>> from slither import Slither
>>> s = Slither('a.sol')
>>> d = s.contracts[1]
>>> d.name
'D'
>>> str(d.functions[0].nodes[1])
'NEW VARIABLE c = new C()'
>>> newvar = d.functions[0].nodes[1]
>>> print(newvar.expression)
c = new C()
>>> c_new_C = newvar.expression
>>> print(c_new_C.expression_right)
new C()
>>> newC = c_new_C.expression_right.called
>>> print(newC)
new C
>>> type(newC)
<class 'slither.core.expressions.new_contract.NewContract'>
>>> newC.contract_name
<slither.core.solidity_types.user_defined_type.UserDefinedType object at 0x76c1d236b310>
@Tiko7454 Tiko7454 added the bug-candidate Bugs reports that are not yet confirmed label Apr 12, 2024
@0xalpharush
Copy link
Contributor

This was changed purposely in #2370. It used to be a late lookup and caused issues with aliasing. In retrospect, I probably could have replaced uses of contract_name where I wanted it to be the contract and left contract_name a str

@0xalpharush
Copy link
Contributor

Ah I see. I didn't update the signature of slither.core.expressions.new_contract.NewContract
https://github.com/crytic/slither/pull/2370/files#diff-fd01d1c9135cdceee138701706ce2947d135c9b32bf89253c5ca2f84a54979d9R619

@Tiko7454
Copy link
Contributor Author

So is this newC.contract_name.type.name the intended way to get the contract name?
Also why is that called contract_name, I think it could cause further confusions and is better to be replaced with something like contract_type or contract

@0xalpharush 0xalpharush changed the title [Bug-Candidate]: slither.core.expressions.new_contract.NewContract object's contract_name field is not str [Bug]: slither.core.expressions.new_contract.NewContract object's contract_name field is not str Apr 15, 2024
@0xalpharush 0xalpharush added bug Something isn't working and removed bug-candidate Bugs reports that are not yet confirmed labels Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants