Skip to content
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
5 changes: 4 additions & 1 deletion ecc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ num-bigint = { version = "0.4", features = ["rand"] }
num-integer = "0.1"
num-traits = "0.2"
rand = "0.8"
group = "0.12"
subtle = { version = "2.3", default-features = false }

[dev-dependencies]
rand_core = { version = "0.6", default-features = false }
paste = "1.0.7"

[features]
default = []
circuit-params = ["integer/circuit-params"]
37 changes: 29 additions & 8 deletions ecc/src/base_field_ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,12 @@ mod tests {
use crate::integer::rns::Rns;
use crate::integer::NUMBER_OF_LOOKUP_LIMBS;
use crate::maingate;
use group::{Curve as _, Group};
use halo2::arithmetic::{CurveAffine, FieldExt};
use halo2::arithmetic::CurveAffine;
use halo2::circuit::{Layouter, SimpleFloorPlanner, Value};
use halo2::halo2curves::{
ff::{Field, FromUniformBytes, PrimeField},
group::{Curve as _, Group},
};
use halo2::plonk::{Circuit, ConstraintSystem, Error};
use integer::maingate::RegionCtx;
use maingate::mock_prover_verify;
Expand Down Expand Up @@ -419,7 +422,10 @@ mod tests {
}
}

fn config_range<N: FieldExt>(&self, layouter: &mut impl Layouter<N>) -> Result<(), Error> {
fn config_range<N: PrimeField>(
&self,
layouter: &mut impl Layouter<N>,
) -> Result<(), Error> {
let range_chip = RangeChip::<N>::new(self.range_config.clone());
range_chip.load_table(layouter)?;

Expand All @@ -435,6 +441,8 @@ mod tests {
impl<C: CurveAffine> Circuit<C::Scalar> for TestEccAddition<C> {
type Config = TestCircuitConfig;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
unimplemented!();
Expand Down Expand Up @@ -505,7 +513,10 @@ mod tests {

#[test]
fn test_base_field_ecc_addition_circuit() {
fn run<C: CurveAffine>() {
fn run<C: CurveAffine>()
where
C::Scalar: FromUniformBytes<64>,
{
let circuit = TestEccAddition::<C>::default();
let instance = vec![vec![]];
mock_prover_verify(&circuit, instance);
Expand All @@ -524,6 +535,8 @@ mod tests {
impl<C: CurveAffine> Circuit<C::Scalar> for TestEccPublicInput<C> {
type Config = TestCircuitConfig;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
unimplemented!();
Expand Down Expand Up @@ -580,7 +593,10 @@ mod tests {

#[test]
fn test_base_field_ecc_public_input() {
fn run<C: CurveAffine>() {
fn run<C: CurveAffine>()
where
C::Scalar: FromUniformBytes<64>,
{
let (rns, _) = setup::<C>(20);
let rns = Rc::new(rns);

Expand Down Expand Up @@ -616,6 +632,8 @@ mod tests {
impl<C: CurveAffine> Circuit<C::Scalar> for TestEccMul<C> {
type Config = TestCircuitConfig;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
unimplemented!();
Expand Down Expand Up @@ -650,7 +668,6 @@ mod tests {
layouter.assign_region(
|| "region 0",
|region| {
use group::ff::Field;
let offset = 0;
let ctx = &mut RegionCtx::new(region, offset);

Expand All @@ -677,7 +694,10 @@ mod tests {

#[test]
fn test_base_field_ecc_mul_circuit() {
fn run<C: CurveAffine>() {
fn run<C: CurveAffine>()
where
C::Scalar: FromUniformBytes<64>,
{
for window_size in 1..5 {
let aux_generator = <C as CurveAffine>::CurveExt::random(OsRng).to_affine();

Expand All @@ -704,6 +724,8 @@ mod tests {
impl<C: CurveAffine> Circuit<C::Scalar> for TestEccBatchMul<C> {
type Config = TestCircuitConfig;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
unimplemented!();
Expand Down Expand Up @@ -739,7 +761,6 @@ mod tests {
layouter.assign_region(
|| "region 0",
|region| {
use group::ff::Field;
let offset = 0;
let ctx = &mut RegionCtx::new(region, offset);

Expand Down
5 changes: 2 additions & 3 deletions ecc/src/base_field_ecc/mul.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::{AssignedPoint, BaseFieldEccChip};
use crate::maingate::{AssignedCondition, AssignedValue, MainGateInstructions};
use crate::{halo2, Selector, Table, Windowed};
use group::ff::PrimeField;
use halo2::arithmetic::CurveAffine;
use halo2::halo2curves::ff::{Field, PrimeField};
use halo2::plonk::Error;
use integer::maingate::RegionCtx;

Expand All @@ -16,14 +16,13 @@ impl<C: CurveAffine, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize>
bits: &mut Vec<AssignedCondition<C::Scalar>>,
window_size: usize,
) -> Result<(), Error> {
use group::ff::Field;
assert_eq!(bits.len(), C::Scalar::NUM_BITS as usize);

// TODO: This is a tmp workaround. Instead of padding with zeros we can use a
// shorter ending window.
let padding_offset = (window_size - (bits.len() % window_size)) % window_size;
let zeros: Vec<AssignedCondition<C::Scalar>> = (0..padding_offset)
.map(|_| self.main_gate().assign_constant(ctx, C::Scalar::zero()))
.map(|_| self.main_gate().assign_constant(ctx, C::Scalar::ZERO))
.collect::<Result<_, Error>>()?;
bits.extend(zeros);
bits.reverse();
Expand Down
Loading