Skip to content

Commit

Permalink
chore: rebase and resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Kindi-0 committed Nov 29, 2023
1 parent b30cac6 commit 99ce513
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 288 deletions.
48 changes: 47 additions & 1 deletion processor/src/chiplets/aux_trace/main_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use miden_air::trace::{
CHIPLETS_OFFSET, CLK_COL_IDX, CTX_COL_IDX, DECODER_TRACE_OFFSET, STACK_TRACE_OFFSET,
};

use vm_core::{utils::range, ZERO};
use vm_core::{utils::range, ONE, ZERO};
const DECODER_HASHER_RANGE: Range<usize> =
range(DECODER_TRACE_OFFSET + HASHER_STATE_OFFSET, NUM_HASHER_COLUMNS);

Expand Down Expand Up @@ -230,4 +230,50 @@ impl<'a> MainTrace<'a> {
pub fn chiplet_kernel_root_3(&self, i: usize) -> Felt {
self.columns.get_column(CHIPLETS_OFFSET + 9)[i]
}
// Merkle path hashing selectors

pub fn f_mv(&self, i: usize) -> bool {
(i % 8 == 0)
&& self.chiplet_selector_0(i) == ZERO
&& self.chiplet_selector_1(i) == ONE
&& self.chiplet_selector_2(i) == ONE
&& self.chiplet_selector_3(i) == ZERO
}

pub fn f_mva(&self, i: usize) -> bool {
(i % 8 == 7)
&& self.chiplet_selector_0(i) == ZERO
&& self.chiplet_selector_1(i) == ONE
&& self.chiplet_selector_2(i) == ONE
&& self.chiplet_selector_3(i) == ZERO
}

pub fn f_mu(&self, i: usize) -> bool {
(i % 8 == 0)
&& self.chiplet_selector_0(i) == ZERO
&& self.chiplet_selector_1(i) == ONE
&& self.chiplet_selector_2(i) == ONE
&& self.chiplet_selector_3(i) == ONE
}

pub fn f_mua(&self, i: usize) -> bool {
(i % 8 == 7)
&& self.chiplet_selector_0(i) == ZERO
&& self.chiplet_selector_1(i) == ONE
&& self.chiplet_selector_2(i) == ONE
&& self.chiplet_selector_3(i) == ONE
}

// Detects if a row is part of the kernel chiplet.
pub fn is_kernel_row(&self, i: usize) -> bool {
self.chiplet_selector_0(i) == ONE
&& self.chiplet_selector_1(i) == ONE
&& self.chiplet_selector_2(i) == ONE
&& self.chiplet_selector_3(i) == ZERO
}

// Helper method to detect change of address in the kernel ROM chiplet.
pub fn is_addr_change(&self, i: usize) -> bool {
self.addr(i) != self.addr(i + 1)
}
}
287 changes: 0 additions & 287 deletions processor/src/chiplets/aux_trace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,293 +1134,6 @@ where
+ alphas[5].mul_base(root3)
}

// HELPER FUNCTIONS
// ================================================================================================

const JOIN: u8 = Operation::Join.op_code();
const SPLIT: u8 = Operation::Split.op_code();
const LOOP: u8 = Operation::Loop.op_code();
const DYN: u8 = Operation::Dyn.op_code();
const CALL: u8 = Operation::Call.op_code();
const SYSCALL: u8 = Operation::SysCall.op_code();
const SPAN: u8 = Operation::Span.op_code();
const RESPAN: u8 = Operation::Respan.op_code();
const END: u8 = Operation::End.op_code();
const AND: u8 = Operation::U32and.op_code();
const XOR: u8 = Operation::U32xor.op_code();
const MLOADW: u8 = Operation::MLoadW.op_code();
const MSTOREW: u8 = Operation::MStoreW.op_code();
const MLOAD: u8 = Operation::MLoad.op_code();
const MSTORE: u8 = Operation::MStore.op_code();
const MSTREAM: u8 = Operation::MStream.op_code();
const HPERM: u8 = Operation::HPerm.op_code();
const MPVERIFY: u8 = Operation::MpVerify.op_code();
const MRUPDATE: u8 = Operation::MrUpdate.op_code();
const DECODER_HASHER_RANGE: Range<usize> =
range(DECODER_TRACE_OFFSET + HASHER_STATE_OFFSET, NUM_HASHER_COLUMNS);

struct MainTrace<'a> {
columns: &'a ColMatrix<Felt>,
}

