Skip to content

Commit

Permalink
chore: update tests, improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fumuran committed Oct 2, 2024
1 parent 6c1cd08 commit 91b25f7
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 73 deletions.
4 changes: 2 additions & 2 deletions miden/tests/integration/operations/decorators/advice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use test_utils::{
expect_exec_error,
rand::{rand_array, rand_value},
serde::Serializable,
Felt, TRUNCATE_STACK,
Felt, TRUNCATE_STACK_PROC,
};

const ADVICE_PUSH_SIG: &str = "
Expand Down Expand Up @@ -67,7 +67,7 @@ fn advice_push_u64div_repeat() {
// Finally the first 2 elements of the stack are removed
let source = format!(
"
{TRUNCATE_STACK}
{TRUNCATE_STACK_PROC}
begin
repeat.7
Expand Down
7 changes: 1 addition & 6 deletions miden/tests/integration/operations/field_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@ fn div_b() {
"11 |",
"12 | begin div.0 exec.truncate_stack end",
" : ^^^^^",
"13 |",
" `----",
r#" help: expected primitive opcode (e.g. "add"), or "end", or control flow opcode (e.g. "if.true")"#
" `----"
);

let test = build_op_test!(build_asm_op(2), &[4]);
Expand Down Expand Up @@ -253,7 +251,6 @@ fn neg_fail() {
"12 | begin neg.1 exec.truncate_stack end",
" : |",
" : `-- found a . here",
"13 |",
" `----",
r#" help: expected primitive opcode (e.g. "add"), or "end", or control flow opcode (e.g. "if.true")"#
);
Expand Down Expand Up @@ -297,7 +294,6 @@ fn inv_fail() {
"12 | begin inv.1 exec.truncate_stack end",
" : |",
" : `-- found a . here",
"13 |",
" `----",
r#" help: expected primitive opcode (e.g. "add"), or "end", or control flow opcode (e.g. "if.true")"#
);
Expand Down Expand Up @@ -380,7 +376,6 @@ fn exp_bits_length_fail() {
"11 |",
"12 | begin exp.u65 exec.truncate_stack end",
" : ^^",
"13 |",
" `----",
r#" help: expected primitive opcode (e.g. "add"), or "end", or control flow opcode (e.g. "if.true")"#
);
Expand Down
4 changes: 2 additions & 2 deletions miden/tests/integration/operations/fri_ops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use test_utils::{build_test, push_inputs, rand::rand_array, Felt, FieldElement, TRUNCATE_STACK};
use test_utils::{build_test, push_inputs, rand::rand_array, Felt, FieldElement, TRUNCATE_STACK_PROC};

// FRI_EXT2FOLD4
// ================================================================================================
Expand All @@ -20,7 +20,7 @@ fn fri_ext2fold4() {

let source = format!(
"
{TRUNCATE_STACK}
{TRUNCATE_STACK_PROC}
begin
{inputs}
Expand Down
6 changes: 3 additions & 3 deletions miden/tests/integration/operations/io_ops/adv_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use processor::{ExecutionError, ExecutionError::AdviceStackReadFailed};
use test_utils::expect_exec_error;
use vm_core::{chiplets::hasher::apply_permutation, utils::ToElements, Felt};

use super::{build_op_test, build_test, TRUNCATE_STACK};
use super::{build_op_test, build_test, TRUNCATE_STACK_PROC};

// PUSHING VALUES ONTO THE STACK (PUSH)
// ================================================================================================
Expand Down Expand Up @@ -63,7 +63,7 @@ fn adv_loadw_invalid() {
fn adv_pipe() {
let source = format!(
"
{TRUNCATE_STACK}
{TRUNCATE_STACK_PROC}
begin
push.12.11.10.9.8.7.6.5.4.3.2.1
Expand Down Expand Up @@ -96,7 +96,7 @@ fn adv_pipe() {
fn adv_pipe_with_hperm() {
let source = format!(
"
{TRUNCATE_STACK}
{TRUNCATE_STACK_PROC}
begin
push.12.11.10.9.8.7.6.5.4.3.2.1
Expand Down
6 changes: 3 additions & 3 deletions miden/tests/integration/operations/io_ops/env_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use vm_core::{
Operation,
};

use super::TRUNCATE_STACK;
use super::TRUNCATE_STACK_PROC;

// SDEPTH INSTRUCTION
// ================================================================================================
Expand All @@ -27,7 +27,7 @@ fn sdepth() {
// push 2 values to increase the lenth of the stack beyond 16
let source = format!(
"
{TRUNCATE_STACK}
{TRUNCATE_STACK_PROC}
begin
push.1
Expand Down Expand Up @@ -84,7 +84,7 @@ fn locaddr() {
// --- locaddr returns expected addresses in nested procedures --------------------------------
let source = format!(
"
{TRUNCATE_STACK}
{TRUNCATE_STACK_PROC}
proc.foo.3
locaddr.0
Expand Down
4 changes: 2 additions & 2 deletions miden/tests/integration/operations/io_ops/local_ops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{build_test, TRUNCATE_STACK};
use super::{build_test, TRUNCATE_STACK_PROC};

// PUSHING VALUES ONTO THE STACK (PUSH)
// ================================================================================================
Expand Down Expand Up @@ -91,7 +91,7 @@ fn storew_local() {
// --- test write to local memory -------------------------------------------------------------
let source = format!(
"
{TRUNCATE_STACK}
{TRUNCATE_STACK_PROC}
proc.foo.2
loc_storew.0
Expand Down
6 changes: 3 additions & 3 deletions miden/tests/integration/operations/io_ops/mem_ops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{apply_permutation, build_op_test, build_test, Felt, ToElements, TRUNCATE_STACK};
use super::{apply_permutation, build_op_test, build_test, Felt, ToElements, TRUNCATE_STACK_PROC};

// LOADING SINGLE ELEMENT ONTO THE STACK (MLOAD)
// ================================================================================================
Expand Down Expand Up @@ -93,7 +93,7 @@ fn mem_storew() {
fn mem_stream() {
let source = format!(
"
{TRUNCATE_STACK}
{TRUNCATE_STACK_PROC}
begin
push.1
Expand Down Expand Up @@ -132,7 +132,7 @@ fn mem_stream() {
fn mem_stream_with_hperm() {
let source = format!(
"
{TRUNCATE_STACK}
{TRUNCATE_STACK_PROC}
begin
push.1
Expand Down
2 changes: 1 addition & 1 deletion miden/tests/integration/operations/io_ops/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use test_utils::{assert_eq, build_op_test, build_test, Felt, ToElements, TRUNCATE_STACK};
use test_utils::{assert_eq, build_op_test, build_test, Felt, ToElements, TRUNCATE_STACK_PROC};
use vm_core::chiplets::hasher::apply_permutation;

mod adv_ops;
Expand Down
16 changes: 0 additions & 16 deletions miden/tests/integration/operations/stack_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ fn dupn_fail() {
"11 |",
"12 | begin dup.16 exec.truncate_stack end",
" : ^^",
"13 |",
" `----"
);
}
Expand Down Expand Up @@ -103,7 +102,6 @@ fn dupwn_fail() {
"11 |",
"12 | begin dupw.4 exec.truncate_stack end",
" : ^",
"13 |",
" `----"
);
}
Expand Down Expand Up @@ -140,7 +138,6 @@ fn swapn_fail() {
"11 |",
"12 | begin swap.16 exec.truncate_stack end",
" : ^^",
"13 |",
" `----"
);
}
Expand Down Expand Up @@ -177,7 +174,6 @@ fn swapwn_fail() {
"11 |",
"12 | begin swapw.4 exec.truncate_stack end",
" : ^",
"13 |",
" `----"
);
}
Expand Down Expand Up @@ -211,7 +207,6 @@ fn movup_fail() {
"11 |",
"12 | begin movup.0 exec.truncate_stack end",
" : ^",
"13 |",
" `----"
);

Expand All @@ -225,7 +220,6 @@ fn movup_fail() {
"11 |",
"12 | begin movup.1 exec.truncate_stack end",
" : ^",
"13 |",
" `----"
);

Expand All @@ -239,7 +233,6 @@ fn movup_fail() {
"11 |",
"12 | begin movup.16 exec.truncate_stack end",
" : ^^",
"13 |",
" `----"
);
}
Expand All @@ -264,7 +257,6 @@ fn movupw_fail() {
"11 |",
"12 | begin movupw.0 exec.truncate_stack end",
" : ^",
"13 |",
" `----"
);

Expand All @@ -278,7 +270,6 @@ fn movupw_fail() {
"11 |",
"12 | begin movupw.1 exec.truncate_stack end",
" : ^",
"13 |",
" `----"
);

Expand All @@ -292,7 +283,6 @@ fn movupw_fail() {
"11 |",
"12 | begin movupw.4 exec.truncate_stack end",
" : ^",
"13 |",
" `----"
);
}
Expand All @@ -317,7 +307,6 @@ fn movdn_fail() {
"11 |",
"12 | begin movdn.0 exec.truncate_stack end",
" : ^",
"13 |",
" `----"
);

Expand All @@ -331,7 +320,6 @@ fn movdn_fail() {
"11 |",
"12 | begin movdn.1 exec.truncate_stack end",
" : ^",
"13 |",
" `----"
);

Expand All @@ -345,7 +333,6 @@ fn movdn_fail() {
"11 |",
"12 | begin movdn.16 exec.truncate_stack end",
" : ^^",
"13 |",
" `----"
);
}
Expand All @@ -370,7 +357,6 @@ fn movdnw_fail() {
"11 |",
"12 | begin movdnw.0 exec.truncate_stack end",
" : ^",
"13 |",
" `----"
);

Expand All @@ -384,7 +370,6 @@ fn movdnw_fail() {
"11 |",
"12 | begin movdnw.1 exec.truncate_stack end",
" : ^",
"13 |",
" `----"
);

Expand All @@ -398,7 +383,6 @@ fn movdnw_fail() {
"11 |",
"12 | begin movdnw.4 exec.truncate_stack end",
" : ^",
"13 |",
" `----"
);
}
Expand Down
16 changes: 4 additions & 12 deletions processor/src/operations/comb_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ where
mod tests {
use alloc::{borrow::ToOwned, vec::Vec};

use test_utils::{build_test, rand::rand_array};
use test_utils::{build_test, rand::rand_array, TRUNCATE_STACK_PROC};
use vm_core::{Felt, FieldElement, Operation, StackInputs, ONE, ZERO};

use crate::{ContextId, Process, QuadFelt};
Expand Down Expand Up @@ -272,16 +272,8 @@ mod tests {

#[test]
fn prove_verify() {
let source = "
proc.truncate_stack.1
loc_storew.0 dropw movupw.3
sdepth neq.16
while.true
dropw movupw.3
sdepth neq.16
end
loc_loadw.0
end
let source = format!("
{TRUNCATE_STACK_PROC}
begin
# I) Prepare memory and stack
Expand Down Expand Up @@ -324,7 +316,7 @@ mod tests {
exec.truncate_stack
end
";
");

// generate the data
let tx: [Felt; 8] = rand_array();
Expand Down
3 changes: 3 additions & 0 deletions processor/src/stack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ impl Stack {
}

/// Returns [StackOutputs] consisting of all values on the stack.
///
/// # Errors
/// Returns an error if the overflow table is not empty at the current clock cycle.
pub fn build_stack_outputs(&self) -> Result<StackOutputs, ExecutionError> {
if self.overflow.num_active_rows() != 0 {
return Err(ExecutionError::OutputStackOverflow(self.overflow.num_active_rows()));
Expand Down
10 changes: 6 additions & 4 deletions processor/src/stack/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::{Felt, OverflowTableRow, Stack, StackInputs, MIN_STACK_DEPTH, ONE, ZE

type StackHelpersState = [Felt; NUM_STACK_HELPER_COLS];

// INITIALIZATION TESTS
// INITIALIZATION TEST
// ================================================================================================

#[test]
Expand All @@ -35,8 +35,11 @@ fn initialize() {
assert_eq!(stack.helpers_state(), expected_helpers);
}

// OVERFLOW TEST
// ================================================================================================

#[test]
fn initialize_overflow() {
fn stack_overflow() {
// Initialize a new fully loaded stack.
let mut stack_values_holder: [u64; 19] =
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19];
Expand Down Expand Up @@ -185,8 +188,7 @@ fn shift_right() {

#[test]
fn start_restore_context() {
let stack_init = (0..16).map(|v| v as u64 + 1);
let stack = StackInputs::try_from_ints(stack_init).unwrap();
let stack = StackInputs::try_from_ints(1..17).unwrap();
let mut stack = Stack::new(&stack, 8, false);

// ----- when overflow table is empty -------------------------------------
Expand Down
Loading

0 comments on commit 91b25f7

Please sign in to comment.