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

[dev-dependencies]
Expand Down
8 changes: 6 additions & 2 deletions ecc/src/base_field_ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,9 @@ mod tests {
use crate::integer::rns::Rns;
use crate::integer::NUMBER_OF_LOOKUP_LIMBS;
use crate::maingate;
use group::ff::PrimeField;
use group::{Curve as _, Group};
use halo2::arithmetic::{CurveAffine, FieldExt};
use halo2::arithmetic::CurveAffine;
use halo2::circuit::{Layouter, SimpleFloorPlanner, Value};
use halo2::plonk::{Circuit, ConstraintSystem, Error};
use integer::maingate::RegionCtx;
Expand Down Expand Up @@ -419,7 +420,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 Down
47 changes: 26 additions & 21 deletions ecc/src/ecc.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::halo2::arithmetic::{CurveAffine, FieldExt};
use crate::halo2::arithmetic::CurveAffine;
use crate::integer::chip::IntegerConfig;
use crate::integer::rns::{Integer, Rns};
use crate::integer::AssignedInteger;
use crate::maingate::{big_to_fe, Assigned, AssignedCondition, MainGateConfig, RangeConfig};
use crate::FieldExt;
use crate::PrimeField;
use group::ff::PrimeField;
use group::Curve;
use num_bigint::BigUint as big_uint;
use num_traits::One;
Expand All @@ -12,13 +13,17 @@ use std::rc::Rc;

/// Represent a Point in affine coordinates
#[derive(Clone, Debug)]
pub struct Point<W: FieldExt, N: FieldExt, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize>
{
pub struct Point<
W: PrimeField,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
> {
x: Integer<W, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>,
y: Integer<W, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>,
}

impl<W: FieldExt, N: FieldExt, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize>
impl<W: PrimeField, N: PrimeField, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize>
Point<W, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
{
/// Returns `Point` form a point in a EC with W as its base field
Expand Down Expand Up @@ -58,17 +63,17 @@ impl<W: FieldExt, N: FieldExt, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB:
#[derive(Clone)]
/// point that is assumed to be on curve and not infinity
pub struct AssignedPoint<
W: FieldExt,
N: FieldExt,
W: PrimeField,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
> {
pub(crate) x: AssignedInteger<W, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>,
pub(crate) y: AssignedInteger<W, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>,
}

impl<W: FieldExt, N: FieldExt, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize> fmt::Debug
for AssignedPoint<W, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
impl<W: PrimeField, N: PrimeField, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize>
fmt::Debug for AssignedPoint<W, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("AssignedPoint")
Expand All @@ -79,7 +84,7 @@ impl<W: FieldExt, N: FieldExt, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB:
}
}

impl<W: FieldExt, N: FieldExt, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize>
impl<W: PrimeField, N: PrimeField, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize>
AssignedPoint<W, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
{
/// Returns a new `AssignedPoint` given its coordinates as `AssignedInteger`
Expand Down Expand Up @@ -166,9 +171,9 @@ pub(crate) fn make_mul_aux<C: CurveAffine>(
/// Allows to select values of precomputed table in efficient multiplication
/// algorithm
#[derive(Default)]
pub(crate) struct Selector<F: FieldExt>(Vec<AssignedCondition<F>>);
pub(crate) struct Selector<F: PrimeField>(Vec<AssignedCondition<F>>);

impl<F: FieldExt> fmt::Debug for Selector<F> {
impl<F: PrimeField> fmt::Debug for Selector<F> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut debug = f.debug_struct("Selector");
for (i, bit) in self.0.iter().enumerate() {
Expand All @@ -181,9 +186,9 @@ impl<F: FieldExt> fmt::Debug for Selector<F> {

/// Vector of `Selectors` which represent the binary representation of a scalar
/// split in window sized selectors.
pub(crate) struct Windowed<F: FieldExt>(Vec<Selector<F>>);
pub(crate) struct Windowed<F: PrimeField>(Vec<Selector<F>>);

impl<F: FieldExt> fmt::Debug for Windowed<F> {
impl<F: PrimeField> fmt::Debug for Windowed<F> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut debug = f.debug_struct("Window");
for (i, selector) in self.0.iter().enumerate() {
Expand All @@ -198,14 +203,14 @@ impl<F: FieldExt> fmt::Debug for Windowed<F> {

/// Table of precomputed values for efficient multiplication algorithm.
pub(crate) struct Table<
W: FieldExt,
N: FieldExt,
W: PrimeField,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
>(pub(crate) Vec<AssignedPoint<W, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>>);

impl<W: FieldExt, N: FieldExt, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize> fmt::Debug
for Table<W, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
impl<W: PrimeField, N: PrimeField, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize>
fmt::Debug for Table<W, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut debug = f.debug_struct("Table");
Expand All @@ -223,8 +228,8 @@ impl<W: FieldExt, N: FieldExt, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB:
/// Auxiliary points for efficient multiplication algorithm
/// See: https://hackmd.io/ncuKqRXzR-Cw-Au2fGzsMg
pub(super) struct MulAux<
W: FieldExt,
N: FieldExt,
W: PrimeField,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
> {
Expand All @@ -233,7 +238,7 @@ pub(super) struct MulAux<
}

/// Constructs `MulAux`
impl<W: FieldExt, N: FieldExt, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize>
impl<W: PrimeField, N: PrimeField, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize>
MulAux<W, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
{
pub(super) fn new(
Expand Down
66 changes: 43 additions & 23 deletions ecc/src/general_ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::halo2;
use crate::integer::rns::{Integer, Rns};
use crate::integer::{IntegerChip, IntegerInstructions, Range, UnassignedInteger};
use crate::maingate;
use halo2::arithmetic::{CurveAffine, FieldExt};
use group::ff::PrimeField;
use halo2::arithmetic::CurveAffine;
use halo2::circuit::{Layouter, Value};
use halo2::plonk::Error;
use integer::maingate::RegionCtx;
Expand All @@ -20,7 +21,7 @@ mod mul;
#[allow(clippy::type_complexity)]
pub struct GeneralEccChip<
Emulated: CurveAffine,
N: FieldExt,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
> {
Expand All @@ -41,7 +42,7 @@ pub struct GeneralEccChip<

impl<
Emulated: CurveAffine,
N: FieldExt,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
> GeneralEccChip<Emulated, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
Expand Down Expand Up @@ -158,7 +159,7 @@ impl<

impl<
Emulated: CurveAffine,
N: FieldExt,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
> GeneralEccChip<Emulated, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
Expand Down Expand Up @@ -401,7 +402,7 @@ mod tests {
use crate::integer::{AssignedInteger, IntegerInstructions};
use crate::maingate;
use group::{prime::PrimeCurveAffine, Curve as _, Group};
use halo2::arithmetic::{CurveAffine, FieldExt};
use halo2::arithmetic::{CurveAffine, PrimeField};
use halo2::circuit::{Layouter, SimpleFloorPlanner, Value};
use halo2::plonk::{Circuit, ConstraintSystem, Error};
use integer::rns::Integer;
Expand All @@ -425,7 +426,7 @@ mod tests {
#[allow(clippy::type_complexity)]
fn setup<
C: CurveAffine,
N: FieldExt,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
>(
Expand Down Expand Up @@ -462,7 +463,7 @@ mod tests {
impl TestCircuitConfig {
fn new<
C: CurveAffine,
N: FieldExt,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
>(
Expand Down Expand Up @@ -490,7 +491,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 @@ -501,15 +505,19 @@ mod tests {
#[derive(Clone, Debug, Default)]
struct TestEccAddition<
C: CurveAffine,
N: FieldExt,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
> {
_marker: PhantomData<(C, N)>,
}

impl<C: CurveAffine, N: FieldExt, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize>
Circuit<N> for TestEccAddition<C, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
impl<
C: CurveAffine,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
> Circuit<N> for TestEccAddition<C, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
{
type Config = TestCircuitConfig;
type FloorPlanner = SimpleFloorPlanner;
Expand Down Expand Up @@ -585,7 +593,7 @@ mod tests {
fn test_general_ecc_addition_circuit() {
fn run<
C: CurveAffine,
N: FieldExt,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
>() {
Expand Down Expand Up @@ -614,7 +622,7 @@ mod tests {
#[derive(Default, Clone, Debug)]
struct TestEccPublicInput<
C: CurveAffine,
N: FieldExt,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
> {
Expand All @@ -623,8 +631,12 @@ mod tests {
_marker: PhantomData<N>,
}

impl<C: CurveAffine, N: FieldExt, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize>
Circuit<N> for TestEccPublicInput<C, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
impl<
C: CurveAffine,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
> Circuit<N> for TestEccPublicInput<C, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
{
type Config = TestCircuitConfig;
type FloorPlanner = SimpleFloorPlanner;
Expand Down Expand Up @@ -686,7 +698,7 @@ mod tests {
fn test_general_ecc_public_input() {
fn run<
C: CurveAffine,
N: FieldExt,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
>() {
Expand Down Expand Up @@ -731,7 +743,7 @@ mod tests {
#[derive(Default, Clone, Debug)]
struct TestEccMul<
C: CurveAffine,
N: FieldExt,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
> {
Expand All @@ -740,8 +752,12 @@ mod tests {
_marker: PhantomData<N>,
}

impl<C: CurveAffine, N: FieldExt, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize>
Circuit<N> for TestEccMul<C, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
impl<
C: CurveAffine,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
> Circuit<N> for TestEccMul<C, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
{
type Config = TestCircuitConfig;
type FloorPlanner = SimpleFloorPlanner;
Expand Down Expand Up @@ -814,7 +830,7 @@ mod tests {
fn test_general_ecc_mul_circuit() {
fn run<
C: CurveAffine,
N: FieldExt,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
>() {
Expand Down Expand Up @@ -851,7 +867,7 @@ mod tests {
#[derive(Default, Clone, Debug)]
struct TestEccBatchMul<
C: CurveAffine,
N: FieldExt,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
> {
Expand All @@ -861,8 +877,12 @@ mod tests {
_marker: PhantomData<N>,
}

impl<C: CurveAffine, N: FieldExt, const NUMBER_OF_LIMBS: usize, const BIT_LEN_LIMB: usize>
Circuit<N> for TestEccBatchMul<C, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
impl<
C: CurveAffine,
N: PrimeField,
const NUMBER_OF_LIMBS: usize,
const BIT_LEN_LIMB: usize,
> Circuit<N> for TestEccBatchMul<C, N, NUMBER_OF_LIMBS, BIT_LEN_LIMB>
{
type Config = TestCircuitConfig;
type FloorPlanner = SimpleFloorPlanner;
Expand Down
Loading