Skip to content

Commit

Permalink
Merge pull request #1892 from AleoHQ/rm/to-min-bits
Browse files Browse the repository at this point in the history
Removes to minimal bits
  • Loading branch information
howardwu authored Aug 15, 2023
2 parents 8b65a77 + 889d9c3 commit c55d6f8
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 93 deletions.
7 changes: 0 additions & 7 deletions algorithms/src/polycommit/kzg10/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use snarkvm_utilities::{
serialize::{CanonicalDeserialize, CanonicalSerialize, Compress, SerializationError, Valid, Validate},
FromBytes,
ToBytes,
ToMinimalBits,
};

use crate::srs::{UniversalProver, UniversalVerifier};
Expand Down Expand Up @@ -288,12 +287,6 @@ impl<E: PairingEngine> ToBytes for KZGCommitment<E> {
}
}

impl<E: PairingEngine> ToMinimalBits for KZGCommitment<E> {
fn write_minimal_bits(&self, vec: &mut Vec<bool>) {
self.0.write_minimal_bits(vec);
}
}

impl<E: PairingEngine> KZGCommitment<E> {
#[inline]
pub fn empty() -> Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::{fft::EvaluationDomain, polycommit::sonic_pc, r1cs::SynthesisError, snark::marlin::ahp::indexer::*};
use crate::{fft::EvaluationDomain, polycommit::sonic_pc, snark::marlin::ahp::indexer::*};
use snarkvm_curves::PairingEngine;
use snarkvm_fields::{ConstraintFieldError, ToConstraintField};
use snarkvm_utilities::{
Expand All @@ -22,10 +22,8 @@ use snarkvm_utilities::{
string::String,
FromBytes,
FromBytesDeserializer,
ToBits,
ToBytes,
ToBytesSerializer,
ToMinimalBits,
};

use anyhow::Result;
Expand All @@ -43,40 +41,6 @@ pub struct CircuitVerifyingKey<E: PairingEngine> {
pub id: CircuitId,
}

impl<E: PairingEngine> ToMinimalBits for CircuitVerifyingKey<E> {
fn write_minimal_bits(&self, vec: &mut Vec<bool>) {
let constraint_domain = EvaluationDomain::<E::Fr>::new(self.circuit_info.num_constraints)
.ok_or(SynthesisError::PolynomialDegreeTooLarge)
.unwrap();
let non_zero_domain_a = EvaluationDomain::<E::Fr>::new(self.circuit_info.num_non_zero_a)
.ok_or(SynthesisError::PolynomialDegreeTooLarge)
.unwrap();
let non_zero_domain_b = EvaluationDomain::<E::Fr>::new(self.circuit_info.num_non_zero_b)
.ok_or(SynthesisError::PolynomialDegreeTooLarge)
.unwrap();
let non_zero_domain_c = EvaluationDomain::<E::Fr>::new(self.circuit_info.num_non_zero_c)
.ok_or(SynthesisError::PolynomialDegreeTooLarge)
.unwrap();

assert!(constraint_domain.size() < u64::MAX as usize);
assert!(non_zero_domain_a.size() < u64::MAX as usize);
assert!(non_zero_domain_b.size() < u64::MAX as usize);
assert!(non_zero_domain_c.size() < u64::MAX as usize);

let constraint_domain_size = constraint_domain.size() as u64;
let non_zero_domain_a_size = non_zero_domain_a.size() as u64;
let non_zero_domain_b_size = non_zero_domain_b.size() as u64;
let non_zero_domain_c_size = non_zero_domain_c.size() as u64;

constraint_domain_size.write_bits_le(vec);
non_zero_domain_a_size.write_bits_le(vec);
non_zero_domain_b_size.write_bits_le(vec);
non_zero_domain_c_size.write_bits_le(vec);

self.circuit_commitments.write_minimal_bits(vec);
}
}

impl<E: PairingEngine> FromBytes for CircuitVerifyingKey<E> {
fn read_le<R: Read>(r: R) -> io::Result<Self> {
Self::deserialize_compressed(r).map_err(|_| error("could not deserialize CircuitVerifyingKey"))
Expand Down
11 changes: 2 additions & 9 deletions algorithms/src/traits/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use crate::{errors::SNARKError, r1cs::ConstraintSynthesizer, AlgebraicSponge};
use snarkvm_fields::{PrimeField, ToConstraintField};
use snarkvm_utilities::{CanonicalDeserialize, CanonicalSerialize, FromBytes, ToBytes, ToMinimalBits};
use snarkvm_utilities::{CanonicalDeserialize, CanonicalSerialize, FromBytes, ToBytes};

use anyhow::Result;
use rand::{CryptoRng, Rng};
Expand Down Expand Up @@ -49,14 +49,7 @@ pub trait SNARK {
type UniversalVerifier;

type VerifierInput: ?Sized;
type VerifyingKey: Clone
+ Send
+ Sync
+ ToBytes
+ FromBytes
+ ToConstraintField<Self::BaseField>
+ ToMinimalBits
+ Ord;
type VerifyingKey: Clone + Send + Sync + ToBytes + FromBytes + ToConstraintField<Self::BaseField> + Ord;

type FiatShamirRng: AlgebraicSponge<Self::BaseField, 2, Parameters = Self::FSParameters>;
type FSParameters;
Expand Down
10 changes: 0 additions & 10 deletions curves/src/templates/short_weierstrass_jacobian/affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ use snarkvm_utilities::{
rand::Uniform,
serialize::*,
FromBytes,
ToBits,
ToBytes,
ToMinimalBits,
};

use core::{
Expand Down Expand Up @@ -262,14 +260,6 @@ impl<P: Parameters> AffineCurve for Affine<P> {
}
}

impl<P: Parameters> ToMinimalBits for Affine<P> {
fn write_minimal_bits(&self, vec: &mut Vec<bool>) {
self.x.write_bits_le(vec);
vec.push(*self.y.to_bits_le().first().unwrap());
vec.push(self.infinity);
}
}

impl<P: Parameters> Neg for Affine<P> {
type Output = Self;

Expand Down
8 changes: 0 additions & 8 deletions curves/src/templates/twisted_edwards_extended/affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ use snarkvm_utilities::{
rand::Uniform,
serialize::*,
FromBytes,
ToBits,
ToBytes,
ToMinimalBits,
};

use core::{
Expand Down Expand Up @@ -255,12 +253,6 @@ impl<P: Parameters> AffineCurve for Affine<P> {
}
}

impl<P: Parameters> ToMinimalBits for Affine<P> {
fn write_minimal_bits(&self, vec: &mut Vec<bool>) {
self.x.write_bits_le(vec);
}
}

impl<P: Parameters> Neg for Affine<P> {
type Output = Self;

Expand Down
3 changes: 1 addition & 2 deletions curves/src/traits/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use crate::{templates::short_weierstrass_jacobian, PairingEngine};
use snarkvm_fields::{Field, PrimeField, SquareRootField, Zero};
use snarkvm_utilities::{rand::Uniform, serialize::*, FromBytes, ToBytes, ToMinimalBits};
use snarkvm_utilities::{rand::Uniform, serialize::*, FromBytes, ToBytes};

use core::{
fmt::{Debug, Display},
Expand Down Expand Up @@ -136,7 +136,6 @@ pub trait AffineCurve:
+ DeserializeOwned
+ ToBytes
+ From<<Self as AffineCurve>::Projective>
+ ToMinimalBits
+ Zero
{
type Projective: ProjectiveCurve<Affine = Self, ScalarField = Self::ScalarField> + From<Self> + Into<Self>;
Expand Down
20 changes: 0 additions & 20 deletions utilities/src/bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,6 @@ pub trait FromBits: Sized {
fn from_bits_be(bits: &[bool]) -> Result<Self>;
}

pub trait ToMinimalBits: Sized {
/// Returns `self` as a minimal boolean array.
fn to_minimal_bits(&self) -> Vec<bool> {
let mut bits = vec![];
self.write_minimal_bits(&mut bits);
bits
}

/// Writes `self` as a minimal boolean array into the given vector.
fn write_minimal_bits(&self, vec: &mut Vec<bool>);
}

impl<T: ToMinimalBits> ToMinimalBits for Vec<T> {
fn write_minimal_bits(&self, vec: &mut Vec<bool>) {
for elem in self.iter() {
elem.write_minimal_bits(vec);
}
}
}

/********************/
/****** Tuples ******/
/********************/
Expand Down

0 comments on commit c55d6f8

Please sign in to comment.