From 0eabe2a6ee20b5f53dd25161564c178ecc7da985 Mon Sep 17 00:00:00 2001 From: Danil Date: Tue, 10 Oct 2023 19:29:04 +0200 Subject: [PATCH] Remove finish_global_frame optimization Signed-off-by: Danil --- core/lib/vm/src/old_vm/memory.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/lib/vm/src/old_vm/memory.rs b/core/lib/vm/src/old_vm/memory.rs index 76d6ca42d5e1..4b7bc300306e 100644 --- a/core/lib/vm/src/old_vm/memory.rs +++ b/core/lib/vm/src/old_vm/memory.rs @@ -269,15 +269,23 @@ impl Memory for SimpleMemory { fn finish_global_frame( &mut self, - _base_page: MemoryPage, + base_page: MemoryPage, returndata_fat_pointer: FatPointer, timestamp: Timestamp, ) { + // Safe to unwrap here, since `finish_global_frame` is never called with empty stack + let current_observable_pages = self.observable_pages.inner().current_frame(); let returndata_page = returndata_fat_pointer.memory_page; - self.observable_pages.clear_frame(timestamp); - self.observable_pages.merge_frame(timestamp); - + for &page in current_observable_pages { + // If the page's number is greater than or equal to the base_page, + // it means that it was created by the internal calls of this contract. + // We need to add this check as the calldata pointer is also part of the + // observable pages. + if page >= base_page.0 && page != returndata_page { + self.memory.clear_page(page as usize, timestamp); + } + } self.observable_pages .push_to_frame(returndata_page, timestamp); }