diff --git a/core/lib/multivm/src/versions/vm_fast/evm_deploy_tracer.rs b/core/lib/multivm/src/versions/vm_fast/evm_deploy_tracer.rs index 6d0d5b531111..d869796cd2c1 100644 --- a/core/lib/multivm/src/versions/vm_fast/evm_deploy_tracer.rs +++ b/core/lib/multivm/src/versions/vm_fast/evm_deploy_tracer.rs @@ -2,17 +2,15 @@ use std::{cell::RefCell, collections::HashMap, rc::Rc}; -use zk_evm_1_5_0::zkevm_opcode_defs::CALL_IMPLICIT_CALLDATA_FAT_PTR_REGISTER; use zksync_system_constants::{CONTRACT_DEPLOYER_ADDRESS, KNOWN_CODES_STORAGE_ADDRESS}; use zksync_types::U256; use zksync_utils::{bytecode::hash_evm_bytecode, h256_to_u256}; -use zksync_vm2::{ - interface::{ - CallframeInterface, CallingMode, GlobalStateInterface, Opcode, OpcodeType, Tracer, - }, - FatPointer, +use zksync_vm2::interface::{ + CallframeInterface, CallingMode, GlobalStateInterface, Opcode, OpcodeType, Tracer, }; +use super::utils::read_fat_pointer; + /// Container for dynamic bytecodes added by [`EvmDeployTracer`]. #[derive(Debug, Clone, Default)] pub(super) struct DynamicBytecodes(Rc>>>); @@ -55,21 +53,7 @@ impl EvmDeployTracer { return; } - let (calldata_ptr, is_pointer) = - state.read_register(CALL_IMPLICIT_CALLDATA_FAT_PTR_REGISTER + 1); - assert!( - is_pointer, - "far call convention violated: register 1 is not a pointer to calldata" - ); - let calldata_ptr = FatPointer::from(calldata_ptr); - assert_eq!( - calldata_ptr.offset, 0, - "far call convention violated: calldata fat pointer is not shrunk to have 0 offset" - ); - - let data: Vec<_> = (calldata_ptr.start..calldata_ptr.start + calldata_ptr.length) - .map(|addr| state.read_heap_byte(calldata_ptr.memory_page, addr)) - .collect(); + let data = read_fat_pointer(state, state.read_register(1).0); if data.len() < 4 { return; } diff --git a/core/lib/multivm/src/versions/vm_fast/mod.rs b/core/lib/multivm/src/versions/vm_fast/mod.rs index 35f3909a3bdf..ad9718f9fd79 100644 --- a/core/lib/multivm/src/versions/vm_fast/mod.rs +++ b/core/lib/multivm/src/versions/vm_fast/mod.rs @@ -15,4 +15,5 @@ mod refund; #[cfg(test)] mod tests; mod transaction_data; +mod utils; mod vm; diff --git a/core/lib/multivm/src/versions/vm_fast/utils.rs b/core/lib/multivm/src/versions/vm_fast/utils.rs new file mode 100644 index 000000000000..20a6545d3385 --- /dev/null +++ b/core/lib/multivm/src/versions/vm_fast/utils.rs @@ -0,0 +1,13 @@ +use zksync_types::U256; +use zksync_vm2::{interface::StateInterface, FatPointer}; + +pub(super) fn read_fat_pointer(state: &S, raw: U256) -> Vec { + let pointer = FatPointer::from(raw); + let length = pointer.length - pointer.offset; + let start = pointer.start + pointer.offset; + let mut result = vec![0; length as usize]; + for i in 0..length { + result[i as usize] = state.read_heap_byte(pointer.memory_page, start + i); + } + result +}