Skip to content

Commit

Permalink
remove the padded_height from the Claim
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-ferdinand committed Jun 13, 2023
1 parent 9e146e7 commit 4be177e
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 95 deletions.
12 changes: 4 additions & 8 deletions triton-vm/benches/prove_fib_100.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use triton_profiler::triton_profiler::TritonProfiler;
use triton_vm::proof::Claim;
use triton_vm::shared_tests::FIBONACCI_SEQUENCE;
use triton_vm::stark::Stark;
use triton_vm::table::master_table::MasterBaseTable;
use triton_vm::vm::simulate;
use triton_vm::StarkParameters;

Expand Down Expand Up @@ -44,25 +43,22 @@ fn prove_fib_100(criterion: &mut Criterion) {
}

let parameters = StarkParameters::default();
let padded_height = MasterBaseTable::padded_height(&aet, parameters.num_trace_randomizers);
let padded_height = BFieldElement::new(padded_height as u64);
let claim = Claim {
input: public_input,
program_digest: Tip5::hash(&program),
output,
padded_height,
};
let _proof = Stark::prove(&parameters, &claim, &aet, &mut maybe_profiler);
let proof = Stark::prove(&parameters, &claim, &aet, &mut maybe_profiler);

let max_degree =
Stark::derive_max_degree(claim.padded_height(), parameters.num_trace_randomizers);
let padded_height = proof.padded_height(&parameters);
let max_degree = Stark::derive_max_degree(padded_height, parameters.num_trace_randomizers);
let fri = Stark::derive_fri(&parameters, max_degree);

if let Some(profiler) = maybe_profiler.as_mut() {
profiler.finish();
report = profiler.report(
Some(aet.processor_trace.nrows()),
Some(claim.padded_height()),
Some(padded_height),
Some(fri.domain.length),
);
}
Expand Down
13 changes: 4 additions & 9 deletions triton-vm/benches/prove_halt.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use criterion::criterion_group;
use criterion::criterion_main;
use criterion::Criterion;
use triton_opcodes::program::Program;
use twenty_first::shared_math::b_field_element::BFieldElement;
use twenty_first::shared_math::tip5::Tip5;
use twenty_first::util_types::algebraic_hasher::AlgebraicHasher;

use triton_opcodes::program::Program;
use triton_profiler::prof_start;
use triton_profiler::prof_stop;
use triton_profiler::triton_profiler::Report;
Expand All @@ -14,7 +13,6 @@ use triton_vm::proof::Claim;
use triton_vm::shared_tests::save_proof;
use triton_vm::stark::Stark;
use triton_vm::stark::StarkParameters;
use triton_vm::table::master_table::MasterBaseTable;
use triton_vm::vm::simulate;

