Skip to content

Commit

Permalink
removeed serde
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip committed Nov 21, 2020
1 parent 4fa2e58 commit ff55fcc
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 123 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ digest = { version = "0.9.0", default-features = false, features = ["alloc"] }
rand_core = { version = "0.5", default-features = false, features = ["alloc"] }
rand = { version = "0.7", default-features = false, optional = true }
byteorder = { version = "1", default-features = false }
serde = { version = "1", default-features = false, features = ["alloc"] }
serde_derive = { version = "1", default-features = false }
# serde = { version = "1", default-features = false, features = ["alloc"] }
# serde_derive = { version = "1", default-features = false }
thiserror = { version = "1", optional = true }
merlin = { version = "2", default-features = false }
clear_on_drop = { version = "0.2", default-features = false, features = ["nightly"] }
Expand Down
86 changes: 43 additions & 43 deletions src/r1cs/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::errors::R1CSError;
use crate::inner_product_proof::InnerProductProof;
use crate::util;

use serde::de::Visitor;
use serde::{self, Deserialize, Deserializer, Serialize, Serializer};
// use serde::de::Visitor;
// use serde::{self, Deserialize, Deserializer, Serialize, Serializer};

const ONE_PHASE_COMMITMENTS: u8 = 0;
const TWO_PHASE_COMMITMENTS: u8 = 1;
Expand Down Expand Up @@ -205,44 +205,44 @@ impl R1CSProof {
}
}

impl Serialize for R1CSProof {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_bytes(&self.to_bytes()[..])
}
}

impl<'de> Deserialize<'de> for R1CSProof {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct R1CSProofVisitor;

impl<'de> Visitor<'de> for R1CSProofVisitor {
type Value = R1CSProof;

fn expecting(&self, formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
formatter.write_str("a valid R1CSProof")
}

fn visit_bytes<E>(self, v: &[u8]) -> Result<R1CSProof, E>
where
E: serde::de::Error,
{
// Using Error::custom requires T: Display, which our error
// type only implements when it implements std::error::Error.
#[cfg(feature = "std")]
return R1CSProof::from_bytes(v).map_err(serde::de::Error::custom);
// In no-std contexts, drop the error message.
#[cfg(not(feature = "std"))]
return R1CSProof::from_bytes(v)
.map_err(|_| serde::de::Error::custom("deserialization error"));
}
}

deserializer.deserialize_bytes(R1CSProofVisitor)
}
}
// impl Serialize for R1CSProof {
// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
// where
// S: Serializer,
// {
// serializer.serialize_bytes(&self.to_bytes()[..])
// }
// }

// impl<'de> Deserialize<'de> for R1CSProof {
// fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
// where
// D: Deserializer<'de>,
// {
// struct R1CSProofVisitor;

// impl<'de> Visitor<'de> for R1CSProofVisitor {
// type Value = R1CSProof;

// fn expecting(&self, formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
// formatter.write_str("a valid R1CSProof")
// }

// fn visit_bytes<E>(self, v: &[u8]) -> Result<R1CSProof, E>
// where
// E: serde::de::Error,
// {
// // Using Error::custom requires T: Display, which our error
// // type only implements when it implements std::error::Error.
// #[cfg(feature = "std")]
// return R1CSProof::from_bytes(v).map_err(serde::de::Error::custom);
// // In no-std contexts, drop the error message.
// #[cfg(not(feature = "std"))]
// return R1CSProof::from_bytes(v)
// .map_err(|_| serde::de::Error::custom("deserialization error"));
// }
// }

// deserializer.deserialize_bytes(R1CSProofVisitor)
// }
// }
156 changes: 78 additions & 78 deletions src/range_proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use crate::transcript::TranscriptProtocol;
use crate::util;

use rand_core::{CryptoRng, RngCore};
use serde::de::Visitor;
use serde::{self, Deserialize, Deserializer, Serialize, Serializer};
// use serde::de::Visitor;
// use serde::{self, Deserialize, Deserializer, Serialize, Serializer};

// Modules for MPC protocol

Expand Down Expand Up @@ -538,47 +538,47 @@ impl RangeProof {
}
}

impl Serialize for RangeProof {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_bytes(&self.to_bytes()[..])
}
}

