Skip to content

Commit

Permalink
chore: factored AcceptableOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Kindi-0 committed Oct 25, 2023
1 parent ee06f97 commit 33d24c7
Show file tree
Hide file tree
Showing 19 changed files with 430 additions and 250 deletions.
6 changes: 3 additions & 3 deletions air/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use vm_core::{
ExtensionOf, ProgramInfo, StackInputs, StackOutputs, ONE, ZERO,
};
use winter_air::{
Air, AirContext, Assertion, AuxTraceRandElements, EvaluationFrame,
ProofOptions as WinterProofOptions, TraceInfo, TransitionConstraintDegree,
Air, AirContext, Assertion, AuxTraceRandElements, EvaluationFrame, TraceInfo,
TransitionConstraintDegree,
};

mod constraints;
Expand All @@ -37,7 +37,7 @@ pub use vm_core::{
utils::{DeserializationError, ToElements},
Felt, FieldElement, StarkField,
};
pub use winter_air::FieldExtension;
pub use winter_air::{FieldExtension, ProofOptions as WinterProofOptions};

// PROCESSOR AIR
// ================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion air/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{ExecutionOptionsError, HashFunction};
use super::{FieldExtension, WinterProofOptions};
use crate::trace::MIN_TRACE_LEN;
use winter_air::{FieldExtension, ProofOptions as WinterProofOptions};

// PROVING OPTIONS
// ================================================================================================
Expand Down
12 changes: 2 additions & 10 deletions miden/src/cli/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::data::{InputFile, OutputFile, ProgramHash, ProofFile};
use clap::Parser;
use miden::{Kernel, ProgramInfo};
use std::{path::PathBuf, time::Instant};
use verifier::AcceptableOptions;