/// cargo criterion --bench prove_halt
Expand All @@ -40,25 +38,22 @@ fn prove_halt(_criterion: &mut Criterion) {

let cycle_count = aet.processor_trace.nrows();
let parameters = StarkParameters::default();
let num_trace_randomizers = parameters.num_trace_randomizers;
let padded_height = MasterBaseTable::padded_height(&aet, num_trace_randomizers);
let padded_height = BFieldElement::new(padded_height as u64);
let claim = Claim {
input: vec![],
program_digest: Tip5::hash(&program),
output,
padded_height,
};
let proof = Stark::prove(&parameters, &claim, &aet, &mut maybe_profiler);

let max_degree = Stark::derive_max_degree(claim.padded_height(), num_trace_randomizers);
let padded_height = proof.padded_height(&parameters);
let max_degree = Stark::derive_max_degree(padded_height, parameters.num_trace_randomizers);
let fri = Stark::derive_fri(&parameters, max_degree);

if let Some(profiler) = &mut maybe_profiler {
profiler.finish();
report = profiler.report(
Some(cycle_count),
Some(claim.padded_height()),
Some(padded_height),
Some(fri.domain.length),
);
};
Expand Down
7 changes: 3 additions & 4 deletions triton-vm/benches/verify_halt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ fn verify_halt(criterion: &mut Criterion) {
input: vec![],
program_digest: Tip5::hash(&program),
output: vec![],
padded_height: 256_u64.into(), // domain-specific knowledge
};

let filename = "halt.tsp";
Expand Down Expand Up @@ -57,12 +56,12 @@ fn verify_halt(criterion: &mut Criterion) {

let mut profiler = profiler.unwrap();
profiler.finish();
let max_degree =
Stark::derive_max_degree(claim.padded_height(), parameters.num_trace_randomizers);
let padded_height = proof.padded_height(&parameters);
let max_degree = Stark::derive_max_degree(padded_height, parameters.num_trace_randomizers);
let fri = Stark::derive_fri(&parameters, max_degree);
let report = profiler.report(
maybe_cycle_count,
Some(claim.padded_height()),
Some(padded_height),
Some(fri.domain.length),
);

Expand Down
14 changes: 4 additions & 10 deletions triton-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
//! of programs written in Triton assembly. The proof system is a zk-STARK, which is a
//! state-of-the-art ZKPS.
use triton_opcodes::program::Program;
pub use twenty_first::shared_math::b_field_element::BFieldElement;
pub use twenty_first::shared_math::tip5::Digest;
use twenty_first::shared_math::tip5::Tip5;
use twenty_first::util_types::algebraic_hasher::AlgebraicHasher;

use triton_opcodes::program::Program;

pub use crate::proof::Claim;
use crate::proof::Proof;
pub use crate::proof::Proof;
use crate::stark::Stark;
pub use crate::stark::StarkParameters;
use crate::table::master_table::MasterBaseTable;

pub mod arithmetic_domain;
pub mod error;
Expand Down Expand Up @@ -91,18 +91,12 @@ pub fn prove(
// The default parameters give a (conjectured) security level of 160 bits.
let parameters = StarkParameters::default();

// Compute the padded height of the AET. The padded height is the smallest power of two
// that is larger than or equal to the height of the largest table in the AET.
let padded_height = MasterBaseTable::padded_height(&aet, parameters.num_trace_randomizers);
let padded_height = BFieldElement::new(padded_height as u64);

// Set up the claim that is to be proven. The claim contains all public information. The
// proof is zero-knowledge with respect to everything else.
let claim = Claim {
input: public_input,
program_digest,
input: public_input,
output: public_output,
padded_height,
};

// Generate the proof.
Expand Down
28 changes: 7 additions & 21 deletions triton-vm/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ impl Proof {
}
}

/// Contains all the public information of a verifiably correct computation.
/// Contains the public information of a verifiably correct computation.
/// A corresponding [`Proof`] is needed to verify the computation.
/// One additional piece of public information not explicitly listed in the [`Claim`] is the
/// `padded_height`, an upper bound on the length of the computation.
/// It is derivable from a [`Proof`] by calling [`Proof::padded_height()`].
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, GetSize, BFieldCodec)]
pub struct Claim {
/// The hash digest of the program that was executed. The hash function in use is Tip5.
Expand All @@ -158,9 +161,6 @@ pub struct Claim {

/// The public output of the computation.
pub output: Vec<BFieldElement>,

/// An upper bound on the length of the computation.
pub padded_height: BFieldElement,
}

impl Claim {
Expand All @@ -175,12 +175,6 @@ impl Claim {
pub fn public_output(&self) -> Vec<u64> {
self.output.iter().map(|x| x.value()).collect()
}

/// The padded height as `u64`.
/// If a `BFieldElement` is needed, use field `padded_height`.
pub fn padded_height(&self) -> usize {
self.padded_height.value() as usize
}
}

#[cfg(test)]
Expand All @@ -191,7 +185,6 @@ pub mod test_claim_proof {
use twenty_first::shared_math::b_field_element::BFieldElement;
use twenty_first::shared_math::bfield_codec::BFieldCodec;
use twenty_first::shared_math::other::random_elements;
use twenty_first::shared_math::tip5::Digest;

use crate::stark::Stark;

Expand All @@ -210,16 +203,10 @@ pub mod test_claim_proof {

#[test]
fn test_decode_claim() {
let program_digest: Digest = random();
let input: Vec<BFieldElement> = random_elements(346);
let output: Vec<BFieldElement> = random_elements(125);
let padded_height = 11_u64.into();

let claim = Claim {
program_digest,
input,
output,
padded_height,
program_digest: random(),
input: random_elements(346),
output: random_elements(125),
};

let encoded = claim.encode();
Expand All @@ -228,7 +215,6 @@ pub mod test_claim_proof {
assert_eq!(claim.program_digest, decoded.program_digest);
assert_eq!(claim.input, decoded.input);
assert_eq!(claim.output, decoded.output);
// padded height is ignored
}

#[test]
Expand Down
2 changes: 0 additions & 2 deletions triton-vm/src/proof_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,10 @@ mod proof_stream_typed_tests {
let program_digest = random_elements(rng.next_u64(), 1)[0];
let input = random_elements(rng.next_u64(), 5);
let output = random_elements(rng.next_u64(), 5);
let padded_height = random_elements(rng.next_u64(), 1)[0];
let claim = Claim {
program_digest,
input,
output,
padded_height,
};

let mut sponge_states = VecDeque::new();
Expand Down
4 changes: 0 additions & 4 deletions triton-vm/src/shared_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::proof::Claim;
use crate::proof::Proof;
use crate::stark::Stark;
use crate::stark::StarkParameters;
use crate::table::master_table::MasterBaseTable;
use crate::vm::simulate;
use crate::vm::AlgebraicExecutionTrace;

Expand Down Expand Up @@ -55,13 +54,10 @@ pub fn parse_simulate_prove(
let security_level = 32;
let parameters = StarkParameters::new(security_level, log_expansion_factor);

let padded_height = MasterBaseTable::padded_height(&aet, parameters.num_trace_randomizers);
let padded_height = BFieldElement::new(padded_height as u64);
let claim = Claim {
input: public_input,
program_digest: Tip5::hash(&aet.program),
output: public_output,
padded_height,
};

prof_start!(maybe_profiler, "prove");
Expand Down
Loading

0 comments on commit 4be177e

Please sign in to comment.