Skip to content

Commit

Permalink
Minor changes to run midnight_circuits
Browse files Browse the repository at this point in the history
  • Loading branch information
iquerejeta committed Dec 27, 2024
1 parent e2d2525 commit a47d40c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ backtrace = { version = "0.3", optional = true }
ff = "0.13"
group = "0.13"
halo2curves = { version = "0.7.0", default-features = false }
blstrs = { git = "https://github.com/davidnevadoc/blstrs", rev = "8ca6da7" }
rand_core = { version = "0.6", default-features = false }
tracing = "0.1"
blake2b_simd = "1" # MSRV 1.66.0
Expand Down
7 changes: 7 additions & 0 deletions src/poly/kzg/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ impl<E: Engine> Params for ParamsKZG<E> {
}

impl<E: Engine + Debug> ParamsKZG<E> {
/// Downsize the current parameters to match a smaller `k`.
pub fn downsize(&mut self, new_k: u32) {
assert!(new_k < self.g_lagrange.len() as u32);
self.g.truncate(new_k as usize);
self.g_lagrange = g_to_lagrange(self.g.iter().map(|g| g.to_curve()).collect(), new_k);
}

/// Initializes parameters for the curve, draws toxic secret from given rng.
/// MUST NOT be used in production.
pub fn unsafe_setup<R: RngCore>(k: u32, rng: R) -> Self {
Expand Down
48 changes: 47 additions & 1 deletion src/transcript/implementors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::transcript::{
Hashable, Sampleable, TranscriptHash, BLAKE2B_PREFIX_CHALLENGE, BLAKE2B_PREFIX_COMMON,
};
use blake2b_simd::{Params, State as Blake2bState};
use ff::FromUniformBytes;
use ff::{FromUniformBytes, PrimeField};
use group::GroupEncoding;
use halo2curves::bn256::{Fr, G1Affine};

Expand Down Expand Up @@ -52,3 +52,49 @@ impl Sampleable<Blake2bState> for Fr {
Fr::from_uniform_bytes(&bytes)
}
}

//////////////////////////////////////////////////////////
/// Implementation of Hashable for BLS12-381 with Blake //
//////////////////////////////////////////////////////////

impl Hashable<Blake2bState> for blstrs::G1Affine {
fn to_input(&self) -> Vec<u8> {
self.to_bytes().as_ref().to_vec()
}
}

impl Hashable<Blake2bState> for blstrs::Scalar {
fn to_input(&self) -> Vec<u8> {
self.to_repr().to_vec()
}
}

impl Sampleable<Blake2bState> for blstrs::Scalar {
fn sample(out: Vec<u8>) -> Self {
assert!(out.len() <= 64);
let mut bytes = [0u8; 64];
bytes[..out.len()].copy_from_slice(&out);
blstrs::Scalar::from_uniform_bytes(&bytes)
}
}

impl Hashable<Blake2bState> for halo2curves::bls12381::G1Affine {
fn to_input(&self) -> Vec<u8> {
self.to_bytes().as_ref().to_vec()
}
}

impl Hashable<Blake2bState> for halo2curves::bls12381::Fr {
fn to_input(&self) -> Vec<u8> {
self.to_repr().as_ref().to_vec()
}
}

impl Sampleable<Blake2bState> for halo2curves::bls12381::Fr {
fn sample(out: Vec<u8>) -> Self {
assert!(out.len() <= 64);
let mut bytes = [0u8; 64];
bytes[..out.len()].copy_from_slice(&out);
halo2curves::bls12381::Fr::from_uniform_bytes(&bytes)
}
}

0 comments on commit a47d40c

Please sign in to comment.