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

feat: updated Solidity interface policy #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

smartcontracts
Copy link
Contributor

Introduces a new proposal to update the Solidity interface policy such that source contracts do not use interfaces at all and interfaces live in an entirely separate folder. Proposal is intended to set us up to fully automate interface generation while still maintaining most of the compilation benefits.

Introduces a new proposal to update the Solidity interface
policy such that source contracts do not use interfaces at all
and interfaces live in an entirely separate folder. Proposal is
intended to set us up to fully automate interface generation
while still maintaining most of the compilation benefits.

Proposed solution would increase compilation time for source contracts, but the impact would not be
nearly as significant as the original compilation time when no interfaces existed at all. We're
talking about something on the order of 5-20s instead of the current 2-10s. Not ideal but fine.
Copy link
Contributor

Choose a reason for hiding this comment

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

How do we know this? I would rather deal with some manual iface hassles than suffer a major slow down.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can run a script to show the exact compile time

### Continued Automation Challenges

Simply removing interface usage will solve the problems that come with using interfaces within the
source contracts but will not solve all of the challenges to automating interface generation. We do
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is iface generation hard? Can't most of it be done using cast interface <(forge inspect Contract abi)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cast interface gets the types all wrong, it can't be used out of the box. Same with forge inspect.

You can use it but you're losing some type safety. For example, anything that takes a specific contract type as input is just an address according to foundry.

Supporting interface generation that's actually good is harder.

Comment on lines +44 to +45
- Contract interfaces don't have source code, so navigating the functions in the source files
becomes awkward as each external call goes through an interface.
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you referring to functionality like "Go to definition" here, which would take you to the uninformative interface definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

Comment on lines +42 to +43
- Using interfaces within the source contracts leads to other awkward situations with function
types that are challenging to resolve in an automated generation script.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the primary source of pain I have experienced myself.

crafting contract interfaces. For instance, if `ContractA` depends on `IContractB` and
`ContractB` depends on `IContractA` but neither contract interface exists yet (new contracts)
then the contracts cannot be compiled (because neither interface exists) and the interfaces can
not be generated. Catch 22.
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO the two items above can be fairly easily resolved during development just by manually defining the interface being used in the same file as the contract using it, and when the interface is stable it can be autogenerated into /interfaces.

My concern is that creating a new contract is a rare occurrence vs. compiling the source contracts, maybe something on the order of 1:1000 in terms of compilation cycles, thus even a fairly small slow down in the compilation process requires a strong justification.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah fair, makes total sense!

@skeletor-spaceman
Copy link
Contributor

Copying over some counter-arguments from discord:
re-compilation: it'd be better to maximize the efficiency of the most used path, which is modifying existing contracts, rather than creating new ones.

circular dependency: it is indeed a pain. But it seems to be an edge case that can be solved by writing an empty implementation first, or manually crafting a temporary interface.

security: it is a bit misleading to be pointed to a specific implementation rather than just seeing an external call that uses an interface, which forces you to double check "what the hell is being called on here"

bonus in-favor argument:
auto-gen: being able to automatically generate interfaces is awesome!

locations that interact with the source contracts. Removing interfaces from source contracts
entirely would also be a much clearer mental model ("just don't use interfaces in src/").

In addition, interfaces would live in a new `interfaces` folder at the root of the contracts
Copy link
Contributor

Choose a reason for hiding this comment

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

really like this, since my biggest issue with interface generation right now is I feel it generates way too many files and clutters up src/, and it makes it unclear when you are depending on machine generated interfaces vs beautifully handwritten interfaces

@smartcontracts
Copy link
Contributor Author

Alright it sounds like the latest consensus is to allow usage of interfaces within src/ but we would still do the move to interfaces/ at the root. Any objections?

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.

4 participants