Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ewynx committed Sep 3, 2024
2 parents 7598d95 + f60da60 commit 528cbd0
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 15 deletions.
8 changes: 8 additions & 0 deletions .github/NIGHTLY_CANARY_DIED.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: "Tests fail on latest Nargo nightly release"
assignees: TomAFrench
---

The tests on this Noir project have started failing when using the latest nightly release of the Noir compiler. This likely means that there have been breaking changes for which this project needs to be updated to take into account.

Check the [{{env.WORKFLOW_NAME}}]({{env.WORKFLOW_URL}}) workflow for details.
40 changes: 40 additions & 0 deletions .github/workflows/nightly-canary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Noir Nightly Canary

on:
schedule:
# Run a check at 9 AM UTC
- cron: "0 9 * * *"

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: Test on Nargo ${{matrix.toolchain}}
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install Nargo
uses: noir-lang/[email protected]
with:
toolchain: nightly

- name: Run Noir tests
run: nargo test

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

- name: Alert on dead links
uses: JasonEtco/create-an-issue@v2
if: ${{ failure() }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WORKFLOW_NAME: ${{ github.workflow }}
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
update_existing: true
filename: .github/NIGHTLY_CANARY_DIED.md

44 changes: 44 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Noir tests

on:
push:
branches:
- main
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: Test on Nargo ${{matrix.toolchain}}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
toolchain: [nightly, 0.32.0]
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install Nargo
uses: noir-lang/[email protected]
with:
toolchain: ${{ matrix.toolchain }}

- name: Run Noir tests
run: nargo test

format:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install Nargo
uses: noir-lang/[email protected]
with:
toolchain: 0.32.0

- name: Run formatter
run: nargo fmt --check
18 changes: 8 additions & 10 deletions src/runtime_bignum.nr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait BigNumTrait {
fn new() -> Self;
fn one() -> Self;
fn from(limbs: [Field]) -> Self;
fn from_byte_be<let NBytes: u32>(x: [u8; NBytes]) -> Self;
fn from_be_bytes<let NBytes: u32>(x: [u8; NBytes]) -> Self;
fn to_le_bytes<let NBytes: u32>(val: Self) -> [u8; NBytes];
fn get(self) -> [Field];
fn get_limb(self, idx: u64) -> Field;
Expand Down Expand Up @@ -144,7 +144,7 @@ impl<let N: u32, Params> BigNumTrait for BigNum<N, Params> where Params: BigNumP
* is precisely large enough to cover Params::modulus_bits()
* @param x: input byte array
**/
fn from_byte_be<let NBytes: u32>(x: [u8; NBytes]) -> BigNum<N, Params> {
fn from_be_bytes<let NBytes: u32>(x: [u8; NBytes]) -> BigNum<N, Params> {
let num_bits = NBytes * 8;
let modulus_bits = Params::modulus_bits();
assert(num_bits > modulus_bits);
Expand Down Expand Up @@ -173,12 +173,10 @@ impl<let N: u32, Params> BigNumTrait for BigNum<N, Params> where Params: BigNumP
}

// max_bits_in_most_significant_byte should be known at comptime. if not...messy!
let mut max_bits_in_most_significant_byte = num_bits - modulus_bits;
if num_bits == modulus_bits {
max_bits_in_most_significant_byte = 8;
}
let mut max_bits_in_most_significant_byte = 8 - (num_bits - modulus_bits);

let most_significant_byte: Field = x[0] as Field;

let most_significant_byte: Field = x[NBytes - 1] as Field;
most_significant_byte.assert_max_bit_size(max_bits_in_most_significant_byte as u32);
result
}
Expand Down Expand Up @@ -285,7 +283,7 @@ impl<let N: u32, Params> BigNum<N, Params> where Params: BigNumParamsTrait<N> {
}
}

impl<let N: u32, Params,> BigNumInstanceTrait<BigNum<N, Params>> for BigNumInstance<N, Params> where Params: BigNumParamsTrait<N> {
impl<let N: u32, Params> BigNumInstanceTrait<BigNum<N, Params>> for BigNumInstance<N, Params> where Params: BigNumParamsTrait<N> {

fn modulus(self) -> BigNum<N, Params> { BigNum{ limbs: self.modulus } }
fn __derive_from_seed<let SeedBytes: u32>(self, seed: [u8; SeedBytes]) -> BigNum<N, Params> {
Expand Down Expand Up @@ -1273,7 +1271,7 @@ impl<let N: u32, Params> BigNumInstance<N, Params> where Params: BigNumParamsTra

for i in 0..NUM_PRODUCTS {
lhs[i] = self.__add_linear_expression(lhs_terms[i], lhs_flags[i]);
rhs[i]= self.__add_linear_expression(rhs_terms[i], rhs_flags[i]);
rhs[i] = self.__add_linear_expression(rhs_terms[i], rhs_flags[i]);
}

let add: [Field; N] = self.__add_linear_expression(linear_terms, linear_flags);
Expand Down Expand Up @@ -1375,7 +1373,7 @@ impl<let N: u32, Params> BigNumInstance<N, Params> where Params: BigNumParamsTra
linear_terms,
linear_flags
);
let mut mulout_n: ArrayX<Field, N,2> = ArrayX::new();
let mut mulout_n: ArrayX<Field, N, 2> = ArrayX::new();

let relation_result: ArrayX<Field, N, 2> = mulout_p.__normalize_limbs(N + N);
let modulus: [Field; N] = self.modulus;
Expand Down
9 changes: 6 additions & 3 deletions src/utils/arrayX.nr
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ impl<T, let N: u32, let SizeMultiplier: u32> ArrayX<T, N, SizeMultiplier> {
let index = i % N;
self.segments[segment][index]
}
}

impl<let N: u32, let SizeMultiplier: u32> ArrayX<Field, N, SizeMultiplier> {

unconstrained fn __normalize_limbs<let NumSegments: u32>(x: ArrayX<Field, N, NumSegments>, range: u32) -> ArrayX<Field, N, NumSegments> {
let mut normalized: ArrayX<Field, N, NumSegments> = ArrayX::new();
let mut inp = x;
unconstrained fn __normalize_limbs(self, range: u32) -> Self {
let mut normalized: Self = ArrayX::new();
let mut inp = self;
// (9 limb mul = 17 product terms)

// a2 a1 a0
Expand Down
4 changes: 2 additions & 2 deletions src/utils/u60_representation.nr
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ impl<let N: u32, let NumSegments: u32> U60Repr<N, NumSegments> {
let value = self.limbs.get(0);

let mut remainder = (value >> remainder_shift);
result.limbs.set(num_shifted_limbs, (value << limb_shift) & mask);
result.limbs.set(num_shifted_limbs, (value << (limb_shift as u8)) & mask);

// shift 84. num shifted = 1

for i in 1..((N * NumSegments) - num_shifted_limbs) {
let value = self.limbs.get(i);
let upshift = ((value << limb_shift) + remainder) & mask;
let upshift = ((value << (limb_shift as u8)) + remainder) & mask;
result.limbs.set(i + num_shifted_limbs, upshift);
remainder = (value >> remainder_shift);
// let remainder: u64 = (self.limbs.get(i + num_shifted_limbs as u64) << remainder_shift as u8) & mask;
Expand Down

0 comments on commit 528cbd0

Please sign in to comment.