diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6e74870..b7b31a4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 diff --git a/Nargo.toml b/Nargo.toml index f72bcf1..6e42d05 100644 --- a/Nargo.toml +++ b/Nargo.toml @@ -2,6 +2,6 @@ name = "nodash" type = "lib" authors = ["Oleh Misarosh "] -compiler_version = ">=0.30.0" +compiler_version = ">=0.38.0" [dependencies] diff --git a/README.md b/README.md index ec4fe08..f740878 100644 --- a/README.md +++ b/README.md @@ -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 @@ -98,14 +88,14 @@ assert(str_to_u64("02345678912345678912") == 02345678912345678912); ### `ArrayExtensions` -#### `slice` +#### `slice(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` diff --git a/src/array.nr b/src/array.nr index 8a4e441..401991f 100644 --- a/src/array.nr +++ b/src/array.nr @@ -1,9 +1,9 @@ impl crate::ArrayExtensions for [T; N] { - fn slice(self, start: u32, end: u32) -> [T; M] { - assert(start + M == end, "slice: invalid slice length"); + fn slice(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 @@ -44,7 +44,7 @@ pub fn pack_bytes(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 @@ -65,7 +65,7 @@ fn field_from_bytes(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] diff --git a/src/lib.nr b/src/lib.nr index 5a5c71b..ea8b02d 100644 --- a/src/lib.nr +++ b/src/lib.nr @@ -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 { - fn slice(self, start: u32, end: u32) -> [T; M]; + fn slice(self, start: u32) -> [T; L]; fn concat(self, other: [T; M]) -> [T; N + M]; fn pad_start(self, pad_value: T) -> [T; M]; fn pad_end(self, pad_value: T) -> [T; M]; diff --git a/src/math.nr b/src/math.nr index 9386d9e..8e756d4 100644 --- a/src/math.nr +++ b/src/math.nr @@ -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(x: T, min: T, max: T) -> T where diff --git a/src/math/sqrt.nr b/src/math/sqrt.nr index 543fd11..d9c51cd 100644 --- a/src/math/sqrt.nr +++ b/src/math/sqrt.nr @@ -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(value: T) -> T diff --git a/src/tables.nr b/src/tables.nr index 36109ac..98e8e78 100644 --- a/src/tables.nr +++ b/src/tables.nr @@ -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 @@ -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, ];