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

create a variable API that filters out constants and immutables #1644

Closed
0xalpharush opened this issue Feb 2, 2023 · 5 comments
Closed

create a variable API that filters out constants and immutables #1644

0xalpharush opened this issue Feb 2, 2023 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@0xalpharush
Copy link
Contributor

There's discussion about changing code data location keywords and it would be convenient/ more robust to have one API rather than filtering state_variables.

For example, this code could use the new API #1451

Ref ethereum/solidity#13723

@0xalpharush 0xalpharush added the enhancement New feature or request label Feb 2, 2023
@0xalpharush 0xalpharush added good first issue Good for newcomers and removed design labels Oct 18, 2023
@dokzai
Copy link
Contributor

dokzai commented Feb 17, 2024

I would like to help out with this issue. Can you share more information?

@0xalpharush
Copy link
Contributor Author

There's several places where code like contract.state_variables_ordered if not (variable.is_constant or variable.is_immutable) exists. We could an API that only returns variables that have a storage location instead of filtering everywhere and having to update if a new non-storage keyword is add e.g. codedata in place of constant and immutable https://crytic.github.io/slither/slither/core/declarations/contract.html#Contract.state_variables_ordered

@0xalpharush
Copy link
Contributor Author

0xalpharush commented Feb 17, 2024

For instance

variables.append(c.state_variables)
functions.append(c.all_functions_called)
valid_candidates: Set[StateVariable] = {
item for sublist in variables for item in sublist if _valid_candidate(item)
}

if not variable.is_constant and not variable.is_immutable:

for s in self.contract.state_variables_ordered:
if s.initialized and not (s.is_constant or s.is_immutable):

if not var.is_constant and not var.is_immutable:

for var in contract.state_variables_ordered:
if var.is_constant or var.is_immutable:

dokzai added a commit to dokzai/slither that referenced this issue Feb 18, 2024
…bles that have a storage location instead of filtering
@dokzai
Copy link
Contributor

dokzai commented Feb 18, 2024

Hi @0xalpharush

https://github.com/dokzai/slither/blob/4f4acae1af3e4c68555972ea09afe686427d20db/slither/core/declarations/contract.py#L440-L464

Please let me know if the following changes are what you had in mind for the new API.

Thanks!

@0xalpharush
Copy link
Contributor Author

Looks good! Go ahead and open a PR please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants