From 5de8afb1347c8842e4f87f334e7728ece83f6100 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Tue, 13 Aug 2024 15:45:10 -0300 Subject: [PATCH 1/5] Derive partial-eq for VmState --- src/call_frame.rs | 4 ++-- src/heaps.rs | 2 +- src/state.rs | 9 +++++---- src/store.rs | 2 +- src/value.rs | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/call_frame.rs b/src/call_frame.rs index 7d228d10..862a3153 100644 --- a/src/call_frame.rs +++ b/src/call_frame.rs @@ -4,7 +4,7 @@ use zkevm_opcode_defs::ethereum_types::Address; use crate::{state::Stack, store::SnapShot, utils::is_kernel}; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct CallFrame { pub pc: u64, pub transient_storage_snapshot: SnapShot, @@ -14,7 +14,7 @@ pub struct CallFrame { pub storage_snapshot: SnapShot, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Context { pub frame: CallFrame, pub near_call_frames: Vec, diff --git a/src/heaps.rs b/src/heaps.rs index caaafb6f..8f7611b6 100644 --- a/src/heaps.rs +++ b/src/heaps.rs @@ -2,7 +2,7 @@ use zkevm_opcode_defs::system_params::NEW_FRAME_MEMORY_STIPEND; use crate::{eravm_error::HeapError, state::Heap}; -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, PartialEq)] pub struct Heaps { heaps: Vec, } diff --git a/src/state.rs b/src/state.rs index ddb91b6c..df55d247 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,4 +1,5 @@ use std::num::Saturating; +use std::u32; use crate::call_frame::{CallFrame, Context}; use crate::heaps::Heaps; @@ -18,16 +19,16 @@ pub const CALLDATA_HEAP: u32 = 1; pub const FIRST_HEAP: u32 = 2; pub const FIRST_AUX_HEAP: u32 = 3; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Stack { pub stack: Vec, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Heap { heap: Vec, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct VMState { // The first register, r0, is actually always zero and not really used. // Writing to it does nothing. @@ -478,7 +479,7 @@ impl Heap { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Event { pub key: U256, pub value: U256, diff --git a/src/store.rs b/src/store.rs index 7eeb5821..e7fb9ff1 100644 --- a/src/store.rs +++ b/src/store.rs @@ -125,7 +125,7 @@ impl StateStorage { } } -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, PartialEq)] pub struct SnapShot { pub storage_changes: HashMap, } diff --git a/src/value.rs b/src/value.rs index 65383814..431b70ec 100644 --- a/src/value.rs +++ b/src/value.rs @@ -2,7 +2,7 @@ use u256::U256; /// In the zkEVM, all data in the stack and on registers is tagged to determine /// whether they are a pointer or not. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] pub struct TaggedValue { pub value: U256, pub is_pointer: bool, From 59470a72d0d82a55b762f7d740b1bfeae65390b0 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Tue, 13 Aug 2024 15:45:39 -0300 Subject: [PATCH 2/5] Add initial gas param for VmState new --- src/state.rs | 6 ++---- src/tracers/last_state_saver_tracer.rs | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/state.rs b/src/state.rs index df55d247..7c0f934a 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,5 +1,4 @@ use std::num::Saturating; -use std::u32; use crate::call_frame::{CallFrame, Context}; use crate::heaps::Heaps; @@ -51,8 +50,6 @@ pub struct VMState { pub use_hooks: bool, } -// Totally arbitrary, probably we will have to change it later. -pub const DEFAULT_INITIAL_GAS: u32 = 1 << 16; impl VMState { #[allow(clippy::too_many_arguments)] pub fn new( @@ -65,6 +62,7 @@ impl VMState { evm_interpreter_code_hash: [u8; 32], hook_address: u32, use_hooks: bool, + initial_gas: u32, ) -> Self { let mut registers = [TaggedValue::default(); 15]; let calldata_ptr = FatPointer { @@ -78,7 +76,7 @@ impl VMState { let context = Context::new( program_code.clone(), - u32::MAX - 0x80000000, + initial_gas, contract_address, contract_address, caller, diff --git a/src/tracers/last_state_saver_tracer.rs b/src/tracers/last_state_saver_tracer.rs index 533e0c25..7e2bdcb6 100644 --- a/src/tracers/last_state_saver_tracer.rs +++ b/src/tracers/last_state_saver_tracer.rs @@ -25,6 +25,7 @@ impl LastStateSaverTracer { Default::default(), 0, false, + 0, ), } } From 26c2b18ae054e47eef621efab53ecd694a32f321 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Tue, 13 Aug 2024 16:11:34 -0300 Subject: [PATCH 3/5] Update era-compiler-tester branch --- .gitmodules | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitmodules b/.gitmodules index 203428a9..8f39238b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "era-compiler-tester"] path = era-compiler-tester url = https://github.com/lambdaclass/era-compiler-tester.git + branch = zksync-era-tests From e5cb98ba4e938a1f00792eea606d21a7fb2e82be Mon Sep 17 00:00:00 2001 From: Juan Munoz Date: Wed, 14 Aug 2024 10:39:30 -0300 Subject: [PATCH 4/5] fix test bytecode_publishing --- src/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store.rs b/src/store.rs index e7fb9ff1..720a276e 100644 --- a/src/store.rs +++ b/src/store.rs @@ -56,7 +56,7 @@ impl ContractStorage for ContractStorageMemory { pub struct StateStorage { pub storage_changes: HashMap, pub initial_storage: Rc>, - l2_to_l1_logs: Vec, + pub l2_to_l1_logs: Vec, } impl Default for StateStorage { From f0dce4107263dec4ea6458d2584e63a25eff6882 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Wed, 14 Aug 2024 11:07:56 -0300 Subject: [PATCH 5/5] Store changes for get_used_contracts tests --- src/store.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/store.rs b/src/store.rs index 720a276e..7f27e99c 100644 --- a/src/store.rs +++ b/src/store.rs @@ -40,6 +40,7 @@ impl InitialStorage for InitialStorageMemory { pub trait ContractStorage: Debug { fn decommit(&self, hash: U256) -> Result>, StorageError>; + fn hash_map(&self) -> Result>, StorageError>; } #[derive(Debug)] pub struct ContractStorageMemory { @@ -50,6 +51,10 @@ impl ContractStorage for ContractStorageMemory { fn decommit(&self, hash: U256) -> Result>, StorageError> { Ok(self.contract_storage.get(&hash).cloned()) } + + fn hash_map(&self) -> Result>, StorageError> { + Ok(self.contract_storage.clone()) + } } #[derive(Debug)]