diff --git a/CHANGELOG.md b/CHANGELOG.md index be3fa8798d..952328bbad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ - Use `IndexVec::try_from` instead of pushing elements one by one in `DebugInfo::empty_for_nodes` ([#2559](https://github.com/0xMiden/miden-vm/pull/2559)). - [BREAKING] Remove `NodeExecutionState` in favor of `Continuation` ([#2587](https://github.com/0xMiden/miden-vm/pull/2587)). +- Made `StackInputs` and `StackOutputs` implement `Copy` trait ([#2581](https://github.com/0xMiden/miden-vm/pull/2581)). ## 0.20.2 (TBD) - Fix issue where decorator access was not bypassed properly in release mode ([#2529](https://github.com/0xMiden/miden-vm/pull/2529)). diff --git a/air/src/lib.rs b/air/src/lib.rs index 7cb9e834f8..19da793540 100644 --- a/air/src/lib.rs +++ b/air/src/lib.rs @@ -72,11 +72,11 @@ impl PublicInputs { } pub fn stack_inputs(&self) -> StackInputs { - self.stack_inputs.clone() + self.stack_inputs } pub fn stack_outputs(&self) -> StackOutputs { - self.stack_outputs.clone() + self.stack_outputs } pub fn program_info(&self) -> ProgramInfo { diff --git a/core/src/stack/inputs.rs b/core/src/stack/inputs.rs index c909ea77ab..2ac20e03b9 100644 --- a/core/src/stack/inputs.rs +++ b/core/src/stack/inputs.rs @@ -15,7 +15,7 @@ use crate::{ /// Defines the initial state of the VM's operand stack. /// /// The first element is at position 0 (top of stack). -#[derive(Clone, Debug, Default)] +#[derive(Clone, Copy, Debug, Default)] pub struct StackInputs { elements: [Felt; MIN_STACK_DEPTH], } diff --git a/core/src/stack/outputs.rs b/core/src/stack/outputs.rs index ee3312c643..e3c70573f7 100644 --- a/core/src/stack/outputs.rs +++ b/core/src/stack/outputs.rs @@ -19,7 +19,7 @@ use crate::utils::{ByteReader, Deserializable, DeserializationError}; /// `stack` is expected to be ordered as if the elements were popped off the stack one by one. /// Thus, the value at the top of the stack is expected to be in the first position, and the order /// of the rest of the output elements will also match the order on the stack. -#[derive(Debug, Clone, Default, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] pub struct StackOutputs { elements: [Felt; MIN_STACK_DEPTH], } diff --git a/crates/lib/core/tests/crypto/falcon.rs b/crates/lib/core/tests/crypto/falcon.rs index ed61d2572d..f2fd67e716 100644 --- a/crates/lib/core/tests/crypto/falcon.rs +++ b/crates/lib/core/tests/crypto/falcon.rs @@ -356,7 +356,7 @@ fn falcon_prove_verify() { let options = ProvingOptions::with_96_bit_security(miden_air::HashFunction::Blake3_256); let (stack_outputs, proof) = - prove_sync(&program, stack_inputs.clone(), advice_inputs, &mut host, options) + prove_sync(&program, stack_inputs, advice_inputs, &mut host, options) .expect("failed to generate proof"); let program_info = ProgramInfo::from(program); diff --git a/crates/lib/core/tests/stark/mod.rs b/crates/lib/core/tests/stark/mod.rs index bc4975636d..8edf5d3f52 100644 --- a/crates/lib/core/tests/stark/mod.rs +++ b/crates/lib/core/tests/stark/mod.rs @@ -88,7 +88,7 @@ pub fn generate_recursive_verifier_data( ProvingOptions::new(27, 8, 0, FieldExtension::Quadratic, 4, 127, HashFunction::Rpo256); let (stack_outputs, proof) = - prove(&program, stack_inputs.clone(), advice_inputs, &mut host, options).unwrap(); + prove(&program, stack_inputs, advice_inputs, &mut host, options).unwrap(); let program_info = ProgramInfo::from(program); diff --git a/crates/lib/core/tests/sys/mod.rs b/crates/lib/core/tests/sys/mod.rs index 32808a89e3..3745075f7c 100644 --- a/crates/lib/core/tests/sys/mod.rs +++ b/crates/lib/core/tests/sys/mod.rs @@ -108,14 +108,9 @@ fn log_precompile_request_procedure() { .expect("failed to register dummy handler"); let options = ProvingOptions::with_96_bit_security(miden_air::HashFunction::Blake3_256); - let (stack_outputs, proof) = miden_utils_testing::prove_sync( - &program, - stack_inputs.clone(), - advice_inputs, - &mut host, - options, - ) - .expect("failed to generate proof for log_precompile helper"); + let (stack_outputs, proof) = + miden_utils_testing::prove_sync(&program, stack_inputs, advice_inputs, &mut host, options) + .expect("failed to generate proof for log_precompile helper"); // Proof should include the single deferred request that we expect. assert_eq!(proof.precompile_requests().len(), 1); diff --git a/crates/test-utils/src/lib.rs b/crates/test-utils/src/lib.rs index 1b217a3ca4..0b91e56b2f 100644 --- a/crates/test-utils/src/lib.rs +++ b/crates/test-utils/src/lib.rs @@ -277,7 +277,7 @@ impl Test { let mut host = host.with_source_manager(self.source_manager.clone()); // execute the test - let stack_inputs: Vec = self.stack_inputs.clone().into_iter().collect(); + let stack_inputs: Vec = self.stack_inputs.into_iter().collect(); let processor = if self.in_debug_mode { FastProcessor::new_debug(&stack_inputs, self.advice_inputs.clone()) } else { @@ -386,7 +386,7 @@ impl Test { let mut host = host.with_source_manager(self.source_manager.clone()); let fast_stack_result = { - let stack_inputs: Vec = self.stack_inputs.clone().into_iter().collect(); + let stack_inputs: Vec = self.stack_inputs.into_iter().collect(); let advice_inputs: AdviceInputs = self.advice_inputs.clone(); let fast_processor = FastProcessor::new_with_options( &stack_inputs, @@ -424,7 +424,7 @@ impl Test { let mut host = host.with_source_manager(self.source_manager.clone()); let processor = FastProcessor::new_debug( - &self.stack_inputs.clone().into_iter().collect::>(), + &self.stack_inputs.into_iter().collect::>(), self.advice_inputs.clone(), ); @@ -445,7 +445,7 @@ impl Test { .with_debug_handler(debug_handler); let processor = FastProcessor::new_debug( - &self.stack_inputs.clone().into_iter().collect::>(), + &self.stack_inputs.into_iter().collect::>(), self.advice_inputs.clone(), ); @@ -473,7 +473,7 @@ impl Test { let stack_inputs = StackInputs::try_from_ints(pub_inputs).unwrap(); let (mut stack_outputs, proof) = miden_prover::prove_sync( &program, - stack_inputs.clone(), + stack_inputs, self.advice_inputs.clone(), &mut host, ProvingOptions::default(), @@ -579,7 +579,7 @@ impl Test { let mut host = host.with_source_manager(self.source_manager.clone()); let fast_result_by_step = { - let stack_inputs: Vec = self.stack_inputs.clone().into_iter().collect(); + let stack_inputs: Vec = self.stack_inputs.into_iter().collect(); let advice_inputs: AdviceInputs = self.advice_inputs.clone(); let fast_process = if self.in_debug_mode { FastProcessor::new_debug(&stack_inputs, advice_inputs) @@ -590,7 +590,7 @@ impl Test { }; compare_results( - fast_result.as_ref().map(|(output, _)| output.stack.clone()), + fast_result.as_ref().map(|(output, _)| output.stack), &fast_result_by_step, "fast processor", "fast processor by step", diff --git a/miden-vm/README.md b/miden-vm/README.md index 59707aa18c..97e51f403a 100644 --- a/miden-vm/README.md +++ b/miden-vm/README.md @@ -71,7 +71,7 @@ let mut host = DefaultHost::default(); let exec_options = ExecutionOptions::default(); // execute the program with no inputs -let trace = execute_sync(&program, stack_inputs.clone(), advice_inputs.clone(), &mut host, exec_options).unwrap(); +let trace = execute_sync(&program, stack_inputs, advice_inputs.clone(), &mut host, exec_options).unwrap(); ``` ### Proving program execution diff --git a/miden-vm/benches/build_trace.rs b/miden-vm/benches/build_trace.rs index 61e2cf2f27..0292e9ad71 100644 --- a/miden-vm/benches/build_trace.rs +++ b/miden-vm/benches/build_trace.rs @@ -108,7 +108,6 @@ fn build_trace(c: &mut Criterion) { let host = DefaultHost::default() .with_library(&CoreLibrary::default()) .unwrap(); - let stack_inputs = stack_inputs.clone(); let advice_inputs = advice_inputs.clone(); (host, stack_inputs, advice_inputs, program.clone()) diff --git a/miden-vm/tests/integration/prove_verify.rs b/miden-vm/tests/integration/prove_verify.rs index cb81f41be7..9833839af8 100644 --- a/miden-vm/tests/integration/prove_verify.rs +++ b/miden-vm/tests/integration/prove_verify.rs @@ -29,7 +29,7 @@ fn test_blake3_256_prove_verify() { println!("Proving with Blake3_256..."); let (stack_outputs, proof) = - prove_sync(&program, stack_inputs.clone(), advice_inputs, &mut host, options) + prove_sync(&program, stack_inputs, advice_inputs, &mut host, options) .expect("Proving failed"); println!("Proof generated successfully!"); @@ -67,7 +67,7 @@ fn test_keccak_prove_verify() { // Prove the program println!("Proving with Keccak..."); let (stack_outputs, proof) = - prove_sync(&program, stack_inputs.clone(), advice_inputs, &mut host, options) + prove_sync(&program, stack_inputs, advice_inputs, &mut host, options) .expect("Proving failed"); println!("Proof generated successfully!"); @@ -107,7 +107,7 @@ fn test_rpo_prove_verify() { // Prove the program println!("Proving with RPO..."); let (stack_outputs, proof) = - prove_sync(&program, stack_inputs.clone(), advice_inputs, &mut host, options) + prove_sync(&program, stack_inputs, advice_inputs, &mut host, options) .expect("Proving failed"); println!("Proof generated successfully!"); @@ -143,7 +143,7 @@ fn test_poseidon2_prove_verify() { println!("Proving with Poseidon2..."); let (stack_outputs, proof) = - prove_sync(&program, stack_inputs.clone(), advice_inputs, &mut host, options) + prove_sync(&program, stack_inputs, advice_inputs, &mut host, options) .expect("Proving failed"); println!("Proof generated successfully!"); @@ -179,7 +179,7 @@ fn test_rpx_prove_verify() { println!("Proving with RPX..."); let (stack_outputs, proof) = - prove_sync(&program, stack_inputs.clone(), advice_inputs, &mut host, options) + prove_sync(&program, stack_inputs, advice_inputs, &mut host, options) .expect("Proving failed"); println!("Proof generated successfully!"); @@ -236,7 +236,7 @@ mod fast_parallel { let mut host = DefaultHost::default().with_source_manager(Arc::new(DefaultSourceManager::default())); - let stack_inputs_vec: Vec = stack_inputs.clone().into_iter().collect(); + let stack_inputs_vec: Vec = stack_inputs.into_iter().collect(); let options = ExecutionOptions::default() .with_core_trace_fragment_size(FRAGMENT_SIZE) @@ -247,7 +247,7 @@ mod fast_parallel { .execute_for_trace_sync(&program, &mut host) .expect("Fast processor execution failed"); - let fast_stack_outputs = execution_output.stack.clone(); + let fast_stack_outputs = execution_output.stack; // Build trace using parallel trace generation let trace = diff --git a/processor/src/trace/mod.rs b/processor/src/trace/mod.rs index e1a05bda40..2413700a4f 100644 --- a/processor/src/trace/mod.rs +++ b/processor/src/trace/mod.rs @@ -113,7 +113,7 @@ impl ExecutionTrace { let public_inputs = PublicInputs::new( self.program_info.clone(), self.init_stack_state(), - self.stack_outputs.clone(), + self.stack_outputs, self.final_pc_transcript.state(), ); public_inputs.to_elements() diff --git a/prover/src/lib.rs b/prover/src/lib.rs index b2b2ee1a58..ede2c67755 100644 --- a/prover/src/lib.rs +++ b/prover/src/lib.rs @@ -78,7 +78,7 @@ pub async fn prove( trace.trace_len_summary().main_trace_len() ); - let stack_outputs = trace.stack_outputs().clone(); + let stack_outputs = *trace.stack_outputs(); let precompile_requests = trace.precompile_requests().to_vec(); let hash_fn = options.hash_fn();