Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bincode deserialization for VM run data #3044

Merged
merged 5 commits into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions core/lib/prover_interface/src/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{collections::HashMap, convert::TryInto, fmt::Debug};
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, Bytes};
use zksync_multivm::interface::{L1BatchEnv, SystemEnv};
use zksync_object_store::{serialize_using_bincode, Bucket, StoredObject};
use zksync_object_store::{_reexports::BoxedError, serialize_using_bincode, Bucket, StoredObject};
use zksync_types::{
basic_fri_types::Eip4844Blobs, block::L2BlockExecutionData,
witness_block_state::WitnessStorageState, L1BatchNumber, ProtocolVersionId, H256, U256,
Expand Down Expand Up @@ -151,6 +151,38 @@ pub struct VMRunWitnessInputData {
pub witness_block_state: WitnessStorageState,
}

// skip_serializing_if for field evm_emulator_code_hash doesn't work fine with bincode,
// so we are implementing custom deserialization for it
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VMRunWitnessInputDataLegacy {
pub l1_batch_number: L1BatchNumber,
pub used_bytecodes: HashMap<U256, Vec<[u8; 32]>>,
pub initial_heap_content: Vec<(usize, U256)>,
pub protocol_version: ProtocolVersionId,
pub bootloader_code: Vec<[u8; 32]>,
pub default_account_code_hash: U256,
pub storage_refunds: Vec<u32>,
pub pubdata_costs: Vec<i32>,
pub witness_block_state: WitnessStorageState,
}

impl From<VMRunWitnessInputDataLegacy> for VMRunWitnessInputData {
fn from(value: VMRunWitnessInputDataLegacy) -> Self {
Self {
l1_batch_number: value.l1_batch_number,
used_bytecodes: value.used_bytecodes,
initial_heap_content: value.initial_heap_content,
protocol_version: value.protocol_version,
bootloader_code: value.bootloader_code,
default_account_code_hash: value.default_account_code_hash,
evm_emulator_code_hash: None,
storage_refunds: value.storage_refunds,
pubdata_costs: value.pubdata_costs,
witness_block_state: value.witness_block_state,
}
}
}

impl StoredObject for VMRunWitnessInputData {
const BUCKET: Bucket = Bucket::WitnessInput;

Expand All @@ -160,7 +192,17 @@ impl StoredObject for VMRunWitnessInputData {
format!("vm_run_data_{key}.bin")
}

serialize_using_bincode!();
fn serialize(&self) -> Result<Vec<u8>, BoxedError> {
zksync_object_store::bincode::serialize(self).map_err(Into::into)
}

fn deserialize(bytes: Vec<u8>) -> Result<Self, BoxedError> {
zksync_object_store::bincode::deserialize::<VMRunWitnessInputData>(&bytes).or_else(|_| {
zksync_object_store::bincode::deserialize::<VMRunWitnessInputDataLegacy>(&bytes)
.map(Into::into)
.map_err(Into::into)
})
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
Loading