Skip to content

Commit 4de3622

Browse files
authored
fix(c&c): adding serde::* for all types (#55)
In case you are doing a full C&C with intermediate state preservation you need all types to serialize and deserialize, this PR fixes the flaw that some types didn't do that
1 parent 1d636b3 commit 4de3622

File tree

10 files changed

+21
-9
lines changed

10 files changed

+21
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "garbled-snark-verifier"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
edition = "2024"
55
authors = ["BitVM Alliance"]
66
license = "GPL-3.0-only"

src/cac/adaptor_sigs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fn is_odd(y: &Fq) -> bool {
2727
y.into_bigint().is_odd()
2828
}
2929

30+
#[derive(Clone, Debug)]
3031
pub struct AdaptorInfo {
3132
garbler_commit: Projective,
3233
evaluator_nonce_commit: Projective,

src/cac/vsss.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ use ark_ec::PrimeGroup;
44
use ark_ff::{Field, One, UniformRand, Zero};
55
use ark_secp256k1::{Fr, Projective};
66
use rand::Rng;
7+
use serde::{Deserialize, Serialize};
78

89
// we use this for both polynomials over scalars and over projective points
10+
#[derive(Clone, Debug, Serialize, Deserialize)]
911
pub struct Polynomial<T>(Vec<T>);
1012

1113
impl<T> Polynomial<T>
@@ -55,8 +57,10 @@ impl Polynomial<Fr> {
5557
}
5658
}
5759

60+
#[derive(Clone, Debug)]
5861
pub struct PolynomialCommits(Polynomial<Projective>);
5962

63+
#[derive(Clone, Debug)]
6064
pub struct ShareCommits(pub Vec<Projective>);
6165

6266
impl ShareCommits {

src/circuit/modes/evaluate_mode.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::num::NonZero;
22

3+
use serde::{Deserialize, Serialize};
4+
35
use super::garble_mode::{GarbledWire, halfgates_garbling};
46
use crate::{
57
Gate, S, WireId,
@@ -9,7 +11,7 @@ use crate::{
911
storage::{Credits, Storage},
1012
};
1113

12-
#[derive(Clone, Debug, PartialEq, Eq)]
14+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1315
pub struct EvaluatedWire {
1416
pub active_label: S,
1517
pub value: bool,

src/cut_and_choose/evaluator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ where
169169
}
170170
}
171171

172+
#[derive(Debug, Serialize, Deserialize)]
172173
pub struct EvaluatorCaseInput<I> {
173174
pub index: usize,
174175
pub input: I,

src/cut_and_choose/garbler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
cut_and_choose::{Commit, Config, Seed, commit_label},
1818
};
1919

20-
#[derive(Serialize, Deserialize)]
20+
#[derive(Debug, Serialize, Deserialize)]
2121
pub struct GarbledInstance {
2222
/// Constant to represent false wire constant
2323
///
@@ -127,7 +127,7 @@ pub enum OpenForInstance {
127127
},
128128
}
129129

130-
#[derive(Serialize, Deserialize)]
130+
#[derive(Debug, Serialize, Deserialize)]
131131
pub enum GarblerStage {
132132
Generating { seeds: Box<[Seed]> },
133133
PreparedForEval { indexes_to_eval: Box<[usize]> },
@@ -148,7 +148,7 @@ impl GarblerStage {
148148
}
149149
}
150150

151-
#[derive(Serialize, Deserialize)]
151+
#[derive(Debug, Serialize, Deserialize)]
152152
pub struct Garbler<I: CircuitInput + Clone> {
153153
stage: GarblerStage,
154154
instances: Vec<GarbledInstance>,

src/cut_and_choose/groth16.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub const DEFAULT_CAPACITY: usize = 150_000;
1818

1919
/// Groth16-specific wrapper preserving the existing API while delegating
2020
/// to the generic cut-and-choose implementation.
21+
#[derive(Debug, Serialize, Deserialize)]
2122
pub struct Garbler {
2223
inner: generic::Garbler<garbled_groth16::GarblerCompressedInput>,
2324
}

src/garbled_groth16.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<H: GateHasher, CTH: CiphertextHandler> EncodeInput<GarbleMode<H, CTH>> for
168168
// ============================================================================
169169

170170
/// Bit-vector wrapper for field element wires evaluated against garbled labels.
171-
#[derive(Debug, Clone)]
171+
#[derive(Debug, Clone, Serialize, Deserialize)]
172172
pub struct EvaluatedFrWires(pub Vec<EvaluatedWire>);
173173

174174
impl Deref for EvaluatedFrWires {
@@ -481,23 +481,25 @@ impl<H: GateHasher, CTH: CiphertextHandler> EncodeInput<GarbleMode<H, CTH>>
481481
}
482482
}
483483

484-
#[derive(Debug)]
484+
#[derive(Debug, Clone, Serialize, Deserialize)]
485485
pub struct EvaluatedCompressedG1Wires {
486486
pub x: EvaluatedFrWires,
487487
pub y_flag: EvaluatedWire,
488488
}
489489

490-
#[derive(Debug)]
490+
#[derive(Debug, Clone, Serialize, Deserialize)]
491491
pub struct EvaluatedCompressedG2Wires {
492492
pub x: [EvaluatedFrWires; 2],
493493
pub y_flag: EvaluatedWire,
494494
}
495495

496+
#[derive(Debug, Clone, Serialize, Deserialize)]
496497
pub struct EvaluatorCompressedInput {
497498
pub public: Vec<EvaluatedFrWires>,
498499
pub a: EvaluatedCompressedG1Wires,
499500
pub b: EvaluatedCompressedG2Wires,
500501
pub c: EvaluatedCompressedG1Wires,
502+
#[serde(with = "ark_canonical")]
501503
pub vk: VerifyingKey<Bn254>,
502504
}
503505

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub mod ark {
6767
lc,
6868
r1cs::{ConstraintSynthesizer, ConstraintSystemRef, SynthesisError},
6969
};
70+
pub use ark_serialize;
7071
pub use ark_snark::{CircuitSpecificSetupSNARK, SNARK};
7172
}
7273

0 commit comments

Comments
 (0)