impl<'de> Deserialize<'de> for RangeProof {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct RangeProofVisitor;

impl<'de> Visitor<'de> for RangeProofVisitor {
type Value = RangeProof;

fn expecting(&self, formatter: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
formatter.write_str("a valid RangeProof")
}

fn visit_bytes<E>(self, v: &[u8]) -> Result<RangeProof, E>
where
E: serde::de::Error,
{
// Using Error::custom requires T: Display, which our error
// type only implements when it implements std::error::Error.
#[cfg(feature = "std")]
return RangeProof::from_bytes(v).map_err(serde::de::Error::custom);
// In no-std contexts, drop the error message.
#[cfg(not(feature = "std"))]
return RangeProof::from_bytes(v)
.map_err(|_| serde::de::Error::custom("deserialization error"));
}
}

deserializer.deserialize_bytes(RangeProofVisitor)
}
}
// impl Serialize for RangeProof {
// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
// where
// S: Serializer,
// {
// serializer.serialize_bytes(&self.to_bytes()[..])
// }
// }

// impl<'de> Deserialize<'de> for RangeProof {
// fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
// where
// D: Deserializer<'de>,
// {
// struct RangeProofVisitor;

// impl<'de> Visitor<'de> for RangeProofVisitor {
// type Value = RangeProof;

// fn expecting(&self, formatter: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
// formatter.write_str("a valid RangeProof")
// }

// fn visit_bytes<E>(self, v: &[u8]) -> Result<RangeProof, E>
// where
// E: serde::de::Error,
// {
// // Using Error::custom requires T: Display, which our error
// // type only implements when it implements std::error::Error.
// #[cfg(feature = "std")]
// return RangeProof::from_bytes(v).map_err(serde::de::Error::custom);
// // In no-std contexts, drop the error message.
// #[cfg(not(feature = "std"))]
// return RangeProof::from_bytes(v)
// .map_err(|_| serde::de::Error::custom("deserialization error"));
// }
// }

// deserializer.deserialize_bytes(RangeProofVisitor)
// }
// }

/// Compute
/// \\[
Expand Down Expand Up @@ -644,45 +644,45 @@ mod tests {
let bp_gens = BulletproofGens::new(max_bitsize, max_parties);

// Prover's scope
let (proof_bytes, value_commitments) = {
use self::rand::Rng;
let mut rng = rand::thread_rng();

// 0. Create witness data
let (min, max) = (0u64, ((1u128 << n) - 1) as u64);
let values: Vec<u64> = (0..m).map(|_| rng.gen_range(min, max)).collect();
let blindings: Vec<Scalar> = (0..m).map(|_| Scalar::random(&mut rng)).collect();

// 1. Create the proof
let mut transcript = Transcript::new(b"AggregatedRangeProofTest");
let (proof, value_commitments) = RangeProof::prove_multiple(
&bp_gens,
&pc_gens,
&mut transcript,
&values,
&blindings,
n,
)
.unwrap();

// 2. Return serialized proof and value commitments
(bincode::serialize(&proof).unwrap(), value_commitments)
};

println!("proof byte size = {}", proof_bytes.len());
// let (proof_bytes, value_commitments) = {
// use self::rand::Rng;
// let mut rng = rand::thread_rng();

// // 0. Create witness data
// let (min, max) = (0u64, ((1u128 << n) - 1) as u64);
// let values: Vec<u64> = (0..m).map(|_| rng.gen_range(min, max)).collect();
// let blindings: Vec<Scalar> = (0..m).map(|_| Scalar::random(&mut rng)).collect();

// // 1. Create the proof
// let mut transcript = Transcript::new(b"AggregatedRangeProofTest");
// let (proof, value_commitments) = RangeProof::prove_multiple(
// &bp_gens,
// &pc_gens,
// &mut transcript,
// &values,
// &blindings,
// n,
// )
// .unwrap();

// // 2. Return serialized proof and value commitments
// (bincode::serialize(&proof).unwrap(), value_commitments)
// };

// println!("proof byte size = {}", proof_bytes.len());

// Verifier's scope
{
// 3. Deserialize
let proof: RangeProof = bincode::deserialize(&proof_bytes).unwrap();
// {
// // 3. Deserialize
// let proof: RangeProof = bincode::deserialize(&proof_bytes).unwrap();

// 4. Verify with the same customization label as above
let mut transcript = Transcript::new(b"AggregatedRangeProofTest");
// // 4. Verify with the same customization label as above
// let mut transcript = Transcript::new(b"AggregatedRangeProofTest");

assert!(proof
.verify_multiple(&bp_gens, &pc_gens, &mut transcript, &value_commitments, n)
.is_ok());
}
// assert!(proof
// .verify_multiple(&bp_gens, &pc_gens, &mut transcript, &value_commitments, n)
// .is_ok());
// }
}

#[test]
Expand Down

0 comments on commit ff55fcc

Please sign in to comment.