Implement generic serialization/deserialization (#260)

* complete general serialization

* bump default params temporarily

* disable recursion in great_boy_pod example
This commit is contained in:
Eduard S. 2025-06-10 12:17:30 +02:00 committed by GitHub
parent c66506c048
commit 621f8be6b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 392 additions and 253 deletions

View file

@ -10,11 +10,13 @@ pub mod signedpod;
use std::sync::LazyLock;
use base64::{prelude::BASE64_STANDARD, Engine};
pub use error::*;
use plonky2::util::serialization::{Buffer, Read};
use crate::{
backends::plonky2::{
basetypes::CircuitData,
basetypes::{CircuitData, CommonCircuitData, Proof},
circuits::mainpod::{MainPodVerifyTarget, NUM_PUBLIC_INPUTS},
recursion::RecursiveCircuit,
},
@ -37,3 +39,36 @@ pub static STANDARD_REC_MAIN_POD_CIRCUIT_DATA: LazyLock<CircuitData> = LazyLock:
.1
)
});
pub fn serialize_bytes(bytes: &[u8]) -> String {
BASE64_STANDARD.encode(bytes)
}
pub fn deserialize_bytes(data: &str) -> Result<Vec<u8>> {
BASE64_STANDARD.decode(data).map_err(|e| {
Error::custom(format!(
"Failed to decode data from base64: {}. Value: {}",
e, data
))
})
}
pub fn deserialize_proof(common: &CommonCircuitData, proof: &str) -> Result<Proof> {
let decoded = deserialize_bytes(proof)?;
let mut buf = Buffer::new(&decoded);
let proof = buf.read_proof(common).map_err(|e| {
Error::custom(format!(
"Failed to read proof from buffer: {}. Value: {}",
e, proof
))
})?;
Ok(proof)
}
pub fn serialize_proof(proof: &Proof) -> String {
let mut buffer = Vec::new();
use plonky2::util::serialization::Write;
buffer.write_proof(proof).unwrap();
serialize_bytes(&buffer)
}