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[tool]: support storage layouts via json and xyz #4370

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

tserg
Copy link
Collaborator

@tserg tserg commented Nov 23, 2024

What I did

Resolves #4367

How I did it

  • For solc_json and archive outputs, emit the storage layout as output if it was overriden.
  • Extract a storage layout for solc_json and archive inputs if provided.

How to verify it

See tests.

Commit message

feat[tool]: support storage layouts via json and xyz

This commit adds support for overriding the storage layout
using `solc_json` and archive inputs, and consequently
adding the storage layout if it was provided to these formats 
as output.

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

Copy link

codecov bot commented Nov 24, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 88.71%. Comparing base (8f433f8) to head (08f0396).

Files with missing lines Patch % Lines
vyper/cli/vyper_json.py 88.23% 1 Missing and 1 partial ⚠️
vyper/compiler/output_bundle.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4370      +/-   ##
==========================================
- Coverage   91.27%   88.71%   -2.57%     
==========================================
  Files         112      112              
  Lines       16025    16049      +24     
  Branches     2696     2702       +6     
==========================================
- Hits        14627    14238     -389     
- Misses        966     1292     +326     
- Partials      432      519      +87     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@tserg
Copy link
Collaborator Author

tserg commented Nov 24, 2024

@charles-cooper requesting a review before I update the docs

@tserg tserg marked this pull request as ready for review November 24, 2024 09:36
storage_layout_overrides: dict[PurePath, StorageLayout] = {}

for path, value in input_dict.get("storage_layout_overrides", {}).items():
if path not in input_dict["sources"]:
Copy link
Member

Choose a reason for hiding this comment

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

i guess we can have contracts which do not have corresponding override files

Copy link
Member

Choose a reason for hiding this comment

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

i think that's fine, since each key in "sources" is a compilation target.

input_json = {
"language": "Vyper",
"sources": {"contracts/foo.vy": {"content": code}},
"storage_layout_overrides": {"contracts/foo.vy": {"content": storage_layout_overrides}},
Copy link
Member

Choose a reason for hiding this comment

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

i don't think we need to hide it inside the "content" key, since it's already a dict.

Comment on lines +49 to +53
storage_layout = (
json.loads(archive.read(storage_layout_path).decode("utf-8"))
if storage_layout_path in archive.namelist()
else None
)
Copy link
Member

@charles-cooper charles-cooper Nov 24, 2024

Choose a reason for hiding this comment

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

style:

Suggested change
storage_layout = (
json.loads(archive.read(storage_layout_path).decode("utf-8"))
if storage_layout_path in archive.namelist()
else None
)
storage_layout = None
if storage_layout_path in archive.namelist():
storage_layout = json.loads(archive.read(storage_layout_path).decode("utf-8"))

@@ -347,6 +364,9 @@ def format_to_output_dict(compiler_data: dict) -> dict:
if key in data:
output_contracts[key] = data[key]

if data.get("layout"):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if data.get("layout"):
if "layout" in data:

@@ -160,6 +166,10 @@ def write(self):
self.write_settings(self.compiler_data.original_settings)
self.write_integrity(self.compiler_data.resolved_imports.integrity_sum)
self.write_sources(self.bundle.compiler_inputs)
if self.compiler_data.storage_layout_override:
Copy link
Member

Choose a reason for hiding this comment

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

don't use truthy unless you mean it!

Suggested change
if self.compiler_data.storage_layout_override:
if self.compiler_data.storage_layout_override is not None:

@@ -299,6 +314,7 @@ def compile_from_input_dict(
res, warnings_dict = {}, {}
warnings.simplefilter("always")
for contract_path in compilation_targets:
storage_layout_override = storage_layout_overrides.get(contract_path, None)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
storage_layout_override = storage_layout_overrides.get(contract_path, None)
storage_layout_override = storage_layout_overrides.get(contract_path)

Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

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

looks overall pretty good to me. left a few comments. @cyberthirst could you also take a look?

@@ -12,6 +12,7 @@
from vyper.compiler.settings import Settings
Copy link
Member

Choose a reason for hiding this comment

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

for verification, storage layout override can (and should) affect integrity hash.

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.

tool: allow storage layout overrides in standard-json and vyz files
2 participants