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

Generate interface code in new slither.utils.code_generation #1730

Merged
merged 23 commits into from
Mar 22, 2023

Conversation

webthethird
Copy link
Contributor

@webthethird webthethird commented Mar 8, 2023

Adds Function.interface_signature_str, Structure.interface_def_str() and Contract.generate_interface().

The new Contract method uses the other two to generate Solidity code for an interface to the contract.

Still isn't quite as clean as the code @glarregay-tob wrote outside of Slither, which I think handles struct return types better.

@webthethird
Copy link
Contributor Author

webthethird commented Mar 8, 2023

pylint is complaining about the following line in Function:

returns = ["address" if isinstance(ret.type, UserDefinedType) and isinstance(ret.type.type, Contract)
           else str(ret.type) for ret in self.returns]

It says E0601: Using variable 'Contract' before assignment (used-before-assignment) but I don't think that's correct.

@0xalpharush
Copy link
Contributor

I think this should not be on the core object and should instead be a utility like generate_interface(Contract)

@webthethird
Copy link
Contributor Author

I think this should not be on the core object and should instead be a utility like generate_interface(Contract)

That sounds reasonable enough. Do you think I should start a new util in slither.utils? Perhaps one for everything related to code generation?

@0xalpharush
Copy link
Contributor

@webthethird That sounds like a good idea

@webthethird
Copy link
Contributor Author

Looks like the failing CI checks related to linting are unrelated to this PR:
Pull down action image 'ghcr.io/github/super-linter:slim-v4.9.2'
Error: Docker pull failed with exit code 1

@webthethird webthethird changed the title Generate interface code from Contract class Generate interface code in new slither.utils.code_generation Mar 16, 2023
Copy link
Member

@montyly montyly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add tests? (cc @0xalpharush )

slither/utils/code_generation.py Show resolved Hide resolved
@webthethird
Copy link
Contributor Author

can we add tests? (cc @0xalpharush )

Would we just test this by having an input .sol file and an expected output .sol file, and doing a diff between the expected and actual output?

@montyly montyly merged commit 3c55228 into crytic:dev Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants