diff --git a/vyper/compiler/phases.py b/vyper/compiler/phases.py index b834269ce7..3d5791a644 100644 --- a/vyper/compiler/phases.py +++ b/vyper/compiler/phases.py @@ -148,29 +148,41 @@ def vyper_module(self): _, ast = self._generate_ast return ast + def _compute_integrity_sum(self, imports_integrity_sum: str) -> str: + if self.storage_layout_override is not None: + layout_sum = sha256sum(json.dumps(self.storage_layout_override)) + return sha256sum(layout_sum + imports_integrity_sum) + return imports_integrity_sum + @cached_property def _resolve_imports(self): # deepcopy so as to not interfere with `-f ast` output vyper_module = copy.deepcopy(self.vyper_module) with self.input_bundle.search_path(Path(vyper_module.resolved_path).parent): - return vyper_module, resolve_imports(vyper_module, self.input_bundle) + imports = resolve_imports(vyper_module, self.input_bundle) - @cached_property - def resolved_imports(self): - imports = self._resolve_imports[1] + # check integrity sum + integrity_sum = self._compute_integrity_sum(imports._integrity_sum) expected = self.expected_integrity_sum - - if expected is not None and imports.integrity_sum != expected: + if expected is not None and integrity_sum != expected: # warn for now. strict/relaxed mode was considered but it costs # interface and testing complexity to add another feature flag. vyper_warn( f"Mismatched integrity sum! Expected {expected}" - f" but got {imports.integrity_sum}." + f" but got {integrity_sum}." " (This likely indicates a corrupted archive)" ) - return imports + return vyper_module, imports, integrity_sum + + @cached_property + def integrity_sum(self): + return self._resolve_imports[2] + + @cached_property + def resolved_imports(self): + return self._resolve_imports[1] @cached_property def _annotate(self) -> tuple[natspec.NatspecOutput, vy_ast.Module]: @@ -285,15 +297,6 @@ 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]: """ diff --git a/vyper/semantics/analysis/imports.py b/vyper/semantics/analysis/imports.py index 3268f12e94..0a160639d2 100644 --- a/vyper/semantics/analysis/imports.py +++ b/vyper/semantics/analysis/imports.py @@ -79,11 +79,11 @@ def __init__(self, input_bundle: InputBundle, graph: _ImportGraph): self.seen: set[int] = set() - self.integrity_sum = None + self._integrity_sum = None def resolve_imports(self, module_ast: vy_ast.Module): self._resolve_imports_r(module_ast) - self.integrity_sum = self._calculate_integrity_sum_r(module_ast) + self._integrity_sum = self._calculate_integrity_sum_r(module_ast) def _calculate_integrity_sum_r(self, module_ast: vy_ast.Module): acc = [sha256sum(module_ast.full_source_code)]