Skip to content

Commit

Permalink
Serialization (#75)
Browse files Browse the repository at this point in the history
* chore: make structures serializable

* chore: more serialization
  • Loading branch information
chancehudson authored Dec 20, 2024
1 parent f65cbea commit 57533f7
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/commitments.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use super::group::{GroupElement, VartimeMultiscalarMul, GROUP_BASEPOINT_COMPRESSED};
use super::scalar::Scalar;
use digest::{ExtendableOutput, Input, XofReader};
use serde::{Deserialize, Serialize};
use sha3::Shake256;

#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
pub struct MultiCommitGens {
pub n: usize,
pub G: Vec<GroupElement>,
Expand Down
3 changes: 2 additions & 1 deletion src/dense_mlpoly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "multicore")]
use rayon::prelude::*;

#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
pub struct DensePolynomial {
num_vars: usize, // the number of variables in the multilinear polynomial
len: usize,
Z: Vec<Scalar>, // evaluations of the polynomial in all the 2^num_vars Boolean inputs
}

#[derive(Serialize, Deserialize)]
pub struct PolyCommitmentGens {
pub gens: DotProductProofGens,
}
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@ use timer::Timer;
use transcript::{AppendToTranscript, ProofTranscript};

/// `ComputationCommitment` holds a public preprocessed NP statement (e.g., R1CS)
#[derive(Serialize, Deserialize)]
pub struct ComputationCommitment {
comm: R1CSCommitment,
}

/// `ComputationDecommitment` holds information to decommit `ComputationCommitment`
#[derive(Serialize, Deserialize)]
pub struct ComputationDecommitment {
decomm: R1CSDecommitment,
}

/// `Assignment` holds an assignment of values to either the inputs or variables in an `Instance`
#[derive(Clone)]
#[derive(Clone, Serialize, Deserialize)]
pub struct Assignment {
assignment: Vec<Scalar>,
}
Expand Down Expand Up @@ -276,6 +278,7 @@ impl Instance {
}

/// `SNARKGens` holds public parameters for producing and verifying proofs with the Spartan SNARK
#[derive(Serialize, Deserialize)]
pub struct SNARKGens {
gens_r1cs_sat: R1CSGens,
gens_r1cs_eval: R1CSCommitmentGens,
Expand Down
1 change: 1 addition & 0 deletions src/nizk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ impl DotProductProof {
}
}

#[derive(Serialize, Deserialize)]
pub struct DotProductProofGens {
n: usize,
pub gens_n: MultiCommitGens,
Expand Down
2 changes: 2 additions & 0 deletions src/r1csinstance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct R1CSInstance {
C: SparseMatPolynomial,
}

#[derive(Serialize, Deserialize)]
pub struct R1CSCommitmentGens {
gens: SparseMatPolyCommitmentGens,
}
Expand Down Expand Up @@ -63,6 +64,7 @@ impl AppendToTranscript for R1CSCommitment {
}
}

#[derive(Serialize, Deserialize)]
pub struct R1CSDecommitment {
dense: MultiSparseMatPolynomialAsDense,
}
Expand Down
2 changes: 2 additions & 0 deletions src/r1csproof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct R1CSProof {
proof_eq_sc_phase2: EqualityProof,
}

#[derive(Serialize, Deserialize)]
pub struct R1CSSumcheckGens {
gens_1: MultiCommitGens,
gens_3: MultiCommitGens,
Expand All @@ -57,6 +58,7 @@ impl R1CSSumcheckGens {
}
}

#[derive(Serialize, Deserialize)]
pub struct R1CSGens {
gens_sc: R1CSSumcheckGens,
gens_pc: PolyCommitmentGens,
Expand Down
3 changes: 3 additions & 0 deletions src/sparse_mlpoly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl AppendToTranscript for DerefsCommitment {
}
}

#[derive(Serialize, Deserialize)]
struct AddrTimestamps {
ops_addr_usize: Vec<Vec<usize>>,
ops_addr: Vec<DensePolynomial>,
Expand Down Expand Up @@ -270,6 +271,7 @@ impl AddrTimestamps {
}
}

#[derive(Serialize, Deserialize)]
pub struct MultiSparseMatPolynomialAsDense {
batch_size: usize,
val: Vec<DensePolynomial>,
Expand All @@ -279,6 +281,7 @@ pub struct MultiSparseMatPolynomialAsDense {
comb_mem: DensePolynomial,
}

#[derive(Serialize, Deserialize)]
pub struct SparseMatPolyCommitmentGens {
gens_ops: PolyCommitmentGens,
gens_mem: PolyCommitmentGens,
Expand Down

0 comments on commit 57533f7

Please sign in to comment.