From b4945ce4714bbdcd9d7df3913e8c0c40647e7040 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 1 Aug 2023 10:58:23 +0800 Subject: [PATCH] Update `ChunkProof` for serialization (#184) Update `ChunkProof` for serialization. --- prover/src/proof/chunk.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/prover/src/proof/chunk.rs b/prover/src/proof/chunk.rs index 44c12a39a..0f60aa81e 100644 --- a/prover/src/proof/chunk.rs +++ b/prover/src/proof/chunk.rs @@ -4,12 +4,14 @@ use halo2_proofs::{halo2curves::bn256::G1Affine, plonk::ProvingKey}; use serde_derive::{Deserialize, Serialize}; use snark_verifier::Protocol; use snark_verifier_sdk::Snark; -use types::eth::StorageTrace; +use types::{base64, eth::StorageTrace}; #[derive(Debug, Deserialize, Serialize)] pub struct ChunkProof { - pub storage_trace: StorageTrace, - pub protocol: Protocol, + #[serde(with = "base64")] + pub storage_trace: Vec, + #[serde(with = "base64")] + pub protocol: Vec, pub proof: Proof, } @@ -19,7 +21,8 @@ impl ChunkProof { storage_trace: StorageTrace, pk: Option<&ProvingKey>, ) -> Result { - let protocol = snark.protocol; + let storage_trace = serde_json::to_vec(&storage_trace)?; + let protocol = serde_json::to_vec(&snark.protocol)?; let proof = Proof::new(snark.proof, &snark.instances, pk)?; Ok(Self { @@ -42,14 +45,16 @@ impl ChunkProof { pub fn to_snark_and_storage_trace(self) -> (Snark, StorageTrace) { let instances = self.proof.instances(); + let storage_trace = serde_json::from_slice::(&self.storage_trace).unwrap(); + let protocol = serde_json::from_slice::>(&self.protocol).unwrap(); ( Snark { - protocol: self.protocol, + protocol, proof: self.proof.proof, instances, }, - self.storage_trace, + storage_trace, ) } }