From 70f3d95785068c991652dd3422718d732afc297f Mon Sep 17 00:00:00 2001 From: Jan Ferdinand Sauer Date: Fri, 6 Oct 2023 13:29:42 +0200 Subject: [PATCH] fix!: use `Copy`-trait of `StarkParameters` BREAKING CHANGE: never use references `&StarkParameters` --- triton-vm/benches/proof_size.rs | 4 ++-- triton-vm/benches/prove_fib.rs | 6 +++--- triton-vm/benches/prove_halt.rs | 6 +++--- triton-vm/benches/verify_halt.rs | 8 +++---- triton-vm/src/lib.rs | 18 ++++++++-------- triton-vm/src/shared_tests.rs | 4 ++-- triton-vm/src/stark.rs | 36 ++++++++++++++++---------------- 7 files changed, 41 insertions(+), 41 deletions(-) diff --git a/triton-vm/benches/proof_size.rs b/triton-vm/benches/proof_size.rs index fe0102f2f..4e1711af9 100644 --- a/triton-vm/benches/proof_size.rs +++ b/triton-vm/benches/proof_size.rs @@ -181,7 +181,7 @@ fn program_halt() -> ProgramAndInput { } /// The base 2, integer logarithm of the FRI domain length. -fn log_2_fri_domain_length(parameters: &StarkParameters, proof: &Proof) -> u32 { +fn log_2_fri_domain_length(parameters: StarkParameters, proof: &Proof) -> u32 { let padded_height = proof.padded_height().unwrap(); let fri = Stark::derive_fri(parameters, padded_height); fri.domain.length.ilog2() @@ -265,7 +265,7 @@ fn generate_proof_and_benchmark_id( &program_and_input.non_determinism, ) .unwrap(); - let log_2_fri_domain_length = log_2_fri_domain_length(¶meters, &proof); + let log_2_fri_domain_length = log_2_fri_domain_length(parameters, &proof); let benchmark_id = BenchmarkId::new(program_name, log_2_fri_domain_length); (proof, benchmark_id) } diff --git a/triton-vm/benches/prove_fib.rs b/triton-vm/benches/prove_fib.rs index 61aec68a6..dd3e230e4 100644 --- a/triton-vm/benches/prove_fib.rs +++ b/triton-vm/benches/prove_fib.rs @@ -33,7 +33,7 @@ fn fib_benchmark_group(criterion: &mut Criterion, claim: &Claim, aet: &Algebraic let parameters = StarkParameters::default(); group.bench_function(bench_id, |bencher| { - bencher.iter(|| Stark::prove(¶meters, claim, aet, &mut None)) + bencher.iter(|| Stark::prove(parameters, claim, aet, &mut None)) }); group.finish(); } @@ -42,12 +42,12 @@ fn prover_timing_report(claim: &Claim, aet: &AlgebraicExecutionTrace) -> Report let profile_name = format!("Prove Fibonacci {FIBONACCI_INDEX}"); let parameters = StarkParameters::default(); let mut profiler = Some(TritonProfiler::new(&profile_name)); - let proof = Stark::prove(¶meters, claim, aet, &mut profiler); + let proof = Stark::prove(parameters, claim, aet, &mut profiler); let mut profiler = profiler.unwrap(); profiler.finish(); let padded_height = proof.padded_height().unwrap(); - let fri = Stark::derive_fri(¶meters, padded_height); + let fri = Stark::derive_fri(parameters, padded_height); profiler .report() .with_cycle_count(aet.processor_trace.nrows()) diff --git a/triton-vm/benches/prove_halt.rs b/triton-vm/benches/prove_halt.rs index 9275d7998..2892cdfad 100644 --- a/triton-vm/benches/prove_halt.rs +++ b/triton-vm/benches/prove_halt.rs @@ -22,7 +22,7 @@ fn prove_halt(criterion: &mut Criterion) { output, }; let mut profiler = Some(TritonProfiler::new("Prove Halt")); - let proof = Stark::prove(¶meters, &claim, &aet, &mut profiler); + let proof = Stark::prove(parameters, &claim, &aet, &mut profiler); let mut profiler = profiler.unwrap(); profiler.finish(); @@ -31,14 +31,14 @@ fn prove_halt(criterion: &mut Criterion) { group.sample_size(10); group.bench_function(bench_id, |bencher| { bencher.iter(|| { - let _proof = Stark::prove(¶meters, &claim, &aet, &mut None); + let _proof = Stark::prove(parameters, &claim, &aet, &mut None); }); }); group.finish(); println!("Writing report ..."); let padded_height = proof.padded_height().unwrap(); - let fri = Stark::derive_fri(¶meters, padded_height); + let fri = Stark::derive_fri(parameters, padded_height); let report = profiler .report() .with_cycle_count(aet.processor_trace.nrows()) diff --git a/triton-vm/benches/verify_halt.rs b/triton-vm/benches/verify_halt.rs index 70b6f38d6..d90d4f6cb 100644 --- a/triton-vm/benches/verify_halt.rs +++ b/triton-vm/benches/verify_halt.rs @@ -22,16 +22,16 @@ fn verify_halt(criterion: &mut Criterion) { }; let (aet, _) = program.trace_execution([].into(), [].into()).unwrap(); - let proof = Stark::prove(¶meters, &claim, &aet, &mut None); + let proof = Stark::prove(parameters, &claim, &aet, &mut None); let mut profiler = Some(TritonProfiler::new("Verify Halt")); - let verdict = Stark::verify(¶meters, &claim, &proof, &mut profiler).unwrap(); + let verdict = Stark::verify(parameters, &claim, &proof, &mut profiler).unwrap(); assert!(verdict); let mut profiler = profiler.unwrap(); profiler.finish(); let padded_height = proof.padded_height().unwrap(); - let fri = Stark::derive_fri(¶meters, padded_height); + let fri = Stark::derive_fri(parameters, padded_height); let report = profiler .report() .with_cycle_count(aet.processor_trace.nrows()) @@ -43,7 +43,7 @@ fn verify_halt(criterion: &mut Criterion) { group.sample_size(10); group.bench_function(bench_id, |bencher| { bencher.iter(|| { - let _ = Stark::verify(¶meters, &claim, &proof, &mut None); + let _ = Stark::verify(parameters, &claim, &proof, &mut None); }); }); group.finish(); diff --git a/triton-vm/src/lib.rs b/triton-vm/src/lib.rs index d6c76ae12..e88bf8979 100644 --- a/triton-vm/src/lib.rs +++ b/triton-vm/src/lib.rs @@ -57,7 +57,7 @@ //! let (parameters, claim, proof) = //! prove_program(&factorial_program, &public_input, &non_determinism).unwrap(); //! -//! let verdict = verify(¶meters, &claim, &proof); +//! let verdict = verify(parameters, &claim, &proof); //! assert!(verdict); //! //! let public_output = claim.public_output(); @@ -117,7 +117,7 @@ //! let (parameters, claim, proof) = //! prove_program(&sum_of_squares_program, &public_input, &non_determinism).unwrap(); //! -//! let verdict = verify(¶meters, &claim, &proof); +//! let verdict = verify(parameters, &claim, &proof); //! assert!(verdict); //! ``` //! @@ -460,7 +460,7 @@ pub fn prove_program( }; // Generate the proof. - let proof = Stark::prove(¶meters, &claim, &aet, &mut None); + let proof = Stark::prove(parameters, &claim, &aet, &mut None); Ok((parameters, claim, proof)) } @@ -491,7 +491,7 @@ fn input_elements_have_unique_representation( /// A convenience function for proving a [`Claim`] and the program that claim corresponds to. /// Method [`prove_program`] gives a simpler interface with less control. pub fn prove( - parameters: &StarkParameters, + parameters: StarkParameters, claim: &Claim, program: &Program, non_determinism: NonDeterminism, @@ -506,7 +506,7 @@ pub fn prove( /// Verify a proof generated by [`prove`] or [`prove_program`]. #[must_use] -pub fn verify(parameters: &StarkParameters, claim: &Claim, proof: &Proof) -> bool { +pub fn verify(parameters: StarkParameters, claim: &Claim, proof: &Proof) -> bool { Stark::verify(parameters, claim, proof, &mut None).unwrap_or(false) } @@ -576,7 +576,7 @@ mod public_interface_tests { claim.output.is_empty(), "Output must be empty for program that doesn't write to output" ); - let verdict = verify(¶meters, &claim, &proof); + let verdict = verify(parameters, &claim, &proof); assert!(verdict); } @@ -594,7 +594,7 @@ mod public_interface_tests { let (parameters, claim, proof) = prove_program(&program, &[], &non_determinism).unwrap(); assert_eq!(13 * 17, claim.output[0].value()); - let verdict = verify(¶meters, &claim, &proof); + let verdict = verify(parameters, &claim, &proof); assert!(verdict); } @@ -608,8 +608,8 @@ mod public_interface_tests { output: vec![], }; - let proof = prove(¶meters, &claim, &program, [].into()).unwrap(); - let verdict = verify(¶meters, &claim, &proof); + let proof = prove(parameters, &claim, &program, [].into()).unwrap(); + let verdict = verify(parameters, &claim, &proof); assert!(verdict); } diff --git a/triton-vm/src/shared_tests.rs b/triton-vm/src/shared_tests.rs index dff190aa8..aa5ce170a 100644 --- a/triton-vm/src/shared_tests.rs +++ b/triton-vm/src/shared_tests.rs @@ -105,7 +105,7 @@ pub(crate) fn prove_with_low_security_level( let claim = construct_claim(&aet, public_input.individual_tokens, public_output); prof_start!(maybe_profiler, "prove"); - let proof = Stark::prove(¶meters, &claim, &aet, maybe_profiler); + let proof = Stark::prove(parameters, &claim, &aet, maybe_profiler); prof_stop!(maybe_profiler, "prove"); (parameters, claim, proof) @@ -131,7 +131,7 @@ pub(crate) fn stark_parameters_with_low_security_level() -> StarkParameters { } pub(crate) fn construct_master_base_table( - parameters: &StarkParameters, + parameters: StarkParameters, aet: &AlgebraicExecutionTrace, ) -> MasterBaseTable { let padded_height = MasterBaseTable::padded_height(aet); diff --git a/triton-vm/src/stark.rs b/triton-vm/src/stark.rs index 17bbbdc95..b85e2563b 100644 --- a/triton-vm/src/stark.rs +++ b/triton-vm/src/stark.rs @@ -139,7 +139,7 @@ pub struct Stark {} impl Stark { pub fn prove( - parameters: &StarkParameters, + parameters: StarkParameters, claim: &Claim, aet: &AlgebraicExecutionTrace, maybe_profiler: &mut Option, @@ -633,7 +633,7 @@ impl Stark { /// In principle, the FRI domain is also influenced by the AIR's degree /// (see [`AIR_TARGET_DEGREE`]). However, by segmenting the quotient polynomial into /// [`AIR_TARGET_DEGREE`]-many parts, that influence is mitigated. - pub fn derive_fri(parameters: &StarkParameters, padded_height: usize) -> Fri { + pub fn derive_fri(parameters: StarkParameters, padded_height: usize) -> Fri { let interpolant_degree = interpolant_degree(padded_height, parameters.num_trace_randomizers); let interpolant_codeword_length = interpolant_degree as usize + 1; @@ -753,7 +753,7 @@ impl Stark { } pub fn verify( - parameters: &StarkParameters, + parameters: StarkParameters, claim: &Claim, proof: &Proof, maybe_profiler: &mut Option, @@ -1177,7 +1177,7 @@ pub(crate) mod triton_stark_tests { .unwrap(); let parameters = stark_parameters_with_low_security_level(); let claim = construct_claim(&aet, public_input.individual_tokens, stdout); - let master_base_table = construct_master_base_table(¶meters, &aet); + let master_base_table = construct_master_base_table(parameters, &aet); (parameters, claim, master_base_table) } @@ -1764,7 +1764,7 @@ pub(crate) mod triton_stark_tests { &mut None, ); - let verdict = Stark::verify(¶meters, &claim, &proof, &mut None).unwrap(); + let verdict = Stark::verify(parameters, &claim, &proof, &mut None).unwrap(); assert!(verdict); } @@ -1781,14 +1781,14 @@ pub(crate) mod triton_stark_tests { let mut profiler = profiler.unwrap(); profiler.finish(); - let result = Stark::verify(¶meters, &claim, &proof, &mut None); + let result = Stark::verify(parameters, &claim, &proof, &mut None); if let Err(e) = result { panic!("The Verifier is unhappy! {e}"); } assert!(result.unwrap()); let padded_height = proof.padded_height().unwrap(); - let fri = Stark::derive_fri(¶meters, padded_height); + let fri = Stark::derive_fri(parameters, padded_height); let report = profiler .report() .with_padded_height(padded_height) @@ -1809,7 +1809,7 @@ pub(crate) mod triton_stark_tests { &mut None, ); - let verdict = Stark::verify(¶meters, &claim, &proof, &mut None); + let verdict = Stark::verify(parameters, &claim, &proof, &mut None); if verdict.is_err() { let filename = "halt_error.tsp"; save_proof(filename, proof).unwrap(); @@ -1832,7 +1832,7 @@ pub(crate) mod triton_stark_tests { let filename = "halt_error.tsp"; let proof = load_proof(filename).unwrap(); - let verdict = Stark::verify(¶meters, &claim, &proof, &mut None).unwrap(); + let verdict = Stark::verify(parameters, &claim, &proof, &mut None).unwrap(); assert!(verdict); } @@ -1849,14 +1849,14 @@ pub(crate) mod triton_stark_tests { println!("between prove and verify"); - let result = Stark::verify(¶meters, &claim, &proof, &mut None); + let result = Stark::verify(parameters, &claim, &proof, &mut None); if let Err(e) = result { panic!("The Verifier is unhappy! {e}"); } assert!(result.unwrap()); let padded_height = proof.padded_height().unwrap(); - let fri = Stark::derive_fri(¶meters, padded_height); + let fri = Stark::derive_fri(parameters, padded_height); let report = profiler .report() .with_padded_height(padded_height) @@ -1871,7 +1871,7 @@ pub(crate) mod triton_stark_tests { let secret_in = [].into(); let (parameters, claim, proof) = prove_with_low_security_level(&FIBONACCI_SEQUENCE, stdin, secret_in, &mut None); - match Stark::verify(¶meters, &claim, &proof, &mut None) { + match Stark::verify(parameters, &claim, &proof, &mut None) { Ok(result) => assert!(result, "The Verifier disagrees!"), Err(err) => panic!("The Verifier is unhappy! {err}"), } @@ -1899,14 +1899,14 @@ pub(crate) mod triton_stark_tests { let mut profiler = profiler.unwrap(); profiler.finish(); - let result = Stark::verify(¶meters, &claim, &proof, &mut None); + let result = Stark::verify(parameters, &claim, &proof, &mut None); if let Err(e) = result { panic!("The Verifier is unhappy! {e}"); } assert!(result.unwrap()); let padded_height = proof.padded_height().unwrap(); - let fri = Stark::derive_fri(¶meters, padded_height); + let fri = Stark::derive_fri(parameters, padded_height); let report = profiler .report() .with_padded_height(padded_height) @@ -1921,7 +1921,7 @@ pub(crate) mod triton_stark_tests { claim in arb::(), proof in arb::(), ) { - let _ = Stark::verify(¶meters, &claim, &proof, &mut None); + let _ = Stark::verify(parameters, &claim, &proof, &mut None); } } @@ -1938,7 +1938,7 @@ pub(crate) mod triton_stark_tests { profiler.finish(); let padded_height = proof.padded_height().unwrap(); - let fri = Stark::derive_fri(¶meters, padded_height); + let fri = Stark::derive_fri(parameters, padded_height); let report = profiler .report() .with_padded_height(padded_height) @@ -1956,7 +1956,7 @@ pub(crate) mod triton_stark_tests { let program = triton_program!(push {st0} log_2_floor halt); let (parameters, claim, proof) = prove_with_low_security_level(&program, [].into(), [].into(), &mut None); - let result = Stark::verify(¶meters, &claim, &proof, &mut None); + let result = Stark::verify(parameters, &claim, &proof, &mut None); assert!(result.is_ok()); assert!(result.unwrap()); } @@ -1967,7 +1967,7 @@ pub(crate) mod triton_stark_tests { let program = triton_program!(push 0 log_2_floor halt); let (parameters, claim, proof) = prove_with_low_security_level(&program, [].into(), [].into(), &mut None); - let result = Stark::verify(¶meters, &claim, &proof, &mut None); + let result = Stark::verify(parameters, &claim, &proof, &mut None); assert!(result.is_ok()); assert!(result.unwrap()); }