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!: bump bignum to v0.5.0 #30

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
29 changes: 25 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,41 @@ name: Noir tests

on:
push:
branches:
- main
branches:
- main
pull_request:

env:
CARGO_TERM_COLOR: always
MINIMUM_NOIR_VERSION: v1.0.0-beta.0

jobs:
noir-version-list:
name: Query supported Noir versions
runs-on: ubuntu-latest
outputs:
noir_versions: ${{ steps.get_versions.outputs.versions }}
steps:
- name: Checkout sources
id: get_versions
run: |
# gh returns the Noir releases in reverse chronological order so we keep all releases published after the minimum supported version.
VERSIONS=$(gh release list -R noir-lang/noir --exclude-pre-releases --json tagName -q 'map(.tagName) | index(env.MINIMUM_NOIR_VERSION) as $index | if $index then .[0:$index+1] else [env.MINIMUM_NOIR_VERSION] end')
echo "versions=$VERSIONS"
echo "versions=$VERSIONS" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ github.token }}

test:
needs: [noir-version-list]
name: Test on Nargo ${{matrix.toolchain}}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
toolchain: [nightly, 0.37.0]
toolchain: ${{ fromJson( needs.noir-version-list.outputs.noir_versions )}}
include:
- toolchain: nightly
steps:
- name: Checkout sources
uses: actions/checkout@v4
Expand All @@ -40,11 +60,12 @@ jobs:
- name: Install Nargo
uses: noir-lang/[email protected]
with:
toolchain: 0.37.0
toolchain: ${{ env.MINIMUM_NOIR_VERSION }}

- name: Run formatter
run: nargo fmt --check


# This is a job which depends on all test jobs and reports the overall status.
# This allows us to add/remove test jobs without having to update the required workflows.
tests-end:
Expand Down
6 changes: 3 additions & 3 deletions Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
name = "noir_bigcurve"
type = "lib"
authors = [""]
compiler_version = ">=0.37.0"
compiler_version = ">=1.0.0"

[dependencies]
bignum = {tag = "v0.4.2", git = "https://github.com/noir-lang/noir-bignum"}
sort = {tag = "v0.2.1", git = "https://github.com/noir-lang/noir_sort"}
bignum = {tag = "v0.5.0", git = "https://github.com/noir-lang/noir-bignum"}
sort = {tag = "v0.2.2", git = "https://github.com/noir-lang/noir_sort"}
8 changes: 5 additions & 3 deletions src/bigcurve_test.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use dep::bignum::BigNum;
use std::ops::{Add, Neg, Sub};

use dep::bignum::{BigNum, BigNumTrait};
use dep::bignum::fields::bn254Fq::BN254_Fq_Params;

use crate::BigCurve;
use crate::{BigCurve, BigCurveTrait};
use crate::curve_jac;
use crate::curve_jac::AffineTranscript;
use crate::curve_jac::CurveJ;
Expand All @@ -17,7 +19,7 @@ use crate::curves::secp256r1::{Secp256r1, Secp256r1Fr, Secp256r1Scalar};
use crate::curves::secp384r1::{Secp384r1, Secp384r1Fr, Secp384r1Scalar};
use crate::curves::vesta::{Vesta, VestaFr, VestaScalar};
use crate::PointTable;
use crate::scalar_field::ScalarField;
use crate::scalar_field::{ScalarField, ScalarFieldTrait};
use super::curves::mnt6_753::MNT6_753Fq;

type Fq = BigNum<3, 254, BN254_Fq_Params>;
Expand Down
14 changes: 7 additions & 7 deletions src/curve_jac.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use dep::bignum::BigNumTrait;

