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

Fix Hardhat compile error when library or interface has namespace struct, print warning for library #1086

Merged
merged 6 commits into from
Oct 2, 2024

Conversation

ericglau
Copy link
Member

@ericglau ericglau commented Sep 27, 2024

This PR addresses two issues:


  1. Fixes compilation error if library or interface contains namespace.

When making modified solc input to extract storage layouts, we normally detect namespace annotated structs in contracts and insert corresponding storage variables in order to get the detailed storage layouts of those structs.

However, libraries and interfaces do not support storage variables, so we should skip this insertion for libraries and interfaces.

(Note that if contracts inherit interfaces, namespaces in those interfaces can still be validated but they won't have detailed type information such as slots or lengths)

Fixes #1066


  1. Warn if library contains namespace.

ERC-7201 states, "Structs with this annotation found outside of contracts are not considered to be namespaces for any contract in the source code."

Storage layout validations can only occur on namespaces that we can detect in contracts and their inheritance (including inherited interfaces). Particularly, namespaces in libraries are NOT validated, although we can see from this GitHub query that it is quite common.

This PR also adds a warning (not an error, to avoid breaking changes) if namespaces are defined in libraries.

@ericglau ericglau changed the title Fix Hardhat compile error when library or interface has struct with namespace annotation Fix Hardhat compile error when library or interface has namespace struct, print warning for library Sep 27, 2024
@ericglau ericglau marked this pull request as ready for review September 27, 2024 22:13
@ericglau ericglau requested review from a team and frangio September 27, 2024 22:13
@frangio
Copy link
Contributor

frangio commented Sep 28, 2024

(Note that if contracts inherit interfaces, namespaces in those interfaces can still be validated but they won't have detailed type information such as slots or lengths)

This is unfortunate. Have you considered any workarounds?

Can the interface be converted into a contract by the transformation?

@ericglau
Copy link
Member Author

ericglau commented Oct 2, 2024

(Note that if contracts inherit interfaces, namespaces in those interfaces can still be validated but they won't have detailed type information such as slots or lengths)

This is unfortunate. Have you considered any workarounds?

Can the interface be converted into a contract by the transformation?

@frangio I've opened #1089 to consider this.

@ericglau ericglau enabled auto-merge (squash) October 2, 2024 14:46
@ericglau ericglau merged commit 8c42f06 into OpenZeppelin:master Oct 2, 2024
12 checks passed
@ericglau ericglau deleted the 1066 branch October 2, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants