From 8ae96d6fd8555c4f0885a651dba1ea0e1985a627 Mon Sep 17 00:00:00 2001 From: Jonathan Wang <31040440+jonathanpwang@users.noreply.github.com> Date: Mon, 14 Aug 2023 12:35:19 -0700 Subject: [PATCH] chore: fixes --- halo2-base/src/gates/builder/mod.rs | 32 +++++++++++++++++++++++++++++ halo2-base/src/utils/mod.rs | 9 +++++--- halo2-ecc/src/fields/fp.rs | 2 +- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/halo2-base/src/gates/builder/mod.rs b/halo2-base/src/gates/builder/mod.rs index 61adb301..ab2864ea 100644 --- a/halo2-base/src/gates/builder/mod.rs +++ b/halo2-base/src/gates/builder/mod.rs @@ -593,6 +593,24 @@ impl GateCircuitBuilder { pub struct RangeCircuitBuilder(pub GateCircuitBuilder); impl RangeCircuitBuilder { + /// Convenience function to create a new [RangeCircuitBuilder] with a given [CircuitBuilderStage]. + pub fn from_stage( + stage: CircuitBuilderStage, + builder: GateThreadBuilder, + config_params: BaseConfigParams, + break_points: Option, + ) -> 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, config_params: BaseConfigParams) -> Self { Self(GateCircuitBuilder::keygen(builder, config_params)) @@ -678,6 +696,20 @@ pub struct RangeWithInstanceCircuitBuilder { } impl RangeWithInstanceCircuitBuilder { + /// Convenience function to create a new [RangeWithInstanceCircuitBuilder] with a given [CircuitBuilderStage]. + pub fn from_stage( + stage: CircuitBuilderStage, + builder: GateThreadBuilder, + config_params: BaseConfigParams, + break_points: Option, + assigned_instances: Vec>, + ) -> Self { + Self { + circuit: RangeCircuitBuilder::from_stage(stage, builder, config_params, break_points), + assigned_instances, + } + } + /// See [`RangeCircuitBuilder::keygen`] pub fn keygen( builder: GateThreadBuilder, diff --git a/halo2-base/src/utils/mod.rs b/halo2-base/src/utils/mod.rs index 66f91166..54c88491 100644 --- a/halo2-base/src/utils/mod.rs +++ b/halo2-base/src/utils/mod.rs @@ -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::*; @@ -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); @@ -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); diff --git a/halo2-ecc/src/fields/fp.rs b/halo2-ecc/src/fields/fp.rs index f7022eb9..c26d8cc6 100644 --- a/halo2-ecc/src/fields/fp.rs +++ b/halo2-ecc/src/fields/fp.rs @@ -45,7 +45,7 @@ impl From, Fp>> for ProperCrtUint {