use crate::BigCurve;
use crate::CurveParamsTrait;
use crate::scalar_field::ScalarField;
use crate::scalar_field::{ScalarField, ScalarFieldTrait};
/**
* @brief CurveJ represents a Short Weierstrass elliptic curve using Jacobian coordinates.
* representation in Jacobian form is X, Y, Z
Expand Down Expand Up @@ -44,7 +44,7 @@ pub struct JTranscript<BigNum> {

impl<BigNum> JTranscript<BigNum>
where
BigNum: BigNumTrait + std::ops::Add + std::ops::Mul + std::cmp::Eq,
BigNum: BigNumTrait,
{
unconstrained fn new() -> Self {
JTranscript {
Expand Down Expand Up @@ -75,7 +75,7 @@ pub struct AffineTranscript<BigNum> {
**/
impl<BigNum> AffineTranscript<BigNum>
where
BigNum: BigNumTrait + std::ops::Add + std::ops::Mul + std::cmp::Eq,
BigNum: BigNumTrait,
{
pub(crate) fn new() -> Self {
AffineTranscript { lambda: BigNum::new(), x3: BigNum::new(), y3: BigNum::new() }
Expand Down Expand Up @@ -144,7 +144,7 @@ pub struct PointTable<BigNum> {

impl<BigNum> PointTable<BigNum>
where
BigNum: BigNumTrait + std::ops::Add + std::ops::Mul + std::cmp::Eq,
BigNum: BigNumTrait,
{
pub(crate) fn empty() -> Self {
PointTable {
Expand Down Expand Up @@ -214,7 +214,7 @@ where
**/
impl<BigNum, CurveParams> std::convert::From<BigCurve<BigNum, CurveParams>> for CurveJ<BigNum, CurveParams>
where
BigNum: BigNumTrait + std::ops::Add + std::ops::Mul + std::cmp::Eq,
BigNum: BigNumTrait,
CurveParams: CurveParamsTrait<BigNum>,
{
fn from(affine_point: BigCurve<BigNum, CurveParams>) -> Self {
Expand All @@ -233,7 +233,7 @@ where
**/
impl<BigNum, CurveParams> std::cmp::Eq for CurveJ<BigNum, CurveParams>
where
BigNum: BigNumTrait + std::ops::Add + std::ops::Mul + std::cmp::Eq,
BigNum: BigNumTrait,
CurveParams: CurveParamsTrait<BigNum>,
{
fn eq(self, other: Self) -> bool {
Expand Down Expand Up @@ -269,7 +269,7 @@ where

impl<BigNum, CurveParams> CurveJ<BigNum, CurveParams>
where
BigNum: BigNumTrait + std::ops::Add + std::ops::Mul + std::cmp::Eq,
BigNum: BigNumTrait,
CurveParams: CurveParamsTrait<BigNum>,
{
/**
Expand Down
2 changes: 1 addition & 1 deletion src/curves/bls12_377.nr
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub type BLS12_377Fr = BigNum<3, 253, BLS12_377_Fr_Params>;
mod test {

use crate::curves::bls12_377::BLS12_377_SCALAR_SLICES;
use dep::bignum::BigNum;
use dep::bignum::{BigNum, BigNumTrait};
use dep::bignum::fields::bls12_377Fr::BLS12_377_Fr_Params;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/curves/bls12_381.nr
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub type BLS12_381Fr = BigNum<3, 255, BLS12_381_Fr_Params>;
mod test {

use crate::curves::bls12_381::BLS12_381_SCALAR_SLICES;
use dep::bignum::BigNum;
use dep::bignum::{BigNum, BigNumTrait};
use dep::bignum::fields::bls12_381Fr::BLS12_381_Fr_Params;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/curves/bn254.nr
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub type BN254Fq = BigNum<3, 254, BN254_Fq_Params>;
// pub type Secp256r1Fr = BigNum<3, Secp256r1_Fr_Params>;

// mod test {
// use dep::bignum::BigNum;
// use dep::bignum::{BigNum, BigNumTrait};
// use crate::curves::secp256r1::SECP256r1_SCALAR_SLICES;
// #[test]
// fn test_bn254_bits() {
Expand Down
2 changes: 1 addition & 1 deletion src/curves/mnt4_753.nr
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub type MNT4_753Fr = BigNum<7, 753, MNT4_753_Fr_Params>;
mod test {

use crate::curves::mnt4_753::MNT4_753_SCALAR_SLICES;
use dep::bignum::BigNum;
use dep::bignum::{BigNum, BigNumTrait};
use dep::bignum::fields::mnt4_753Fr::MNT4_753_Fr_Params;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/curves/mnt6_753.nr
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub type MNT6_753Fr = BigNum<7, 753, MNT6_753_Fr_Params>;
mod test {

use crate::curves::mnt6_753::MNT6_753_SCALAR_SLICES;
use dep::bignum::BigNum;
use dep::bignum::{BigNum, BigNumTrait};
use dep::bignum::fields::mnt6_753Fr::MNT6_753_Fr_Params;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/curves/pallas.nr
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub type PallasFr = BigNum<3, 255, Pallas_Fr_Params>;
mod test {

use crate::curves::pallas::PALLAS_SCALAR_SLICES;
use dep::bignum::BigNum;
use dep::bignum::{BigNum, BigNumTrait};
use dep::bignum::fields::pallasFr::Pallas_Fr_Params;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/curves/secp256k1.nr
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub type Secp256k1Fr = BigNum<3, 256, Secp256k1_Fr_Params>;

mod test {
use crate::curves::secp256k1::SECP256k1_SCALAR_SLICES;
use dep::bignum::BigNum;
use dep::bignum::{BigNum, BigNumTrait};
use dep::bignum::fields::secp256k1Fr::Secp256k1_Fr_Params;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/curves/secp256r1.nr
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub type Secp256r1Fr = BigNum<3, 256, Secp256r1_Fr_Params>;
mod test {

use crate::curves::secp256r1::SECP256r1_SCALAR_SLICES;
use dep::bignum::BigNum;
use dep::bignum::{BigNum, BigNumTrait};
use dep::bignum::fields::secp256r1Fr::Secp256r1_Fr_Params;

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/curves/secp384r1.nr
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ pub type Secp384r1Fr = BigNum<4, 384, Secp384r1_Fr_Params>;
mod test {

use crate::curves::secp384r1::Secp384r1Scalar;
use crate::scalar_field::ScalarField;
use dep::bignum::BigNum;
use crate::scalar_field::{ScalarField, ScalarFieldTrait};
use dep::bignum::{BigNum, BigNumTrait};
use dep::bignum::fields::secp384r1Fr::Secp384r1_Fr_Params;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/curves/vesta.nr
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub type VestaFr = BigNum<3, 255, Vesta_Fr_Params>;
mod test {

use crate::curves::vesta::VESTA_SCALAR_SLICES;
use dep::bignum::BigNum;
use dep::bignum::{BigNum, BigNumTrait};
use dep::bignum::fields::vestaFr::Vesta_Fr_Params;

#[test]
Expand Down
34 changes: 18 additions & 16 deletions src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use crate::utils::hash_to_curve::hash_to_curve;

use dep::sort::sort_advanced;

use scalar_field::ScalarFieldTrait;

fn __sort_field_as_u32(lhs: Field, rhs: Field) -> bool {
lhs as u32 < rhs as u32
}
Expand Down Expand Up @@ -174,9 +176,9 @@ where
{
fn offset_generator() -> [BigNum; 2];
fn offset_generator_final() -> [BigNum; 2];
pub fn one() -> [BigNum; 2];
pub fn b() -> BigNum;
pub fn a() -> BigNum;
fn one() -> [BigNum; 2];
fn b() -> BigNum;
fn a() -> BigNum;
}

/**
Expand All @@ -196,7 +198,7 @@ struct PointTable<BigNum> {

impl<BigNum> PointTable<BigNum>
where
BigNum: BigNumTrait + std::ops::Add + std::ops::Mul + std::cmp::Eq,
BigNum: BigNumTrait,
{
pub(crate) fn empty() -> Self {
PointTable { x: [BigNum::new(); 16], y: [BigNum::new(); 16] }
Expand Down Expand Up @@ -244,21 +246,21 @@ where
}

trait BigCurveTrait {
pub fn neg(self) -> Self;
pub fn point_at_infinity() -> Self;
fn neg(self) -> Self;
fn point_at_infinity() -> Self;
fn offset_generator() -> Self;
fn offset_generator_final() -> Self;
pub fn one() -> Self;
pub fn conditional_select(lhs: Self, rhs: Self, predicate: bool) -> Self;
pub fn validate_on_curve(self);
pub fn mul<let NScalarSlices: u32>(self, scalar: ScalarField<NScalarSlices>) -> Self;
pub fn hash_to_curve<let N: u32>(seed: [u8; N]) -> Self;
fn one() -> Self;
fn conditional_select(lhs: Self, rhs: Self, predicate: bool) -> Self;
fn validate_on_curve(self);
fn mul<let NScalarSlices: u32>(self, scalar: ScalarField<NScalarSlices>) -> Self;
fn hash_to_curve<let N: u32>(seed: [u8; N]) -> Self;
}

impl<BigNum, CurveParams> BigCurveTrait for BigCurve<BigNum, CurveParams>
where
CurveParams: CurveParamsTrait<BigNum>,
BigNum: BigNumTrait + std::ops::Add + std::ops::Mul + std::cmp::Eq,
BigNum: BigNumTrait,
{

fn hash_to_curve<let N: u32>(seed: [u8; N]) -> Self {
Expand Down Expand Up @@ -335,7 +337,7 @@ where
impl<BigNum, CurveParams> BigCurve<BigNum, CurveParams>
where
CurveParams: CurveParamsTrait<BigNum>,
BigNum: BigNumTrait + std::ops::Add + std::ops::Mul + std::cmp::Eq,
BigNum: BigNumTrait,
{

/**
Expand Down Expand Up @@ -1004,7 +1006,7 @@ where
impl<BigNum, CurveParams> std::ops::Add for BigCurve<BigNum, CurveParams>
where
CurveParams: CurveParamsTrait<BigNum>,
BigNum: BigNumTrait + std::ops::Add + std::ops::Mul + std::cmp::Eq,
BigNum: BigNumTrait,
{
// Expensive witness generation! Avoid if possible
fn add(self, other: Self) -> Self {
Expand All @@ -1020,7 +1022,7 @@ where
impl<BigNum, CurveParams> std::ops::Sub for BigCurve<BigNum, CurveParams>
where
CurveParams: CurveParamsTrait<BigNum>,
BigNum: BigNumTrait + std::ops::Add + std::ops::Mul + std::cmp::Eq,
BigNum: BigNumTrait,
{
// Expensive witness generation! Avoid if possible
fn sub(self, other: Self) -> Self {
Expand All @@ -1038,7 +1040,7 @@ where
**/
impl<BigNum, CurveParams> std::cmp::Eq for BigCurve<BigNum, CurveParams>
where
BigNum: BigNumTrait + std::ops::Add + std::ops::Mul + std::cmp::Eq,
BigNum: BigNumTrait,
{
fn eq(self, other: Self) -> bool {
let coords_equal =
Expand Down
6 changes: 4 additions & 2 deletions src/utils/derive_offset_generators.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::BigCurve;
use std::ops::Neg;

use crate::{BigCurve, BigCurveTrait};
use crate::curve_jac::CurveJ;
use crate::CurveParamsTrait;

Expand Down Expand Up @@ -456,7 +458,7 @@ unconstrained fn compute_and_print_offset_generators<Fq, Curve, let K: u32, let
cofactor: Field,
)
where
Fq: BigNumTrait + std::ops::Mul + std::ops::Add + std::cmp::Eq,
Fq: BigNumTrait,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change has happened in many places. wondering why we're not getting warnings about the std traits not being in scope?

Curve: CurveParamsTrait<Fq>,
{
let a = Curve::a();
Expand Down
6 changes: 3 additions & 3 deletions src/utils/hash_to_curve.nr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ unconstrained fn hash_to_curve_inner<Fq>(
b: Fq,
) -> (Fq, Fq, Field)
where
Fq: BigNumTrait + std::ops::Mul + std::ops::Add + std::cmp::Eq,
Fq: BigNumTrait,
{
let seedhash = std::hash::poseidon2::Poseidon2::hash([seedbase, seed_counter], 2);
// TODO: assert in field?
Expand Down Expand Up @@ -39,7 +39,7 @@ unconstrained fn __hash_to_curve_witgen<Fq, let SeedBytes: u32>(
b: Fq,
) -> (Fq, Fq, Field)
where
Fq: BigNumTrait + std::ops::Mul + std::ops::Add + std::cmp::Eq,
Fq: BigNumTrait,
{
let hashed_seed = poseidon_hash_bytes(seed);
hash_to_curve_inner(hashed_seed, 0, a, b)
Expand All @@ -63,7 +63,7 @@ fn poseidon_hash_bytes<let SeedBytes: u32>(seed: [u8; SeedBytes]) -> Field {
}
pub fn hash_to_curve<Fq, let SeedBytes: u32>(seed: [u8; SeedBytes], a: Fq, b: Fq) -> (Fq, Fq)
where
Fq: BigNumTrait + std::ops::Mul + std::ops::Add + std::cmp::Eq,
Fq: BigNumTrait,
{
let (_, y, salt) = unsafe { __hash_to_curve_witgen(seed, a, b) };
let outer_hash: Field = poseidon_hash_bytes(seed);
Expand Down
Loading