From b575aa01346d139ca7f82efc9cbeeaad04c6aab6 Mon Sep 17 00:00:00 2001 From: sergerad Date: Sun, 21 Jul 2024 18:34:06 +1200 Subject: [PATCH] rm u32 suffix --- air/src/constraints/chiplets/bitwise/mod.rs | 4 +- air/src/constraints/chiplets/bitwise/tests.rs | 7 ++- air/src/constraints/chiplets/hasher/tests.rs | 8 +-- air/src/utils.rs | 28 ++++++++-- processor/src/chiplets/kernel_rom/mod.rs | 2 +- processor/src/chiplets/memory/mod.rs | 2 +- .../src/decoder/aux_trace/block_hash_table.rs | 2 +- processor/src/trace/tests/chiplets/hasher.rs | 52 +++++++++---------- processor/src/trace/tests/chiplets/memory.rs | 12 ++--- 9 files changed, 69 insertions(+), 48 deletions(-) diff --git a/air/src/constraints/chiplets/bitwise/mod.rs b/air/src/constraints/chiplets/bitwise/mod.rs index 48cb4eb694..8875bfdf9e 100644 --- a/air/src/constraints/chiplets/bitwise/mod.rs +++ b/air/src/constraints/chiplets/bitwise/mod.rs @@ -426,8 +426,8 @@ pub const BITWISE_K1_MASK: [Felt; OP_CYCLE_LEN] = [ONE, ONE, ONE, ONE, ONE, ONE, #[cfg(test)] fn get_periodic_values(cycle_row: crate::utils::Step) -> [Felt; 2] { match cycle_row.into() { - 0u32 => [ONE, ONE], - 8u32 => [ZERO, ZERO], + 0 => [ONE, ONE], + 8 => [ZERO, ZERO], _ => [ZERO, ONE], } } diff --git a/air/src/constraints/chiplets/bitwise/tests.rs b/air/src/constraints/chiplets/bitwise/tests.rs index 9ea31d5cb1..2018b3af59 100644 --- a/air/src/constraints/chiplets/bitwise/tests.rs +++ b/air/src/constraints/chiplets/bitwise/tests.rs @@ -46,7 +46,7 @@ fn test_bitwise_change_ops_fail() { /// cycle when the low limb of a is one. #[test] fn output_aggregation_and() { - let cycle_row: Step = 0u32.into(); + let cycle_row: Step = 0.into(); // create a valid test frame manually let mut current = vec![ZERO; TRACE_WIDTH]; @@ -249,12 +249,11 @@ pub fn get_test_frame_with_two_ops( /// which is the number of the `current` row within the operation cycle. fn get_row_shifts(cycle_row: Step) -> (Step, Step, Step) { // Define the shift amount for output in this row and the next row. - let cycle_row_num: usize = cycle_row.into(); - let current_shift = NUM_DECOMP_BITS * (OP_CYCLE_LEN - cycle_row_num - 1); + let current_shift = NUM_DECOMP_BITS * (OP_CYCLE_LEN - cycle_row - 1); let previous_shift = current_shift + NUM_DECOMP_BITS; let next_shift = current_shift - NUM_DECOMP_BITS; - (previous_shift.into(), current_shift.into(), next_shift.into()) + (previous_shift, current_shift, next_shift) } /// Sets the input aggregation and decomposition columns in the provided current and next rows with diff --git a/air/src/constraints/chiplets/hasher/tests.rs b/air/src/constraints/chiplets/hasher/tests.rs index 8531852d45..b1d4f42cba 100644 --- a/air/src/constraints/chiplets/hasher/tests.rs +++ b/air/src/constraints/chiplets/hasher/tests.rs @@ -21,7 +21,7 @@ use winter_air::EvaluationFrame; fn hash_round() { let expected = [ZERO; NUM_CONSTRAINTS]; - let cycle_row = 3u32.into(); + let cycle_row = 3.into(); let current_selectors = [ZERO, LINEAR_HASH[1], LINEAR_HASH[2]]; let next_selectors = current_selectors; @@ -51,9 +51,9 @@ fn get_constraint_evaluation( fn get_test_periodic_values(cycle_row: Step) -> Vec { // Set the periodic column values. let mut periodic_values = match cycle_row.into() { - 0u32 => vec![ZERO, ZERO, ONE], - 7u32 => vec![ZERO, ONE, ZERO], - 8u32 => vec![ONE, ZERO, ZERO], + 0 => vec![ZERO, ZERO, ONE], + 7 => vec![ZERO, ONE, ZERO], + 8 => vec![ONE, ZERO, ZERO], _ => vec![ZERO, ZERO, ZERO], }; diff --git a/air/src/utils.rs b/air/src/utils.rs index b09285ce2a..cc08af03bb 100644 --- a/air/src/utils.rs +++ b/air/src/utils.rs @@ -1,5 +1,5 @@ use alloc::vec::Vec; -use core::ops::{Add, AddAssign, Index, IndexMut, Range, Rem, Shr, Sub}; +use core::ops::{Add, AddAssign, Index, IndexMut, Mul, Range, Rem, Shr, Sub}; use super::FieldElement; use vm_core::{utils::range as create_range, Felt}; @@ -19,6 +19,12 @@ impl From for u32 { } } +impl From for i32 { + fn from(step: Step) -> i32 { + step.0 as i32 + } +} + impl From for usize { fn from(step: Step) -> usize { step.0 as usize @@ -61,6 +67,14 @@ impl Sub for Step { } } +impl Sub for usize { + type Output = Step; + + fn sub(self, rhs: Step) -> Self::Output { + (self - rhs.0 as usize).into() + } +} + impl Sub for Step { type Output = Step; @@ -99,6 +113,14 @@ impl AddAssign for Step { } } +impl Mul for usize { + type Output = Step; + + fn mul(self, rhs: Step) -> Self::Output { + (self * rhs.0 as usize).into() + } +} + impl Rem for Step { type Output = usize; @@ -299,7 +321,7 @@ mod tests { // Into Step let _: Step = 5.into(); let _: Step = 5u32.into(); - let _: Step = (5_usize).into(); + let _: Step = (5usize).into(); // From Step let _: u32 = Step(5).into(); @@ -318,7 +340,7 @@ mod tests { assert_eq!(Step(5) + 3, 8); assert_eq!(Step(5) - 3, 2); assert_eq!(3 + Step(5), 8); - assert_eq!(6 - Step(5), 1); + assert_eq!(2 * Step(5), 10); assert_eq!(Step(5) % 3, 2); // Add assign diff --git a/processor/src/chiplets/kernel_rom/mod.rs b/processor/src/chiplets/kernel_rom/mod.rs index e8507d6f9a..42bfb13d65 100644 --- a/processor/src/chiplets/kernel_rom/mod.rs +++ b/processor/src/chiplets/kernel_rom/mod.rs @@ -99,7 +99,7 @@ impl KernelRom { /// Populates the provided execution trace fragment with execution trace of this kernel ROM. pub fn fill_trace(self, trace: &mut TraceFragment) { debug_assert_eq!(TRACE_WIDTH, trace.width(), "inconsistent trace fragment width"); - let mut row: Step = 0u32.into(); + let mut row: Step = 0.into(); for (idx, access_info) in self.access_map.values().enumerate() { let idx = Felt::from(idx as u16); diff --git a/processor/src/chiplets/memory/mod.rs b/processor/src/chiplets/memory/mod.rs index ae1d6d68c7..ce2f15f488 100644 --- a/processor/src/chiplets/memory/mod.rs +++ b/processor/src/chiplets/memory/mod.rs @@ -206,7 +206,7 @@ impl Memory { // iterate through addresses in ascending order, and write trace row for each memory access // into the trace. we expect the trace to be 14 columns wide. - let mut row: Step = 0u32.into(); + let mut row: Step = 0.into(); for (ctx, segment) in self.trace { let ctx = Felt::from(ctx); diff --git a/processor/src/decoder/aux_trace/block_hash_table.rs b/processor/src/decoder/aux_trace/block_hash_table.rs index 99fb544db9..8da307d20e 100644 --- a/processor/src/decoder/aux_trace/block_hash_table.rs +++ b/processor/src/decoder/aux_trace/block_hash_table.rs @@ -90,7 +90,7 @@ impl BlockHashTableRow { pub fn table_init(main_trace: &MainTrace) -> Self { let program_hash = { let row_with_halt = (0..main_trace.num_rows()) - .find(|row| main_trace.get_op_code(Step::from(*row)) == Felt::from(OPCODE_HALT)) + .find(|row| main_trace.get_op_code((*row).into()) == Felt::from(OPCODE_HALT)) .expect("execution trace must include at least one occurrence of HALT"); main_trace.decoder_hasher_state_first_half(row_with_halt.into()) diff --git a/processor/src/trace/tests/chiplets/hasher.rs b/processor/src/trace/tests/chiplets/hasher.rs index e5818a2361..99e9eddfe5 100644 --- a/processor/src/trace/tests/chiplets/hasher.rs +++ b/processor/src/trace/tests/chiplets/hasher.rs @@ -74,14 +74,14 @@ pub fn b_chip_span() { // initialize the request state. let mut state = [ZERO; STATE_WIDTH]; - fill_state_from_decoder_with_domain(&trace, &mut state, 0u32.into()); + fill_state_from_decoder_with_domain(&trace, &mut state, 0.into()); // request the initialization of the span hash let request_init = build_expected(&alphas, LINEAR_HASH_LABEL, state, [ZERO; STATE_WIDTH], ONE, ZERO); let mut expected = request_init.inv(); // provide the initialization of the span hash - expected *= build_expected_from_trace(&trace, &alphas, 0u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 0.into()); assert_eq!(expected, b_chip[1]); // Nothing changes when there is no communication with the hash chiplet. @@ -146,14 +146,14 @@ pub fn b_chip_span_with_respan() { // initialize the request state. let mut state = [ZERO; STATE_WIDTH]; - fill_state_from_decoder_with_domain(&trace, &mut state, 0u32.into()); + fill_state_from_decoder_with_domain(&trace, &mut state, 0.into()); // request the initialization of the span hash let request_init = build_expected(&alphas, LINEAR_HASH_LABEL, state, [ZERO; STATE_WIDTH], ONE, ZERO); let mut expected = request_init.inv(); // provide the initialization of the span hash - expected *= build_expected_from_trace(&trace, &alphas, 0u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 0.into()); assert_eq!(expected, b_chip[1]); // Nothing changes when there is no communication with the hash chiplet. @@ -163,7 +163,7 @@ pub fn b_chip_span_with_respan() { // At the end of the first hash cycle at cycle 7, the absorption of the next operation batch is // provided by the hasher. - expected *= build_expected_from_trace(&trace, &alphas, 7u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 7.into()); assert_eq!(expected, b_chip[8]); // Nothing changes when there is no communication with the hash chiplet. @@ -174,7 +174,7 @@ pub fn b_chip_span_with_respan() { apply_permutation(&mut state); let prev_state = state; // get the state with the next absorbed batch. - fill_state_from_decoder(&trace, &mut state, 9u32.into()); + fill_state_from_decoder(&trace, &mut state, 9.into()); let request_respan = build_expected(&alphas, LINEAR_HASH_LABEL, prev_state, state, Felt::new(8), ZERO); @@ -188,7 +188,7 @@ pub fn b_chip_span_with_respan() { // At cycle 15 at the end of the second hash cycle, the result of the span hash is provided by // the hasher - expected *= build_expected_from_trace(&trace, &alphas, 15u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 15.into()); assert_eq!(expected, b_chip[16]); // Nothing changes when there is no communication with the hash chiplet. @@ -245,20 +245,20 @@ pub fn b_chip_merge() { // initialize the request state. let mut split_state = [ZERO; STATE_WIDTH]; - fill_state_from_decoder_with_domain(&trace, &mut split_state, 0u32.into()); + fill_state_from_decoder_with_domain(&trace, &mut split_state, 0.into()); // request the initialization of the span hash let split_init = build_expected(&alphas, LINEAR_HASH_LABEL, split_state, [ZERO; STATE_WIDTH], ONE, ZERO); let mut expected = split_init.inv(); // provide the initialization of the span hash - expected *= build_expected_from_trace(&trace, &alphas, 0u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 0.into()); assert_eq!(expected, b_chip[1]); // at cycle 1 the initialization of the span block hash for the false branch is requested by the // decoder let mut f_branch_state = [ZERO; STATE_WIDTH]; - fill_state_from_decoder_with_domain(&trace, &mut f_branch_state, 1u32.into()); + fill_state_from_decoder_with_domain(&trace, &mut f_branch_state, 1.into()); // request the initialization of the false branch hash let f_branch_init = build_expected( &alphas, @@ -306,12 +306,12 @@ pub fn b_chip_merge() { } // at cycle 7 the result of the merge is provided by the hasher - expected *= build_expected_from_trace(&trace, &alphas, 7u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 7.into()); assert_eq!(expected, b_chip[8]); // at cycle 8 the initialization of the hash of the span block for the false branch is provided // by the hasher - expected *= build_expected_from_trace(&trace, &alphas, 8u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 8.into()); assert_eq!(expected, b_chip[9]); // Nothing changes when there is no communication with the hash chiplet. @@ -320,7 +320,7 @@ pub fn b_chip_merge() { } // at cycle 15 the result of the span block for the false branch is provided by the hasher - expected *= build_expected_from_trace(&trace, &alphas, 15u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 15.into()); assert_eq!(expected, b_chip[16]); // The value in b_chip should be ONE now and for the rest of the trace. @@ -364,13 +364,13 @@ pub fn b_chip_permutation() { // initialize the request state. let mut span_state = [ZERO; STATE_WIDTH]; - fill_state_from_decoder_with_domain(&trace, &mut span_state, 0u32.into()); + fill_state_from_decoder_with_domain(&trace, &mut span_state, 0.into()); // request the initialization of the span hash let span_init = build_expected(&alphas, LINEAR_HASH_LABEL, span_state, [ZERO; STATE_WIDTH], ONE, ZERO); let mut expected = span_init.inv(); // provide the initialization of the span hash - expected *= build_expected_from_trace(&trace, &alphas, 0u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 0.into()); assert_eq!(expected, b_chip[1]); // at cycle 1 hperm is executed and the initialization and result of the hash are both @@ -417,11 +417,11 @@ pub fn b_chip_permutation() { } // at cycle 7 the result of the span hash is provided by the hasher - expected *= build_expected_from_trace(&trace, &alphas, 7u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 7.into()); assert_eq!(expected, b_chip[8]); // at cycle 8 the initialization of the hperm hash is provided by the hasher - expected *= build_expected_from_trace(&trace, &alphas, 8u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 8.into()); assert_eq!(expected, b_chip[9]); // Nothing changes when there is no communication with the hash chiplet. @@ -430,7 +430,7 @@ pub fn b_chip_permutation() { } // at cycle 15 the result of the hperm hash is provided by the hasher - expected *= build_expected_from_trace(&trace, &alphas, 15u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 15.into()); assert_eq!(expected, b_chip[16]); // The value in b_chip should be ONE now and for the rest of the trace. @@ -479,13 +479,13 @@ fn b_chip_mpverify() { // initialize the request state. let mut span_state = [ZERO; STATE_WIDTH]; - fill_state_from_decoder_with_domain(&trace, &mut span_state, 0u32.into()); + fill_state_from_decoder_with_domain(&trace, &mut span_state, 0.into()); // request the initialization of the span hash let span_init = build_expected(&alphas, LINEAR_HASH_LABEL, span_state, [ZERO; STATE_WIDTH], ONE, ZERO); let mut expected = span_init.inv(); // provide the initialization of the span hash - expected *= build_expected_from_trace(&trace, &alphas, 0u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 0.into()); assert_eq!(expected, b_chip[1]); // at cycle 1 a merkle path verification is executed and the initialization and result of the @@ -554,11 +554,11 @@ fn b_chip_mpverify() { } // at cycle 7 the result of the span hash is provided by the hasher - expected *= build_expected_from_trace(&trace, &alphas, 7u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 7.into()); assert_eq!(expected, b_chip[8]); // at cycle 8 the initialization of the merkle path is provided by the hasher - expected *= build_expected_from_trace(&trace, &alphas, 8u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 8.into()); assert_eq!(expected, b_chip[9]); // Nothing changes when there is no communication with the hash chiplet. @@ -625,13 +625,13 @@ fn b_chip_mrupdate() { // initialize the request state. let mut span_state = [ZERO; STATE_WIDTH]; - fill_state_from_decoder_with_domain(&trace, &mut span_state, 0u32.into()); + fill_state_from_decoder_with_domain(&trace, &mut span_state, 0.into()); // request the initialization of the span hash let span_init = build_expected(&alphas, LINEAR_HASH_LABEL, span_state, [ZERO; STATE_WIDTH], ONE, ZERO); let mut expected = span_init.inv(); // provide the initialization of the span hash - expected *= build_expected_from_trace(&trace, &alphas, 0u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 0.into()); assert_eq!(expected, b_chip[1]); // at cycle 1 a merkle path verification is executed and the initialization and result of the @@ -754,11 +754,11 @@ fn b_chip_mrupdate() { } // at cycle 7 the result of the span hash is provided by the hasher - expected *= build_expected_from_trace(&trace, &alphas, 7u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 7.into()); assert_eq!(expected, b_chip[8]); // at cycle 8 the initialization of the first merkle path is provided by the hasher - expected *= build_expected_from_trace(&trace, &alphas, 8u32.into()); + expected *= build_expected_from_trace(&trace, &alphas, 8.into()); assert_eq!(expected, b_chip[9]); // Nothing changes when there is no communication with the hash chiplet. diff --git a/processor/src/trace/tests/chiplets/memory.rs b/processor/src/trace/tests/chiplets/memory.rs index 0d6027d8bf..7e4bef6911 100644 --- a/processor/src/trace/tests/chiplets/memory.rs +++ b/processor/src/trace/tests/chiplets/memory.rs @@ -86,15 +86,15 @@ fn b_chip_trace_mem() { let value = build_expected_memory(&rand_elements, MEMORY_READ_LABEL, ZERO, ZERO, Felt::new(8), word); expected *= value.inv(); - expected *= build_expected_memory_from_trace(&trace, &rand_elements, 8u32.into()); + expected *= build_expected_memory_from_trace(&trace, &rand_elements, 8.into()); assert_eq!(expected, b_chip[9]); // At cycle 9, `MLoad` is provided by memory. - expected *= build_expected_memory_from_trace(&trace, &rand_elements, 9u32.into()); + expected *= build_expected_memory_from_trace(&trace, &rand_elements, 9.into()); assert_eq!(expected, b_chip[10]); // At cycle 10, `MLoadW` is provided by memory. - expected *= build_expected_memory_from_trace(&trace, &rand_elements, 10u32.into()); + expected *= build_expected_memory_from_trace(&trace, &rand_elements, 10.into()); assert_eq!(expected, b_chip[11]); // At cycle 11, `MStore` is requested by the stack and the first read of `MStream` is provided @@ -108,11 +108,11 @@ fn b_chip_trace_mem() { [ONE, ZERO, ZERO, ZERO], ); expected *= value.inv(); - expected *= build_expected_memory_from_trace(&trace, &rand_elements, 11u32.into()); + expected *= build_expected_memory_from_trace(&trace, &rand_elements, 11.into()); assert_eq!(expected, b_chip[12]); // At cycle 12, `MStore` is provided by the memory - expected *= build_expected_memory_from_trace(&trace, &rand_elements, 12u32.into()); + expected *= build_expected_memory_from_trace(&trace, &rand_elements, 12.into()); assert_eq!(expected, b_chip[13]); // At cycle 13, `MStream` is requested by the stack, and the second read of `MStream` is @@ -128,7 +128,7 @@ fn b_chip_trace_mem() { [ONE, ZERO, ZERO, ZERO], ); expected *= (value1 * value2).inv(); - expected *= build_expected_memory_from_trace(&trace, &rand_elements, 13u32.into()); + expected *= build_expected_memory_from_trace(&trace, &rand_elements, 13.into()); assert_eq!(expected, b_chip[14]); // At cycle 14 the decoder requests the span hash. We set this as the inverse of the previously