Skip to content

Commit

Permalink
fix!: use Copy-trait of StarkParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-ferdinand committed Oct 6, 2023
1 parent 1032930 commit 85b8df3
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions triton-vm/benches/proof_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(&parameters, &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)
}
Expand Down
6 changes: 3 additions & 3 deletions triton-vm/benches/prove_fib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&parameters, claim, aet, &mut None))
bencher.iter(|| Stark::prove(parameters, claim, aet, &mut None))
});
group.finish();
}
Expand All @@ -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(&parameters, 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(&parameters, padded_height);
let fri = Stark::derive_fri(parameters, padded_height);
profiler
.report()
.with_cycle_count(aet.processor_trace.nrows())
Expand Down
6 changes: 3 additions & 3 deletions triton-vm/benches/prove_halt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn prove_halt(criterion: &mut Criterion) {
output,
};
let mut profiler = Some(TritonProfiler::new("Prove Halt"));
let proof = Stark::prove(&parameters, &claim, &aet, &mut profiler);
let proof = Stark::prove(parameters, &claim, &aet, &mut profiler);
let mut profiler = profiler.unwrap();
profiler.finish();

Expand All @@ -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(&parameters, &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(&parameters, padded_height);
let fri = Stark::derive_fri(parameters, padded_height);
let report = profiler
.report()
.with_cycle_count(aet.processor_trace.nrows())
Expand Down
8 changes: 4 additions & 4 deletions triton-vm/benches/verify_halt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ fn verify_halt(criterion: &mut Criterion) {
};

let (aet, _) = program.trace_execution([].into(), [].into()).unwrap();
let proof = Stark::prove(&parameters, &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(&parameters, &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(&parameters, padded_height);
let fri = Stark::derive_fri(parameters, padded_height);
let report = profiler
.report()
.with_cycle_count(aet.processor_trace.nrows())
Expand All @@ -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(&parameters, &claim, &proof, &mut None);
let _ = Stark::verify(parameters, &claim, &proof, &mut None);
});
});
group.finish();
Expand Down
18 changes: 9 additions & 9 deletions triton-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
//! let (parameters, claim, proof) =
//! prove_program(&factorial_program, &public_input, &non_determinism).unwrap();
//!
//! let verdict = verify(&parameters, &claim, &proof);
//! let verdict = verify(parameters, &claim, &proof);
//! assert!(verdict);
//!
//! let public_output = claim.public_output();
Expand Down Expand Up @@ -117,7 +117,7 @@
//! let (parameters, claim, proof) =
//! prove_program(&sum_of_squares_program, &public_input, &non_determinism).unwrap();
//!
//! let verdict = verify(&parameters, &claim, &proof);
//! let verdict = verify(parameters, &claim, &proof);
//! assert!(verdict);
//! ```
//!
Expand Down Expand Up @@ -460,7 +460,7 @@ pub fn prove_program(
};

// Generate the proof.
let proof = Stark::prove(&parameters, &claim, &aet, &mut None);
let proof = Stark::prove(parameters, &claim, &aet, &mut None);

Ok((parameters, claim, proof))
}
Expand Down Expand Up @@ -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<BFieldElement>,
Expand All @@ -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)
}

Expand Down Expand Up @@ -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(&parameters, &claim, &proof);
let verdict = verify(parameters, &claim, &proof);
assert!(verdict);
}

Expand All @@ -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(&parameters, &claim, &proof);
let verdict = verify(parameters, &claim, &proof);
assert!(verdict);
}

Expand All @@ -608,8 +608,8 @@ mod public_interface_tests {
output: vec![],
};

let proof = prove(&parameters, &claim, &program, [].into()).unwrap();
let verdict = verify(&parameters, &claim, &proof);
let proof = prove(parameters, &claim, &program, [].into()).unwrap();
let verdict = verify(parameters, &claim, &proof);
assert!(verdict);
}

Expand Down
4 changes: 2 additions & 2 deletions triton-vm/src/shared_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&parameters, &claim, &aet, maybe_profiler);
let proof = Stark::prove(parameters, &claim, &aet, maybe_profiler);
prof_stop!(maybe_profiler, "prove");

(parameters, claim, proof)
Expand All @@ -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);
Expand Down
36 changes: 18 additions & 18 deletions triton-vm/src/stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub struct Stark {}

impl Stark {
pub fn prove(
parameters: &StarkParameters,
parameters: StarkParameters,
claim: &Claim,
aet: &AlgebraicExecutionTrace,
maybe_profiler: &mut Option<TritonProfiler>,
Expand Down Expand Up @@ -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<StarkHasher> {
pub fn derive_fri(parameters: StarkParameters, padded_height: usize) -> Fri<StarkHasher> {
let interpolant_degree =
interpolant_degree(padded_height, parameters.num_trace_randomizers);
let interpolant_codeword_length = interpolant_degree as usize + 1;
Expand Down Expand Up @@ -753,7 +753,7 @@ impl Stark {
}

pub fn verify(
parameters: &StarkParameters,
parameters: StarkParameters,
claim: &Claim,
proof: &Proof,
maybe_profiler: &mut Option<TritonProfiler>,
Expand Down Expand Up @@ -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(&parameters, &aet);
let master_base_table = construct_master_base_table(parameters, &aet);

(parameters, claim, master_base_table)
}
Expand Down Expand Up @@ -1764,7 +1764,7 @@ pub(crate) mod triton_stark_tests {
&mut None,
);

let verdict = Stark::verify(&parameters, &claim, &proof, &mut None).unwrap();
let verdict = Stark::verify(parameters, &claim, &proof, &mut None).unwrap();
assert!(verdict);
}

Expand All @@ -1781,14 +1781,14 @@ pub(crate) mod triton_stark_tests {
let mut profiler = profiler.unwrap();
profiler.finish();

let result = Stark::verify(&parameters, &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(&parameters, padded_height);
let fri = Stark::derive_fri(parameters, padded_height);
let report = profiler
.report()
.with_padded_height(padded_height)
Expand All @@ -1809,7 +1809,7 @@ pub(crate) mod triton_stark_tests {
&mut None,
);

let verdict = Stark::verify(&parameters, &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();
Expand All @@ -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(&parameters, &claim, &proof, &mut None).unwrap();
let verdict = Stark::verify(parameters, &claim, &proof, &mut None).unwrap();
assert!(verdict);
}

Expand All @@ -1849,14 +1849,14 @@ pub(crate) mod triton_stark_tests {

println!("between prove and verify");

let result = Stark::verify(&parameters, &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(&parameters, padded_height);
let fri = Stark::derive_fri(parameters, padded_height);
let report = profiler
.report()
.with_padded_height(padded_height)
Expand All @@ -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(&parameters, &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}"),
}
Expand Down Expand Up @@ -1899,14 +1899,14 @@ pub(crate) mod triton_stark_tests {
let mut profiler = profiler.unwrap();
profiler.finish();

let result = Stark::verify(&parameters, &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(&parameters, padded_height);
let fri = Stark::derive_fri(parameters, padded_height);
let report = profiler
.report()
.with_padded_height(padded_height)
Expand All @@ -1921,7 +1921,7 @@ pub(crate) mod triton_stark_tests {
claim in arb::<Claim>(),
proof in arb::<Proof>(),
) {
let _ = Stark::verify(&parameters, &claim, &proof, &mut None);
let _ = Stark::verify(parameters, &claim, &proof, &mut None);
}
}

Expand All @@ -1938,7 +1938,7 @@ pub(crate) mod triton_stark_tests {
profiler.finish();

let padded_height = proof.padded_height().unwrap();
let fri = Stark::derive_fri(&parameters, padded_height);
let fri = Stark::derive_fri(parameters, padded_height);
let report = profiler
.report()
.with_padded_height(padded_height)
Expand All @@ -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(&parameters, &claim, &proof, &mut None);
let result = Stark::verify(parameters, &claim, &proof, &mut None);
assert!(result.is_ok());
assert!(result.unwrap());
}
Expand All @@ -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(&parameters, &claim, &proof, &mut None);
let result = Stark::verify(parameters, &claim, &proof, &mut None);
assert!(result.is_ok());
assert!(result.unwrap());
}
Expand Down

0 comments on commit 85b8df3

Please sign in to comment.