impl<'a> MainTrace<'a> {
pub fn new(main_trace: &'a ColMatrix<Felt>) -> Self {
Self {
columns: main_trace,
}
}

// System columns

pub fn clk(&self, i: usize) -> Felt {
self.columns.get_column(CLK_COL_IDX)[i]
}

pub fn ctx(&self, i: usize) -> Felt {
self.columns.get_column(CTX_COL_IDX)[i]
}

// Decoder columns

pub fn addr(&self, i: usize) -> Felt {
self.columns.get_column(DECODER_TRACE_OFFSET)[i]
}

pub fn helper_0(&self, i: usize) -> Felt {
self.columns.get_column(DECODER_TRACE_OFFSET + USER_OP_HELPERS_OFFSET)[i]
}

pub fn helper_1(&self, i: usize) -> Felt {
self.columns.get_column(DECODER_TRACE_OFFSET + USER_OP_HELPERS_OFFSET + 1)[i]
}

pub fn helper_2(&self, i: usize) -> Felt {
self.columns.get_column(DECODER_TRACE_OFFSET + USER_OP_HELPERS_OFFSET + 2)[i]
}

pub fn decoder_hasher_state(&self, i: usize) -> [Felt; NUM_HASHER_COLUMNS] {
let mut state = [ZERO; NUM_HASHER_COLUMNS];
for (idx, col_idx) in DECODER_HASHER_RANGE.enumerate() {
let column = self.columns.get_column(col_idx);
state[idx] = column[i];
}
state
}

pub fn get_op_code(&self, i: usize) -> Felt {
let col_b0 = self.columns.get_column(DECODER_TRACE_OFFSET + 1);
let col_b1 = self.columns.get_column(DECODER_TRACE_OFFSET + 2);
let col_b2 = self.columns.get_column(DECODER_TRACE_OFFSET + 3);
let col_b3 = self.columns.get_column(DECODER_TRACE_OFFSET + 4);
let col_b4 = self.columns.get_column(DECODER_TRACE_OFFSET + 5);
let col_b5 = self.columns.get_column(DECODER_TRACE_OFFSET + 6);
let col_b6 = self.columns.get_column(DECODER_TRACE_OFFSET + 7);
let [b0, b1, b2, b3, b4, b5, b6] =
[col_b0[i], col_b1[i], col_b2[i], col_b3[i], col_b4[i], col_b5[i], col_b6[i]];
b0 + b1.mul_small(2)
+ b2.mul_small(4)
+ b3.mul_small(8)
+ b4.mul_small(16)
+ b5.mul_small(32)
+ b6.mul_small(64)
}

// Stack columns

pub fn s0(&self, i: usize) -> Felt {
self.columns.get_column(STACK_TRACE_OFFSET)[i]
}

pub fn s1(&self, i: usize) -> Felt {
self.columns.get_column(STACK_TRACE_OFFSET + 1)[i]
}

pub fn s2(&self, i: usize) -> Felt {
self.columns.get_column(STACK_TRACE_OFFSET + 2)[i]
}

pub fn s3(&self, i: usize) -> Felt {
self.columns.get_column(STACK_TRACE_OFFSET + 3)[i]
}

pub fn s4(&self, i: usize) -> Felt {
self.columns.get_column(STACK_TRACE_OFFSET + 4)[i]
}

pub fn s5(&self, i: usize) -> Felt {
self.columns.get_column(STACK_TRACE_OFFSET + 5)[i]
}

pub fn s6(&self, i: usize) -> Felt {
self.columns.get_column(STACK_TRACE_OFFSET + 6)[i]
}

pub fn s7(&self, i: usize) -> Felt {
self.columns.get_column(STACK_TRACE_OFFSET + 7)[i]
}

pub fn s8(&self, i: usize) -> Felt {
self.columns.get_column(STACK_TRACE_OFFSET + 8)[i]
}

pub fn s9(&self, i: usize) -> Felt {
self.columns.get_column(STACK_TRACE_OFFSET + 9)[i]
}

pub fn s10(&self, i: usize) -> Felt {
self.columns.get_column(STACK_TRACE_OFFSET + 10)[i]
}

pub fn s11(&self, i: usize) -> Felt {
self.columns.get_column(STACK_TRACE_OFFSET + 11)[i]
}

pub fn s12(&self, i: usize) -> Felt {
self.columns.get_column(STACK_TRACE_OFFSET + 12)[i]
}

pub fn s13(&self, i: usize) -> Felt {
self.columns.get_column(STACK_TRACE_OFFSET + 13)[i]
}

// Chiplets columns

pub fn chiplet_selector_0(&self, i: usize) -> Felt {
self.columns.get_column(CHIPLETS_OFFSET)[i]
}

pub fn chiplet_selector_1(&self, i: usize) -> Felt {
self.columns.get_column(CHIPLETS_OFFSET + 1)[i]
}

pub fn chiplet_selector_2(&self, i: usize) -> Felt {
self.columns.get_column(CHIPLETS_OFFSET + 2)[i]
}

pub fn chiplet_selector_3(&self, i: usize) -> Felt {
self.columns.get_column(CHIPLETS_OFFSET + 3)[i]
}

pub fn chiplet_selector_4(&self, i: usize) -> Felt {
self.columns.get_column(CHIPLETS_OFFSET + 4)[i]
}

pub fn chiplet_hasher_state(&self, i: usize) -> [Felt; STATE_WIDTH] {
let mut state = [ZERO; STATE_WIDTH];
for (idx, col_idx) in HASHER_STATE_COL_RANGE.enumerate() {
let column = self.columns.get_column(col_idx);
state[idx] = column[i];
}
state
}

pub fn chiplet_node_index(&self, i: usize) -> Felt {
self.columns.get(HASHER_NODE_INDEX_COL_IDX, i)
}

pub fn chiplet_bitwise_a(&self, i: usize) -> Felt {
self.columns.get_column(BITWISE_A_COL_IDX)[i]
}

pub fn chiplet_bitwise_b(&self, i: usize) -> Felt {
self.columns.get_column(BITWISE_B_COL_IDX)[i]
}

pub fn chiplet_bitwise_z(&self, i: usize) -> Felt {
self.columns.get_column(BITWISE_OUTPUT_COL_IDX)[i]
}

pub fn chiplet_memory_ctx(&self, i: usize) -> Felt {
self.columns.get_column(MEMORY_CTX_COL_IDX)[i]
}

pub fn chiplet_memory_addr(&self, i: usize) -> Felt {
self.columns.get_column(MEMORY_ADDR_COL_IDX)[i]
}

pub fn chiplet_memory_clk(&self, i: usize) -> Felt {
self.columns.get_column(MEMORY_CLK_COL_IDX)[i]
}

pub fn chiplet_memory_value_0(&self, i: usize) -> Felt {
self.columns.get_column(MEMORY_V_COL_RANGE.start)[i]
}

pub fn chiplet_memory_value_1(&self, i: usize) -> Felt {
self.columns.get_column(MEMORY_V_COL_RANGE.start + 1)[i]
}

pub fn chiplet_memory_value_2(&self, i: usize) -> Felt {
self.columns.get_column(MEMORY_V_COL_RANGE.start + 2)[i]
}

pub fn chiplet_memory_value_3(&self, i: usize) -> Felt {
self.columns.get_column(MEMORY_V_COL_RANGE.start + 3)[i]
}

fn chiplet_kernel_root_0(&self, i: usize) -> Felt {
self.columns.get_column(CHIPLETS_OFFSET + 6)[i]
}

fn chiplet_kernel_root_1(&self, i: usize) -> Felt {
self.columns.get_column(CHIPLETS_OFFSET + 7)[i]
}

fn chiplet_kernel_root_2(&self, i: usize) -> Felt {
self.columns.get_column(CHIPLETS_OFFSET + 8)[i]
}

fn chiplet_kernel_root_3(&self, i: usize) -> Felt {
self.columns.get_column(CHIPLETS_OFFSET + 9)[i]
}

// Merkle path hashing selectors

fn f_mv(&self, i: usize) -> bool {
(i % 8 == 0)
&& self.chiplet_selector_0(i) == ZERO
&& self.chiplet_selector_1(i) == ONE
&& self.chiplet_selector_2(i) == ONE
&& self.chiplet_selector_3(i) == ZERO
}

fn f_mva(&self, i: usize) -> bool {
(i % 8 == 7)
&& self.chiplet_selector_0(i) == ZERO
&& self.chiplet_selector_1(i) == ONE
&& self.chiplet_selector_2(i) == ONE
&& self.chiplet_selector_3(i) == ZERO
}

fn f_mu(&self, i: usize) -> bool {
(i % 8 == 0)
&& self.chiplet_selector_0(i) == ZERO
&& self.chiplet_selector_1(i) == ONE
&& self.chiplet_selector_2(i) == ONE
&& self.chiplet_selector_3(i) == ONE
}

fn f_mua(&self, i: usize) -> bool {
(i % 8 == 7)
&& self.chiplet_selector_0(i) == ZERO
&& self.chiplet_selector_1(i) == ONE
&& self.chiplet_selector_2(i) == ONE
&& self.chiplet_selector_3(i) == ONE
}

fn is_kernel_row(&self, i: usize) -> bool {
self.chiplet_selector_0(i) == ONE
&& self.chiplet_selector_1(i) == ONE
&& self.chiplet_selector_2(i) == ONE
&& self.chiplet_selector_3(i) == ZERO
}

// Helper method to detect change of address in the kernel ROM chiplet.
fn is_addr_change(&self, i: usize) -> bool {
self.addr(i) != self.addr(i + 1)
}
}

/// Reduces a slice of elements to a single field element in the field specified by E using a slice
/// of alphas of matching length. This can be used to build the value for a single word or for an
/// entire [HasherState].
Expand Down

0 comments on commit 99ce513

Please sign in to comment.