Skip to content

Commit 57533f7

Browse files
authored
Serialization (#75)
* chore: make structures serializable * chore: more serialization
1 parent f65cbea commit 57533f7

7 files changed

+16
-3
lines changed

src/commitments.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use super::group::{GroupElement, VartimeMultiscalarMul, GROUP_BASEPOINT_COMPRESSED};
22
use super::scalar::Scalar;
33
use digest::{ExtendableOutput, Input, XofReader};
4+
use serde::{Deserialize, Serialize};
45
use sha3::Shake256;
56

6-
#[derive(Debug)]
7+
#[derive(Debug, Serialize, Deserialize)]
78
pub struct MultiCommitGens {
89
pub n: usize,
910
pub G: Vec<GroupElement>,

src/dense_mlpoly.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ use serde::{Deserialize, Serialize};
1414
#[cfg(feature = "multicore")]
1515
use rayon::prelude::*;
1616

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

24+
#[derive(Serialize, Deserialize)]
2425
pub struct PolyCommitmentGens {
2526
pub gens: DotProductProofGens,
2627
}

src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,19 @@ use timer::Timer;
4545
use transcript::{AppendToTranscript, ProofTranscript};
4646

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

5253
/// `ComputationDecommitment` holds information to decommit `ComputationCommitment`
54+
#[derive(Serialize, Deserialize)]
5355
pub struct ComputationDecommitment {
5456
decomm: R1CSDecommitment,
5557
}
5658

5759
/// `Assignment` holds an assignment of values to either the inputs or variables in an `Instance`
58-
#[derive(Clone)]
60+
#[derive(Clone, Serialize, Deserialize)]
5961
pub struct Assignment {
6062
assignment: Vec<Scalar>,
6163
}
@@ -276,6 +278,7 @@ impl Instance {
276278
}
277279

278280
/// `SNARKGens` holds public parameters for producing and verifying proofs with the Spartan SNARK
281+
#[derive(Serialize, Deserialize)]
279282
pub struct SNARKGens {
280283
gens_r1cs_sat: R1CSGens,
281284
gens_r1cs_eval: R1CSCommitmentGens,

src/nizk/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ impl DotProductProof {
404404
}
405405
}
406406

407+
#[derive(Serialize, Deserialize)]
407408
pub struct DotProductProofGens {
408409
n: usize,
409410
pub gens_n: MultiCommitGens,

src/r1csinstance.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct R1CSInstance {
2525
C: SparseMatPolynomial,
2626
}
2727

28+
#[derive(Serialize, Deserialize)]
2829
pub struct R1CSCommitmentGens {
2930
gens: SparseMatPolyCommitmentGens,
3031
}
@@ -63,6 +64,7 @@ impl AppendToTranscript for R1CSCommitment {
6364
}
6465
}
6566

67+
#[derive(Serialize, Deserialize)]
6668
pub struct R1CSDecommitment {
6769
dense: MultiSparseMatPolynomialAsDense,
6870
}

src/r1csproof.rs

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub struct R1CSProof {
3636
proof_eq_sc_phase2: EqualityProof,
3737
}
3838

39+
#[derive(Serialize, Deserialize)]
3940
pub struct R1CSSumcheckGens {
4041
gens_1: MultiCommitGens,
4142
gens_3: MultiCommitGens,
@@ -57,6 +58,7 @@ impl R1CSSumcheckGens {
5758
}
5859
}
5960

61+
#[derive(Serialize, Deserialize)]
6062
pub struct R1CSGens {
6163
gens_sc: R1CSSumcheckGens,
6264
gens_pc: PolyCommitmentGens,

src/sparse_mlpoly.rs

+3
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ impl AppendToTranscript for DerefsCommitment {
209209
}
210210
}
211211

212+
#[derive(Serialize, Deserialize)]
212213
struct AddrTimestamps {
213214
ops_addr_usize: Vec<Vec<usize>>,
214215
ops_addr: Vec<DensePolynomial>,
@@ -270,6 +271,7 @@ impl AddrTimestamps {
270271
}
271272
}
272273

274+
#[derive(Serialize, Deserialize)]
273275
pub struct MultiSparseMatPolynomialAsDense {
274276
batch_size: usize,
275277
val: Vec<DensePolynomial>,
@@ -279,6 +281,7 @@ pub struct MultiSparseMatPolynomialAsDense {
279281
comb_mem: DensePolynomial,
280282
}
281283

284+
#[derive(Serialize, Deserialize)]
282285
pub struct SparseMatPolyCommitmentGens {
283286
gens_ops: PolyCommitmentGens,
284287
gens_mem: PolyCommitmentGens,

0 commit comments

Comments
 (0)