From 693b74ccd0a7a46bc9efdfd6f3d184b3ac78c912 Mon Sep 17 00:00:00 2001 From: "Augusto F. Hack" Date: Tue, 25 Apr 2023 14:31:56 +0200 Subject: [PATCH] tests: add struct for big return value --- stdlib/tests/crypto/fri/mod.rs | 34 +++++++--- stdlib/tests/crypto/fri/verifier_fri_e2f4.rs | 67 ++++++++++---------- 2 files changed, 59 insertions(+), 42 deletions(-) diff --git a/stdlib/tests/crypto/fri/mod.rs b/stdlib/tests/crypto/fri/mod.rs index c2cefc8011..4ffa9078a4 100644 --- a/stdlib/tests/crypto/fri/mod.rs +++ b/stdlib/tests/crypto/fri/mod.rs @@ -25,24 +25,31 @@ fn fri_fold4_ext2_remainder32() { let depth = trace_len_e + blowup_exp; let domain_size = 1 << depth; - let (advice_provider, position_eval, alphas, commitments, remainder, num_queries) = - fri_prove_verify_fold4_ext2(trace_len_e).expect("should not panic"); + let FriResult { + merkle_sets, + advice_maps, + positions, + alphas, + commitments, + remainder, + num_queries, + } = fri_prove_verify_fold4_ext2(trace_len_e).unwrap(); let advice_stack = prepare_advice_stack( depth, domain_size, num_queries, - position_eval, + positions, alphas, commitments, remainder, ); - let advice_map: BTreeMap<[u8; 32], Vec> = BTreeMap::from_iter(advice_provider.1); + let advice_map: BTreeMap<[u8; 32], Vec> = BTreeMap::from_iter(advice_maps); let domain_generator = Felt::get_root_of_unity(domain_size.ilog2()).as_int(); let mut store = MerkleStore::new(); - for path_set in &advice_provider.0 { + for path_set in &merkle_sets { store.add_merkle_path_set(&path_set).unwrap(); } let test = build_test!(source, &[domain_generator], &advice_stack, store, advice_map.clone()); @@ -66,24 +73,31 @@ fn fri_fold4_ext2_remainder64() { let depth = trace_len_e + blowup_exp; let domain_size = 1 << depth; - let (advice_provider, position_eval, alphas, commitments, remainder, num_queries) = - fri_prove_verify_fold4_ext2(trace_len_e).expect("should not panic"); + let FriResult { + merkle_sets, + advice_maps, + positions, + alphas, + commitments, + remainder, + num_queries, + } = fri_prove_verify_fold4_ext2(trace_len_e).unwrap(); let advice_stack = prepare_advice_stack( depth, domain_size, num_queries, - position_eval, + positions, alphas, commitments, remainder, ); - let advice_map: BTreeMap<[u8; 32], Vec> = BTreeMap::from_iter(advice_provider.1); + let advice_map: BTreeMap<[u8; 32], Vec> = BTreeMap::from_iter(advice_maps); let domain_generator = Felt::get_root_of_unity(domain_size.ilog2()).as_int(); let mut store = MerkleStore::new(); - for path_set in &advice_provider.0 { + for path_set in &merkle_sets { store.add_merkle_path_set(&path_set).unwrap(); } let test = build_test!(source, &[domain_generator], &advice_stack, store, advice_map.clone()); diff --git a/stdlib/tests/crypto/fri/verifier_fri_e2f4.rs b/stdlib/tests/crypto/fri/verifier_fri_e2f4.rs index d384a2da2d..6d605ad6d8 100644 --- a/stdlib/tests/crypto/fri/verifier_fri_e2f4.rs +++ b/stdlib/tests/crypto/fri/verifier_fri_e2f4.rs @@ -14,6 +14,32 @@ use winter_fri::{ folding::fold_positions, DefaultProverChannel, FriOptions, FriProof, FriProver, VerifierError, }; +pub struct FriResult { + /// contains the Merkle authentication paths used to authenticate the queries. + pub merkle_sets: Vec, + + /// used to unhash Merkle nodes to a sequence of field elements representing the query-values. + pub advice_maps: Vec<([u8; 32], Vec)>, + + /// A vector of consecutive quadruples of the form (poe, p, e1, e0) where p is index of the + /// query at the first layer and (e1, e0) is its corresponding evaluation and poe is g^p with g + /// being the initial domain generator. + pub positions: Vec, + + /// A vector of tuples representing the folding challenges. + pub alphas: Vec, + + /// A vector of consecutive quadruples (c3, c2, c1, c0) representing the Merkle tree layer + /// commitments. + pub commitments: Vec, + + /// The remainder codeword as consecutive (r0, r1). + pub remainder: Vec, + + /// The number of queries contained in the current FRI proof. + pub num_queries: usize, +} + // This function proves and then verifies a FRI proof with the following fixed parameters: // 1) Max remainder codeword (1 << 6). // 2) Blow up factor 8. @@ -22,31 +48,7 @@ use winter_fri::{ // The main purpose of this function is to build the non-deterministic inputs needed to verify // a FRI proof inside the Miden VM. // The output is organized as follows: -// 1) `(merkle_sets, advice_maps): (Vec, Vec<([u8; 32], Vec)>)` where -// merkle_sets contains the Merkle authentication paths used to authenticate the queries. -// advice_maps is used to unhash Merkle nodes to a sequence of field elements representing -// the query-values. TODO: Make use of the advice_maps. -// 2) `positions: Vec` a vector of consecutive quadruples of the form (poe, p, e1, e0) -// where p is index of the query at the first layer and (e1, e0) is its corresponding -// evaluation and poe is g^p with g being the initial domain generator. -// 3) `alphas: Vec` is a vector of tuples representing the folding challenges. -// 4) `commitments: Vec` is a vector of consecutive quadruples (c3, c2, c1, c0) -// representing the Merkle tree layer commitments. -// 5) `remainder: Vec` is the remainder codeword as consecutive (r0, r1). -// 6) `num_queries: usize` is the number of queries contained in the current FRI proof. -pub fn fri_prove_verify_fold4_ext2( - trace_length_e: usize, -) -> Result< - ( - (Vec, Vec<([u8; 32], Vec)>), - Vec, - Vec, - Vec, - Vec, - usize, - ), - VerifierError, -> { +pub fn fri_prove_verify_fold4_ext2(trace_length_e: usize) -> Result { let max_remainder_size_e = 3; let folding_factor_e = 2; let trace_length = 1 << trace_length_e; @@ -97,15 +99,16 @@ pub fn fri_prove_verify_fold4_ext2( .collect(); match result { - Ok(((merkle_path_set, advice_values), all_position_evaluation, all_alphas)) => { - return Ok(( - (merkle_path_set, advice_values), - all_position_evaluation, - all_alphas, + Ok(((merkle_sets, advice_maps), all_position_evaluation, alphas)) => { + return Ok(FriResult { + merkle_sets, + advice_maps, + positions: all_position_evaluation, + alphas, commitments, remainder, - positions.len(), - )); + num_queries: positions.len(), + }); } Err(err) => return Err(err), }