Skip to content

Commit

Permalink
apply cc suggestion on refactoring integrity hash
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Dec 10, 2024
1 parent 4036b67 commit 43f5643
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion vyper/compiler/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def build_archive_b64(compiler_data: CompilerData) -> str:


def build_integrity(compiler_data: CompilerData) -> str:
return compiler_data.resolved_imports.integrity_sum
return compiler_data.integrity_sum


def build_external_interface_output(compiler_data: CompilerData) -> str:
Expand Down
2 changes: 1 addition & 1 deletion vyper/compiler/output_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def write(self):
self.write_compilation_target([self.bundle.compilation_target_path])
self.write_search_paths(self.bundle.used_search_paths)
self.write_settings(self.compiler_data.original_settings)
self.write_integrity(self.compiler_data.resolved_imports.integrity_sum)
self.write_integrity(self.compiler_data.integrity_sum)
self.write_sources(self.bundle.compiler_inputs)
if self.compiler_data.storage_layout_override is not None:
self.write_storage_layout_overrides(
Expand Down
14 changes: 12 additions & 2 deletions vyper/compiler/phases.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import json
import warnings
from functools import cached_property
from pathlib import Path, PurePath
Expand All @@ -18,7 +19,7 @@
from vyper.semantics.types.function import ContractFunctionT
from vyper.semantics.types.module import ModuleT
from vyper.typing import StorageLayout
from vyper.utils import ERC5202_PREFIX, vyper_warn
from vyper.utils import ERC5202_PREFIX, sha256sum, vyper_warn
from vyper.venom import generate_assembly_experimental, generate_ir

DEFAULT_CONTRACT_PATH = PurePath("VyperContract.vy")
Expand Down Expand Up @@ -267,7 +268,7 @@ def assembly_runtime(self) -> list:
def bytecode(self) -> bytes:
metadata = None
if not self.no_bytecode_metadata:
metadata = bytes.fromhex(self.resolved_imports.integrity_sum)
metadata = bytes.fromhex(self.integrity_sum)
return generate_bytecode(self.assembly, compiler_metadata=metadata)

@cached_property
Expand All @@ -284,6 +285,15 @@ def blueprint_bytecode(self) -> bytes:

return deploy_bytecode + blueprint_bytecode

@cached_property
def integrity_sum(self) -> str:
if self.storage_layout_override:
return sha256sum(
sha256sum(json.dumps(self.storage_layout_override))
+ self.resolved_imports.integrity_sum
)
return self.resolved_imports.integrity_sum


def generate_ir_nodes(global_ctx: ModuleT, settings: Settings) -> tuple[IRnode, IRnode]:
"""
Expand Down

0 comments on commit 43f5643

Please sign in to comment.