Skip to content

Commit

Permalink
Merge pull request #25 from iosis-tech/consts_refactor
Browse files Browse the repository at this point in the history
Consts refactor
  • Loading branch information
rkdud007 authored Jul 24, 2024
2 parents 547e8e3 + 13edf21 commit 0ab6f9a
Show file tree
Hide file tree
Showing 19 changed files with 308 additions and 337 deletions.
11 changes: 6 additions & 5 deletions crates/air/src/layout/dex/autogenerated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::global_values::GlobalValues;
use super::{CONSTRAINT_DEGREE, NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND};
use crate::layout::LayoutTrait;
use starknet_core::types::NonZeroFelt;
use starknet_crypto::Felt;

Expand Down Expand Up @@ -1371,7 +1371,7 @@ pub fn eval_composition_polynomial_inner(
total_sum
}

pub fn eval_oods_polynomial_inner(
pub fn eval_oods_polynomial_inner<Layout: LayoutTrait>(
column_values: &[Felt],
oods_values: &[Felt],
constraint_coefficients: &[Felt],
Expand Down Expand Up @@ -2291,13 +2291,14 @@ pub fn eval_oods_polynomial_inner(
total_sum += constraint_coefficients[199] * value;

// Sum the OODS boundary constraints on the composition polynomials.
let oods_point_to_deg = oods_point.pow(CONSTRAINT_DEGREE);
let oods_point_to_deg = oods_point.pow(Layout::CONSTRAINT_DEGREE as u128);

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

value = (column_values[(NUM_COLUMNS_FIRST + NUM_COLUMNS_SECOND + 1) as usize]
value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND + 1]
- oods_values[201])
.field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg));
total_sum += constraint_coefficients[201] * value;
Expand Down
67 changes: 34 additions & 33 deletions crates/air/src/layout/dex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,34 @@ use swiftness_transcript::ensure;

use super::{CompositionPolyEvalError, LayoutTrait, PublicInputError};

pub const N_DYNAMIC_PARAMS: u32 = 0;
pub const N_CONSTRAINTS: u32 = 179;
pub const MASK_SIZE: u32 = 200;
pub const CPU_COMPONENT_STEP: u32 = 1;
pub const CPU_COMPONENT_HEIGHT: u32 = 16;
pub const PUBLIC_MEMORY_STEP: u32 = 8;
pub const HAS_DILUTED_POOL: u32 = 0;
pub const PEDERSEN_BUILTIN_RATIO: u32 = 8;
pub const PEDERSEN_BUILTIN_ROW_RATIO: u32 = 128;
pub const PEDERSEN_BUILTIN_REPETITIONS: u32 = 4;
pub const RANGE_CHECK_BUILTIN_RATIO: u32 = 8;
pub const RANGE_CHECK_BUILTIN_ROW_RATIO: u32 = 128;
pub const RANGE_CHECK_N_PARTS: u32 = 8;
pub const ECDSA_BUILTIN_RATIO: u32 = 512;
pub const ECDSA_BUILTIN_ROW_RATIO: u32 = 8192;
pub const ECDSA_BUILTIN_REPETITIONS: u32 = 1;
pub const ECDSA_ELEMENT_BITS: u32 = 251;
pub const ECDSA_ELEMENT_HEIGHT: u32 = 256;
pub const HAS_OUTPUT_BUILTIN: u32 = 1;
pub const HAS_PEDERSEN_BUILTIN: u32 = 1;
pub const HAS_RANGE_CHECK_BUILTIN: u32 = 1;
pub const HAS_ECDSA_BUILTIN: u32 = 1;
pub const HAS_BITWISE_BUILTIN: u32 = 0;
pub const HAS_EC_OP_BUILTIN: u32 = 0;
pub const HAS_KECCAK_BUILTIN: u32 = 0;
pub const HAS_POSEIDON_BUILTIN: u32 = 0;
pub const HAS_RANGE_CHECK96_BUILTIN: u32 = 0;
pub const CPU_COMPONENT_HEIGHT: usize = 16;
pub const CPU_COMPONENT_STEP: usize = 1;
pub const ECDSA_BUILTIN_RATIO: usize = 512;
pub const ECDSA_BUILTIN_REPETITIONS: usize = 1;
pub const ECDSA_BUILTIN_ROW_RATIO: usize = 8192;
pub const ECDSA_ELEMENT_BITS: usize = 251;
pub const ECDSA_ELEMENT_HEIGHT: usize = 256;
pub const HAS_BITWISE_BUILTIN: usize = 0;
pub const HAS_DILUTED_POOL: usize = 0;
pub const HAS_EC_OP_BUILTIN: usize = 0;
pub const HAS_ECDSA_BUILTIN: usize = 1;
pub const HAS_KECCAK_BUILTIN: usize = 0;
pub const HAS_OUTPUT_BUILTIN: usize = 1;
pub const HAS_PEDERSEN_BUILTIN: usize = 1;
pub const HAS_POSEIDON_BUILTIN: usize = 0;
pub const HAS_RANGE_CHECK_BUILTIN: usize = 1;
pub const HAS_RANGE_CHECK96_BUILTIN: usize = 0;
pub const IS_DYNAMIC_AIR: usize = 0;
pub const LAYOUT_CODE: Felt = Felt::from_hex_unchecked("0x646578");
pub const CONSTRAINT_DEGREE: u32 = 2;
pub const LOG_CPU_COMPONENT_HEIGHT: u32 = 4;
pub const NUM_COLUMNS_FIRST: u32 = 21;
pub const NUM_COLUMNS_SECOND: u32 = 1;
pub const IS_DYNAMIC_AIR: u32 = 0;
pub const LOG_CPU_COMPONENT_HEIGHT: usize = 4;
pub const N_DYNAMIC_PARAMS: usize = 0;
pub const PEDERSEN_BUILTIN_RATIO: usize = 8;
pub const PEDERSEN_BUILTIN_REPETITIONS: usize = 4;
pub const PEDERSEN_BUILTIN_ROW_RATIO: usize = 128;
pub const PUBLIC_MEMORY_STEP: usize = 8;
pub const RANGE_CHECK_BUILTIN_RATIO: usize = 8;
pub const RANGE_CHECK_BUILTIN_ROW_RATIO: usize = 128;
pub const RANGE_CHECK_N_PARTS: usize = 8;

