Skip to content

Commit

Permalink
chore: update to Noir 0.38.0
Browse files Browse the repository at this point in the history
  • Loading branch information
olehmisar committed Nov 21, 2024
1 parent fa8c058 commit 727116e
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 191 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
toolchain: [0.35.0, 0.36.0]
toolchain: [0.38.0]
steps:
- name: Checkout sources
uses: actions/checkout@v4
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Install Nargo
uses: noir-lang/noirup@v0.1.3
with:
toolchain: 0.36.0
toolchain: 0.38.0

- name: Run formatter
run: nargo fmt --check
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 = "nodash"
type = "lib"
authors = ["Oleh Misarosh <olehmisar@gmail.com>"]
compiler_version = ">=0.30.0"
compiler_version = ">=0.38.0"

[dependencies]
20 changes: 5 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@ Put this into your Nargo.toml.
If you are using Noir:

```toml
nodash = { git = "https://github.com/olehmisar/nodash/", tag = "v0.36.0" }
nodash = { git = "https://github.com/olehmisar/nodash/", tag = "v0.38.0" }
```

The version of nodash matches the version of Noir. The patch version may be different if a bugfix or a new feature is added for the same version of Noir. E.g., nodash@v0.35.0 and nodash@v0.35.1 are compatible with noir@v0.35.0.

---

If you are using Aztec:

```toml
nodash = { git = "https://github.com/olehmisar/nodash/", tag = "aztec-v0.57.0" }
```

The version of nodash matches the version of Aztec. E.g., nodash@aztec-v0.57.0 is compatible with aztec@v0.57.0.
The version of nodash matches the version of Noir. The patch version may be different if a bugfix or a new feature is added for the same version of Noir. E.g., nodash@v0.38.0 and nodash@v0.38.1 are compatible with noir@v0.38.0.

## Docs

Expand Down Expand Up @@ -98,14 +88,14 @@ assert(str_to_u64("02345678912345678912") == 02345678912345678912);

### `ArrayExtensions`

#### `slice`
#### `slice<L>(start: u32) -> [T; L]`

Returns a slice of the array.
Returns a slice of the array, starting at `start` and ending at `start + L`. Panics if `start + L` is out of bounds.

```rs
use nodash::ArrayExtensions;

assert([1, 2, 3, 4, 5].slice::<3>(1, 4) == [2, 3, 4]);
assert([1, 2, 3, 4, 5].slice::<3>(1) == [2, 3, 4]);
```

#### `concat`
Expand Down
12 changes: 6 additions & 6 deletions src/array.nr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
impl<T, let N: u32> crate::ArrayExtensions<T, N> for [T; N] {
fn slice<let M: u32>(self, start: u32, end: u32) -> [T; M] {
assert(start + M == end, "slice: invalid slice length");
fn slice<let L: u32>(self, start: u32) -> [T; L] {
let end = start + L;
assert(end <= N, "slice: slice end out of bounds");
let mut result = [self[0]; M];
for i in 0..M {
let mut result = [self[0]; L];
for i in 0..L {
result[i] = self[start + i];
}
result
Expand Down Expand Up @@ -44,7 +44,7 @@ pub fn pack_bytes<let N: u32>(bytes: [u8; N]) -> [Field; N / 31 + 1] {
let bytes_padded = bytes.pad_end::<(N / 31 + 1) * 31>(0);
let mut res = [0 as Field; N / 31 + 1];
for i in 0..N / 31 + 1 {
let chunk = bytes_padded.slice::<31>(i * 31, i * 31 + 31);
let chunk = bytes_padded.slice::<31>(i * 31);
res[i] = field_from_bytes(chunk);
}
res
Expand All @@ -65,7 +65,7 @@ fn field_from_bytes<let N: u32>(bytes: [u8; N]) -> Field {
mod tests {
#[test]
fn test_slice() {
assert([1, 2, 3, 4, 5].slice::<3>(1, 4) == [2, 3, 4]);
assert([1, 2, 3, 4, 5].slice::<3>(1) == [2, 3, 4]);
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ mod string;
mod tables;
mod array;

pub use string::{to_hex_string_bytes, str_to_u64};
pub use math::{clamp, div_ceil, sqrt::sqrt};
pub use array::pack_bytes;
pub use math::{clamp, div_ceil, sqrt::sqrt};
pub use string::{str_to_u64, to_hex_string_bytes};

trait ArrayExtensions<T, let N: u32> {
fn slice<let M: u32>(self, start: u32, end: u32) -> [T; M];
fn slice<let L: u32>(self, start: u32) -> [T; L];
fn concat<let M: u32>(self, other: [T; M]) -> [T; N + M];
fn pad_start<let M: u32>(self, pad_value: T) -> [T; M];
fn pad_end<let M: u32>(self, pad_value: T) -> [T; M];
Expand Down
2 changes: 1 addition & 1 deletion src/math.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub(crate) mod sqrt;
pub(crate) mod numeric;

use std::{ops::{Add, Div, Rem}, cmp::Eq};
use numeric::Numeric;
use std::{cmp::Eq, ops::{Add, Div, Rem}};

pub fn clamp<T>(x: T, min: T, max: T) -> T
where
Expand Down
2 changes: 1 addition & 1 deletion src/math/sqrt.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{ops::{Mul, Div, Add}, cmp::Ord};
use crate::math::numeric::Numeric;
use std::{cmp::Ord, ops::{Add, Div, Mul}};

// TODO: check if this is correct
pub fn sqrt<T>(value: T) -> T
Expand Down
243 changes: 81 additions & 162 deletions src/tables.nr
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,22 @@
pub(crate) global ASCII_TO_NUMBER: [u8; 128] = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* */
0,
/*"!"*/
0,
/* " */
0,
/*"#"*/
0,
/*"$"*/
0,
/*"%"*/
0,
/*"&"*/
0,
/*"'"*/
0,
/*"("*/
0,
/*")"*/
0,
/*"*"*/
0,
/*"+"*/
0,
/*","*/
0,
/*"-"*/
0,
/*"."*/
0,
/*"/"*/
0,
/*"0"*/
0, /*"!"*/
0, /* " */
0, /*"#"*/
0, /*"$"*/
0, /*"%"*/
0, /*"&"*/
0, /*"'"*/
0, /*"("*/
0, /*")"*/
0, /*"*"*/
0, /*"+"*/
0, /*","*/
0, /*"-"*/
0, /*"."*/
0, /*"/"*/
0, /*"0"*/
0, // numeric value
/*"1"*/
1, // numeric value
Expand All @@ -54,143 +38,78 @@ pub(crate) global ASCII_TO_NUMBER: [u8; 128] = [
/*"9"*/
9, // numeric value
/*":"*/
0,
/*";"*/
0,
/*"<"*/
0,
/*"="*/
0,
/*">"*/
0,
/*"?"*/
0,
/*"@"*/
0,
/*"A"*/
0,
/*"B"*/
0,
/*"C"*/
0,
/*"D"*/
0,
/*"E"*/
0,
/*"F"*/
0,
/*"G"*/
0,
/*"H"*/
0,
/*"I"*/
0,
/*"J"*/
0,
/*"K"*/
0,
/*"L"*/
0,
/*"M"*/
0,
/*"N"*/
0,
/*"O"*/
0,
/*"P"*/
0,
/*"Q"*/
0,
/*"R"*/
0,
/*"S"*/
0,
/*"T"*/
0,
/*"U"*/
0,
/*"V"*/
0,
/*"W"*/
0,
/*"X"*/
0,
/*"Y"*/
0,
/*"Z"*/
0,
/*"["*/
0, /*";"*/
0, /*"<"*/
0, /*"="*/
0, /*">"*/
0, /*"?"*/
0, /*"@"*/
0, /*"A"*/
0, /*"B"*/
0, /*"C"*/
0, /*"D"*/
0, /*"E"*/
0, /*"F"*/
0, /*"G"*/
0, /*"H"*/
0, /*"I"*/
0, /*"J"*/
0, /*"K"*/
0, /*"L"*/
0, /*"M"*/
0, /*"N"*/
0, /*"O"*/
0, /*"P"*/
0, /*"Q"*/
0, /*"R"*/
0, /*"S"*/
0, /*"T"*/
0, /*"U"*/
0, /*"V"*/
0, /*"W"*/
0, /*"X"*/
0, /*"Y"*/
0, /*"Z"*/
0, /*"["*/
0, // an array
/*"\"*/
0,
/*"]"*/
0,
/*"^"*/
0,
/*"_"*/
0,
/*"`"*/
0,
/*"a"*/
0,
/*"b"*/
0,
/*"c"*/
0,
/*"d"*/
0,
/*"e"*/
0,
/*"f"*/
0, /*"]"*/
0, /*"^"*/
0, /*"_"*/
0, /*"`"*/
0, /*"a"*/
0, /*"b"*/
0, /*"c"*/
0, /*"d"*/
0, /*"e"*/
0, /*"f"*/
0, // "0"
/*"g"*/
0,
/*"h"*/
0,
/*"i"*/
0,
/*"j"*/
0,
/*"k"*/
0,
/*"l"*/
0,
/*"m"*/
0,
/*"n"*/
0,
/*"o"*/
0,
/*"p"*/
0,
/*"q"*/
0,
/*"r"*/
0,
/*"s"*/
0,
/*"t"*/
0, /*"h"*/
0, /*"i"*/
0, /*"j"*/
0, /*"k"*/
0, /*"l"*/
0, /*"m"*/
0, /*"n"*/
0, /*"o"*/
0, /*"p"*/
0, /*"q"*/
0, /*"r"*/
0, /*"s"*/
0, /*"t"*/
0, // "0"
/*"u"*/
0,
/*"v"*/
0,
/*"w"*/
0,
/*"x"*/
0,
/*"y"*/
0,
/*"z"*/
0,
/*"{"*/
0, /*"v"*/
0, /*"w"*/
0, /*"x"*/
0, /*"y"*/
0, /*"z"*/
0, /*"{"*/
0, // an object
/*"|"*/
0,
/*"}"*/
0,
/*"~"*/
0,
/*DEL*/
0, /*"}"*/
0, /*"~"*/
0, /*DEL*/
0,
];

0 comments on commit 727116e

Please sign in to comment.