#[derive(Debug, Clone, Parser)]
#[clap(about = "Verify a miden program")]
Expand Down Expand Up @@ -50,15 +49,8 @@ impl VerifyCmd {
let program_info = ProgramInfo::new(program_hash, kernel);

// verify proof
let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
verifier::verify(
program_info,
stack_inputs,
outputs_data.stack_outputs()?,
proof,
&min_opts,
)
.map_err(|err| format!("Program failed verification! - {}", err))?;
verifier::verify(program_info, stack_inputs, outputs_data.stack_outputs()?, proof)
.map_err(|err| format!("Program failed verification! - {}", err))?;

println!("Verification complete in {} ms", now.elapsed().as_millis());

Expand Down
9 changes: 3 additions & 6 deletions miden/src/examples/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use miden::{ExecutionProof, Host, Program, ProgramInfo, ProvingOptions, StackInp
use processor::{ExecutionOptions, ExecutionOptionsError, ONE, ZERO};
use std::io::Write;
use std::time::Instant;
use verifier::AcceptableOptions;

pub mod fibonacci;

Expand Down Expand Up @@ -122,11 +121,10 @@ impl ExampleOptions {
// verify that executing a program with a given hash and given inputs
// results in the expected output
let proof = ExecutionProof::from_bytes(&proof_bytes).unwrap();
let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
let now = Instant::now();
let program_info = ProgramInfo::from(program);

match miden::verify(program_info, stack_inputs, stack_outputs, proof, &min_opts) {
match miden::verify(program_info, stack_inputs, stack_outputs, proof) {
Ok(_) => println!("Execution verified in {} ms", now.elapsed().as_millis()),
Err(err) => println!("Failed to verify execution: {}", err),
}
Expand Down Expand Up @@ -162,12 +160,11 @@ where

let kernel = miden::Kernel::default();
let program_info = ProgramInfo::new(program.hash(), kernel);
let min_opts = AcceptableOptions::MinConjecturedSecurity(80);

if fail {
outputs.stack_mut()[0] += 1;
assert!(miden::verify(program_info, stack_inputs, outputs, proof, &min_opts).is_err())
assert!(miden::verify(program_info, stack_inputs, outputs, proof).is_err())
} else {
assert!(miden::verify(program_info, stack_inputs, outputs, proof, &min_opts).is_ok());
assert!(miden::verify(program_info, stack_inputs, outputs, proof).is_ok());
}
}
14 changes: 5 additions & 9 deletions miden/tests/integration/air/chiplets/bitwise.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use test_utils::{build_op_test, build_test, AcceptableOptions};
use test_utils::{build_op_test, build_test};

#[test]
fn bitwise_and() {
// Test all bit input combinations: (1, 1), (1, 0), (0, 0). Then test larger numbers.
let asm_op = "u32checked_and push.0 u32checked_and push.0 u32checked_and push.65535 push.137 u32checked_and";
let pub_inputs = vec![1, 1];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(&asm_op, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_op_test!(&asm_op, &pub_inputs).prove_and_verify(pub_inputs, false);
}

#[test]
Expand All @@ -16,8 +15,7 @@ fn bitwise_or() {
let asm_op = "u32checked_or push.0 u32checked_or not push.0 u32checked_or push.65535 push.137 u32checked_or";
let pub_inputs = vec![1, 1];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(&asm_op, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_op_test!(&asm_op, &pub_inputs).prove_and_verify(pub_inputs, false);
}

#[test]
Expand All @@ -26,15 +24,13 @@ fn bitwise_xor() {
let asm_op = "u32checked_xor push.0 u32checked_xor push.1 u32checked_xor push.65535 push.137 u32checked_xor";
let pub_inputs = vec![1, 1];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(&asm_op, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_op_test!(&asm_op, &pub_inputs).prove_and_verify(pub_inputs, false);
}

#[test]
fn all_operations() {
let source = "begin u32checked_and push.0 u32checked_or push.0 u32checked_xor end";
let pub_inputs = vec![1, 1];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_test!(source, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_test!(source, &pub_inputs).prove_and_verify(pub_inputs, false);
}
40 changes: 11 additions & 29 deletions miden/tests/integration/air/chiplets/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@ use test_utils::{
build_op_test,
crypto::{init_merkle_leaf, init_merkle_store, MerkleStore, MerkleTree, Rpo256},
rand::rand_vector,
AcceptableOptions, StarkField, Word,
StarkField, Word,
};

#[test]
fn hperm() {
let asm_op = "hperm";
let pub_inputs = rand_vector::<u64>(8);

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(asm_op, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_op_test!(asm_op, &pub_inputs).prove_and_verify(pub_inputs, false);
}

#[test]
fn hmerge() {
let asm_op = "hmerge";
let pub_inputs = rand_vector::<u64>(8);

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(asm_op, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_op_test!(asm_op, &pub_inputs).prove_and_verify(pub_inputs, false);
}

#[test]
Expand All @@ -40,25 +38,17 @@ fn mtree_get() {
tree.depth() as u64,
];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(asm_op, &stack_inputs, &[], store).prove_and_verify(
stack_inputs.to_vec(),
&min_opts,
false,
);
build_op_test!(asm_op, &stack_inputs, &[], store)
.prove_and_verify(stack_inputs.to_vec(), false);
}

#[test]
fn mtree_set() {
let asm_op = "mtree_set";
let (stack_inputs, store, _leaves) = build_mtree_update_test_inputs();

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(asm_op, &stack_inputs, &[], store).prove_and_verify(
stack_inputs.to_vec(),
&min_opts,
false,
);
build_op_test!(asm_op, &stack_inputs, &[], store)
.prove_and_verify(stack_inputs.to_vec(), false);
}

#[test]
Expand All @@ -82,12 +72,8 @@ fn mtree_verify() {
leaves[index][3].as_int(),
];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(asm_op, &stack_inputs, &[], store).prove_and_verify(
stack_inputs.to_vec(),
&min_opts,
false,
);
build_op_test!(asm_op, &stack_inputs, &[], store)
.prove_and_verify(stack_inputs.to_vec(), false);
}

#[test]
Expand Down Expand Up @@ -127,12 +113,8 @@ fn mtree_merge() {
root_merged[3].as_int(),
];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(asm_op, &stack_inputs, &stack_outputs, store).prove_and_verify(
stack_inputs,
&min_opts,
false,
);
build_op_test!(asm_op, &stack_inputs, &stack_outputs, store)
.prove_and_verify(stack_inputs, false);
}

/// Helper function that builds a test stack and Merkle tree for testing mtree updates.
Expand Down
23 changes: 8 additions & 15 deletions miden/tests/integration/air/chiplets/memory.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use test_utils::{build_op_test, build_test, AcceptableOptions, ToElements};
use test_utils::{build_op_test, build_test, ToElements};

#[test]
fn mem_load() {
let asm_op = "mem_load.0 swap";

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(asm_op).prove_and_verify(vec![], &min_opts, false);
build_op_test!(asm_op).prove_and_verify(vec![], false);
}

#[test]
fn mem_store() {
let asm_op = "mem_store.0";
let pub_inputs = vec![1];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(asm_op, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_op_test!(asm_op, &pub_inputs).prove_and_verify(pub_inputs, false);
}

#[test]
Expand Down Expand Up @@ -43,17 +41,15 @@ fn helper_mem_store() {
fn mem_loadw() {
let asm_op = "mem_loadw.0";

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(asm_op).prove_and_verify(vec![], &min_opts, false);
build_op_test!(asm_op).prove_and_verify(vec![], false);
}

#[test]
fn mem_storew() {
let asm_op = "mem_storew.0";
let pub_inputs = vec![1, 2, 3, 4];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(asm_op, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_op_test!(asm_op, &pub_inputs).prove_and_verify(pub_inputs, false);
}

#[test]
Expand All @@ -62,8 +58,7 @@ fn write_read() {

let pub_inputs = vec![4, 3, 2, 1];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_test!(source, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_test!(source, &pub_inputs).prove_and_verify(pub_inputs, false);
}

#[test]
Expand All @@ -85,15 +80,13 @@ fn update() {
let source = "begin push.0.0.0.0 mem_loadw.0 mem_storew.0 swapw end";
let pub_inputs = vec![8, 7, 6, 5, 4, 3, 2, 1];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_test!(source, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_test!(source, &pub_inputs).prove_and_verify(pub_inputs, false);
}

#[test]
fn incr_write_addr() {
let source = "begin mem_storew.0 mem_storew.1 end";
let pub_inputs = vec![4, 3, 2, 1];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_test!(source, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_test!(source, &pub_inputs).prove_and_verify(pub_inputs, false);
}
5 changes: 2 additions & 3 deletions miden/tests/integration/air/chiplets/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use test_utils::{build_test, rand::rand_vector, AcceptableOptions};
use test_utils::{build_test, rand::rand_vector};

mod bitwise;
mod hasher;
Expand All @@ -14,6 +14,5 @@ fn chiplets() {
end";
let pub_inputs = rand_vector::<u64>(8);

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_test!(source, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_test!(source, &pub_inputs).prove_and_verify(pub_inputs, false);
}
11 changes: 4 additions & 7 deletions miden/tests/integration/air/range.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use test_utils::{build_op_test, build_test, AcceptableOptions};
use test_utils::{build_op_test, build_test};

/// Range checks the result of 1 + 1. This results in 2 range checks, one for each 16-bit limb of
/// the 32-bit result (2 and 0).
Expand All @@ -7,8 +7,7 @@ fn range_check_once() {
let asm_op = "u32overflowing_add";
let stack = vec![1, 1];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(asm_op, &stack).prove_and_verify(stack, &min_opts, false);
build_op_test!(asm_op, &stack).prove_and_verify(stack, false);
}

/// Range checks multiple values a varying number of times, since each value is checked as an input.
Expand All @@ -18,8 +17,7 @@ fn range_check_multi() {
let source = "begin u32checked_add u32checked_add end";
let stack = vec![5, 5, 5];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_test!(source, &stack).prove_and_verify(stack, &min_opts, false);
build_test!(source, &stack).prove_and_verify(stack, false);
}

/// Range checks the result of 1 + u32::MAX - 1, which is u32::MAX. Therefore, it requires range
Expand All @@ -29,6 +27,5 @@ fn range_check_u16max() {
let asm_op = "u32overflowing_add";
let stack = vec![1, (u32::MAX - 1) as u64];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(asm_op, &stack).prove_and_verify(stack, &min_opts, false);
build_op_test!(asm_op, &stack).prove_and_verify(stack, false);
}
14 changes: 5 additions & 9 deletions miden/tests/integration/air/stack/field_ops.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
use test_utils::{build_op_test, AcceptableOptions};
use test_utils::build_op_test;

#[test]
fn incr() {
let asm_op = "add.1 add.1 push.0 add.1 add.1 eq assert";
let pub_inputs = vec![0];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(&asm_op, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_op_test!(&asm_op, &pub_inputs).prove_and_verify(pub_inputs, false);
}

#[test]
fn neg() {
let asm_op = "dup.0 neg add eq.0 assert";
let pub_inputs = vec![7];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(&asm_op, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_op_test!(&asm_op, &pub_inputs).prove_and_verify(pub_inputs, false);
}

#[test]
fn not() {
let asm_op = "dup.0 not add eq.1 assert";
let pub_inputs = vec![1];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(&asm_op, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_op_test!(&asm_op, &pub_inputs).prove_and_verify(pub_inputs, false);
}

#[test]
Expand All @@ -33,6 +30,5 @@ fn expacc() {
let asm_op = "push.10 exp eq.3486784401 assert";
let pub_inputs = vec![9];

let min_opts = AcceptableOptions::MinConjecturedSecurity(80);
build_op_test!(&asm_op, &pub_inputs).prove_and_verify(pub_inputs, &min_opts, false);
build_op_test!(&asm_op, &pub_inputs).prove_and_verify(pub_inputs, false);
}
Loading

0 comments on commit 33d24c7

Please sign in to comment.