Skip to content

Commit 89ec1a3

Browse files
authored
Tidy new curves (#26)
1 parent 5f28f81 commit 89ec1a3

File tree

20 files changed

+64
-797
lines changed

20 files changed

+64
-797
lines changed

curves/pallas/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ std = [
3232
"ark-serialize/std",
3333
"ark-std/std",
3434
]
35-
parallel = [ "ark-ec/parallel", "ark-ff/parallel", "ark-std/parallel" ]
35+
parallel = [
36+
"ark-ec/parallel",
37+
"ark-ff/parallel",
38+
"ark-std/parallel"
39+
]

curves/pallas/LICENSE-APACHE

Lines changed: 0 additions & 201 deletions
This file was deleted.

curves/pallas/LICENSE-MIT

Lines changed: 0 additions & 19 deletions
This file was deleted.

curves/pallas/src/curves/mod.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
use ark_ff::MontFp;
21
use ark_models_ext::{
32
models::CurveConfig,
43
short_weierstrass::{self, SWCurveConfig},
54
};
6-
use ark_pallas::PallasConfig as ArkConfig;
5+
use ark_pallas::{PallasConfig as ArkConfig, G_GENERATOR_X, G_GENERATOR_Y};
76
use ark_std::marker::PhantomData;
87

9-
/// G_GENERATOR_X = -1
10-
pub const G_GENERATOR_X: <ArkConfig as CurveConfig>::BaseField = MontFp!("-1");
11-
12-
/// G_GENERATOR_Y = 2
13-
pub const G_GENERATOR_Y: <ArkConfig as CurveConfig>::BaseField = MontFp!("2");
8+
#[cfg(test)]
9+
mod tests;
1410

1511
pub type Affine<H> = short_weierstrass::Affine<PallasConfig<H>>;
1612
pub type Projective<H> = short_weierstrass::Projective<PallasConfig<H>>;
@@ -21,16 +17,13 @@ pub struct PallasConfig<H: CurveHooks>(PhantomData<fn() -> H>);
2117
/// Hooks for *Pallas*.
2218
pub trait CurveHooks: 'static + Sized {
2319
/// Short Weierstrass multi scalar multiplication.
24-
fn pallas_msm(
20+
fn msm(
2521
bases: &[Affine<Self>],
2622
scalars: &[<PallasConfig<Self> as CurveConfig>::ScalarField],
27-
) -> Result<Projective<Self>, ()>;
23+
) -> Projective<Self>;
2824

2925
/// Short Weierstrass projective multiplication.
30-
fn pallas_mul_projective(
31-
base: &Projective<Self>,
32-
scalar: &[u64],
33-
) -> Result<Projective<Self>, ()>;
26+
fn mul_projective(base: &Projective<Self>, scalar: &[u64]) -> Projective<Self>;
3427
}
3528

3629
impl<H: CurveHooks> CurveConfig for PallasConfig<H> {
@@ -47,19 +40,18 @@ impl<H: CurveHooks> SWCurveConfig for PallasConfig<H> {
4740

4841
const GENERATOR: Affine<H> = Affine::<H>::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y);
4942

50-
/// Multi scalar multiplication jumping into the user-defined `pallas_msm` hook.
51-
///
52-
/// On any internal error returns `Err(0)`.
43+
/// Multi scalar multiplication jumping into the user-defined `msm` hook.
5344
#[inline(always)]
5445
fn msm(bases: &[Affine<H>], scalars: &[Self::ScalarField]) -> Result<Projective<H>, usize> {
55-
H::pallas_msm(bases, scalars).map_err(|_| 0)
46+
if bases.len() != scalars.len() {
47+
return Err(bases.len().min(scalars.len()));
48+
}
49+
Ok(H::msm(bases, scalars))
5650
}
5751

58-
/// Projective multiplication jumping into the user-defined `pallas_mul_projective` hook.
59-
///
60-
/// On any internal error returns `Projective::zero()`.
52+
/// Projective multiplication jumping into the user-defined `mul_projective` hook.
6153
#[inline(always)]
6254
fn mul_projective(base: &Projective<H>, scalar: &[u64]) -> Projective<H> {
63-
H::pallas_mul_projective(base, scalar).unwrap_or_default()
55+
H::mul_projective(base, scalar)
6456
}
6557
}

curves/pallas/src/curves/tests.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#[cfg(test)]
2-
mod tests;
3-
41
use crate::CurveHooks;
52

63
use ark_algebra_test_templates::*;
7-
use ark_pallas::PallasConfig as ArkConfig;
84
use ark_models_ext::CurveConfig;
5+
use ark_pallas::PallasConfig as ArkConfig;
96

107
pub struct TestHooks;
118

@@ -14,19 +11,13 @@ type Affine = crate::Affine<TestHooks>;
1411
type Projective = crate::Projective<TestHooks>;
1512

1613
impl CurveHooks for TestHooks {
17-
fn pallas_msm(
18-
bases: &[Affine],
19-
scalars: &[<Config as CurveConfig>::ScalarField],
20-
) -> Result<Projective, ()> {
14+
fn msm(bases: &[Affine], scalars: &[<Config as CurveConfig>::ScalarField]) -> Projective {
2115
test_utils::msm_sw_generic::<Config, ArkConfig>(bases, scalars)
2216
}
2317

24-
fn pallas_mul_projective(
25-
base: &Projective,
26-
scalar: &[u64],
27-
) -> Result<Projective, ()> {
18+
fn mul_projective(base: &Projective, scalar: &[u64]) -> Projective {
2819
test_utils::mul_projective_sw_generic::<Config, ArkConfig>(base, scalar)
2920
}
3021
}
3122

32-
test_group!(sw; SWProjective; sw);
23+
test_group!(sw; Projective; sw);

curves/pallas/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414
//! * Valuation(r - 1, 2) = 32
1515
1616
#![cfg_attr(not(feature = "std"), no_std)]
17-
#![deny(
18-
warnings,
19-
unused,
20-
future_incompatible,
21-
nonstandard_style,
22-
rust_2018_idioms,
23-
unsafe_code
24-
)]
25-
#![allow(clippy::result_unit_err)]
2617

2718
pub mod curves;
2819

curves/secp256k1/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ std = [
3232
"ark-serialize/std",
3333
"ark-std/std",
3434
]
35-
parallel = [ "ark-ec/parallel", "ark-ff/parallel", "ark-std/parallel" ]
35+
parallel = [
36+
"ark-ec/parallel",
37+
"ark-ff/parallel",
38+
"ark-std/parallel"
39+
]

0 commit comments

Comments
 (0)