Skip to content

Commit

Permalink
halo2/loader: require aux_generator to allow implementations to contr…
Browse files Browse the repository at this point in the history
…ol randomness
  • Loading branch information
pinkiebell committed Oct 14, 2022
1 parent f42c7c5 commit 8a2e7fb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/evm-verifier-with-accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ mod aggregation {
let ctx = RegionCtx::new(region, 0);

let ecc_chip = config.ecc_chip();
let loader = Halo2Loader::new(ecc_chip, ctx);
let loader = Halo2Loader::new(ecc_chip, ctx, G1Affine::random(OsRng));
let KzgAccumulator { lhs, rhs } =
aggregate(&self.svk, &loader, &self.snarks, self.as_proof());

Expand Down
10 changes: 5 additions & 5 deletions src/loader/halo2/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ use crate::{
EcPointLoader, LoadedEcPoint, LoadedScalar, Loader, ScalarLoader,
},
util::{
arithmetic::{Curve, CurveAffine, Field, FieldExt, FieldOps, Group},
arithmetic::{CurveAffine, Field, FieldExt, FieldOps},
Itertools,
},
};
use halo2_proofs::circuit::{self, Region};
use halo2_wrong_ecc::maingate::RegionCtx;
use rand::rngs::OsRng;
use std::{
cell::{Ref, RefCell},
collections::btree_map::{BTreeMap, Entry},
Expand All @@ -30,6 +29,7 @@ pub struct Halo2Loader<'a, C: CurveAffine, N: FieldExt, EccChip: EccInstructions
num_scalar: RefCell<usize>,
num_ec_point: RefCell<usize>,
const_ec_point: RefCell<BTreeMap<(C::Base, C::Base), EcPoint<'a, C, N, EccChip>>>,
aux_generator: C,
_marker: PhantomData<C>,
#[cfg(test)]
row_meterings: RefCell<Vec<(String, usize)>>,
Expand All @@ -38,13 +38,14 @@ pub struct Halo2Loader<'a, C: CurveAffine, N: FieldExt, EccChip: EccInstructions
impl<'a, C: CurveAffine, N: FieldExt, EccChip: EccInstructions<C, N>>
Halo2Loader<'a, C, N, EccChip>
{
pub fn new(ecc_chip: EccChip, ctx: RegionCtx<'a, N>) -> Rc<Self> {
pub fn new(ecc_chip: EccChip, ctx: RegionCtx<'a, N>, aux_generator: C) -> Rc<Self> {
Rc::new(Self {
ecc_chip: RefCell::new(ecc_chip),
ctx: RefCell::new(ctx),
num_scalar: RefCell::default(),
num_ec_point: RefCell::default(),
const_ec_point: RefCell::default(),
aux_generator,
#[cfg(test)]
row_meterings: RefCell::default(),
_marker: PhantomData,
Expand Down Expand Up @@ -522,13 +523,12 @@ impl<'a, C: CurveAffine, N: FieldExt, EccChip: EccInstructions<C, N>> LoadedEcPo
.chain(if scaled.is_empty() {
None
} else {
let aux_generator = C::CurveExt::random(OsRng).to_affine();
loader
.ecc_chip
.borrow_mut()
.assign_aux_generator(
&mut loader.ctx.borrow_mut(),
circuit::Value::known(aux_generator),
circuit::Value::known(loader.aux_generator),
)
.unwrap();
loader
Expand Down
3 changes: 2 additions & 1 deletion src/system/halo2/test/kzg/halo2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use halo2_wrong_ecc::{
};
use halo2_wrong_transcript::NativeRepresentation;
use paste::paste;
use rand::rngs::OsRng;
use rand_chacha::{rand_core::SeedableRng, ChaCha20Rng};
use std::{iter, rc::Rc};

Expand Down Expand Up @@ -299,7 +300,7 @@ impl Circuit<Fr> for Accumulation {
let ctx = RegionCtx::new(region, 0);

let ecc_chip = config.ecc_chip();
let loader = Halo2Loader::new(ecc_chip, ctx);
let loader = Halo2Loader::new(ecc_chip, ctx, G1Affine::random(OsRng));
let KzgAccumulator { lhs, rhs } = accumulate(
&self.svk,
&loader,
Expand Down

0 comments on commit 8a2e7fb

Please sign in to comment.