From 9ee587d95c4b992b939ce8b0d56b458078d8203d Mon Sep 17 00:00:00 2001 From: iAmMichaelConnor Date: Wed, 21 Aug 2024 10:30:18 +0000 Subject: [PATCH 1/7] fix: from_bytes_be --- src/runtime_bignum.nr | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/runtime_bignum.nr b/src/runtime_bignum.nr index 6d97d7c..c73be8b 100644 --- a/src/runtime_bignum.nr +++ b/src/runtime_bignum.nr @@ -13,7 +13,7 @@ trait BigNumTrait { fn new() -> Self; fn one() -> Self; fn from(limbs: [Field]) -> Self; - fn from_byte_be(x: [u8; NBytes]) -> Self; + fn from_be_bytes(x: [u8; NBytes]) -> Self; fn to_le_bytes(val: Self) -> [u8; NBytes]; fn get(self) -> [Field]; fn get_limb(self, idx: u64) -> Field; @@ -144,7 +144,7 @@ impl BigNumTrait for BigNum where Params: BigNumP * is precisely large enough to cover Params::modulus_bits() * @param x: input byte array **/ - fn from_byte_be(x: [u8; NBytes]) -> BigNum { + fn from_be_bytes(x: [u8; NBytes]) -> BigNum { let num_bits = NBytes * 8; let modulus_bits = Params::modulus_bits(); assert(num_bits > modulus_bits); @@ -173,12 +173,10 @@ impl BigNumTrait for BigNum 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 } From 75d10a4916d85e713fb895c414b489be46f68034 Mon Sep 17 00:00:00 2001 From: sirasistant Date: Mon, 26 Aug 2024 16:21:19 +0000 Subject: [PATCH 2/7] fix: workaround shifts to compile with latest noir --- src/utils/u60_representation.nr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/u60_representation.nr b/src/utils/u60_representation.nr index 5f46edb..37b8ed8 100644 --- a/src/utils/u60_representation.nr +++ b/src/utils/u60_representation.nr @@ -195,13 +195,13 @@ impl U60Repr { 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; From e8e3314beb9d18eb1415042bfb72c842f8a1cb0e Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 29 Aug 2024 12:33:52 +0000 Subject: [PATCH 3/7] chore: add CI --- .github/workflows/test.yml | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..58d31fc --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,41 @@ +name: Noir tests + +on: + push: + branches: + - master + pull_request: + +env: + CARGO_TERM_COLOR: always + NARGO_VERSION: 0.32.0 + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install Nargo + uses: noir-lang/noirup@v0.1.3 + with: + toolchain: $NARGO_VERSION + + - name: Run Noir tests + run: nargo test + + # Disabled as the formatter panics + # format: + # runs-on: ubuntu-latest + # steps: + # - name: Checkout sources + # uses: actions/checkout@v4 + + # - name: Install Nargo + # uses: noir-lang/noirup@v0.1.3 + # with: + # toolchain: $NARGO_VERSION + + # - name: Run formatter + # run: nargo fmt --check \ No newline at end of file From 960a3a137561dc7cedd751e1005fbaa03190f879 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 29 Aug 2024 12:36:25 +0000 Subject: [PATCH 4/7] . --- .github/workflows/test.yml | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 58d31fc..842e661 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,17 +25,16 @@ jobs: - name: Run Noir tests run: nargo test - # Disabled as the formatter panics - # format: - # runs-on: ubuntu-latest - # steps: - # - name: Checkout sources - # uses: actions/checkout@v4 - - # - name: Install Nargo - # uses: noir-lang/noirup@v0.1.3 - # with: - # toolchain: $NARGO_VERSION - - # - name: Run formatter - # run: nargo fmt --check \ No newline at end of file + format: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install Nargo + uses: noir-lang/noirup@v0.1.3 + with: + toolchain: $NARGO_VERSION + + - name: Run formatter + run: nargo fmt --check \ No newline at end of file From 9783ce42892129575995ab316a1787ce3736b904 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 29 Aug 2024 17:23:36 +0000 Subject: [PATCH 5/7] chore: add a canary for tests failing on nightly releases of nargo --- .github/NIGHTLY_CANARY_DIED.md | 8 ++++++ .github/workflows/nightly-canary.yml | 40 ++++++++++++++++++++++++++++ .github/workflows/test.yml | 10 ++++--- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 .github/NIGHTLY_CANARY_DIED.md create mode 100644 .github/workflows/nightly-canary.yml diff --git a/.github/NIGHTLY_CANARY_DIED.md b/.github/NIGHTLY_CANARY_DIED.md new file mode 100644 index 0000000..f72f3e1 --- /dev/null +++ b/.github/NIGHTLY_CANARY_DIED.md @@ -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. \ No newline at end of file diff --git a/.github/workflows/nightly-canary.yml b/.github/workflows/nightly-canary.yml new file mode 100644 index 0000000..ddacb4d --- /dev/null +++ b/.github/workflows/nightly-canary.yml @@ -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/noirup@v0.1.3 + 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 + \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 842e661..8e58c35 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,11 +8,15 @@ on: env: CARGO_TERM_COLOR: always - NARGO_VERSION: 0.32.0 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 @@ -20,7 +24,7 @@ jobs: - name: Install Nargo uses: noir-lang/noirup@v0.1.3 with: - toolchain: $NARGO_VERSION + toolchain: ${{ matrix.toolchain }} - name: Run Noir tests run: nargo test @@ -34,7 +38,7 @@ jobs: - name: Install Nargo uses: noir-lang/noirup@v0.1.3 with: - toolchain: $NARGO_VERSION + toolchain: 0.32.0 - name: Run formatter run: nargo fmt --check \ No newline at end of file From b5afd7b65b9e93a6932a1d9ae33cdc4472212db3 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 29 Aug 2024 18:20:38 +0000 Subject: [PATCH 6/7] fix: remove unnecessary generic from `ArrayX.__normalize_limbs()` --- src/runtime_bignum.nr | 6 +++--- src/utils/arrayX.nr | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/runtime_bignum.nr b/src/runtime_bignum.nr index c73be8b..a73f053 100644 --- a/src/runtime_bignum.nr +++ b/src/runtime_bignum.nr @@ -283,7 +283,7 @@ impl BigNum where Params: BigNumParamsTrait { } } -impl BigNumInstanceTrait> for BigNumInstance where Params: BigNumParamsTrait { +impl BigNumInstanceTrait> for BigNumInstance where Params: BigNumParamsTrait { fn modulus(self) -> BigNum { BigNum{ limbs: self.modulus } } fn __derive_from_seed(self, seed: [u8; SeedBytes]) -> BigNum { @@ -1271,7 +1271,7 @@ impl BigNumInstance 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); @@ -1373,7 +1373,7 @@ impl BigNumInstance where Params: BigNumParamsTra linear_terms, linear_flags ); - let mut mulout_n: ArrayX = ArrayX::new(); + let mut mulout_n: ArrayX = ArrayX::new(); let relation_result: ArrayX = mulout_p.__normalize_limbs(N + N); let modulus: [Field; N] = self.modulus; diff --git a/src/utils/arrayX.nr b/src/utils/arrayX.nr index f3d9505..f34ec1e 100644 --- a/src/utils/arrayX.nr +++ b/src/utils/arrayX.nr @@ -74,10 +74,13 @@ impl ArrayX { let index = i % N; self.segments[segment][index] } +} + +impl ArrayX { - unconstrained fn __normalize_limbs(x: ArrayX, range: u32) -> ArrayX { - let mut normalized: ArrayX = 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 From f60da60f96d525c366c735eb7a132cf69dbba9e0 Mon Sep 17 00:00:00 2001 From: Tom French Date: Fri, 30 Aug 2024 16:51:26 +0100 Subject: [PATCH 7/7] chore: fix branch name in workflow --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8e58c35..6ffba86 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ name: Noir tests on: push: branches: - - master + - main pull_request: env: @@ -41,4 +41,4 @@ jobs: toolchain: 0.32.0 - name: Run formatter - run: nargo fmt --check \ No newline at end of file + run: nargo fmt --check