-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
433e67b
commit 8e2173e
Showing
8 changed files
with
94 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,50 @@ | ||
#[cfg(test)] | ||
mod test { | ||
use crate::{ | ||
trace::virtual_bus::{prover::VirtualBusProver, verifier::VirtualBusVerifier}, | ||
DefaultHost, ExecutionTrace, Process, | ||
}; | ||
use alloc::vec::Vec; | ||
use miden_air::{trace::main_trace::MainTrace, ExecutionOptions}; | ||
use vm_core::crypto::random::RpoRandomCoin; | ||
use vm_core::{ | ||
code_blocks::CodeBlock, CodeBlockTable, Felt, FieldElement, Kernel, Operation, StackInputs, | ||
}; | ||
|
||
#[test] | ||
fn test_vb_prover() { | ||
let s = 5; | ||
let e = 5; | ||
let stack: Vec<_> = (0..(1 << s)).into_iter().collect(); | ||
let operations: Vec<_> = (0..(1 << e)) | ||
.flat_map(|_| { | ||
vec![Operation::U32split, Operation::U32add, Operation::U32xor, Operation::MStoreW] | ||
}) | ||
.collect(); | ||
|
||
let trace = build_full_trace(&stack, operations, Kernel::default()); | ||
|
||
// TODO: this should be generated using the transcript up to when the prover sends the commitment | ||
// of the main trace. | ||
let alphas = vec![Felt::from(7898787_u32)]; | ||
|
||
let seed = [Felt::ZERO; 4]; // TODO: should be initialized with the appropriate transcript | ||
let mut transcript = RpoRandomCoin::new(seed.into()); | ||
|
||
let vb_prover = VirtualBusProver::new(alphas.clone()).unwrap(); | ||
|
||
let proof = vb_prover.prove(trace, &mut transcript); | ||
|
||
let seed = [Felt::ZERO; 4]; // TODO: should be initialized with the appropriate transcript | ||
let mut transcript = RpoRandomCoin::new(seed.into()); | ||
let vb_verifier = VirtualBusVerifier::new(alphas).unwrap(); | ||
let _final_opening_claim = vb_verifier.verify(proof, &mut transcript); | ||
} | ||
use crate::{ | ||
trace::virtual_bus::{prover::VirtualBusProver, verifier::VirtualBusVerifier}, | ||
DefaultHost, ExecutionTrace, Process, | ||
}; | ||
use alloc::vec::Vec; | ||
use miden_air::{trace::main_trace::MainTrace, ExecutionOptions}; | ||
use vm_core::crypto::random::RpoRandomCoin; | ||
use vm_core::{ | ||
code_blocks::CodeBlock, CodeBlockTable, Felt, FieldElement, Kernel, Operation, StackInputs, | ||
}; | ||
|
||
#[test] | ||
fn test_vb_prover_verifier() { | ||
let s = 6; | ||
let o = 6; | ||
let stack: Vec<_> = (0..(1 << s)).into_iter().collect(); | ||
let operations: Vec<_> = (0..(1 << o)) | ||
.flat_map(|_| { | ||
vec![Operation::U32split, Operation::U32add, Operation::U32xor, Operation::MStoreW] | ||
}) | ||
.collect(); | ||
|
||
let trace = build_full_trace(&stack, operations, Kernel::default()); | ||
|
||
// this should be generated using the transcript up to when the prover sends the commitment | ||
// to the main trace. | ||
let alphas: Vec<Felt> = vec![test_utils::rand::rand_value()]; | ||
|
||
let seed = [Felt::ZERO; 4]; // should be initialized with the appropriate transcript | ||
let mut transcript = RpoRandomCoin::new(seed.into()); | ||
let vb_prover = VirtualBusProver::new(alphas.clone()).unwrap(); | ||
let proof = vb_prover.prove(&trace, &mut transcript); | ||
|
||
let seed = [Felt::ZERO; 4]; // should be initialized with the appropriate transcript | ||
let mut transcript = RpoRandomCoin::new(seed.into()); | ||
let vb_verifier = VirtualBusVerifier::new(alphas).unwrap(); | ||
let _final_opening_claim = vb_verifier.verify(proof, &mut transcript); | ||
} | ||
|
||
fn build_full_trace( | ||
stack_inputs: &[u64], | ||
operations: Vec<Operation>, | ||
kernel: Kernel, | ||
) -> MainTrace { | ||
let stack_inputs: Vec<Felt> = stack_inputs.iter().map(|a| Felt::new(*a)).collect(); | ||
let stack_inputs = StackInputs::new(stack_inputs).unwrap(); | ||
let host = DefaultHost::default(); | ||
let mut process = Process::new(kernel, stack_inputs, host, ExecutionOptions::default()); | ||
let program = CodeBlock::new_span(operations); | ||
process.execute_code_block(&program, &CodeBlockTable::default()).unwrap(); | ||
let (trace, _, _): (MainTrace, _, _) = ExecutionTrace::test_finalize_trace(process); | ||
fn build_full_trace(stack_inputs: &[u64], operations: Vec<Operation>, kernel: Kernel) -> MainTrace { | ||
let stack_inputs: Vec<Felt> = stack_inputs.iter().map(|a| Felt::new(*a)).collect(); | ||
let stack_inputs = StackInputs::new(stack_inputs).unwrap(); | ||
let host = DefaultHost::default(); | ||
let mut process = Process::new(kernel, stack_inputs, host, ExecutionOptions::default()); | ||
let program = CodeBlock::new_span(operations); | ||
process.execute_code_block(&program, &CodeBlockTable::default()).unwrap(); | ||
let (trace, _, _): (MainTrace, _, _) = ExecutionTrace::test_finalize_trace(process); | ||
|
||
trace | ||
} | ||
trace | ||
} |