Skip to content

Commit

Permalink
fix: bincode deserialize for WitnessInputData (#3055)
Browse files Browse the repository at this point in the history
## What ❔

Fix bincode deserialization for WitnessInputData

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk_supervisor fmt` and `zk_supervisor
lint`.
  • Loading branch information
Artemka374 authored Oct 10, 2024
1 parent e51ec49 commit 91d0595
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion core/lib/prover_interface/src/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,25 @@ pub struct WitnessInputData {
pub eip_4844_blobs: Eip4844Blobs,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WitnessInputDataLegacy {
pub vm_run_data: VMRunWitnessInputDataLegacy,
pub merkle_paths: WitnessInputMerklePaths,
pub previous_batch_metadata: L1BatchMetadataHashes,
pub eip_4844_blobs: Eip4844Blobs,
}

impl From<WitnessInputDataLegacy> for WitnessInputData {
fn from(value: WitnessInputDataLegacy) -> Self {
Self {
vm_run_data: value.vm_run_data.into(),
merkle_paths: value.merkle_paths,
previous_batch_metadata: value.previous_batch_metadata,
eip_4844_blobs: value.eip_4844_blobs,
}
}
}

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

Expand All @@ -222,7 +241,17 @@ impl StoredObject for WitnessInputData {
format!("witness_inputs_{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::<WitnessInputData>(&bytes).or_else(|_| {
zksync_object_store::bincode::deserialize::<WitnessInputDataLegacy>(&bytes)
.map(Into::into)
.map_err(Into::into)
})
}
}

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

0 comments on commit 91d0595

Please sign in to comment.