forked from 0xPolygonZero/plonky2
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove usage of unstable
generic_const_exprs
in starky
This PR mostly lifts 0xPolygonZero#1246 down into the lib level into the starky crate, getting rid of the unstable `generic_const_exprs` feature from the crate entirely. This should work towards the 0xPolygonZero#417 as well. This would probably warrant a minor version bump in the starky crate to 0.2.0, since this would be an API change for anyone relying on starky.
- Loading branch information
1 parent
49976ea
commit 4024621
Showing
11 changed files
with
181 additions
and
176 deletions.
There are no files selected for viewing
This file contains 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,66 @@ | ||
/// A trait for viewing an evaluation frame of a STARK table. | ||
/// | ||
/// It allows to access the current and next rows at a given step | ||
/// and can be used to implement constraint evaluation both natively | ||
/// and recursively. | ||
pub trait StarkEvaluationFrame<T: Copy + Clone + Default, U: Copy + Clone + Default>: | ||
Sized | ||
{ | ||
/// The number of columns for the STARK table this evaluation frame views. | ||
const COLUMNS: usize; | ||
const PUBLIC_INPUTS: usize; | ||
|
||
/// Returns the local values (i.e. current row) for this evaluation frame. | ||
fn get_local_values(&self) -> &[T]; | ||
/// Returns the next values (i.e. next row) for this evaluation frame. | ||
fn get_next_values(&self) -> &[T]; | ||
|
||
fn get_public_inputs(&self) -> &[U]; | ||
/// Outputs a new evaluation frame from the provided local and next values. | ||
/// | ||
/// **NOTE**: Concrete implementations of this method SHOULD ensure that | ||
/// the provided slices lengths match the `Self::COLUMNS` value. | ||
fn from_values(lv: &[T], nv: &[T], pis: &[U]) -> Self; | ||
} | ||
|
||
pub struct StarkFrame< | ||
T: Copy + Clone + Default, | ||
U: Copy + Clone + Default, | ||
const N: usize, | ||
const N2: usize, | ||
> { | ||
local_values: [T; N], | ||
next_values: [T; N], | ||
public_inputs: [U; N2], | ||
} | ||
|
||
impl<T: Copy + Clone + Default, U: Copy + Clone + Default, const N: usize, const N2: usize> | ||
StarkEvaluationFrame<T, U> for StarkFrame<T, U, N, N2> | ||
{ | ||
const COLUMNS: usize = N; | ||
const PUBLIC_INPUTS: usize = N2; | ||
|
||
fn get_local_values(&self) -> &[T] { | ||
&self.local_values | ||
} | ||
|
||
fn get_next_values(&self) -> &[T] { | ||
&self.next_values | ||
} | ||
|
||
fn get_public_inputs(&self) -> &[U] { | ||
&self.public_inputs | ||
} | ||
|
||
fn from_values(lv: &[T], nv: &[T], pis: &[U]) -> Self { | ||
assert_eq!(lv.len(), Self::COLUMNS); | ||
assert_eq!(nv.len(), Self::COLUMNS); | ||
assert_eq!(pis.len(), Self::PUBLIC_INPUTS); | ||
|
||
Self { | ||
local_values: lv.try_into().unwrap(), | ||
next_values: nv.try_into().unwrap(), | ||
public_inputs: pis.try_into().unwrap(), | ||
} | ||
} | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.