Skip to content

Commit

Permalink
rm u32 suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
sergerad committed Jul 21, 2024
1 parent d33b0ab commit b575aa0
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 48 deletions.
4 changes: 2 additions & 2 deletions air/src/constraints/chiplets/bitwise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}
}
7 changes: 3 additions & 4 deletions air/src/constraints/chiplets/bitwise/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions air/src/constraints/chiplets/hasher/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -51,9 +51,9 @@ fn get_constraint_evaluation(
fn get_test_periodic_values(cycle_row: Step) -> Vec<Felt> {
// 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],
};

Expand Down
28 changes: 25 additions & 3 deletions air/src/utils.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -19,6 +19,12 @@ impl From<Step> for u32 {
}
}

impl From<Step> for i32 {
fn from(step: Step) -> i32 {
step.0 as i32
}
}

impl From<Step> for usize {
fn from(step: Step) -> usize {
step.0 as usize
Expand Down Expand Up @@ -61,6 +67,14 @@ impl Sub<usize> for Step {
}
}

impl Sub<Step> for usize {
type Output = Step;

fn sub(self, rhs: Step) -> Self::Output {
(self - rhs.0 as usize).into()
}
}

impl Sub<Step> for Step {
type Output = Step;

Expand Down Expand Up @@ -99,6 +113,14 @@ impl AddAssign<usize> for Step {
}
}

impl Mul<Step> for usize {
type Output = Step;

fn mul(self, rhs: Step) -> Self::Output {
(self * rhs.0 as usize).into()
}
}

impl Rem<usize> for Step {
type Output = usize;

Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion processor/src/chiplets/kernel_rom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion processor/src/chiplets/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion processor/src/decoder/aux_trace/block_hash_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
52 changes: 26 additions & 26 deletions processor/src/trace/tests/chiplets/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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);
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit b575aa0

Please sign in to comment.