Skip to content

Commit

Permalink
shrink size of FRI domain by splitting quotients into segments
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-ferdinand committed Aug 2, 2023
2 parents 2c27d10 + 394daa0 commit c4f1e55
Show file tree
Hide file tree
Showing 9 changed files with 814 additions and 466 deletions.
3 changes: 1 addition & 2 deletions triton-vm/benches/proof_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,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 {
let padded_height = proof.padded_height().unwrap();
let max_degree = Stark::derive_max_degree(padded_height, parameters.num_trace_randomizers);
let fri = Stark::derive_fri(parameters, max_degree);
let fri = Stark::derive_fri(parameters, padded_height);
fri.domain.length.ilog2()
}

Expand Down
3 changes: 1 addition & 2 deletions triton-vm/benches/prove_fib_100.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ fn prove_fib_100(criterion: &mut Criterion) {
let proof = Stark::prove(&parameters, &claim, &aet, &mut maybe_profiler);

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

if let Some(profiler) = maybe_profiler.as_mut() {
profiler.finish();
Expand Down
3 changes: 1 addition & 2 deletions triton-vm/benches/prove_halt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ fn prove_halt(criterion: &mut Criterion) {
let proof = Stark::prove(&parameters, &claim, &aet, &mut maybe_profiler);

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

if let Some(profiler) = &mut maybe_profiler {
profiler.finish();
Expand Down
3 changes: 1 addition & 2 deletions triton-vm/benches/verify_halt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ fn verify_halt(criterion: &mut Criterion) {
let mut profiler = profiler.unwrap();
profiler.finish();
let padded_height = proof.padded_height().unwrap();
let max_degree = Stark::derive_max_degree(padded_height, parameters.num_trace_randomizers);
let fri = Stark::derive_fri(&parameters, max_degree);
let fri = Stark::derive_fri(&parameters, padded_height);
let report = profiler.report(
Some(aet.processor_trace.nrows()),
Some(padded_height),
Expand Down
38 changes: 30 additions & 8 deletions triton-vm/src/proof_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use twenty_first::shared_math::bfield_codec::BFieldCodec;
use twenty_first::shared_math::tip5::Digest;
use twenty_first::shared_math::x_field_element::XFieldElement;

use crate::stark::NUM_QUOTIENT_SEGMENTS;

type AuthenticationStructure = Vec<Digest>;

/// A `FriResponse` is an `AuthenticationStructure` together with the values of the
Expand All @@ -27,9 +29,10 @@ pub enum ProofItem {
MasterExtTableRows(Vec<Vec<XFieldElement>>),
OutOfDomainBaseRow(Vec<XFieldElement>),
OutOfDomainExtRow(Vec<XFieldElement>),
OutOfDomainQuotientSegments([XFieldElement; NUM_QUOTIENT_SEGMENTS]),
MerkleRoot(Digest),
Log2PaddedHeight(u32),
RevealedCombinationElements(Vec<XFieldElement>),
QuotientSegmentsElements(Vec<[XFieldElement; NUM_QUOTIENT_SEGMENTS]>),
FriCodeword(Vec<XFieldElement>),
FriResponse(FriResponse),
}
Expand All @@ -44,9 +47,10 @@ impl ProofItem {
MasterExtTableRows(_) => 2,
OutOfDomainBaseRow(_) => 3,
OutOfDomainExtRow(_) => 4,
OutOfDomainQuotientSegments(_) => 10,
MerkleRoot(_) => 5,
Log2PaddedHeight(_) => 6,
RevealedCombinationElements(_) => 7,
QuotientSegmentsElements(_) => 7,
FriCodeword(_) => 8,
FriResponse(_) => 9,
};
Expand All @@ -67,12 +71,13 @@ impl ProofItem {
MerkleRoot(_) => true,
OutOfDomainBaseRow(_) => true,
OutOfDomainExtRow(_) => true,
OutOfDomainQuotientSegments(_) => true,
// all of the following are implied by a corresponding Merkle root
AuthenticationStructure(_) => false,
MasterBaseTableRows(_) => false,
MasterExtTableRows(_) => false,
Log2PaddedHeight(_) => false,
RevealedCombinationElements(_) => false,
QuotientSegmentsElements(_) => false,
FriCodeword(_) => false,
FriResponse(_) => false,
}
Expand Down Expand Up @@ -113,6 +118,15 @@ impl ProofItem {
}
}

pub fn as_out_of_domain_quotient_segments(
&self,
) -> Result<[XFieldElement; NUM_QUOTIENT_SEGMENTS]> {
match self {
Self::OutOfDomainQuotientSegments(xs) => Ok(*xs),
other => bail!("expected out of domain quotient segments, but got {other:?}",),
}
}

pub fn as_merkle_root(&self) -> Result<Digest> {
match self {
Self::MerkleRoot(bs) => Ok(*bs),
Expand All @@ -127,10 +141,12 @@ impl ProofItem {
}
}

pub fn as_revealed_combination_elements(&self) -> Result<Vec<XFieldElement>> {
pub fn as_quotient_segments_elements(
&self,
) -> Result<Vec<[XFieldElement; NUM_QUOTIENT_SEGMENTS]>> {
match self {
Self::RevealedCombinationElements(xs) => Ok(xs.to_owned()),
other => bail!("expected revealed combination elements, but got {other:?}",),
Self::QuotientSegmentsElements(xs) => Ok(xs.to_owned()),
other => bail!("expected quotient segments' elements, but got {other:?}",),
}
}

Expand Down Expand Up @@ -167,9 +183,14 @@ impl BFieldCodec for ProofItem {
4 => Self::OutOfDomainExtRow(*Vec::<XFieldElement>::decode(str)?),
5 => Self::MerkleRoot(*Digest::decode(str)?),
6 => Self::Log2PaddedHeight(*u32::decode(str)?),
7 => Self::RevealedCombinationElements(*Vec::<XFieldElement>::decode(str)?),
7 => Self::QuotientSegmentsElements(
*Vec::<[XFieldElement; NUM_QUOTIENT_SEGMENTS]>::decode(str)?,
),
8 => Self::FriCodeword(*Vec::<XFieldElement>::decode(str)?),
9 => Self::FriResponse(*FriResponse::decode(str)?),
10 => Self::OutOfDomainQuotientSegments(
*<[XFieldElement; NUM_QUOTIENT_SEGMENTS]>::decode(str)?,
),
i => bail!("Unknown discriminant {i} for ProofItem."),
};
Ok(Box::new(item))
Expand Down Expand Up @@ -198,9 +219,10 @@ impl BFieldCodec for ProofItem {
MasterExtTableRows(something) => something.encode(),
OutOfDomainBaseRow(row) => row.encode(),
OutOfDomainExtRow(row) => row.encode(),
OutOfDomainQuotientSegments(segments) => segments.encode(),
MerkleRoot(something) => something.encode(),
Log2PaddedHeight(height) => height.encode(),
RevealedCombinationElements(something) => something.encode(),
QuotientSegmentsElements(something) => something.encode(),
FriCodeword(something) => something.encode(),
FriResponse(something) => something.encode(),
};
Expand Down
10 changes: 4 additions & 6 deletions triton-vm/src/proof_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ mod proof_stream_typed_tests {

let ood_base_row = random_elements(rng.next_u64(), NUM_BASE_COLUMNS);
let ood_ext_row = random_elements(rng.next_u64(), NUM_EXT_COLUMNS);
let combination_elements = random_elements(rng.next_u64(), 5);
let quot_elements = random_elements(rng.next_u64(), 5);

let revealed_leaves = revealed_indices
.iter()
Expand All @@ -281,9 +281,7 @@ mod proof_stream_typed_tests {
sponge_states.push_back(proof_stream.sponge_state.state);
proof_stream.enqueue(&ProofItem::MerkleRoot(root));
sponge_states.push_back(proof_stream.sponge_state.state);
proof_stream.enqueue(&ProofItem::RevealedCombinationElements(
combination_elements.clone(),
));
proof_stream.enqueue(&ProofItem::QuotientSegmentsElements(quot_elements.clone()));
sponge_states.push_back(proof_stream.sponge_state.state);
proof_stream.enqueue(&ProofItem::FriCodeword(fri_codeword.clone()));
sponge_states.push_back(proof_stream.sponge_state.state);
Expand Down Expand Up @@ -355,8 +353,8 @@ mod proof_stream_typed_tests {
Some(proof_stream.sponge_state.state)
);
match proof_stream.dequeue().unwrap() {
ProofItem::RevealedCombinationElements(combination_elements_) => {
assert_eq!(combination_elements, combination_elements_)
ProofItem::QuotientSegmentsElements(quot_elements_) => {
assert_eq!(quot_elements, quot_elements_)
}
_ => panic!(),
};
Expand Down
12 changes: 9 additions & 3 deletions triton-vm/src/shared_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,16 @@ pub(crate) fn construct_master_base_table(
parameters: &StarkParameters,
aet: &AlgebraicExecutionTrace,
) -> MasterBaseTable {
let padded_height = MasterBaseTable::padded_height(aet, parameters.num_trace_randomizers);
let padded_height = MasterBaseTable::padded_height(aet);
let fri = Stark::derive_fri(parameters, padded_height);
let max_degree = Stark::derive_max_degree(padded_height, parameters.num_trace_randomizers);
let fri = Stark::derive_fri(parameters, max_degree);
MasterBaseTable::new(aet, parameters.num_trace_randomizers, fri.domain)
let quotient_domain = Stark::quotient_domain(fri.domain, max_degree);
MasterBaseTable::new(
aet,
parameters.num_trace_randomizers,
quotient_domain,
fri.domain,
)
}

/// Program and associated inputs.
Expand Down
Loading

0 comments on commit c4f1e55

Please sign in to comment.