Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update to halo2-lib new types #10

Merged
merged 1 commit into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions snark-verifier-sdk/src/halo2/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,12 @@ impl AggregationCircuit {
let lhs = accumulator.lhs.assigned();
let rhs = accumulator.rhs.assigned();
let assigned_instances = lhs
.x
.truncation
.limbs
.x()
.limbs()
.iter()
.chain(lhs.y.truncation.limbs.iter())
.chain(rhs.x.truncation.limbs.iter())
.chain(rhs.y.truncation.limbs.iter())
.chain(lhs.y().limbs().iter())
.chain(rhs.x().limbs().iter())
.chain(rhs.y().limbs().iter())
.copied()
.collect_vec();

Expand Down
11 changes: 5 additions & 6 deletions snark-verifier/examples/evm-verifier-with-accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,12 @@ mod aggregation {
let lhs = lhs.assigned();
let rhs = rhs.assigned();
let assigned_instances = lhs
.x
.truncation
.limbs
.x()
.limbs()
.iter()
.chain(lhs.y.truncation.limbs.iter())
.chain(rhs.x.truncation.limbs.iter())
.chain(rhs.y.truncation.limbs.iter())
.chain(lhs.y().limbs().iter())
.chain(rhs.x().limbs().iter())
.chain(rhs.y().limbs().iter())
.copied()
.collect_vec();

Expand Down
17 changes: 9 additions & 8 deletions snark-verifier/examples/recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ mod recursion {
},
AssignedValue,
};
use halo2_ecc::bn254::FpChip;
use halo2_ecc::{bn254::FpChip, ecc::EcPoint};
use halo2_proofs::plonk::{Column, Instance};
use snark_verifier::loader::halo2::{EccInstructions, IntegerInstructions};

Expand Down Expand Up @@ -410,7 +410,12 @@ mod recursion {
.iter()
.zip([rhs.lhs.assigned(), rhs.rhs.assigned()].iter())
.map(|(lhs, rhs)| {
loader.ecc_chip().select(loader.ctx_mut().main(0), lhs, rhs, *condition)
loader.ecc_chip().select(
loader.ctx_mut().main(0),
EcPoint::clone(&lhs),
EcPoint::clone(&rhs),
*condition,
)
})
.collect::<Vec<_>>()
.try_into()
Expand Down Expand Up @@ -566,12 +571,8 @@ mod recursion {
let loader = Halo2Loader::new(ecc_chip, builder);
let (mut app_instances, app_accumulators) =
succinct_verify(&self.svk, &loader, &self.app, None);
let (mut previous_instances, previous_accumulators) = succinct_verify(
&self.svk,
&loader,
&self.previous,
Some(preprocessed_digest),
);
let (mut previous_instances, previous_accumulators) =
succinct_verify(&self.svk, &loader, &self.previous, Some(preprocessed_digest));

let default_accmulator = self.load_default_accumulator(&loader).unwrap();
let previous_accumulators = previous_accumulators
Expand Down
29 changes: 12 additions & 17 deletions snark-verifier/src/loader/halo2/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,22 @@ mod halo2_lib {
use crate::halo2_proofs::halo2curves::CurveAffineExt;
use crate::{
loader::halo2::{EccInstructions, IntegerInstructions},
util::arithmetic::{CurveAffine, Field},
util::arithmetic::CurveAffine,
};
use halo2_base::{
self,
gates::{builder::GateThreadBuilder, GateChip, GateInstructions, RangeInstructions},
AssignedValue,
QuantumCell::{Constant, Existing},
};
use halo2_ecc::bigint::ProperCrtUint;
use halo2_ecc::{
bigint::CRTInteger,
ecc::{fixed_base::FixedEcPoint, BaseFieldEccChip, EcPoint},
ecc::{BaseFieldEccChip, EcPoint},
fields::{FieldChip, PrimeField},
};
use std::ops::Deref;

type AssignedInteger<C> = CRTInteger<<C as CurveAffine>::ScalarExt>;
type AssignedInteger<C> = ProperCrtUint<<C as CurveAffine>::ScalarExt>;
type AssignedEcPoint<C> = EcPoint<<C as CurveAffine>::ScalarExt, AssignedInteger<C>>;

impl<F: PrimeField> IntegerInstructions<F> for GateChip<F> {
Expand Down Expand Up @@ -250,19 +250,11 @@ mod halo2_lib {
}

fn assign_constant(&self, ctx: &mut Self::Context, point: C) -> Self::AssignedEcPoint {
let fixed = FixedEcPoint::<C::Scalar, C>::from_curve(
point,
self.field_chip.num_limbs,
self.field_chip.limb_bits,
);
FixedEcPoint::assign(fixed, self.field_chip(), ctx.main(0))
self.assign_constant_point(ctx.main(0), point)
}

fn assign_point(&self, ctx: &mut Self::Context, point: C) -> Self::AssignedEcPoint {
let assigned = self.assign_point(ctx.main(0), point);
let is_valid = self.is_on_curve_or_infinity::<C>(ctx.main(0), &assigned);
self.field_chip().gate().assert_is_const(ctx.main(0), &is_valid, &C::Scalar::one());
assigned
self.assign_point(ctx.main(0), point)
}

fn sum_with_const(
Expand All @@ -274,10 +266,13 @@ mod halo2_lib {
let constant = if bool::from(constant.is_identity()) {
None
} else {
let constant = EccInstructions::<C>::assign_constant(self, ctx, constant);
let constant = EccInstructions::assign_constant(self, ctx, constant);
Some(constant)
};
self.sum::<C>(ctx.main(0), constant.iter().chain(values.iter().map(Deref::deref)))
self.sum::<C>(
ctx.main(0),
constant.into_iter().chain(values.iter().map(|v| v.deref().clone())),
)
}

fn variable_base_msm(
Expand Down Expand Up @@ -331,7 +326,7 @@ mod halo2_lib {
a: &Self::AssignedEcPoint,
b: &Self::AssignedEcPoint,
) {
self.assert_equal(ctx.main(0), a, b);
self.assert_equal(ctx.main(0), a.clone(), b.clone());
}
}
}