Skip to content

Commit

Permalink
chore: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpwang committed Aug 14, 2023
1 parent 9a93f73 commit 8ae96d6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
32 changes: 32 additions & 0 deletions halo2-base/src/gates/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,24 @@ impl<F: ScalarField> GateCircuitBuilder<F> {
pub struct RangeCircuitBuilder<F: ScalarField>(pub GateCircuitBuilder<F>);

impl<F: ScalarField> RangeCircuitBuilder<F> {
/// Convenience function to create a new [RangeCircuitBuilder] with a given [CircuitBuilderStage].
pub fn from_stage(
stage: CircuitBuilderStage,
builder: GateThreadBuilder<F>,
config_params: BaseConfigParams,
break_points: Option<MultiPhaseThreadBreakPoints>,
) -> Self {
match stage {
CircuitBuilderStage::Keygen => Self::keygen(builder, config_params),
CircuitBuilderStage::Mock => Self::mock(builder, config_params),
CircuitBuilderStage::Prover => Self::prover(
builder,
config_params,
break_points.expect("break points must be pre-calculated for prover"),
),
}
}

/// Creates an instance of the [RangeCircuitBuilder] and executes in keygen mode.
pub fn keygen(builder: GateThreadBuilder<F>, config_params: BaseConfigParams) -> Self {
Self(GateCircuitBuilder::keygen(builder, config_params))
Expand Down Expand Up @@ -678,6 +696,20 @@ pub struct RangeWithInstanceCircuitBuilder<F: ScalarField> {
}

impl<F: ScalarField> RangeWithInstanceCircuitBuilder<F> {
/// Convenience function to create a new [RangeWithInstanceCircuitBuilder] with a given [CircuitBuilderStage].
pub fn from_stage(
stage: CircuitBuilderStage,
builder: GateThreadBuilder<F>,
config_params: BaseConfigParams,
break_points: Option<MultiPhaseThreadBreakPoints>,
assigned_instances: Vec<AssignedValue<F>>,
) -> Self {
Self {
circuit: RangeCircuitBuilder::from_stage(stage, builder, config_params, break_points),
assigned_instances,
}
}

/// See [`RangeCircuitBuilder::keygen`]
pub fn keygen(
builder: GateThreadBuilder<F>,
Expand Down
9 changes: 6 additions & 3 deletions halo2-base/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,10 @@ pub mod fs {
mod tests {
use crate::halo2_proofs::halo2curves::bn256::Fr;
use num_bigint::RandomBits;
use rand::{rngs::OsRng, Rng};
use rand::{
rngs::{OsRng, StdRng},
Rng, SeedableRng,
};
use std::ops::Shl;

use super::*;
Expand Down Expand Up @@ -596,7 +599,7 @@ mod tests {

#[test]
fn test_get_lower_32() {
let mut rng = OsRng;
let mut rng = StdRng::seed_from_u64(0);
for _ in 0..10_000usize {
let e: u32 = rng.gen_range(0..u32::MAX);
assert_eq!(Fr::from(e as u64).get_lower_32(), e);
Expand All @@ -606,7 +609,7 @@ mod tests {

#[test]
fn test_get_lower_64() {
let mut rng = OsRng;
let mut rng = StdRng::seed_from_u64(0);
for _ in 0..10_000usize {
let e: u64 = rng.gen_range(0..u64::MAX);
assert_eq!(Fr::from(e).get_lower_64(), e);
Expand Down
2 changes: 1 addition & 1 deletion halo2-ecc/src/fields/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<F: ScalarField, Fp> From<Reduced<ProperCrtUint<F>, Fp>> for ProperCrtUint<F
}
}

// `Fp` always needs to be `BigBigPrimeField`, we may later want support for `F` being just `ScalarField` but for optimization reasons we'll assume it's also `BigBigPrimeField` for now
// `Fp` always needs to be `BigPrimeField`, we may later want support for `F` being just `ScalarField` but for optimization reasons we'll assume it's also `BigPrimeField` for now

#[derive(Clone, Debug)]
pub struct FpChip<'range, F: BigPrimeField, Fp: BigPrimeField> {
Expand Down

0 comments on commit 8ae96d6

Please sign in to comment.