Skip to content

Commit

Permalink
Handle additional memory requests made by RCOMBBASE (#1229)
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Kindi-0 authored Feb 8, 2024
1 parent db476d6 commit d8ae2e5
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 250 deletions.
28 changes: 9 additions & 19 deletions air/src/trace/main_trace.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::super::ColMatrix;
use super::{
super::ColMatrix,
chiplets::{
hasher::{DIGEST_LEN, STATE_WIDTH},
hasher::{DIGEST_LEN, HASH_CYCLE_LEN, STATE_WIDTH},
BITWISE_A_COL_IDX, BITWISE_B_COL_IDX, BITWISE_OUTPUT_COL_IDX, HASHER_NODE_INDEX_COL_IDX,
HASHER_STATE_COL_RANGE, MEMORY_ADDR_COL_IDX, MEMORY_CLK_COL_IDX, MEMORY_CTX_COL_IDX,
MEMORY_V_COL_RANGE,
Expand Down Expand Up @@ -92,19 +92,9 @@ impl MainTrace {
self.addr(i) != self.addr(i + 1)
}

/// First decoder helper register at row i.
pub fn helper_0(&self, i: usize) -> Felt {
self.columns.get_column(DECODER_TRACE_OFFSET + USER_OP_HELPERS_OFFSET)[i]
}

/// Second decoder helper register at row i.
pub fn helper_1(&self, i: usize) -> Felt {
self.columns.get_column(DECODER_TRACE_OFFSET + USER_OP_HELPERS_OFFSET + 1)[i]
}

/// Third decoder helper register at row i.
pub fn helper_2(&self, i: usize) -> Felt {
self.columns.get_column(DECODER_TRACE_OFFSET + USER_OP_HELPERS_OFFSET + 2)[i]
/// The i-th decoder helper register at `row`.
pub fn helper_register(&self, i: usize, row: usize) -> Felt {
self.columns.get_column(DECODER_TRACE_OFFSET + USER_OP_HELPERS_OFFSET + i)[row]
}

/// Returns the hasher state at row i.
Expand Down Expand Up @@ -405,7 +395,7 @@ impl MainTrace {
/// Returns `true` if the hasher chiplet flags indicate the initialization of verifying
/// a Merkle path to an old node during Merkle root update procedure (MRUPDATE).
pub fn f_mv(&self, i: usize) -> bool {
(i % 8 == 0)
(i % HASH_CYCLE_LEN == 0)
&& self.chiplet_selector_0(i) == ZERO
&& self.chiplet_selector_1(i) == ONE
&& self.chiplet_selector_2(i) == ONE
Expand All @@ -415,7 +405,7 @@ impl MainTrace {
/// Returns `true` if the hasher chiplet flags indicate the continuation of verifying
/// a Merkle path to an old node during Merkle root update procedure (MRUPDATE).
pub fn f_mva(&self, i: usize) -> bool {
(i % 8 == 7)
(i % HASH_CYCLE_LEN == HASH_CYCLE_LEN - 1)
&& self.chiplet_selector_0(i) == ZERO
&& self.chiplet_selector_1(i) == ONE
&& self.chiplet_selector_2(i) == ONE
Expand All @@ -425,7 +415,7 @@ impl MainTrace {
/// Returns `true` if the hasher chiplet flags indicate the initialization of verifying
/// a Merkle path to a new node during Merkle root update procedure (MRUPDATE).
pub fn f_mu(&self, i: usize) -> bool {
(i % 8 == 0)
(i % HASH_CYCLE_LEN == 0)
&& self.chiplet_selector_0(i) == ZERO
&& self.chiplet_selector_1(i) == ONE
&& self.chiplet_selector_2(i) == ONE
Expand All @@ -435,7 +425,7 @@ impl MainTrace {
/// Returns `true` if the hasher chiplet flags indicate the continuation of verifying
/// a Merkle path to a new node during Merkle root update procedure (MRUPDATE).
pub fn f_mua(&self, i: usize) -> bool {
(i % 8 == 7)
(i % HASH_CYCLE_LEN == HASH_CYCLE_LEN - 1)
&& self.chiplet_selector_0(i) == ZERO
&& self.chiplet_selector_1(i) == ONE
&& self.chiplet_selector_2(i) == ONE
Expand Down
26 changes: 25 additions & 1 deletion docs/src/design/stack/crypto_ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,28 @@ After calling the `mem_stream ` with `x_ptr`, the operation does the following:
> TODO: add detailed constraint descriptions. See discussion [here](https://github.com/0xPolygonMiden/miden-vm/issues/869).
The effect on the rest of the stack is:
* **No change.**
* **No change.**

The `RCOMBBASE` makes two memory access request. To simplify the description of these, we first define the following variables :

$$
v_1 = \sum_{i=0}^3\alpha_{i+5} \cdot h_{i}
$$

$$
v_2 = \sum_{i=0}^1\alpha_{i+5} \cdot h_{i + 4}
$$

Using the above variables, we define the values representing the memory access request as follows:

$$
u_{mem, 1} = \alpha_0 + \alpha_1 \cdot op_{mem\_read} + \alpha_2 \cdot ctx + \alpha_3 \cdot s_{13} + \alpha_4 \cdot clk + v_1
$$

$$
u_{mem, 2} = \alpha_0 + \alpha_1 \cdot op_{mem\_read} + \alpha_2 \cdot ctx + \alpha_3 \cdot s_{14} + \alpha_4 \cdot clk + v_2
$$

$$
u_{mem} = u_{mem, 1} \cdot u_{mem, 2}
$$
2 changes: 1 addition & 1 deletion docs/src/design/stack/op_constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ This group contains operations which require constraints with degree up to $3$.
| `SPAN` | $86$ | `101_0110` | [Flow control ops](../decoder/main.md) | $5$ |
| `JOIN` | $87$ | `101_0111` | [Flow control ops](../decoder/main.md) | $5$ |
| `DYN` | $88$ | `101_1000` | [Flow control ops](../decoder/main.md) | $5$ |
| `RCombBase` | $89$ | `101_1001` | [Crypto ops](./crypto_ops.md) | $5$ |
| `RCOMBBASE` | $89$ | `101_1001` | [Crypto ops](./crypto_ops.md) | $5$ |
| `<unused>` | $90$ | `101_1010` | | $5$ |
| `<unused>` | $91$ | `101_1011` | | $5$ |
| `<unused>` | $92$ | `101_1100` | | $5$ |
Expand Down
Loading

0 comments on commit d8ae2e5

Please sign in to comment.