From 35c3fde5d5ced7c8fc3009160b5cdb802a61a912 Mon Sep 17 00:00:00 2001 From: vimwitch Date: Sun, 20 Oct 2024 23:37:52 -0700 Subject: [PATCH 1/2] chore: make structures serializable --- src/dense_mlpoly.rs | 2 +- src/lib.rs | 2 ++ src/r1csinstance.rs | 1 + src/sparse_mlpoly.rs | 2 ++ 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/dense_mlpoly.rs b/src/dense_mlpoly.rs index 4400b42f..9c7cfd4a 100644 --- a/src/dense_mlpoly.rs +++ b/src/dense_mlpoly.rs @@ -14,7 +14,7 @@ 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, diff --git a/src/lib.rs b/src/lib.rs index ab051d95..dbe8f748 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,11 +45,13 @@ 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, } diff --git a/src/r1csinstance.rs b/src/r1csinstance.rs index 80499c4e..1f396ba9 100644 --- a/src/r1csinstance.rs +++ b/src/r1csinstance.rs @@ -63,6 +63,7 @@ impl AppendToTranscript for R1CSCommitment { } } +#[derive(Serialize, Deserialize)] pub struct R1CSDecommitment { dense: MultiSparseMatPolynomialAsDense, } diff --git a/src/sparse_mlpoly.rs b/src/sparse_mlpoly.rs index 83a51f5b..6a7440e1 100644 --- a/src/sparse_mlpoly.rs +++ b/src/sparse_mlpoly.rs @@ -209,6 +209,7 @@ impl AppendToTranscript for DerefsCommitment { } } +#[derive(Serialize, Deserialize)] struct AddrTimestamps { ops_addr_usize: Vec>, ops_addr: Vec, @@ -270,6 +271,7 @@ impl AddrTimestamps { } } +#[derive(Serialize, Deserialize)] pub struct MultiSparseMatPolynomialAsDense { batch_size: usize, val: Vec, From 065b810c7a8e9dbba087d84f270db5d896ce1171 Mon Sep 17 00:00:00 2001 From: vimwitch Date: Sun, 20 Oct 2024 23:52:04 -0700 Subject: [PATCH 2/2] chore: more serialization --- src/commitments.rs | 3 ++- src/dense_mlpoly.rs | 1 + src/lib.rs | 3 ++- src/nizk/mod.rs | 1 + src/r1csinstance.rs | 1 + src/r1csproof.rs | 2 ++ src/sparse_mlpoly.rs | 1 + 7 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/commitments.rs b/src/commitments.rs index 4fad4155..44e7784d 100644 --- a/src/commitments.rs +++ b/src/commitments.rs @@ -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, diff --git a/src/dense_mlpoly.rs b/src/dense_mlpoly.rs index 9c7cfd4a..f0aabbba 100644 --- a/src/dense_mlpoly.rs +++ b/src/dense_mlpoly.rs @@ -21,6 +21,7 @@ pub struct DensePolynomial { Z: Vec, // evaluations of the polynomial in all the 2^num_vars Boolean inputs } +#[derive(Serialize, Deserialize)] pub struct PolyCommitmentGens { pub gens: DotProductProofGens, } diff --git a/src/lib.rs b/src/lib.rs index dbe8f748..7341fc8a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,7 +57,7 @@ pub struct ComputationDecommitment { } /// `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, } @@ -278,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, diff --git a/src/nizk/mod.rs b/src/nizk/mod.rs index ba7da5a7..78661b15 100644 --- a/src/nizk/mod.rs +++ b/src/nizk/mod.rs @@ -404,6 +404,7 @@ impl DotProductProof { } } +#[derive(Serialize, Deserialize)] pub struct DotProductProofGens { n: usize, pub gens_n: MultiCommitGens, diff --git a/src/r1csinstance.rs b/src/r1csinstance.rs index 1f396ba9..58706d93 100644 --- a/src/r1csinstance.rs +++ b/src/r1csinstance.rs @@ -25,6 +25,7 @@ pub struct R1CSInstance { C: SparseMatPolynomial, } +#[derive(Serialize, Deserialize)] pub struct R1CSCommitmentGens { gens: SparseMatPolyCommitmentGens, } diff --git a/src/r1csproof.rs b/src/r1csproof.rs index 209dcafc..1b3fe2e4 100644 --- a/src/r1csproof.rs +++ b/src/r1csproof.rs @@ -36,6 +36,7 @@ pub struct R1CSProof { proof_eq_sc_phase2: EqualityProof, } +#[derive(Serialize, Deserialize)] pub struct R1CSSumcheckGens { gens_1: MultiCommitGens, gens_3: MultiCommitGens, @@ -57,6 +58,7 @@ impl R1CSSumcheckGens { } } +#[derive(Serialize, Deserialize)] pub struct R1CSGens { gens_sc: R1CSSumcheckGens, gens_pc: PolyCommitmentGens, diff --git a/src/sparse_mlpoly.rs b/src/sparse_mlpoly.rs index 6a7440e1..d7bdc9cb 100644 --- a/src/sparse_mlpoly.rs +++ b/src/sparse_mlpoly.rs @@ -281,6 +281,7 @@ pub struct MultiSparseMatPolynomialAsDense { comb_mem: DensePolynomial, } +#[derive(Serialize, Deserialize)] pub struct SparseMatPolyCommitmentGens { gens_ops: PolyCommitmentGens, gens_mem: PolyCommitmentGens,