Skip to content

Commit

Permalink
Merge pull request #1 from noir-lang/tf/fix-warnings
Browse files Browse the repository at this point in the history
chore: add explicit numeric generics
  • Loading branch information
TomAFrench authored Aug 29, 2024
2 parents 2002c95 + 4329ca2 commit 5652f43
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

env:
CARGO_TERM_COLOR: always
NARGO_VERSION: 0.31.0
NARGO_VERSION: 0.32.0

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
name = "edwards"
type = "lib"
authors = [""]
compiler_version = ">=0.31.0"
compiler_version = ">=0.32.0"

[dependencies]
8 changes: 4 additions & 4 deletions src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ trait CurveTrait<Params> where CurveTrait<Params>: std::ops::Add + std::ops::Sub
fn sub(self, x: Self) -> Self { self - x }
fn neg(self) -> Self { std::ops::Neg::neg(self) }
fn dbl(self) -> Self;
fn mul<NScalarSlices>(self, x: ScalarField<NScalarSlices>) -> Self;
fn msm<N, NScalarSlices> (points: [Self; N], scalars: [ScalarField<NScalarSlices>; N]) -> Self;
fn mul<let NScalarSlices: u32>(self, x: ScalarField<NScalarSlices>) -> Self;
fn msm<let N: u32, let NScalarSlices: u32> (points: [Self; N], scalars: [ScalarField<NScalarSlices>; N]) -> Self;

fn eq(self, x: Self) -> bool { self == x }
fn is_zero(self) -> bool { self == Self::zero() }
Expand Down Expand Up @@ -222,7 +222,7 @@ impl<Params> CurveTrait<Params> for Curve<Params> where Params: TECurveParameter
*
* TODO: use windowed non-adjacent form to remove 7 point additions when creating lookup table
**/
fn mul<NScalarSlices>(self: Self, scalar: ScalarField<NScalarSlices>) -> Self {
fn mul<let NScalarSlices: u32>(self: Self, scalar: ScalarField<NScalarSlices>) -> Self {
// define a, d params locally to make code more readable (shouldn't affect performance)
let a = Params::a();
let d = Params::d();
Expand Down Expand Up @@ -277,7 +277,7 @@ impl<Params> CurveTrait<Params> for Curve<Params> where Params: TECurveParameter
*
* TODO: use windowed non-adjacent form to remove 7 point additions per point when creating lookup table
**/
fn msm<N, NScalarSlices> (points: [Self; N], scalars: [ScalarField<NScalarSlices>; N]) -> Self
fn msm<let N: u32, let NScalarSlices: u32> (points: [Self; N], scalars: [ScalarField<NScalarSlices>; N]) -> Self
{
let a = Params::a();
let d = Params::d();
Expand Down
12 changes: 6 additions & 6 deletions src/scalar_field.nr
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
* N.B. ScalarField bit values are not constrained to be smaller than the TE curve group order.
* ScalarField is used when performing scalar multiplications, where all operations wrap modulo the curve order
**/
struct ScalarField<N> {
struct ScalarField<let N: u32> {
base4_slices: [u8; N],
skew: bool
}

unconstrained fn get_wnaf_slices<N>(x: Field) -> ([u8; N], bool) {
unconstrained fn get_wnaf_slices<let N: u32>(x: Field) -> ([u8; N], bool) {

let mut result: [u8; N] = [0; N];
let mut nibbles = x.to_le_radix(16, N);
Expand Down Expand Up @@ -76,7 +76,7 @@ unconstrained fn get_modulus_slices() -> (Field, Field) {
unconstrained fn get_borrow_flag(lhs_lo: Field, rhs_lo: Field) -> bool {
lhs_lo.lt(rhs_lo + 1)
}
impl<N> std::convert::From<Field> for ScalarField<N> {
impl<let N: u32> std::convert::From<Field> for ScalarField<N> {



Expand Down Expand Up @@ -124,7 +124,7 @@ impl<N> std::convert::From<Field> for ScalarField<N> {
let rlo = plo - lo + borrow * borrow_shift - 1; // -1 because we are checking a strict <, not <=
let rhi = phi - hi - borrow;
let offset = (N & 1 == 1) as u8;
let hibits = (N / 2) * 4;
let hibits = (N as u8 / 2) * 4;
let lobits = hibits + offset * 4;
rlo.assert_max_bit_size(lobits as u32);
rhi.assert_max_bit_size(hibits as u32);
Expand All @@ -136,7 +136,7 @@ impl<N> std::convert::From<Field> for ScalarField<N> {
}
}

impl<N> std::convert::Into<Field> for ScalarField<N> {
impl<let N: u32> std::convert::Into<Field> for ScalarField<N> {
/**
* @brief construct from tuple of field elements
* @details use this method instead of `new` if you know x/y is on the curve
Expand All @@ -152,7 +152,7 @@ impl<N> std::convert::Into<Field> for ScalarField<N> {
}
}

impl<N> ScalarField<N> {
impl<let N: u32> ScalarField<N> {

fn new() -> Self {
Self { base4_slices: [0; N], skew: false }
Expand Down

0 comments on commit 5652f43

Please sign in to comment.