Skip to content

Commit

Permalink
Use read_fat_pointer() for deploy tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
slowli committed Oct 31, 2024
1 parent 293a71e commit c653bc7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
26 changes: 5 additions & 21 deletions core/lib/multivm/src/versions/vm_fast/evm_deploy_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RefCell<HashMap<U256, Vec<u8>>>>);
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions core/lib/multivm/src/versions/vm_fast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ mod refund;
#[cfg(test)]
mod tests;
mod transaction_data;
mod utils;
mod vm;
13 changes: 13 additions & 0 deletions core/lib/multivm/src/versions/vm_fast/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use zksync_types::U256;
use zksync_vm2::{interface::StateInterface, FatPointer};

pub(super) fn read_fat_pointer<S: StateInterface>(state: &S, raw: U256) -> Vec<u8> {
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
}

0 comments on commit c653bc7

Please sign in to comment.