Skip to content

Commit

Permalink
dynamic params usize -> u32
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Dec 18, 2024
1 parent ccb89e8 commit 0605deb
Show file tree
Hide file tree
Showing 20 changed files with 1,556 additions and 1,354 deletions.
4 changes: 2 additions & 2 deletions cli/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ impl TransformTo<PublicInputVerifier> for stark_proof::PublicInput {
let dynamic_params = match self.dynamic_params.is_empty() {
true => None,
false => {
let params: Vec<usize> =
self.dynamic_params.values().map(|&f| f as usize).collect();
let params: Vec<u32> =
self.dynamic_params.values().cloned().collect();
Some(DynamicParams::from(params))
}
};
Expand Down
686 changes: 343 additions & 343 deletions crates/air/src/dynamic.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crates/air/src/layout/dex/autogenerated/autogenerated_oods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,12 +727,12 @@ pub fn eval_oods_polynomial_inner<Layout: StaticLayoutTrait + LayoutTrait>(
// Sum the OODS boundary constraints on the composition polynomials.
let oods_point_to_deg = oods_point.pow_felt(&(Layout::CONSTRAINT_DEGREE.into()));

let value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND]
let value = (column_values[Layout::NUM_COLUMNS_FIRST as usize + Layout::NUM_COLUMNS_SECOND as usize]
- oods_values[200])
.field_div(&felt_nonzero!(point - oods_point_to_deg));
let total_sum = total_sum + constraint_coefficients[200] * value;

let value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND + 1]
let value = (column_values[Layout::NUM_COLUMNS_FIRST as usize + Layout::NUM_COLUMNS_SECOND as usize + 1]
- oods_values[201])
.field_div(&felt_nonzero!(point - oods_point_to_deg));

Expand Down
8 changes: 4 additions & 4 deletions crates/air/src/layout/dex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ pub const BUILTINS: [Felt; 4] =
pub struct Layout {}

impl StaticLayoutTrait for Layout {
const NUM_COLUMNS_FIRST: usize = 21;
const NUM_COLUMNS_SECOND: usize = 1;
const NUM_COLUMNS_FIRST: u32 = 21;
const NUM_COLUMNS_SECOND: u32 = 1;
}

