Serialization of Signed and Main Pods (#128)
This commit is contained in:
parent
fee70af12b
commit
9afc43675d
16 changed files with 817 additions and 189 deletions
|
|
@ -1,8 +1,10 @@
|
|||
use anyhow::{anyhow, Result};
|
||||
use base64::prelude::*;
|
||||
use itertools::Itertools;
|
||||
use log::error;
|
||||
use plonky2::hash::poseidon::PoseidonHash;
|
||||
use plonky2::plonk::config::Hasher;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::any::Any;
|
||||
use std::fmt;
|
||||
|
||||
|
|
@ -27,14 +29,14 @@ impl PodProver for MockProver {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct MockMainPod {
|
||||
params: Params,
|
||||
id: PodId,
|
||||
input_signed_pods: Vec<Box<dyn Pod>>,
|
||||
input_main_pods: Vec<Box<dyn Pod>>,
|
||||
// input_signed_pods: Vec<Box<dyn Pod>>,
|
||||
// input_main_pods: Vec<Box<dyn Pod>>,
|
||||
// New statements introduced by this pod
|
||||
input_statements: Vec<Statement>,
|
||||
// input_statements: Vec<Statement>,
|
||||
public_statements: Vec<Statement>,
|
||||
operations: Vec<Operation>,
|
||||
// All statements (inherited + new)
|
||||
|
|
@ -258,7 +260,7 @@ impl MockMainPod {
|
|||
.map(|mid_arg| Self::find_op_arg(statements, mid_arg))
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
Self::pad_operation_args(params, &mut args);
|
||||
operations.push(Operation(op.code(), args));
|
||||
operations.push(Operation(op.predicate(), args));
|
||||
}
|
||||
Ok(operations)
|
||||
}
|
||||
|
|
@ -332,9 +334,9 @@ impl MockMainPod {
|
|||
Ok(Self {
|
||||
params: params.clone(),
|
||||
id,
|
||||
input_signed_pods,
|
||||
input_main_pods,
|
||||
input_statements,
|
||||
// input_signed_pods,
|
||||
// input_main_pods,
|
||||
// input_statements,
|
||||
public_statements,
|
||||
statements,
|
||||
operations,
|
||||
|
|
@ -360,6 +362,15 @@ impl MockMainPod {
|
|||
fn pad_operation_args(params: &Params, args: &mut Vec<OperationArg>) {
|
||||
fill_pad(args, OperationArg::None, params.max_operation_args)
|
||||
}
|
||||
|
||||
pub fn deserialize(serialized: String) -> Result<Self> {
|
||||
let proof = String::from_utf8(BASE64_STANDARD.decode(&serialized)?)
|
||||
.map_err(|e| anyhow::anyhow!("Invalid base64 encoding: {}", e))?;
|
||||
let pod: MockMainPod = serde_json::from_str(&proof)
|
||||
.map_err(|e| anyhow::anyhow!("Failed to parse proof: {}", e))?;
|
||||
|
||||
Ok(pod)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hash_statements(statements: &[Statement], _params: &Params) -> middleware::Hash {
|
||||
|
|
@ -485,6 +496,10 @@ impl Pod for MockMainPod {
|
|||
fn into_any(self: Box<Self>) -> Box<dyn Any> {
|
||||
self
|
||||
}
|
||||
|
||||
fn serialized_proof(&self) -> String {
|
||||
BASE64_STANDARD.encode(serde_json::to_string(self).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue