Skip to content

Commit 2974b8e

Browse files
authored
chore: pay off more tech debt (#40)
1 parent e45c9b9 commit 2974b8e

22 files changed

+59
-385
lines changed

Nargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ compiler_version = ">=1.0.0"
66

77
[dependencies]
88
noir_sort = {tag = "v0.2.2", git = "https://github.com/noir-lang/noir_sort"}
9+
poseidon = { git = "https://github.com/noir-lang/poseidon", tag = "v0.1.0" }

src/_comparison_tools/bounds_checker.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ in this case, i == M
2626
* cost = 3 gates + 2 gates per iteration
2727
**/
2828
pub fn get_validity_flags<let N: u32>(boundary: u32) -> [Field; N] {
29-
//@Safety: The constraining is happening inside get_validity_flags_inner
29+
// Safety: The constraining is happening inside get_validity_flags_inner
3030
let flags: [Field; N] = unsafe { __get_validity_flags(boundary) };
3131
get_validity_flags_inner(boundary, flags)
3232
}

src/_comparison_tools/lt.nr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub unconstrained fn get_lte_predicate_large(x: Field, y: Field) -> bool {
1414
}
1515

1616
pub fn lte_field_240_bit(x: Field, y: Field) -> bool {
17-
//@Safety: check the comments below
17+
// Safety: check the comments below
1818
let predicate = unsafe { get_lte_predicate_large(x, y) };
1919
let delta = y as Field - x as Field;
2020

@@ -43,7 +43,7 @@ pub fn assert_lte_240_bit(x: Field, y: Field) {
4343
}
4444

4545
pub fn lt_field_16_bit(x: Field, y: Field) -> bool {
46-
//@Safety: check the comments below
46+
// Safety: check the comments below
4747
let predicate = unsafe { get_lt_predicate_f(x, y) };
4848
let delta = y as Field - x as Field;
4949
let lt_parameter = 2 * (predicate as Field) * delta - predicate as Field - delta;
@@ -55,7 +55,7 @@ pub fn lt_field_16_bit(x: Field, y: Field) -> bool {
5555
}
5656

5757
pub fn lt_field_8_bit(x: Field, y: Field) -> bool {
58-
//@Safety: check the comments below
58+
// Safety: check the comments below
5959
let predicate = unsafe { get_lt_predicate_f(x, y) };
6060
let delta = y as Field - x as Field;
6161
let lt_parameter = 2 * (predicate as Field) * delta - predicate as Field - delta;

src/_string_tools/mod.nr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
pub(crate) mod slice_field;
22
pub(crate) mod slice_packed_field;
33
pub(crate) mod string_chopper;
4-
pub(crate) mod sum_bytes_into_field;

src/_string_tools/slice_field.nr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
global PLO: Field = 0x2833E84879B9709143E1F593F0000001;
2-
global PHI: Field = 0x30644E72E131A029B85045B68181585D;
32

43
global PLO_200_felt: Field = 0x29B85045B68181585D2833E84879B9709143E1F593F0000001;
54
global PHI_54_felt: Field = 0x30644E72E131A0;
@@ -10,7 +9,6 @@ struct Slice200 {
109
lohi: u64, // 7 bytes
1110
lolo: u32, // 4 bytes
1211
}
13-
global PHI_54: u64 = 0x30644E72E131A0;
1412
global PLO_200: Slice200 = Slice200 {
1513
hihi: 0x29B85045B68181,
1614
hilo: 0x585D2833E84879,
@@ -64,7 +62,7 @@ unconstrained fn __slice_200_bits_from_field(f: Field) -> (Field, Field, bool) {
6462
}
6563

6664
pub fn slice_200_bits_from_field(f: Field) -> Field {
67-
//@Safety: check the comments below
65+
// Safety: check the comments below
6866
let (lo, hi, borrow) = unsafe { __slice_200_bits_from_field(f) };
6967
// checks that lo and hi are the correct slices of f
7068
assert(hi * TWO_POW_200 + lo == f);

src/_string_tools/slice_packed_field.nr

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -327,44 +327,6 @@ global tail_path_multipliers_chunk0: [Field; 32] = [
327327
0x00,
328328
];
329329

330-
global LIMB_VALID_PATH: [Field; 35] = [
331-
0x000000000, // 0 0 0 0 0 0 0 0 0
332-
0x000000001, // 0 0 0 0 0 0 0 0 1
333-
0x000000003, // 0 0 0 0 0 0 0 1 1
334-
0x000000007, // 0 0 0 0 0 0 1 1 1
335-
0x000000008, // 0 0 0 0 0 1 1 1 1
336-
0x000000010, // 0 0 0 0 1 0 0 0 0
337-
0x000000020, // 0 0 0 1 0 0 0 0 0
338-
0x000000040, // 0 0 1 0 0 0 0 0 0
339-
0x000000080, // 0 1 0 0 0 0 0 0 0
340-
0x000000100, // 1 0 0 0 0 0 0 0 0
341-
0x000000200, // 0 0 0 0 0 0 0 1 0
342-
0x000000400, // 0 0 0 0 0 0 1 0 0
343-
0x000000800, // 0 0 0 0 0 1 0 0 0
344-
0x000001000, // 0 0 0 0 1 0 0 0 0
345-
0x000002000, // 0 0 0 1 0 0 0 0 0
346-
0x000004000, // 0 0 1 0 0 0 0 0 0
347-
0x000008000, // 0 1 0 0 0 0 0 0 0
348-
0x000010000, // 0 0 0 0 0 0 0 0 1
349-
0x000020000, // 0 0 0 0 0 0 0 1 0
350-
0x000040000, // 0 0 0 0 0 0 1 0 0
351-
0x000080000, // 0 0 0 0 0 1 0 0 0
352-
0x000100000, // 0 0 0 0 1 0 0 0 0
353-
0x000200000, // 0 0 0 1 0 0 0 0 0
354-
0x000400000, // 0 0 1 0 0 0 0 0 0
355-
0x000800000, // 0 1 0 0 0 0 0 0 0
356-
0x001000000, // 0 0 0 0 0 0 0 0 1
357-
0x002000000, // 0 0 0 0 0 0 0 1 0
358-
0x004000000, // 0 0 0 0 0 0 1 0 0
359-
0x008000000, // 0 0 0 0 0 1 0 0 0
360-
0x010000000, // 0 0 0 0 1 0 0 0 0
361-
0x020000000, // 0 0 0 1 0 0 0 0 0
362-
0x040000000, // 0 0 1 0 0 0 0 0 0
363-
0x080000000, // 0 1 0 0 0 0 0 0 0
364-
0x100000000,
365-
0x200000000,
366-
];
367-
368330
// these path variables describe the location of a limb in an array
369331
// e.g. LAST_LIMB_PATH[5] produces 2^{5-1},
370332
// which is decomposed into 1 0 0 0 0, and the decompositions turned into an array M
@@ -607,7 +569,7 @@ unconstrained fn __divmod(numerator: Field, denominator: Field) -> (Field, Field
607569
* we know the quotient will fit into a 14 bit range check which will save us some fractional gates
608570
**/
609571
fn divmod_31(numerator: Field) -> (Field, Field) {
610-
//@Safety: we check the bit lengths of qf and rf and their relation to the numerator with assertions later
572+
// Safety: we check the bit lengths of qf and rf and their relation to the numerator with assertions later
611573
let (quotient, remainder) = unsafe { __divmod(numerator, 31) };
612574

613575
let qf = quotient as Field;
@@ -642,7 +604,7 @@ unconstrained fn decompose(val: Field) -> [Field; 16] {
642604
pub fn get_last_limb_path<let OutputFields: u32>(last_limb_index: Field) -> [Field; OutputFields] {
643605
// TODO we offset by 1 explain why (0 byte length produces 0 - 1 which = invalid array index. we just add 1 and increase array length by 1 to compensate)
644606
let path = LAST_LIMB_PATH[last_limb_index + 1]; // 2
645-
//@Safety: check the comments below
607+
// Safety: check the comments below
646608
let path_valid_bits = unsafe { decompose(path) };
647609
let mut path_valid_sum: Field = 0;
648610
let mut path_valid_output: [Field; OutputFields] = [0; OutputFields];
@@ -663,7 +625,7 @@ pub fn get_last_limb_path<let OutputFields: u32>(last_limb_index: Field) -> [Fie
663625
* @details cost 46 gates
664626
**/
665627
pub fn slice_field(f: Field, num_bytes: Field) -> (Field, Field) {
666-
//@Safety: we check the bit lengths of the chunks with assertions later
628+
// Safety: we check the bit lengths of the chunks with assertions later
667629
let chunks = unsafe { __slice_field(f, num_bytes) };
668630
chunks[0].assert_max_bit_size::<8>(); // 1.25 gates
669631
chunks[1].assert_max_bit_size::<16>(); // 1.5 gates
@@ -868,7 +830,7 @@ mod test {
868830
// let start_byte = 26;
869831
let num_bytes = 0;
870832
let start_byte: u32 = 0;
871-
//@Safety: this is a test
833+
// Safety: this is a test
872834
let mut expected_slices: [Field; 3] =
873835
unsafe { build_slices_for_test(text, start_byte, num_bytes) };
874836
let result_slices: [Field; 3] =
@@ -901,19 +863,18 @@ mod test {
901863
let num_bytes = byte_sizes[i];
902864
for j in 0..18 {
903865
let start_byte: u32 = byte_positions[j];
866+
// Safety: this is a test
904867
let mut expected_slices: [Field; 3] =
905-
//@Safety: this is a test
906868
unsafe { build_slices_for_test(text, start_byte, num_bytes) };
907869
let result_slices: [Field; 3] =
908-
//@Safety: this is a test
909-
unsafe { slice_fields(slices, start_byte as Field, num_bytes as Field) };
870+
slice_fields(slices, start_byte as Field, num_bytes as Field);
910871
assert(result_slices == expected_slices);
911872
}
912873

913874
for j in 0..18 {
914875
let start_byte: u32 = text.len() - num_bytes - byte_positions[j];
915876
let mut expected_slices: [Field; 3] =
916-
//@Safety: this is a test
877+
// Safety: this is a test
917878
unsafe { build_slices_for_test(text, start_byte, num_bytes) };
918879
let result_slices: [Field; 3] =
919880
slice_fields(slices, start_byte as Field, num_bytes as Field);

0 commit comments

Comments
 (0)