pub mod segments {
pub const ECDSA: usize = 5;
Expand Down Expand Up @@ -78,7 +73,13 @@ pub const BUILTINS: [Felt; 4] =
pub struct Layout {}

impl LayoutTrait for Layout {
const CONSTRAINT_DEGREE: usize = 2;
const MASK_SIZE: usize = 200;
const N_CONSTRAINTS: usize = 179;
const NUM_COLUMNS_FIRST: usize = 21;
const NUM_COLUMNS_SECOND: usize = 1;
type InteractionElements = InteractionElements;

fn eval_composition_polynomial(
interaction_elements: &Self::InteractionElements,
public_input: &PublicInput,
Expand Down Expand Up @@ -203,7 +204,7 @@ impl LayoutTrait for Layout {
oods_point: &Felt,
trace_generator: &Felt,
) -> Felt {
autogenerated::eval_oods_polynomial_inner(
autogenerated::eval_oods_polynomial_inner::<Self>(
column_values,
oods_values,
constraint_coefficients,
Expand Down
7 changes: 7 additions & 0 deletions crates/air/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ pub mod stark_curve {

pub trait LayoutTrait {
type InteractionElements;

const CONSTRAINT_DEGREE: usize;
const NUM_COLUMNS_FIRST: usize;
const NUM_COLUMNS_SECOND: usize;
const N_CONSTRAINTS: usize;
const MASK_SIZE: usize;

fn eval_composition_polynomial(
interaction_elements: &Self::InteractionElements,
public_input: &PublicInput,
Expand Down
11 changes: 6 additions & 5 deletions crates/air/src/layout/recursive/autogenerated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::global_values::GlobalValues;
use super::{CONSTRAINT_DEGREE, NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND};
use crate::layout::LayoutTrait;
use starknet_core::types::NonZeroFelt;
use starknet_crypto::Felt;

Expand Down Expand Up @@ -862,7 +862,7 @@ pub fn eval_composition_polynomial_inner(
total_sum
}

pub fn eval_oods_polynomial_inner(
pub fn eval_oods_polynomial_inner<Layout: LayoutTrait>(
column_values: &[Felt],
oods_values: &[Felt],
constraint_coefficients: &[Felt],
Expand Down Expand Up @@ -1493,13 +1493,14 @@ pub fn eval_oods_polynomial_inner(
total_sum += constraint_coefficients[132] * value;

// Sum the OODS boundary constraints on the composition polynomials.
let oods_point_to_deg = oods_point.pow(CONSTRAINT_DEGREE);
let oods_point_to_deg = oods_point.pow(Layout::CONSTRAINT_DEGREE as u128);

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

value = (column_values[(NUM_COLUMNS_FIRST + NUM_COLUMNS_SECOND + 1) as usize]
value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND + 1]
- oods_values[134])
.field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg));
total_sum += constraint_coefficients[134] * value;
Expand Down
68 changes: 34 additions & 34 deletions crates/air/src/layout/recursive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,34 @@ use swiftness_transcript::ensure;

use super::{CompositionPolyEvalError, LayoutTrait, PublicInputError};

// Recursive layout consts
pub const BITWISE_RATIO: u32 = 8;
pub const BITWISE_ROW_RATIO: u32 = 128;
pub const BITWISE_TOTAL_N_BITS: u32 = 251;
pub const CONSTRAINT_DEGREE: u32 = 2;
pub const CPU_COMPONENT_HEIGHT: u32 = 16;
pub const CPU_COMPONENT_STEP: u32 = 1;
pub const DILUTED_N_BITS: u32 = 16;
pub const DILUTED_SPACING: u32 = 4;
pub const HAS_BITWISE_BUILTIN: u32 = 1;
pub const HAS_DILUTED_POOL: u32 = 1;
pub const HAS_EC_OP_BUILTIN: u32 = 0;
pub const HAS_ECDSA_BUILTIN: u32 = 0;
pub const HAS_KECCAK_BUILTIN: u32 = 0;
pub const HAS_OUTPUT_BUILTIN: u32 = 1;
pub const HAS_PEDERSEN_BUILTIN: u32 = 1;
pub const HAS_POSEIDON_BUILTIN: u32 = 0;
pub const HAS_RANGE_CHECK_BUILTIN: u32 = 1;
pub const HAS_RANGE_CHECK96_BUILTIN: u32 = 0;
pub const IS_DYNAMIC_AIR: u32 = 0;
pub const BITWISE_RATIO: usize = 8;
pub const BITWISE_ROW_RATIO: usize = 128;
pub const BITWISE_TOTAL_N_BITS: usize = 251;
pub const CPU_COMPONENT_HEIGHT: usize = 16;
pub const CPU_COMPONENT_STEP: usize = 1;
pub const DILUTED_N_BITS: usize = 16;
pub const DILUTED_SPACING: usize = 4;
pub const HAS_BITWISE_BUILTIN: usize = 1;
pub const HAS_DILUTED_POOL: usize = 1;
pub const HAS_EC_OP_BUILTIN: usize = 0;
pub const HAS_ECDSA_BUILTIN: usize = 0;
pub const HAS_KECCAK_BUILTIN: usize = 0;
pub const HAS_OUTPUT_BUILTIN: usize = 1;
pub const HAS_PEDERSEN_BUILTIN: usize = 1;
pub const HAS_POSEIDON_BUILTIN: usize = 0;
pub const HAS_RANGE_CHECK_BUILTIN: usize = 1;
pub const HAS_RANGE_CHECK96_BUILTIN: usize = 0;
pub const IS_DYNAMIC_AIR: usize = 0;
pub const LAYOUT_CODE: Felt = Felt::from_hex_unchecked("0x726563757273697665");
pub const LOG_CPU_COMPONENT_HEIGHT: u32 = 4;
pub const MASK_SIZE: u32 = 133;
pub const N_CONSTRAINTS: u32 = 93;
pub const N_DYNAMIC_PARAMS: u32 = 0;
pub const NUM_COLUMNS_FIRST: u32 = 7;
pub const NUM_COLUMNS_SECOND: u32 = 3;
pub const PEDERSEN_BUILTIN_RATIO: u32 = 128;
pub const PEDERSEN_BUILTIN_REPETITIONS: u32 = 1;
pub const PEDERSEN_BUILTIN_ROW_RATIO: u32 = 2048;
pub const PUBLIC_MEMORY_STEP: u32 = 16;
pub const RANGE_CHECK_BUILTIN_RATIO: u32 = 8;
pub const RANGE_CHECK_BUILTIN_ROW_RATIO: u32 = 128;
pub const RANGE_CHECK_N_PARTS: u32 = 8;
pub const LOG_CPU_COMPONENT_HEIGHT: usize = 4;
pub const N_DYNAMIC_PARAMS: usize = 0;
pub const PEDERSEN_BUILTIN_RATIO: usize = 128;
pub const PEDERSEN_BUILTIN_REPETITIONS: usize = 1;
pub const PEDERSEN_BUILTIN_ROW_RATIO: usize = 2048;
pub const PUBLIC_MEMORY_STEP: usize = 16;
pub const RANGE_CHECK_BUILTIN_RATIO: usize = 8;
pub const RANGE_CHECK_BUILTIN_ROW_RATIO: usize = 128;
pub const RANGE_CHECK_N_PARTS: usize = 8;

pub mod segments {
pub const BITWISE: usize = 5;
Expand Down Expand Up @@ -79,7 +73,13 @@ pub const BUILTINS: [Felt; 4] =
pub struct Layout {}

impl LayoutTrait for Layout {
const CONSTRAINT_DEGREE: usize = 2;
const MASK_SIZE: usize = 133;
const N_CONSTRAINTS: usize = 93;
const NUM_COLUMNS_FIRST: usize = 7;
const NUM_COLUMNS_SECOND: usize = 3;
type InteractionElements = InteractionElements;

fn eval_composition_polynomial(
interaction_elements: &Self::InteractionElements,
public_input: &PublicInput,
Expand Down Expand Up @@ -205,7 +205,7 @@ impl LayoutTrait for Layout {
oods_point: &Felt,
trace_generator: &Felt,
) -> Felt {
autogenerated::eval_oods_polynomial_inner(
autogenerated::eval_oods_polynomial_inner::<Self>(
column_values,
oods_values,
constraint_coefficients,
Expand Down
11 changes: 6 additions & 5 deletions crates/air/src/layout/recursive_with_poseidon/autogenerated.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::global_values::GlobalValues;
use super::{CONSTRAINT_DEGREE, NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND};
use crate::layout::LayoutTrait;
use starknet_core::types::NonZeroFelt;
use starknet_crypto::Felt;

Expand Down Expand Up @@ -1236,7 +1236,7 @@ pub fn eval_composition_polynomial_inner(
total_sum
}

pub fn eval_oods_polynomial_inner(
pub fn eval_oods_polynomial_inner<Layout: LayoutTrait>(
column_values: &[Felt],
oods_values: &[Felt],
constraint_coefficients: &[Felt],
Expand Down Expand Up @@ -2162,13 +2162,14 @@ pub fn eval_oods_polynomial_inner(
total_sum += constraint_coefficients[191] * value;

// Sum the OODS boundary constraints on the composition polynomials.
let oods_point_to_deg = oods_point.pow(CONSTRAINT_DEGREE);
let oods_point_to_deg = oods_point.pow(Layout::CONSTRAINT_DEGREE as u128);

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

value = (column_values[(NUM_COLUMNS_FIRST + NUM_COLUMNS_SECOND + 1) as usize]
value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND + 1]
- oods_values[193])
.field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg));
total_sum += constraint_coefficients[193] * value;
Expand Down
78 changes: 39 additions & 39 deletions crates/air/src/layout/recursive_with_poseidon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,40 @@ use swiftness_transcript::ensure;

use super::{CompositionPolyEvalError, LayoutTrait, PublicInputError};

// Recursive with poseidon layout
pub const BITWISE_RATIO: u32 = 16;
pub const BITWISE_ROW_RATIO: u32 = 256;
pub const BITWISE_TOTAL_N_BITS: u32 = 251;
pub const CONSTRAINT_DEGREE: u32 = 2;
pub const CPU_COMPONENT_HEIGHT: u32 = 16;
pub const CPU_COMPONENT_STEP: u32 = 1;
pub const DILUTED_N_BITS: u32 = 16;
pub const DILUTED_SPACING: u32 = 4;
pub const HAS_BITWISE_BUILTIN: u32 = 1;
pub const HAS_DILUTED_POOL: u32 = 1;
pub const HAS_EC_OP_BUILTIN: u32 = 0;
pub const HAS_ECDSA_BUILTIN: u32 = 0;
pub const HAS_KECCAK_BUILTIN: u32 = 0;
pub const HAS_OUTPUT_BUILTIN: u32 = 1;
pub const HAS_PEDERSEN_BUILTIN: u32 = 1;
pub const HAS_POSEIDON_BUILTIN: u32 = 1;
pub const HAS_RANGE_CHECK_BUILTIN: u32 = 1;
pub const HAS_RANGE_CHECK96_BUILTIN: u32 = 0;
pub const IS_DYNAMIC_AIR: u32 = 0;
pub const BITWISE_RATIO: usize = 16;
pub const BITWISE_ROW_RATIO: usize = 256;
pub const BITWISE_TOTAL_N_BITS: usize = 251;
pub const CPU_COMPONENT_HEIGHT: usize = 16;
pub const CPU_COMPONENT_STEP: usize = 1;
pub const DILUTED_N_BITS: usize = 16;
pub const DILUTED_SPACING: usize = 4;
pub const HAS_BITWISE_BUILTIN: usize = 1;
pub const HAS_DILUTED_POOL: usize = 1;
pub const HAS_EC_OP_BUILTIN: usize = 0;
pub const HAS_ECDSA_BUILTIN: usize = 0;
pub const HAS_KECCAK_BUILTIN: usize = 0;
pub const HAS_OUTPUT_BUILTIN: usize = 1;
pub const HAS_PEDERSEN_BUILTIN: usize = 1;
pub const HAS_POSEIDON_BUILTIN: usize = 1;
pub const HAS_RANGE_CHECK_BUILTIN: usize = 1;
pub const HAS_RANGE_CHECK96_BUILTIN: usize = 0;
pub const IS_DYNAMIC_AIR: usize = 0;
pub const LAYOUT_CODE: Felt =
Felt::from_hex_unchecked("0x7265637572736976655f776974685f706f736569646f6e");
pub const LOG_CPU_COMPONENT_HEIGHT: u32 = 4;
pub const MASK_SIZE: u32 = 192;
pub const N_CONSTRAINTS: u32 = 124;
pub const N_DYNAMIC_PARAMS: u32 = 0;
pub const NUM_COLUMNS_FIRST: u32 = 6;
pub const NUM_COLUMNS_SECOND: u32 = 2;
pub const PEDERSEN_BUILTIN_RATIO: u32 = 256;
pub const PEDERSEN_BUILTIN_REPETITIONS: u32 = 1;
pub const PEDERSEN_BUILTIN_ROW_RATIO: u32 = 4096;
pub const POSEIDON_M: u32 = 3;
pub const POSEIDON_RATIO: u32 = 64;
pub const POSEIDON_ROUNDS_FULL: u32 = 8;
pub const POSEIDON_ROUNDS_PARTIAL: u32 = 83;
pub const POSEIDON_ROW_RATIO: u32 = 1024;
pub const PUBLIC_MEMORY_STEP: u32 = 16;
pub const RANGE_CHECK_BUILTIN_RATIO: u32 = 16;
pub const RANGE_CHECK_BUILTIN_ROW_RATIO: u32 = 256;
pub const RANGE_CHECK_N_PARTS: u32 = 8;
pub const LOG_CPU_COMPONENT_HEIGHT: usize = 4;
pub const N_DYNAMIC_PARAMS: usize = 0;
pub const PEDERSEN_BUILTIN_RATIO: usize = 256;
pub const PEDERSEN_BUILTIN_REPETITIONS: usize = 1;
pub const PEDERSEN_BUILTIN_ROW_RATIO: usize = 4096;
pub const POSEIDON_M: usize = 3;
pub const POSEIDON_RATIO: usize = 64;
pub const POSEIDON_ROUNDS_FULL: usize = 8;
pub const POSEIDON_ROUNDS_PARTIAL: usize = 83;
pub const POSEIDON_ROW_RATIO: usize = 1024;
pub const PUBLIC_MEMORY_STEP: usize = 16;
pub const RANGE_CHECK_BUILTIN_RATIO: usize = 16;
pub const RANGE_CHECK_BUILTIN_ROW_RATIO: usize = 256;
pub const RANGE_CHECK_N_PARTS: usize = 8;

pub mod segments {
pub const BITWISE: usize = 5;
Expand Down Expand Up @@ -96,7 +90,13 @@ pub const BUILTINS: [Felt; 5] = [
pub struct Layout {}

impl LayoutTrait for Layout {
const CONSTRAINT_DEGREE: usize = 2;
const MASK_SIZE: usize = 192;
const N_CONSTRAINTS: usize = 124;
const NUM_COLUMNS_FIRST: usize = 6;
const NUM_COLUMNS_SECOND: usize = 2;
type InteractionElements = InteractionElements;

fn eval_composition_polynomial(
interaction_elements: &Self::InteractionElements,
public_input: &PublicInput,
Expand Down Expand Up @@ -247,7 +247,7 @@ impl LayoutTrait for Layout {
oods_point: &Felt,
trace_generator: &Felt,
) -> Felt {
autogenerated::eval_oods_polynomial_inner(
autogenerated::eval_oods_polynomial_inner::<Self>(
column_values,
oods_values,
constraint_coefficients,
Expand Down
Loading

0 comments on commit 0ab6f9a

Please sign in to comment.