-
Notifications
You must be signed in to change notification settings - Fork 1
Feat/airbuilder constraints #509
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
Closed
Closed
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
38a6b2a
docs: add AirBuilder constraint evaluation spec and plan
diegokingston fde3928
feat: add AirBuilder trait, ProverBuilder, and VerifierBuilder
diegokingston 60cc489
feat: add uses_builder and eval_constraints_with_builder to AIR trait
diegokingston dfdd4fc
fix: make AirBuilder parameterized for dyn-compatibility
diegokingston bc6c6b2
feat: add AirBuilder path to evaluator hot loop
diegokingston 3858851
feat: add AirBuilder path to verifier
diegokingston a55147e
feat: add constraint helper functions for AirBuilder
diegokingston b0df4ae
feat: migrate MEMW_R to AirBuilder (3 constraints)
diegokingston 0b19ae6
feat: migrate BRANCH and MEMW_A to AirBuilder (4+4 constraints)
diegokingston e9be4a8
feat: migrate MUL to AirBuilder (6 constraints)
diegokingston 1330ad1
feat: migrate COMMIT, LOAD, MEMW, SHIFT to AirBuilder (45 constraints)
diegokingston 6f879b5
feat: migrate DVRM to AirBuilder constraint evaluation
diegokingston 04dd7da
feat: migrate CPU table to AirBuilder constraint evaluation (66 const…
diegokingston 2ee2d37
refactor: remove old virtual-dispatch constraint evaluation paths
diegokingston c9534b2
fix: suppress clippy type_complexity for builder_fn field
diegokingston 8cdc2d3
feat: dual-field AirBuilder infrastructure for base-field constraint …
diegokingston 5b82ce3
perf: migrate all table constraint closures to base-field MainAirBuilder
diegokingston c18da78
fix: clippy warnings in main_builder closures
diegokingston ea69e3c
fix: add fallback paths for test AIRs without builders
diegokingston bd6a81e
perf: pre-compute alpha powers to eliminate E×E multiply per constraint
diegokingston 2bd552f
perf: unfuse constraint accumulation for better pipelining
diegokingston b1a1d73
perf: in-place row cache fill + verifier alpha powers fix
diegokingston d9a6337
perf: eliminate dyn dispatch in constraint evaluation
diegokingston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| use crate::frame::Frame; | ||
| use crate::trace::LDETraceTable; | ||
| use math::field::element::FieldElement; | ||
| use math::field::traits::{IsFFTField, IsField, IsSubFieldOf}; | ||
|
|
||
| /// Plonky3-style builder for fused constraint evaluation + alpha combination. | ||
| /// | ||
| /// Constraints call `assert_zero(expr)` which internally accumulates | ||
| /// alpha^i * expr into a running sum. No intermediate buffer, no vtable dispatch. | ||
| /// | ||
| /// Parameterized by field type `F` (not an associated type) so that `dyn AirBuilder<F>` | ||
| /// is object-safe. This allows the AIR trait to remain dyn-compatible while supporting | ||
| /// the builder pattern: `eval_constraints(&self, builder: &mut dyn AirBuilder<E>)`. | ||
| pub trait AirBuilder<F: IsField> { | ||
| /// Read main trace column at (row_offset, col). offset=0 is current row. | ||
| fn main(&self, offset: usize, col: usize) -> FieldElement<F>; | ||
|
|
||
| /// Read aux trace column at (row_offset, col). | ||
| fn aux(&self, offset: usize, col: usize) -> FieldElement<F>; | ||
|
|
||
| /// Assert expr == 0. Internally: accumulator += alpha^constraint_idx * expr. | ||
| fn assert_zero(&mut self, expr: FieldElement<F>); | ||
|
|
||
| /// RAP challenge by index. | ||
| fn challenge(&self, idx: usize) -> &FieldElement<F>; | ||
|
|
||
| /// Pre-computed LogUp alpha powers. | ||
| fn logup_alpha_power(&self, idx: usize) -> &FieldElement<F>; | ||
|
|
||
| /// LogUp table offset (L/N). | ||
| fn logup_table_offset(&self) -> &FieldElement<F>; | ||
| } | ||
|
|
||
| pub struct ProverBuilder<'a, F: IsSubFieldOf<E> + IsFFTField, E: IsField> { | ||
| lde_trace: &'a LDETraceTable<F, E>, | ||
| row: usize, | ||
| step_size: usize, | ||
| num_rows: usize, | ||
| accumulator: FieldElement<E>, | ||
| alpha: FieldElement<E>, | ||
| alpha_power: FieldElement<E>, | ||
| rap_challenges: &'a [FieldElement<E>], | ||
| logup_alpha_powers: &'a [FieldElement<E>], | ||
| logup_table_offset_val: &'a FieldElement<E>, | ||
| } | ||
|
|
||
| impl<'a, F, E> ProverBuilder<'a, F, E> | ||
| where | ||
| F: IsSubFieldOf<E> + IsFFTField + Send + Sync, | ||
| E: IsField + Send + Sync, | ||
| { | ||
| pub fn new( | ||
| lde_trace: &'a LDETraceTable<F, E>, | ||
| row: usize, | ||
| alpha: &FieldElement<E>, | ||
| rap_challenges: &'a [FieldElement<E>], | ||
| logup_alpha_powers: &'a [FieldElement<E>], | ||
| logup_table_offset: &'a FieldElement<E>, | ||
| ) -> Self { | ||
| Self { | ||
| lde_trace, | ||
| row, | ||
| step_size: lde_trace.lde_step_size, | ||
| num_rows: lde_trace.num_rows(), | ||
| accumulator: FieldElement::zero(), | ||
| alpha: alpha.clone(), | ||
| alpha_power: FieldElement::one(), | ||
| rap_challenges, | ||
| logup_alpha_powers, | ||
| logup_table_offset_val: logup_table_offset, | ||
| } | ||
| } | ||
|
|
||
| pub fn finish(self) -> FieldElement<E> { | ||
| self.accumulator | ||
| } | ||
| } | ||
|
|
||
| impl<'a, F, E> AirBuilder<E> for ProverBuilder<'a, F, E> | ||
| where | ||
| F: IsSubFieldOf<E> + IsFFTField + Send + Sync, | ||
| E: IsField + Send + Sync, | ||
| { | ||
| #[inline] | ||
| fn main(&self, offset: usize, col: usize) -> FieldElement<E> { | ||
| let lde_row = (self.row + offset * self.step_size) % self.num_rows; | ||
| self.lde_trace.get_main(lde_row, col).clone().to_extension() | ||
| } | ||
|
|
||
| #[inline] | ||
| fn aux(&self, offset: usize, col: usize) -> FieldElement<E> { | ||
| let lde_row = (self.row + offset * self.step_size) % self.num_rows; | ||
| self.lde_trace.get_aux(lde_row, col).clone() | ||
| } | ||
|
|
||
| #[inline] | ||
| fn assert_zero(&mut self, expr: FieldElement<E>) { | ||
| self.accumulator = &self.accumulator + &self.alpha_power * &expr; | ||
| self.alpha_power = &self.alpha_power * &self.alpha; | ||
| } | ||
|
|
||
| fn challenge(&self, idx: usize) -> &FieldElement<E> { | ||
| &self.rap_challenges[idx] | ||
| } | ||
|
|
||
| fn logup_alpha_power(&self, idx: usize) -> &FieldElement<E> { | ||
| &self.logup_alpha_powers[idx] | ||
| } | ||
|
|
||
| fn logup_table_offset(&self) -> &FieldElement<E> { | ||
| self.logup_table_offset_val | ||
| } | ||
| } | ||
|
|
||
| pub struct VerifierBuilder<'a, E: IsField> { | ||
| frame: &'a Frame<E, E>, | ||
| accumulator: FieldElement<E>, | ||
| alpha: FieldElement<E>, | ||
| alpha_power: FieldElement<E>, | ||
| rap_challenges: &'a [FieldElement<E>], | ||
| logup_alpha_powers: &'a [FieldElement<E>], | ||
| logup_table_offset_val: &'a FieldElement<E>, | ||
| } | ||
|
|
||
| impl<'a, E: IsField> VerifierBuilder<'a, E> { | ||
| pub fn new( | ||
| frame: &'a Frame<E, E>, | ||
| alpha: &FieldElement<E>, | ||
| rap_challenges: &'a [FieldElement<E>], | ||
| logup_alpha_powers: &'a [FieldElement<E>], | ||
| logup_table_offset: &'a FieldElement<E>, | ||
| ) -> Self { | ||
| Self { | ||
| frame, | ||
| accumulator: FieldElement::zero(), | ||
| alpha: alpha.clone(), | ||
| alpha_power: FieldElement::one(), | ||
| rap_challenges, | ||
| logup_alpha_powers, | ||
| logup_table_offset_val: logup_table_offset, | ||
| } | ||
| } | ||
|
|
||
| pub fn finish(self) -> FieldElement<E> { | ||
| self.accumulator | ||
| } | ||
| } | ||
|
|
||
| impl<'a, E: IsField> AirBuilder<E> for VerifierBuilder<'a, E> { | ||
| #[inline] | ||
| fn main(&self, offset: usize, col: usize) -> FieldElement<E> { | ||
| self.frame | ||
| .get_evaluation_step(offset) | ||
| .get_main_evaluation_element(0, col) | ||
| .clone() | ||
| } | ||
|
|
||
| #[inline] | ||
| fn aux(&self, offset: usize, col: usize) -> FieldElement<E> { | ||
| self.frame | ||
| .get_evaluation_step(offset) | ||
| .get_aux_evaluation_element(0, col) | ||
| .clone() | ||
| } | ||
|
|
||
| #[inline] | ||
| fn assert_zero(&mut self, expr: FieldElement<E>) { | ||
| self.accumulator = &self.accumulator + &self.alpha_power * &expr; | ||
| self.alpha_power = &self.alpha_power * &self.alpha; | ||
| } | ||
|
|
||
| fn challenge(&self, idx: usize) -> &FieldElement<E> { | ||
| &self.rap_challenges[idx] | ||
| } | ||
|
|
||
| fn logup_alpha_power(&self, idx: usize) -> &FieldElement<E> { | ||
| &self.logup_alpha_powers[idx] | ||
| } | ||
|
|
||
| fn logup_table_offset(&self) -> &FieldElement<E> { | ||
| self.logup_table_offset_val | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| pub mod air_builder; | ||
| #[cfg(feature = "debug-checks")] | ||
| pub mod bus_debug; | ||
| pub mod constraints; | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Medium:
panic!inside the hot looppanic!("AirBuilder requires uniform zerofiers")is evaluated once per LDE row (inside the parallelmap_initclosure). The same check appears again in the non-parallel path. Sinceis_uniformanduse_builderare both fixed for the lifetime of this call, this should be validated once before the loop starts, not on every row. A production proof with millions of rows would panic mid-way through the computation rather than failing fast.Move the check to the top of
evaluate_transitions, before the iterator is constructed:Then the inner branches can use
zerofier_data.get_uniform(i)unconditionally.