Skip to content

Commit fa8c058

Browse files
committed
chore: update to Noir 0.36.0
1 parent e15265e commit fa8c058

File tree

8 files changed

+251
-124
lines changed

8 files changed

+251
-124
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
toolchain: [0.35.0]
19+
toolchain: [0.35.0, 0.36.0]
2020
steps:
2121
- name: Checkout sources
2222
uses: actions/checkout@v4
@@ -38,7 +38,7 @@ jobs:
3838
- name: Install Nargo
3939
uses: noir-lang/[email protected]
4040
with:
41-
toolchain: 0.35.0
41+
toolchain: 0.36.0
4242

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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Put this into your Nargo.toml.
99
If you are using Noir:
1010

1111
```toml
12-
nodash = { git = "https://github.com/olehmisar/nodash/", tag = "v0.35.6" }
12+
nodash = { git = "https://github.com/olehmisar/nodash/", tag = "v0.36.0" }
1313
```
1414

1515
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., [email protected] and [email protected] are compatible with [email protected].

src/math.nr

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
mod sqrt;
2-
mod numeric;
1+
pub(crate) mod sqrt;
2+
pub(crate) mod numeric;
33

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

7-
pub fn clamp<T>(x: T, min: T, max: T) -> T where T: Ord {
7+
pub fn clamp<T>(x: T, min: T, max: T) -> T
8+
where
9+
T: Ord,
10+
{
811
if (x < min) {
912
min
1013
} else if (x > max) {
@@ -14,7 +17,10 @@ pub fn clamp<T>(x: T, min: T, max: T) -> T where T: Ord {
1417
}
1518
}
1619

17-
pub fn div_ceil<T>(a: T, b: T) -> T where T: Add + Div + Rem + Eq + Numeric {
20+
pub fn div_ceil<T>(a: T, b: T) -> T
21+
where
22+
T: Add + Div + Rem + Eq + Numeric,
23+
{
1824
let q = a / b;
1925
if (a % b == T::zero()) {
2026
q

src/math/numeric.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// TODO: remove this trait if it is implemented in Noir std lib.
2-
trait Numeric {
2+
pub(crate) trait Numeric {
33
fn zero() -> Self;
44
fn one() -> Self;
55
}

src/math/sqrt.nr

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use std::{ops::{Mul, Div, Add}, cmp::Ord};
22
use crate::math::numeric::Numeric;
33

44
// TODO: check if this is correct
5-
pub fn sqrt<T>(value: T) -> T where T: Numeric + Mul + Ord + Add + Div {
5+
pub fn sqrt<T>(value: T) -> T
6+
where
7+
T: Numeric + Mul + Ord + Add + Div,
8+
{
69
let r = unsafe {
710
// Safety: unsafe sqrt is checked to be between bounds
811
let r = sqrt_unconstrained(value);
@@ -15,7 +18,10 @@ pub fn sqrt<T>(value: T) -> T where T: Numeric + Mul + Ord + Add + Div {
1518
r
1619
}
1720

18-
unconstrained fn sqrt_unconstrained<T>(value: T) -> T where T: Numeric + Ord + Add + Div {
21+
unconstrained fn sqrt_unconstrained<T>(value: T) -> T
22+
where
23+
T: Numeric + Ord + Add + Div,
24+
{
1925
let ZERO: T = Numeric::zero();
2026
let ONE: T = Numeric::one();
2127
let TWO = ONE + ONE;
@@ -55,7 +61,10 @@ mod sqrt_tests {
5561
assert(sqrt(18 as u8) == 4);
5662
assert(sqrt(2482737472 as u32) == 49827);
5763
assert(sqrt(14446244073709551616 as u64) == 3800821499);
58-
assert(sqrt(U128::from_integer(1444624284781234073709551616)) == U128::from_integer(38008213385809));
64+
assert(
65+
sqrt(U128::from_integer(1444624284781234073709551616))
66+
== U128::from_integer(38008213385809),
67+
);
5968
}
6069

6170
#[test]
@@ -135,7 +144,7 @@ mod sqrt_tests {
135144
[71, 8],
136145
// some big numbers
137146
[9000000000000000000, 3000000000],
138-
[8274823429819348192323, 90966056470]
147+
[8274823429819348192323, 90966056470],
139148
];
140149

141150
for pair in pairs {

src/solidity.nr

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
global SELECTOR_LENGTH = 4;
22

3-
pub fn encode_with_selector<let N: u32>(selector: u32, args: [Field; N]) -> [u8; SELECTOR_LENGTH + N * 32] {
3+
pub fn encode_with_selector<let N: u32>(
4+
selector: u32,
5+
args: [Field; N],
6+
) -> [u8; SELECTOR_LENGTH + N * 32] {
47
let mut result = [0; SELECTOR_LENGTH + N * 32];
58

69
let selector_bytes: [u8; 4] = (selector as Field).to_be_bytes();
@@ -25,12 +28,14 @@ mod tests {
2528
fn test_simple() {
2629
let selector: u32 = 0xa9059cbb; // transfer(address,uint256)
2730
let args: [Field; 2] = [
28-
0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045,// address
29-
123// uint256
31+
0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045, // address
32+
123, // uint256
3033
];
3134
let encoded = encode_with_selector(selector, args);
3235
let expected: [u8; 68] = [
33-
169, 5, 156, 187, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 216, 218, 107, 242, 105, 100, 175, 157, 126, 237, 158, 3, 229, 52, 21, 211, 122, 169, 96, 69, 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, 123
36+
169, 5, 156, 187, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 216, 218, 107, 242, 105, 100, 175,
37+
157, 126, 237, 158, 3, 229, 52, 21, 211, 122, 169, 96, 69, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
38+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 123,
3439
];
3540
assert(encoded == expected);
3641
}
@@ -41,15 +46,21 @@ mod tests {
4146
// FunctionSelector::from_signature("deposit_private(bytes32,address[2],uint256[2])"),
4247
0x86d09dae,
4348
[
44-
0x1a7097a0f09457b0b0496684b2ed6723a262da3a1b061b598ee92ce3376cb302,
45-
0x610178dA211FEF7D417bC0e6FeD39F05609AD788,
46-
0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e,
47-
333,
48-
64
49-
]
49+
0x1a7097a0f09457b0b0496684b2ed6723a262da3a1b061b598ee92ce3376cb302,
50+
0x610178dA211FEF7D417bC0e6FeD39F05609AD788,
51+
0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e,
52+
333,
53+
64,
54+
],
5055
);
5156
let expected = [
52-
134, 208, 157, 174, 26, 112, 151, 160, 240, 148, 87, 176, 176, 73, 102, 132, 178, 237, 103, 35, 162, 98, 218, 58, 27, 6, 27, 89, 142, 233, 44, 227, 55, 108, 179, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 1, 120, 218, 33, 31, 239, 125, 65, 123, 192, 230, 254, 211, 159, 5, 96, 154, 215, 136, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 183, 248, 188, 99, 187, 202, 209, 129, 85, 32, 19, 8, 200, 243, 84, 11, 7, 248, 79, 94, 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, 1, 77, 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, 64
57+
134, 208, 157, 174, 26, 112, 151, 160, 240, 148, 87, 176, 176, 73, 102, 132, 178, 237,
58+
103, 35, 162, 98, 218, 58, 27, 6, 27, 89, 142, 233, 44, 227, 55, 108, 179, 2, 0, 0, 0,
59+
0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 1, 120, 218, 33, 31, 239, 125, 65, 123, 192, 230, 254,
60+
211, 159, 5, 96, 154, 215, 136, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 183, 248, 188, 99,
61+
187, 202, 209, 129, 85, 32, 19, 8, 200, 243, 84, 11, 7, 248, 79, 94, 0, 0, 0, 0, 0, 0,
62+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 77, 0, 0, 0,
63+
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, 64,
5364
];
5465
assert(result == expected);
5566
}

src/string.nr

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ fn some_test() {
4040
let header_prefix: [u8; 26] = "subject:Re: Tx request: 0x".as_bytes();
4141
let header: [u8; 90] = header_prefix.concat(hex_challenge);
4242
assert(
43-
header == [
44-
115, 117, 98, 106, 101, 99, 116, 58, 82, 101, 58, 32, 84, 120, 32, 114, 101, 113, 117, 101, 115, 116, 58, 32, 48, 120, 48, 100, 54, 55, 56, 50, 52, 102, 101, 97, 100, 57, 54, 54, 49, 57, 50, 48, 50, 57, 48, 57, 51, 97, 51, 97, 97, 53, 99, 55, 49, 57, 102, 50, 98, 56, 48, 50, 54, 50, 99, 52, 102, 49, 52, 97, 53, 99, 57, 55, 99, 53, 100, 55, 48, 101, 52, 98, 50, 55, 102, 50, 98, 102
45-
]
43+
header
44+
== [
45+
115, 117, 98, 106, 101, 99, 116, 58, 82, 101, 58, 32, 84, 120, 32, 114, 101, 113,
46+
117, 101, 115, 116, 58, 32, 48, 120, 48, 100, 54, 55, 56, 50, 52, 102, 101, 97, 100,
47+
57, 54, 54, 49, 57, 50, 48, 50, 57, 48, 57, 51, 97, 51, 97, 97, 53, 99, 55, 49, 57,
48+
102, 50, 98, 56, 48, 50, 54, 50, 99, 52, 102, 49, 52, 97, 53, 99, 57, 55, 99, 53,
49+
100, 55, 48, 101, 52, 98, 50, 55, 102, 50, 98, 102,
50+
],
4651
);
4752
}
4853

0 commit comments

Comments
 (0)