impl GenericLayoutTrait for Layout {
fn get_num_columns_first(_public_input: &PublicInput) -> Option<usize> {
fn get_num_columns_first(_public_input: &PublicInput) -> Option<u32> {
Some(Self::NUM_COLUMNS_FIRST)
}
fn get_num_columns_second(_public_input: &PublicInput) -> Option<usize> {
fn get_num_columns_second(_public_input: &PublicInput) -> Option<u32> {
Some(Self::NUM_COLUMNS_SECOND)
}
}
Expand Down
2,092 changes: 1,144 additions & 948 deletions crates/air/src/layout/dynamic/autogenerated/autogenerated_oods.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crates/air/src/layout/dynamic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ pub const BUILTINS: [Felt; 11] = [
pub struct Layout {}

impl GenericLayoutTrait for Layout {
fn get_num_columns_first(public_input: &PublicInput) -> Option<usize> {
fn get_num_columns_first(public_input: &PublicInput) -> Option<u32> {
public_input.dynamic_params.as_ref().map(|d| d.num_columns_first)
}
fn get_num_columns_second(public_input: &PublicInput) -> Option<usize> {
fn get_num_columns_second(public_input: &PublicInput) -> Option<u32> {
public_input.dynamic_params.as_ref().map(|d| d.num_columns_second)
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/air/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ pub trait LayoutTrait {
}

pub trait StaticLayoutTrait {
const NUM_COLUMNS_FIRST: usize;
const NUM_COLUMNS_SECOND: usize;
const NUM_COLUMNS_FIRST: u32;
const NUM_COLUMNS_SECOND: u32;
}

pub trait GenericLayoutTrait {
fn get_num_columns_first(public_input: &PublicInput) -> Option<usize>;
fn get_num_columns_second(public_input: &PublicInput) -> Option<usize>;
fn get_num_columns_first(public_input: &PublicInput) -> Option<u32>;
fn get_num_columns_second(public_input: &PublicInput) -> Option<u32>;
}

pub fn safe_div(value: Felt, divisor: Felt) -> Result<Felt, FeltIsZeroError> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,12 @@ pub fn eval_oods_polynomial_inner<Layout: StaticLayoutTrait + LayoutTrait>(
// Sum the OODS boundary constraints on the composition polynomials.
let oods_point_to_deg = oods_point.pow_felt(&(Layout::CONSTRAINT_DEGREE.into()));

let value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND]
let value = (column_values[Layout::NUM_COLUMNS_FIRST as usize + Layout::NUM_COLUMNS_SECOND as usize]
- oods_values[133])
.field_div(&felt_nonzero!(point - oods_point_to_deg));
let total_sum = total_sum + constraint_coefficients[133] * value;

let value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND + 1]
let value = (column_values[Layout::NUM_COLUMNS_FIRST as usize + Layout::NUM_COLUMNS_SECOND as usize + 1]
- oods_values[134])
.field_div(&felt_nonzero!(point - oods_point_to_deg));

Expand Down
8 changes: 4 additions & 4 deletions crates/air/src/layout/recursive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ pub const BUILTINS: [Felt; 4] =
pub struct Layout {}

impl StaticLayoutTrait for Layout {
const NUM_COLUMNS_FIRST: usize = 7;
const NUM_COLUMNS_SECOND: usize = 3;
const NUM_COLUMNS_FIRST: u32 = 7;
const NUM_COLUMNS_SECOND: u32 = 3;
}

impl GenericLayoutTrait for Layout {
fn get_num_columns_first(_public_input: &PublicInput) -> Option<usize> {
fn get_num_columns_first(_public_input: &PublicInput) -> Option<u32> {
Some(Self::NUM_COLUMNS_FIRST)
}
fn get_num_columns_second(_public_input: &PublicInput) -> Option<usize> {
fn get_num_columns_second(_public_input: &PublicInput) -> Option<u32> {
Some(Self::NUM_COLUMNS_SECOND)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,12 +742,12 @@ pub fn eval_oods_polynomial_inner<Layout: StaticLayoutTrait + LayoutTrait>(
// Sum the OODS boundary constraints on the composition polynomials.
let oods_point_to_deg = oods_point.pow_felt(&(Layout::CONSTRAINT_DEGREE.into()));

let value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND]
let value = (column_values[Layout::NUM_COLUMNS_FIRST as usize + Layout::NUM_COLUMNS_SECOND as usize]
- oods_values[192])
.field_div(&felt_nonzero!(point - oods_point_to_deg));
let total_sum = total_sum + constraint_coefficients[192] * value;

let value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND + 1]
let value = (column_values[Layout::NUM_COLUMNS_FIRST as usize + Layout::NUM_COLUMNS_SECOND as usize + 1]
- oods_values[193])
.field_div(&felt_nonzero!(point - oods_point_to_deg));

Expand Down
8 changes: 4 additions & 4 deletions crates/air/src/layout/recursive_with_poseidon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ pub const BUILTINS: [Felt; 5] = [
pub struct Layout {}

impl StaticLayoutTrait for Layout {
const NUM_COLUMNS_FIRST: usize = 6;
const NUM_COLUMNS_SECOND: usize = 2;
const NUM_COLUMNS_FIRST: u32 = 6;
const NUM_COLUMNS_SECOND: u32 = 2;
}

impl GenericLayoutTrait for Layout {
fn get_num_columns_first(_public_input: &PublicInput) -> Option<usize> {
fn get_num_columns_first(_public_input: &PublicInput) -> Option<u32> {
Some(Self::NUM_COLUMNS_FIRST)
}
fn get_num_columns_second(_public_input: &PublicInput) -> Option<usize> {
fn get_num_columns_second(_public_input: &PublicInput) -> Option<u32> {
Some(Self::NUM_COLUMNS_SECOND)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,12 @@ pub fn eval_oods_polynomial_inner<Layout: StaticLayoutTrait + LayoutTrait>(
// Sum the OODS boundary constraints on the composition polynomials.
let oods_point_to_deg = oods_point.pow_felt(&(Layout::CONSTRAINT_DEGREE.into()));

let value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND]
let value = (column_values[Layout::NUM_COLUMNS_FIRST as usize + Layout::NUM_COLUMNS_SECOND as usize]
- oods_values[201])
.field_div(&felt_nonzero!(point - oods_point_to_deg));
let total_sum = total_sum + constraint_coefficients[201] * value;

let value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND + 1]
let value = (column_values[Layout::NUM_COLUMNS_FIRST as usize + Layout::NUM_COLUMNS_SECOND as usize + 1]
- oods_values[202])
.field_div(&felt_nonzero!(point - oods_point_to_deg));

Expand Down
8 changes: 4 additions & 4 deletions crates/air/src/layout/small/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ pub const BUILTINS: [Felt; 4] =
pub struct Layout {}

impl StaticLayoutTrait for Layout {
const NUM_COLUMNS_FIRST: usize = 23;
const NUM_COLUMNS_SECOND: usize = 2;
const NUM_COLUMNS_FIRST: u32 = 23;
const NUM_COLUMNS_SECOND: u32 = 2;
}

impl GenericLayoutTrait for Layout {
fn get_num_columns_first(_public_input: &PublicInput) -> Option<usize> {
fn get_num_columns_first(_public_input: &PublicInput) -> Option<u32> {
Some(Self::NUM_COLUMNS_FIRST)
}
fn get_num_columns_second(_public_input: &PublicInput) -> Option<usize> {
fn get_num_columns_second(_public_input: &PublicInput) -> Option<u32> {
Some(Self::NUM_COLUMNS_SECOND)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1040,12 +1040,12 @@ pub fn eval_oods_polynomial_inner<Layout: StaticLayoutTrait + LayoutTrait>(
// Sum the OODS boundary constraints on the composition polynomials.
let oods_point_to_deg = oods_point.pow_felt(&(Layout::CONSTRAINT_DEGREE.into()));

let value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND]
let value = (column_values[Layout::NUM_COLUMNS_FIRST as usize + Layout::NUM_COLUMNS_SECOND as usize]
- oods_values[271])
.field_div(&felt_nonzero!(point - oods_point_to_deg));
let total_sum = total_sum + constraint_coefficients[271] * value;

let value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND + 1]
let value = (column_values[Layout::NUM_COLUMNS_FIRST as usize + Layout::NUM_COLUMNS_SECOND as usize + 1]
- oods_values[272])
.field_div(&felt_nonzero!(point - oods_point_to_deg));

Expand Down
8 changes: 4 additions & 4 deletions crates/air/src/layout/starknet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ pub const BUILTINS: [Felt; 7] = [
pub struct Layout {}

impl StaticLayoutTrait for Layout {
const NUM_COLUMNS_FIRST: usize = 9;
const NUM_COLUMNS_SECOND: usize = 1;
const NUM_COLUMNS_FIRST: u32 = 9;
const NUM_COLUMNS_SECOND: u32 = 1;
}

impl GenericLayoutTrait for Layout {
fn get_num_columns_first(_public_input: &PublicInput) -> Option<usize> {
fn get_num_columns_first(_public_input: &PublicInput) -> Option<u32> {
Some(Self::NUM_COLUMNS_FIRST)
}
fn get_num_columns_second(_public_input: &PublicInput) -> Option<usize> {
fn get_num_columns_second(_public_input: &PublicInput) -> Option<u32> {
Some(Self::NUM_COLUMNS_SECOND)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3014,12 +3014,12 @@ pub fn eval_oods_polynomial_inner<Layout: StaticLayoutTrait + LayoutTrait>(
// Sum the OODS boundary constraints on the composition polynomials.
let oods_point_to_deg = oods_point.pow_felt(&(Layout::CONSTRAINT_DEGREE.into()));

let value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND]
let value = (column_values[Layout::NUM_COLUMNS_FIRST as usize + Layout::NUM_COLUMNS_SECOND as usize]
- oods_values[734])
.field_div(&felt_nonzero!(point - oods_point_to_deg));
let total_sum = total_sum + constraint_coefficients[734] * value;

let value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND + 1]
let value = (column_values[Layout::NUM_COLUMNS_FIRST as usize + Layout::NUM_COLUMNS_SECOND as usize + 1]
- oods_values[735])
.field_div(&felt_nonzero!(point - oods_point_to_deg));

Expand Down
8 changes: 4 additions & 4 deletions crates/air/src/layout/starknet_with_keccak/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ pub const BUILTINS: [Felt; 8] = [
pub struct Layout {}

impl StaticLayoutTrait for Layout {
const NUM_COLUMNS_FIRST: usize = 12;
const NUM_COLUMNS_SECOND: usize = 3;
const NUM_COLUMNS_FIRST: u32 = 12;
const NUM_COLUMNS_SECOND: u32 = 3;
}

impl GenericLayoutTrait for Layout {
fn get_num_columns_first(_public_input: &PublicInput) -> Option<usize> {
fn get_num_columns_first(_public_input: &PublicInput) -> Option<u32> {
Some(Self::NUM_COLUMNS_FIRST)
}
fn get_num_columns_second(_public_input: &PublicInput) -> Option<usize> {
fn get_num_columns_second(_public_input: &PublicInput) -> Option<u32> {
Some(Self::NUM_COLUMNS_SECOND)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/air/src/public_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl PublicInput {
};

if let Some(dynamic_params) = &self.dynamic_params {
let dynamic_params_vec: Vec<usize> = dynamic_params.clone().into();
let dynamic_params_vec: Vec<u32> = dynamic_params.clone().into();
hash_data.extend(dynamic_params_vec.into_iter().map(Felt::from));
}

Expand Down
38 changes: 22 additions & 16 deletions crates/stark/src/oods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ pub enum OodsVerifyError {
}

pub fn eval_oods_boundary_poly_at_points<Layout: LayoutTrait>(
n_original_columns: usize,
n_interaction_columns: usize,
n_original_columns: u32,
n_interaction_columns: u32,
public_input: &PublicInput,
eval_info: &OodsEvaluationInfo,
points: &[Felt],
decommitment: &trace::Decommitment,
composition_decommitment: &table::types::Decommitment,
) -> Vec<Felt> {
assert!(
decommitment.original.values.len() == points.len() * n_original_columns,
decommitment.original.values.len() as u32 == points.len() as u32 * n_original_columns,
"Invalid value"
);
assert!(
decommitment.interaction.values.len() == points.len() * n_interaction_columns,
decommitment.interaction.values.len() as u32 == points.len() as u32 * n_interaction_columns,
"Invalid value"
);
assert!(
Expand All @@ -98,30 +98,36 @@ pub fn eval_oods_boundary_poly_at_points<Layout: LayoutTrait>(

for (i, &point) in points.iter().enumerate() {
let mut column_values = Vec::with_capacity(
n_original_columns + n_interaction_columns + Layout::CONSTRAINT_DEGREE,
n_original_columns as usize
+ n_interaction_columns as usize
+ Layout::CONSTRAINT_DEGREE,
);

column_values.extend(
&decommitment.original.values[i * n_original_columns..(i + 1) * n_original_columns],
&decommitment.original.values
[i * n_original_columns as usize..(i + 1) * n_original_columns as usize],
);
column_values.extend(
&decommitment.interaction.values
[i * n_interaction_columns..(i + 1) * n_interaction_columns],
[i * n_interaction_columns as usize..(i + 1) * n_interaction_columns as usize],
);
column_values.extend(
&composition_decommitment.values
[i * Layout::CONSTRAINT_DEGREE..(i + 1) * Layout::CONSTRAINT_DEGREE],
);

evaluations.push(Layout::eval_oods_polynomial(
public_input,
&column_values,
&eval_info.oods_values,
&eval_info.constraint_coefficients,
&point,
&eval_info.oods_point,
&eval_info.trace_generator,
).unwrap());
evaluations.push(
Layout::eval_oods_polynomial(
public_input,
&column_values,
&eval_info.oods_values,
&eval_info.constraint_coefficients,
&point,
&eval_info.oods_point,
&eval_info.trace_generator,
)
.unwrap(),
);
}

evaluations
Expand Down
4 changes: 2 additions & 2 deletions crates/stark/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use crate::{

// STARK verify phase.
pub fn stark_verify<Layout: LayoutTrait>(
n_original_columns: usize,
n_interaction_columns: usize,
n_original_columns: u32,
n_interaction_columns: u32,
public_input: &PublicInput,
queries: &[Felt],
commitment: StarkCommitment<Layout::InteractionElements>,
Expand Down

0 comments on commit 0605deb

Please sign in to comment.