-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Opt const eval #17
base: main
Are you sure you want to change the base?
Opt const eval #17
Changes from all commits
50e7040
d0def7a
5340ca1
c7331c8
6d5a1cc
df1ecd2
e31f24d
4b93d5e
73136bc
1f30ec3
8b1a197
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,10 @@ | |
// This source code is licensed under the MIT license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
|
||
use air::Air; | ||
use math::{fft, log2, StarkField}; | ||
use std::collections::HashMap; | ||
|
||
use air::{Air, ConstraintDivisor}; | ||
use math::{fft, get_power_series, log2, StarkField}; | ||
use utils::collections::Vec; | ||
|
||
// TYPES AND INTERFACES | ||
|
@@ -15,14 +17,17 @@ pub struct StarkDomain<B: StarkField> { | |
/// vector is half the length of the trace domain size. | ||
trace_twiddles: Vec<B>, | ||
|
||
/// Size of the constraint evaluation domain. | ||
ce_domain_size: usize, | ||
|
||
/// LDE domain size / constraint evaluation domain size | ||
ce_to_lde_blowup: usize, | ||
|
||
/// Offset of the low-degree extension domain. | ||
domain_offset: B, | ||
|
||
/// [g^i for i in (0..ce_domain_size)] where g is the constraint evaluation domain generator. | ||
ce_domain: Vec<B>, | ||
|
||
/// A mapping from adjustment degrees to domain_offset^adjustment_degree. | ||
degree_adj_map: HashMap<u32, B>, | ||
} | ||
|
||
// STARK DOMAIN IMPLEMENTATION | ||
|
@@ -32,11 +37,17 @@ impl<B: StarkField> StarkDomain<B> { | |
/// Returns a new STARK domain initialized with the provided `context`. | ||
pub fn new<A: Air<BaseField = B>>(air: &A) -> Self { | ||
let trace_twiddles = fft::get_twiddles(air.trace_length()); | ||
|
||
let domain_gen = B::get_root_of_unity(log2(air.ce_domain_size())); | ||
let ce_domain = get_power_series(domain_gen, air.ce_domain_size()); | ||
let degree_adj_map = generate_degree_adj_map(air); | ||
|
||
StarkDomain { | ||
trace_twiddles, | ||
ce_domain_size: air.ce_domain_size(), | ||
ce_to_lde_blowup: air.lde_domain_size() / air.ce_domain_size(), | ||
domain_offset: air.domain_offset(), | ||
ce_domain, | ||
degree_adj_map, | ||
} | ||
} | ||
|
||
|
@@ -68,7 +79,17 @@ impl<B: StarkField> StarkDomain<B> { | |
|
||
/// Returns the size of the constraint evaluation domain for this computation. | ||
pub fn ce_domain_size(&self) -> usize { | ||
self.ce_domain_size | ||
self.ce_domain.len() | ||
} | ||
|
||
/// Returns the constraint evaluation domain for this computation. | ||
pub fn ce_domain(&self) -> Vec<B> { | ||
self.ce_domain.clone() | ||
} | ||
|
||
/// Returns the degree adjustment map for this computation. | ||
pub fn degree_adj_map(&self) -> HashMap<u32, B> { | ||
self.degree_adj_map.clone() | ||
} | ||
|
||
/// Returns the generator of constraint evaluation domain. | ||
|
@@ -81,6 +102,24 @@ impl<B: StarkField> StarkDomain<B> { | |
self.ce_to_lde_blowup | ||
} | ||
|
||
/// Returns (offset * g^(step))^degree_adjustment. | ||
#[inline(always)] | ||
pub fn get_ce_x_power_at<A: Air<BaseField = B>>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could try adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I did here and in the helper function on the same file. |
||
&self, | ||
step: usize, | ||
degree_adjustment: u32, | ||
) -> A::BaseField { | ||
let index: usize = step * (degree_adjustment as usize); | ||
let index = index % (self.ce_domain_size()); | ||
let xp = self.ce_domain()[index] | ||
* *self | ||
.degree_adj_map() | ||
.get(°ree_adjustment) | ||
.expect("Degree adjustment map malformed"); | ||
|
||
xp | ||
} | ||
|
||
// LOW-DEGREE EXTENSION DOMAIN | ||
// -------------------------------------------------------------------------------------------- | ||
|
||
|
@@ -94,3 +133,31 @@ impl<B: StarkField> StarkDomain<B> { | |
self.domain_offset | ||
} | ||
} | ||
|
||
// HELPERS | ||
// -------------------------------------------------------------------------------------------- | ||
|
||
#[inline(always)] | ||
fn generate_degree_adj_map<A: Air<BaseField = B>, B: StarkField>(air: &A) -> HashMap<u32, B> { | ||
let mut degree_adj_map = HashMap::new(); | ||
let domain_offset = air.domain_offset(); | ||
let context = air.context(); | ||
let divisor: ConstraintDivisor<B> = ConstraintDivisor::from_transition( | ||
context.trace_len(), | ||
context.num_transition_exemptions(), | ||
); | ||
let div_deg = divisor.degree(); | ||
let constraint_degrees = context.transition_constraint_degrees(); | ||
let trace_len = context.trace_len(); | ||
let comp_deg = context.composition_degree(); | ||
let target_deg = comp_deg + div_deg; | ||
|
||
for degree in constraint_degrees { | ||
let evaluation_degree = degree.get_evaluation_degree(trace_len); | ||
let degree_adjustment = (target_deg - evaluation_degree) as u32; | ||
let _ = degree_adj_map | ||
.entry(degree_adjustment) | ||
.or_insert_with(|| domain_offset.exp(degree_adjustment.into())); | ||
} | ||
degree_adj_map | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment above probably should be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, let me know what you think.