From 1e15043f14f7e6c564735e1d77d94ed6d035d203 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Tue, 23 Jul 2024 20:19:17 +0200 Subject: [PATCH 1/4] consts refactor --- crates/air/src/layout/dex/autogenerated.rs | 11 ++--- crates/air/src/layout/dex/mod.rs | 45 ++++++++++--------- crates/air/src/layout/mod.rs | 7 +++ .../air/src/layout/recursive/autogenerated.rs | 11 ++--- crates/air/src/layout/recursive/mod.rs | 14 +++--- .../recursive_with_poseidon/autogenerated.rs | 11 ++--- .../src/layout/recursive_with_poseidon/mod.rs | 14 +++--- crates/air/src/layout/small/autogenerated.rs | 11 ++--- crates/air/src/layout/small/mod.rs | 13 +++--- .../air/src/layout/starknet/autogenerated.rs | 11 ++--- crates/air/src/layout/starknet/mod.rs | 13 +++--- .../starknet_with_keccak/autogenerated.rs | 11 ++--- .../src/layout/starknet_with_keccak/mod.rs | 13 +++--- crates/air/src/trace/config.rs | 20 ++------- crates/stark/src/commit.rs | 19 ++------ crates/stark/src/config.rs | 6 ++- crates/stark/src/oods.rs | 20 ++------- crates/stark/src/stark.rs | 18 ++------ crates/stark/src/tests/verify.rs | 6 +-- 19 files changed, 123 insertions(+), 151 deletions(-) diff --git a/crates/air/src/layout/dex/autogenerated.rs b/crates/air/src/layout/dex/autogenerated.rs index 961911c..e38c11c 100644 --- a/crates/air/src/layout/dex/autogenerated.rs +++ b/crates/air/src/layout/dex/autogenerated.rs @@ -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; @@ -1371,7 +1371,7 @@ pub fn eval_composition_polynomial_inner( total_sum } -pub fn eval_oods_polynomial_inner( +pub fn eval_oods_polynomial_inner( column_values: &[Felt], oods_values: &[Felt], constraint_coefficients: &[Felt], @@ -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) as usize] + - 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) as usize] - oods_values[201]) .field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg)); total_sum += constraint_coefficients[201] * value; diff --git a/crates/air/src/layout/dex/mod.rs b/crates/air/src/layout/dex/mod.rs index e374300..62ece43 100644 --- a/crates/air/src/layout/dex/mod.rs +++ b/crates/air/src/layout/dex/mod.rs @@ -14,39 +14,34 @@ use swiftness_commitment::table::{commit::table_commit, decommit::table_decommit 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 CPU_COMPONENT_STEP: u32 = 1; 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_BUILTIN_ROW_RATIO: u32 = 8192; 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_DILUTED_POOL: u32 = 0; pub const HAS_EC_OP_BUILTIN: u32 = 0; +pub const HAS_ECDSA_BUILTIN: u32 = 1; 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 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 N_DYNAMIC_PARAMS: u32 = 0; +pub const PEDERSEN_BUILTIN_RATIO: u32 = 8; +pub const PEDERSEN_BUILTIN_REPETITIONS: u32 = 4; +pub const PEDERSEN_BUILTIN_ROW_RATIO: u32 = 128; +pub const PUBLIC_MEMORY_STEP: u32 = 8; +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 mod segments { pub const ECDSA: usize = 5; @@ -76,7 +71,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, @@ -201,7 +202,7 @@ impl LayoutTrait for Layout { oods_point: &Felt, trace_generator: &Felt, ) -> Felt { - autogenerated::eval_oods_polynomial_inner( + autogenerated::eval_oods_polynomial_inner::( column_values, oods_values, constraint_coefficients, diff --git a/crates/air/src/layout/mod.rs b/crates/air/src/layout/mod.rs index e41741e..00e24cc 100644 --- a/crates/air/src/layout/mod.rs +++ b/crates/air/src/layout/mod.rs @@ -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, diff --git a/crates/air/src/layout/recursive/autogenerated.rs b/crates/air/src/layout/recursive/autogenerated.rs index 32c1155..5e1b578 100644 --- a/crates/air/src/layout/recursive/autogenerated.rs +++ b/crates/air/src/layout/recursive/autogenerated.rs @@ -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; @@ -862,7 +862,7 @@ pub fn eval_composition_polynomial_inner( total_sum } -pub fn eval_oods_polynomial_inner( +pub fn eval_oods_polynomial_inner( column_values: &[Felt], oods_values: &[Felt], constraint_coefficients: &[Felt], @@ -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) as usize] + - 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) as usize] - oods_values[134]) .field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg)); total_sum += constraint_coefficients[134] * value; diff --git a/crates/air/src/layout/recursive/mod.rs b/crates/air/src/layout/recursive/mod.rs index f1f5486..50f783b 100644 --- a/crates/air/src/layout/recursive/mod.rs +++ b/crates/air/src/layout/recursive/mod.rs @@ -14,11 +14,9 @@ use swiftness_commitment::table::{commit::table_commit, decommit::table_decommit 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; @@ -36,11 +34,7 @@ pub const HAS_RANGE_CHECK96_BUILTIN: u32 = 0; pub const IS_DYNAMIC_AIR: u32 = 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; @@ -77,7 +71,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, @@ -203,7 +203,7 @@ impl LayoutTrait for Layout { oods_point: &Felt, trace_generator: &Felt, ) -> Felt { - autogenerated::eval_oods_polynomial_inner( + autogenerated::eval_oods_polynomial_inner::( column_values, oods_values, constraint_coefficients, diff --git a/crates/air/src/layout/recursive_with_poseidon/autogenerated.rs b/crates/air/src/layout/recursive_with_poseidon/autogenerated.rs index 9300649..663d397 100644 --- a/crates/air/src/layout/recursive_with_poseidon/autogenerated.rs +++ b/crates/air/src/layout/recursive_with_poseidon/autogenerated.rs @@ -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; @@ -1236,7 +1236,7 @@ pub fn eval_composition_polynomial_inner( total_sum } -pub fn eval_oods_polynomial_inner( +pub fn eval_oods_polynomial_inner( column_values: &[Felt], oods_values: &[Felt], constraint_coefficients: &[Felt], @@ -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) as usize] + - 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) as usize] - oods_values[193]) .field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg)); total_sum += constraint_coefficients[193] * value; diff --git a/crates/air/src/layout/recursive_with_poseidon/mod.rs b/crates/air/src/layout/recursive_with_poseidon/mod.rs index 811f548..cafd759 100644 --- a/crates/air/src/layout/recursive_with_poseidon/mod.rs +++ b/crates/air/src/layout/recursive_with_poseidon/mod.rs @@ -18,11 +18,9 @@ use swiftness_commitment::table::{commit::table_commit, decommit::table_decommit 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; @@ -41,11 +39,7 @@ pub const IS_DYNAMIC_AIR: u32 = 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; @@ -94,7 +88,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, @@ -245,7 +245,7 @@ impl LayoutTrait for Layout { oods_point: &Felt, trace_generator: &Felt, ) -> Felt { - autogenerated::eval_oods_polynomial_inner( + autogenerated::eval_oods_polynomial_inner::( column_values, oods_values, constraint_coefficients, diff --git a/crates/air/src/layout/small/autogenerated.rs b/crates/air/src/layout/small/autogenerated.rs index 1256a46..07dabc4 100644 --- a/crates/air/src/layout/small/autogenerated.rs +++ b/crates/air/src/layout/small/autogenerated.rs @@ -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; @@ -1372,7 +1372,7 @@ pub fn eval_composition_polynomial_inner( total_sum } -pub fn eval_oods_polynomial_inner( +pub fn eval_oods_polynomial_inner( column_values: &[Felt], oods_values: &[Felt], constraint_coefficients: &[Felt], @@ -2298,13 +2298,14 @@ pub fn eval_oods_polynomial_inner( total_sum += constraint_coefficients[200] * 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[201]) + value = (column_values[(Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND) as usize] + - oods_values[201]) .field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg)); total_sum += constraint_coefficients[201] * 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) as usize] - oods_values[202]) .field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg)); total_sum += constraint_coefficients[202] * value; diff --git a/crates/air/src/layout/small/mod.rs b/crates/air/src/layout/small/mod.rs index ca64d3f..2381ca9 100644 --- a/crates/air/src/layout/small/mod.rs +++ b/crates/air/src/layout/small/mod.rs @@ -14,7 +14,6 @@ use swiftness_commitment::table::{commit::table_commit, decommit::table_decommit use super::{CompositionPolyEvalError, LayoutTrait, PublicInputError}; -pub const CONSTRAINT_DEGREE: u32 = 2; pub const CPU_COMPONENT_HEIGHT: u32 = 16; pub const CPU_COMPONENT_STEP: u32 = 1; pub const ECDSA_BUILTIN_RATIO: u32 = 512; @@ -35,11 +34,7 @@ pub const HAS_RANGE_CHECK96_BUILTIN: u32 = 0; pub const IS_DYNAMIC_AIR: u32 = 0; pub const LAYOUT_CODE: Felt = Felt::from_hex_unchecked("0x736d616c6c"); pub const LOG_CPU_COMPONENT_HEIGHT: u32 = 4; -pub const MASK_SIZE: u32 = 201; -pub const N_CONSTRAINTS: u32 = 179; pub const N_DYNAMIC_PARAMS: u32 = 0; -pub const NUM_COLUMNS_FIRST: u32 = 23; -pub const NUM_COLUMNS_SECOND: u32 = 2; pub const PEDERSEN_BUILTIN_RATIO: u32 = 8; pub const PEDERSEN_BUILTIN_REPETITIONS: u32 = 4; pub const PEDERSEN_BUILTIN_ROW_RATIO: u32 = 128; @@ -76,7 +71,13 @@ pub const BUILTINS: [Felt; 4] = pub struct Layout {} impl LayoutTrait for Layout { + const CONSTRAINT_DEGREE: usize = 2; + const MASK_SIZE: usize = 201; + const N_CONSTRAINTS: usize = 179; + const NUM_COLUMNS_FIRST: usize = 23; + const NUM_COLUMNS_SECOND: usize = 2; type InteractionElements = InteractionElements; + fn eval_composition_polynomial( interaction_elements: &Self::InteractionElements, public_input: &PublicInput, @@ -201,7 +202,7 @@ impl LayoutTrait for Layout { oods_point: &Felt, trace_generator: &Felt, ) -> Felt { - autogenerated::eval_oods_polynomial_inner( + autogenerated::eval_oods_polynomial_inner::( column_values, oods_values, constraint_coefficients, diff --git a/crates/air/src/layout/starknet/autogenerated.rs b/crates/air/src/layout/starknet/autogenerated.rs index ffd3c18..909d755 100644 --- a/crates/air/src/layout/starknet/autogenerated.rs +++ b/crates/air/src/layout/starknet/autogenerated.rs @@ -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; @@ -1734,7 +1734,7 @@ pub fn eval_composition_polynomial_inner( total_sum } -pub fn eval_oods_polynomial_inner( +pub fn eval_oods_polynomial_inner( column_values: &[Felt], oods_values: &[Felt], constraint_coefficients: &[Felt], @@ -3037,13 +3037,14 @@ pub fn eval_oods_polynomial_inner( total_sum += constraint_coefficients[270] * 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[271]) + value = (column_values[(Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND) as usize] + - oods_values[271]) .field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg)); total_sum += constraint_coefficients[271] * 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) as usize] - oods_values[272]) .field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg)); total_sum += constraint_coefficients[272] * value; diff --git a/crates/air/src/layout/starknet/mod.rs b/crates/air/src/layout/starknet/mod.rs index d589752..a297abe 100644 --- a/crates/air/src/layout/starknet/mod.rs +++ b/crates/air/src/layout/starknet/mod.rs @@ -23,7 +23,6 @@ use super::{CompositionPolyEvalError, LayoutTrait, PublicInputError}; pub const BITWISE_RATIO: u32 = 64; pub const BITWISE_ROW_RATIO: u32 = 1024; 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; @@ -50,11 +49,7 @@ pub const HAS_RANGE_CHECK96_BUILTIN: u32 = 0; pub const IS_DYNAMIC_AIR: u32 = 0; pub const LAYOUT_CODE: Felt = Felt::from_hex_unchecked("0x737461726b6e6574"); pub const LOG_CPU_COMPONENT_HEIGHT: u32 = 4; -pub const MASK_SIZE: u32 = 271; -pub const N_CONSTRAINTS: u32 = 198; pub const N_DYNAMIC_PARAMS: u32 = 0; -pub const NUM_COLUMNS_FIRST: u32 = 9; -pub const NUM_COLUMNS_SECOND: u32 = 1; pub const PEDERSEN_BUILTIN_RATIO: u32 = 32; pub const PEDERSEN_BUILTIN_REPETITIONS: u32 = 1; pub const PEDERSEN_BUILTIN_ROW_RATIO: u32 = 512; @@ -109,7 +104,13 @@ pub const BUILTINS: [Felt; 7] = [ pub struct Layout {} impl LayoutTrait for Layout { + const CONSTRAINT_DEGREE: usize = 2; + const MASK_SIZE: usize = 271; + const N_CONSTRAINTS: usize = 198; + const NUM_COLUMNS_FIRST: usize = 9; + const NUM_COLUMNS_SECOND: usize = 1; type InteractionElements = InteractionElements; + fn eval_composition_polynomial( interaction_elements: &Self::InteractionElements, public_input: &PublicInput, @@ -286,7 +287,7 @@ impl LayoutTrait for Layout { oods_point: &Felt, trace_generator: &Felt, ) -> Felt { - autogenerated::eval_oods_polynomial_inner( + autogenerated::eval_oods_polynomial_inner::( column_values, oods_values, constraint_coefficients, diff --git a/crates/air/src/layout/starknet_with_keccak/autogenerated.rs b/crates/air/src/layout/starknet_with_keccak/autogenerated.rs index 62f7af2..a3f1d6b 100644 --- a/crates/air/src/layout/starknet_with_keccak/autogenerated.rs +++ b/crates/air/src/layout/starknet_with_keccak/autogenerated.rs @@ -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; @@ -10128,7 +10128,7 @@ pub fn eval_composition_polynomial_inner( total_sum } -pub fn eval_oods_polynomial_inner( +pub fn eval_oods_polynomial_inner( column_values: &[Felt], oods_values: &[Felt], constraint_coefficients: &[Felt], @@ -13724,13 +13724,14 @@ pub fn eval_oods_polynomial_inner( total_sum += constraint_coefficients[733] * 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[734]) + value = (column_values[(Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND) as usize] + - oods_values[734]) .field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg)); total_sum += constraint_coefficients[734] * 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) as usize] - oods_values[735]) .field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg)); total_sum += constraint_coefficients[735] * value; diff --git a/crates/air/src/layout/starknet_with_keccak/mod.rs b/crates/air/src/layout/starknet_with_keccak/mod.rs index 0b67dca..1e8410b 100644 --- a/crates/air/src/layout/starknet_with_keccak/mod.rs +++ b/crates/air/src/layout/starknet_with_keccak/mod.rs @@ -25,7 +25,6 @@ use super::{CompositionPolyEvalError, LayoutTrait, PublicInputError}; pub const BITWISE_RATIO: u32 = 64; pub const BITWISE_ROW_RATIO: u32 = 1024; 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; @@ -55,11 +54,7 @@ pub const KECCAK_ROW_RATIO: u32 = 32768; pub const LAYOUT_CODE: Felt = Felt::from_hex_unchecked("0x737461726b6e65745f776974685f6b656363616b"); pub const LOG_CPU_COMPONENT_HEIGHT: u32 = 4; -pub const MASK_SIZE: u32 = 734; -pub const N_CONSTRAINTS: u32 = 347; pub const N_DYNAMIC_PARAMS: u32 = 0; -pub const NUM_COLUMNS_FIRST: u32 = 12; -pub const NUM_COLUMNS_SECOND: u32 = 3; pub const PEDERSEN_BUILTIN_RATIO: u32 = 32; pub const PEDERSEN_BUILTIN_REPETITIONS: u32 = 1; pub const PEDERSEN_BUILTIN_ROW_RATIO: u32 = 512; @@ -117,7 +112,13 @@ pub const BUILTINS: [Felt; 8] = [ pub struct Layout {} impl LayoutTrait for Layout { + const CONSTRAINT_DEGREE: usize = 2; + const MASK_SIZE: usize = 734; + const N_CONSTRAINTS: usize = 347; + const NUM_COLUMNS_FIRST: usize = 12; + const NUM_COLUMNS_SECOND: usize = 3; type InteractionElements = InteractionElements; + fn eval_composition_polynomial( interaction_elements: &Self::InteractionElements, public_input: &PublicInput, @@ -320,7 +321,7 @@ impl LayoutTrait for Layout { oods_point: &Felt, trace_generator: &Felt, ) -> Felt { - autogenerated::eval_oods_polynomial_inner( + autogenerated::eval_oods_polynomial_inner::( column_values, oods_values, constraint_coefficients, diff --git a/crates/air/src/trace/config.rs b/crates/air/src/trace/config.rs index 723700d..cf652a6 100644 --- a/crates/air/src/trace/config.rs +++ b/crates/air/src/trace/config.rs @@ -1,16 +1,4 @@ -#[cfg(feature = "dex")] -use crate::layout::dex::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND}; -#[cfg(feature = "recursive")] -use crate::layout::recursive::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND}; -#[cfg(feature = "recursive_with_poseidon")] -use crate::layout::recursive_with_poseidon::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND}; -#[cfg(feature = "small")] -use crate::layout::small::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND}; -#[cfg(feature = "starknet")] -use crate::layout::starknet::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND}; -#[cfg(feature = "starknet_with_keccak")] -use crate::layout::starknet_with_keccak::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND}; - +use crate::layout::LayoutTrait; use serde::{Deserialize, Serialize}; use starknet_crypto::Felt; use swiftness_commitment::vector; @@ -25,7 +13,7 @@ pub struct Config { } impl Config { - pub fn validate( + pub fn validate( &self, log_eval_domain_size: Felt, n_verifier_friendly_commitment_layers: Felt, @@ -37,11 +25,11 @@ impl Config { return Err(Error::OutOfBounds { min: Felt::ONE, max: MAX_N_COLUMNS }); } - if self.original.n_columns != NUM_COLUMNS_FIRST.into() { + if self.original.n_columns != Layout::NUM_COLUMNS_FIRST.into() { return Err(Error::ColumnsNumInvalid); } - if self.interaction.n_columns != NUM_COLUMNS_SECOND.into() { + if self.interaction.n_columns != Layout::NUM_COLUMNS_SECOND.into() { return Err(Error::ColumnsNumInvalid); } diff --git a/crates/stark/src/commit.rs b/crates/stark/src/commit.rs index e48d8d7..8e88ea1 100644 --- a/crates/stark/src/commit.rs +++ b/crates/stark/src/commit.rs @@ -1,16 +1,3 @@ -#[cfg(feature = "dex")] -use swiftness_air::layout::dex::{CONSTRAINT_DEGREE, MASK_SIZE, N_CONSTRAINTS}; -#[cfg(feature = "recursive")] -use swiftness_air::layout::recursive::{CONSTRAINT_DEGREE, MASK_SIZE, N_CONSTRAINTS}; -#[cfg(feature = "recursive_with_poseidon")] -use swiftness_air::layout::recursive_with_poseidon::{CONSTRAINT_DEGREE, MASK_SIZE, N_CONSTRAINTS}; -#[cfg(feature = "small")] -use swiftness_air::layout::small::{CONSTRAINT_DEGREE, MASK_SIZE, N_CONSTRAINTS}; -#[cfg(feature = "starknet")] -use swiftness_air::layout::starknet::{CONSTRAINT_DEGREE, MASK_SIZE, N_CONSTRAINTS}; -#[cfg(feature = "starknet_with_keccak")] -use swiftness_air::layout::starknet_with_keccak::{CONSTRAINT_DEGREE, MASK_SIZE, N_CONSTRAINTS}; - use starknet_crypto::Felt; use swiftness_air::{domains::StarkDomains, layout::LayoutTrait, public_memory::PublicInput}; use swiftness_commitment::table::commit::table_commit; @@ -32,7 +19,8 @@ pub fn stark_commit( // Generate interaction values after traces commitment. let composition_alpha = transcript.random_felt_to_prover(); - let traces_coefficients = powers_array(Felt::ONE, composition_alpha, N_CONSTRAINTS); + let traces_coefficients = + powers_array(Felt::ONE, composition_alpha, Layout::N_CONSTRAINTS as u32); // Read composition commitment. let composition_commitment = @@ -57,7 +45,8 @@ pub fn stark_commit( // Generate interaction values after OODS. let oods_alpha = transcript.random_felt_to_prover(); - let oods_coefficients = powers_array(Felt::ONE, oods_alpha, MASK_SIZE + CONSTRAINT_DEGREE); + let oods_coefficients = + powers_array(Felt::ONE, oods_alpha, (Layout::MASK_SIZE + Layout::CONSTRAINT_DEGREE) as u32); // Read fri commitment. let fri_commitment = diff --git a/crates/stark/src/config.rs b/crates/stark/src/config.rs index 46a9331..e021d0a 100644 --- a/crates/stark/src/config.rs +++ b/crates/stark/src/config.rs @@ -30,14 +30,15 @@ impl StarkConfig { self.n_queries * self.log_n_cosets + Felt::from(self.proof_of_work.n_bits) } - pub fn validate(&self, security_bits: Felt) -> Result<(), Error> { + pub fn validate(&self, security_bits: Felt) -> Result<(), Error> { self.proof_of_work.validate()?; assert!(security_bits <= self.security_bits()); // Validate traces config. let log_eval_domain_size = self.log_trace_domain_size + self.log_n_cosets; - self.traces.validate(log_eval_domain_size, self.n_verifier_friendly_commitment_layers)?; + self.traces + .validate::(log_eval_domain_size, self.n_verifier_friendly_commitment_layers)?; // Validate composition config. self.composition @@ -50,6 +51,7 @@ impl StarkConfig { } } +use swiftness_air::layout::LayoutTrait; use swiftness_commitment::vector; use thiserror::Error; diff --git a/crates/stark/src/oods.rs b/crates/stark/src/oods.rs index 7e48db6..ba24abe 100644 --- a/crates/stark/src/oods.rs +++ b/crates/stark/src/oods.rs @@ -1,17 +1,5 @@ use bail_out::assure; use starknet_crypto::Felt; -#[cfg(feature = "dex")] -use swiftness_air::layout::dex::CONSTRAINT_DEGREE; -#[cfg(feature = "recursive")] -use swiftness_air::layout::recursive::CONSTRAINT_DEGREE; -#[cfg(feature = "recursive_with_poseidon")] -use swiftness_air::layout::recursive_with_poseidon::CONSTRAINT_DEGREE; -#[cfg(feature = "small")] -use swiftness_air::layout::small::CONSTRAINT_DEGREE; -#[cfg(feature = "starknet")] -use swiftness_air::layout::starknet::CONSTRAINT_DEGREE; -#[cfg(feature = "starknet_with_keccak")] -use swiftness_air::layout::starknet_with_keccak::CONSTRAINT_DEGREE; use swiftness_air::{ layout::{CompositionPolyEvalError, LayoutTrait}, public_memory::PublicInput, @@ -86,7 +74,7 @@ pub fn eval_oods_boundary_poly_at_points( "Invalid value" ); assert!( - composition_decommitment.values.len() == points.len() * CONSTRAINT_DEGREE as usize, + composition_decommitment.values.len() == points.len() * Layout::CONSTRAINT_DEGREE as usize, "Invalid value" ); @@ -94,7 +82,7 @@ pub fn eval_oods_boundary_poly_at_points( for (i, &point) in points.iter().enumerate() { let mut column_values = Vec::with_capacity( - n_original_columns + n_interaction_columns + CONSTRAINT_DEGREE as usize, + n_original_columns + n_interaction_columns + Layout::CONSTRAINT_DEGREE as usize, ); column_values.extend( @@ -105,8 +93,8 @@ pub fn eval_oods_boundary_poly_at_points( [i * n_interaction_columns..(i + 1) * n_interaction_columns], ); column_values.extend( - &composition_decommitment.values - [i * CONSTRAINT_DEGREE as usize..(i + 1) * CONSTRAINT_DEGREE as usize], + &composition_decommitment.values[i * Layout::CONSTRAINT_DEGREE as usize + ..(i + 1) * Layout::CONSTRAINT_DEGREE as usize], ); evaluations.push(Layout::eval_oods_polynomial( diff --git a/crates/stark/src/stark.rs b/crates/stark/src/stark.rs index 7528fca..4bfe4a4 100644 --- a/crates/stark/src/stark.rs +++ b/crates/stark/src/stark.rs @@ -1,22 +1,10 @@ use crate::{ commit::stark_commit, queries::generate_queries, types::StarkProof, verify::stark_verify, }; -#[cfg(feature = "dex")] -use swiftness_air::layout::dex::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND}; -#[cfg(feature = "recursive")] -use swiftness_air::layout::recursive::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND}; -#[cfg(feature = "recursive_with_poseidon")] -use swiftness_air::layout::recursive_with_poseidon::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND}; -#[cfg(feature = "small")] -use swiftness_air::layout::small::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND}; -#[cfg(feature = "starknet")] -use swiftness_air::layout::starknet::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND}; -#[cfg(feature = "starknet_with_keccak")] -use swiftness_air::layout::starknet_with_keccak::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND}; impl StarkProof { pub fn verify(&self, security_bits: Felt) -> Result<(Felt, Felt), Error> { - self.config.validate(security_bits)?; + self.config.validate::(security_bits)?; // Validate the public input. let stark_domains = @@ -47,8 +35,8 @@ impl StarkProof { // STARK verify phase. stark_verify::( - NUM_COLUMNS_FIRST as usize, - NUM_COLUMNS_SECOND as usize, + Layout::NUM_COLUMNS_FIRST as usize, + Layout::NUM_COLUMNS_SECOND as usize, &queries, stark_commitment, &self.witness, diff --git a/crates/stark/src/tests/verify.rs b/crates/stark/src/tests/verify.rs index e7626bf..8d5328e 100644 --- a/crates/stark/src/tests/verify.rs +++ b/crates/stark/src/tests/verify.rs @@ -2,7 +2,7 @@ use crate::{ fixtures::{commitment, domains, witness}, verify::stark_verify, }; -use swiftness_air::layout::recursive::{Layout, NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND}; +use swiftness_air::layout::{recursive::Layout, LayoutTrait}; use swiftness_fri::fixtures::queries; #[test] @@ -13,8 +13,8 @@ pub fn test_stark_verify() { let stark_domains = domains::get(); stark_verify::( - NUM_COLUMNS_FIRST as usize, - NUM_COLUMNS_SECOND as usize, + Layout::NUM_COLUMNS_FIRST as usize, + Layout::NUM_COLUMNS_SECOND as usize, &queries, commitment, &witness, From 09240b852b909416747139c62f15352f17a3e433 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Tue, 23 Jul 2024 20:20:25 +0200 Subject: [PATCH 2/4] clippy fix --- crates/air/src/layout/dex/autogenerated.rs | 4 ++-- crates/air/src/layout/recursive/autogenerated.rs | 4 ++-- .../src/layout/recursive_with_poseidon/autogenerated.rs | 4 ++-- crates/air/src/layout/small/autogenerated.rs | 4 ++-- crates/air/src/layout/starknet/autogenerated.rs | 4 ++-- .../air/src/layout/starknet_with_keccak/autogenerated.rs | 4 ++-- crates/stark/src/oods.rs | 8 ++++---- crates/stark/src/stark.rs | 4 ++-- crates/stark/src/tests/verify.rs | 4 ++-- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/crates/air/src/layout/dex/autogenerated.rs b/crates/air/src/layout/dex/autogenerated.rs index e38c11c..0cf365e 100644 --- a/crates/air/src/layout/dex/autogenerated.rs +++ b/crates/air/src/layout/dex/autogenerated.rs @@ -2293,12 +2293,12 @@ pub fn eval_oods_polynomial_inner( // Sum the OODS boundary constraints on the composition polynomials. let oods_point_to_deg = oods_point.pow(Layout::CONSTRAINT_DEGREE as u128); - value = (column_values[(Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND) as usize] + 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[(Layout::NUM_COLUMNS_FIRST + Layout::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; diff --git a/crates/air/src/layout/recursive/autogenerated.rs b/crates/air/src/layout/recursive/autogenerated.rs index 5e1b578..30632e0 100644 --- a/crates/air/src/layout/recursive/autogenerated.rs +++ b/crates/air/src/layout/recursive/autogenerated.rs @@ -1495,12 +1495,12 @@ pub fn eval_oods_polynomial_inner( // Sum the OODS boundary constraints on the composition polynomials. let oods_point_to_deg = oods_point.pow(Layout::CONSTRAINT_DEGREE as u128); - value = (column_values[(Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND) as usize] + 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[(Layout::NUM_COLUMNS_FIRST + Layout::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; diff --git a/crates/air/src/layout/recursive_with_poseidon/autogenerated.rs b/crates/air/src/layout/recursive_with_poseidon/autogenerated.rs index 663d397..5de4590 100644 --- a/crates/air/src/layout/recursive_with_poseidon/autogenerated.rs +++ b/crates/air/src/layout/recursive_with_poseidon/autogenerated.rs @@ -2164,12 +2164,12 @@ pub fn eval_oods_polynomial_inner( // Sum the OODS boundary constraints on the composition polynomials. let oods_point_to_deg = oods_point.pow(Layout::CONSTRAINT_DEGREE as u128); - value = (column_values[(Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND) as usize] + 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[(Layout::NUM_COLUMNS_FIRST + Layout::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; diff --git a/crates/air/src/layout/small/autogenerated.rs b/crates/air/src/layout/small/autogenerated.rs index 07dabc4..94378a3 100644 --- a/crates/air/src/layout/small/autogenerated.rs +++ b/crates/air/src/layout/small/autogenerated.rs @@ -2300,12 +2300,12 @@ pub fn eval_oods_polynomial_inner( // Sum the OODS boundary constraints on the composition polynomials. let oods_point_to_deg = oods_point.pow(Layout::CONSTRAINT_DEGREE as u128); - value = (column_values[(Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND) as usize] + value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND] - oods_values[201]) .field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg)); total_sum += constraint_coefficients[201] * value; - value = (column_values[(Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND + 1) as usize] + value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND + 1] - oods_values[202]) .field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg)); total_sum += constraint_coefficients[202] * value; diff --git a/crates/air/src/layout/starknet/autogenerated.rs b/crates/air/src/layout/starknet/autogenerated.rs index 909d755..af220c5 100644 --- a/crates/air/src/layout/starknet/autogenerated.rs +++ b/crates/air/src/layout/starknet/autogenerated.rs @@ -3039,12 +3039,12 @@ pub fn eval_oods_polynomial_inner( // Sum the OODS boundary constraints on the composition polynomials. let oods_point_to_deg = oods_point.pow(Layout::CONSTRAINT_DEGREE as u128); - value = (column_values[(Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND) as usize] + value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND] - oods_values[271]) .field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg)); total_sum += constraint_coefficients[271] * value; - value = (column_values[(Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND + 1) as usize] + value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND + 1] - oods_values[272]) .field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg)); total_sum += constraint_coefficients[272] * value; diff --git a/crates/air/src/layout/starknet_with_keccak/autogenerated.rs b/crates/air/src/layout/starknet_with_keccak/autogenerated.rs index a3f1d6b..857bd4a 100644 --- a/crates/air/src/layout/starknet_with_keccak/autogenerated.rs +++ b/crates/air/src/layout/starknet_with_keccak/autogenerated.rs @@ -13726,12 +13726,12 @@ pub fn eval_oods_polynomial_inner( // Sum the OODS boundary constraints on the composition polynomials. let oods_point_to_deg = oods_point.pow(Layout::CONSTRAINT_DEGREE as u128); - value = (column_values[(Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND) as usize] + value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND] - oods_values[734]) .field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg)); total_sum += constraint_coefficients[734] * value; - value = (column_values[(Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND + 1) as usize] + value = (column_values[Layout::NUM_COLUMNS_FIRST + Layout::NUM_COLUMNS_SECOND + 1] - oods_values[735]) .field_div(&NonZeroFelt::from_felt_unchecked(point - oods_point_to_deg)); total_sum += constraint_coefficients[735] * value; diff --git a/crates/stark/src/oods.rs b/crates/stark/src/oods.rs index ba24abe..c9f5551 100644 --- a/crates/stark/src/oods.rs +++ b/crates/stark/src/oods.rs @@ -74,7 +74,7 @@ pub fn eval_oods_boundary_poly_at_points( "Invalid value" ); assert!( - composition_decommitment.values.len() == points.len() * Layout::CONSTRAINT_DEGREE as usize, + composition_decommitment.values.len() == points.len() * Layout::CONSTRAINT_DEGREE, "Invalid value" ); @@ -82,7 +82,7 @@ pub fn eval_oods_boundary_poly_at_points( for (i, &point) in points.iter().enumerate() { let mut column_values = Vec::with_capacity( - n_original_columns + n_interaction_columns + Layout::CONSTRAINT_DEGREE as usize, + n_original_columns + n_interaction_columns + Layout::CONSTRAINT_DEGREE, ); column_values.extend( @@ -93,8 +93,8 @@ pub fn eval_oods_boundary_poly_at_points( [i * n_interaction_columns..(i + 1) * n_interaction_columns], ); column_values.extend( - &composition_decommitment.values[i * Layout::CONSTRAINT_DEGREE as usize - ..(i + 1) * Layout::CONSTRAINT_DEGREE as usize], + &composition_decommitment.values + [i * Layout::CONSTRAINT_DEGREE..(i + 1) * Layout::CONSTRAINT_DEGREE], ); evaluations.push(Layout::eval_oods_polynomial( diff --git a/crates/stark/src/stark.rs b/crates/stark/src/stark.rs index 4bfe4a4..9f72fb0 100644 --- a/crates/stark/src/stark.rs +++ b/crates/stark/src/stark.rs @@ -35,8 +35,8 @@ impl StarkProof { // STARK verify phase. stark_verify::( - Layout::NUM_COLUMNS_FIRST as usize, - Layout::NUM_COLUMNS_SECOND as usize, + Layout::NUM_COLUMNS_FIRST, + Layout::NUM_COLUMNS_SECOND, &queries, stark_commitment, &self.witness, diff --git a/crates/stark/src/tests/verify.rs b/crates/stark/src/tests/verify.rs index 8d5328e..6adef96 100644 --- a/crates/stark/src/tests/verify.rs +++ b/crates/stark/src/tests/verify.rs @@ -13,8 +13,8 @@ pub fn test_stark_verify() { let stark_domains = domains::get(); stark_verify::( - Layout::NUM_COLUMNS_FIRST as usize, - Layout::NUM_COLUMNS_SECOND as usize, + Layout::NUM_COLUMNS_FIRST, + Layout::NUM_COLUMNS_SECOND, &queries, commitment, &witness, From 5e159ebc8049dce51cc292da5c33efdec6c2e672 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Tue, 23 Jul 2024 20:27:01 +0200 Subject: [PATCH 3/4] more usize --- crates/air/src/layout/dex/mod.rs | 54 ++++++------ crates/air/src/layout/recursive/mod.rs | 54 ++++++------ .../src/layout/recursive_with_poseidon/mod.rs | 64 +++++++------- crates/air/src/layout/small/mod.rs | 54 ++++++------ crates/air/src/layout/starknet/mod.rs | 82 +++++++++--------- .../src/layout/starknet_with_keccak/mod.rs | 86 +++++++++---------- 6 files changed, 197 insertions(+), 197 deletions(-) diff --git a/crates/air/src/layout/dex/mod.rs b/crates/air/src/layout/dex/mod.rs index 62ece43..94bf9c1 100644 --- a/crates/air/src/layout/dex/mod.rs +++ b/crates/air/src/layout/dex/mod.rs @@ -14,34 +14,34 @@ use swiftness_commitment::table::{commit::table_commit, decommit::table_decommit use super::{CompositionPolyEvalError, LayoutTrait, PublicInputError}; -pub const CPU_COMPONENT_HEIGHT: u32 = 16; -pub const CPU_COMPONENT_STEP: u32 = 1; -pub const ECDSA_BUILTIN_RATIO: u32 = 512; -pub const ECDSA_BUILTIN_REPETITIONS: u32 = 1; -pub const ECDSA_BUILTIN_ROW_RATIO: u32 = 8192; -pub const ECDSA_ELEMENT_BITS: u32 = 251; -pub const ECDSA_ELEMENT_HEIGHT: u32 = 256; -pub const HAS_BITWISE_BUILTIN: u32 = 0; -pub const HAS_DILUTED_POOL: u32 = 0; -pub const HAS_EC_OP_BUILTIN: u32 = 0; -pub const HAS_ECDSA_BUILTIN: u32 = 1; -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 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 LOG_CPU_COMPONENT_HEIGHT: u32 = 4; -pub const N_DYNAMIC_PARAMS: u32 = 0; -pub const PEDERSEN_BUILTIN_RATIO: u32 = 8; -pub const PEDERSEN_BUILTIN_REPETITIONS: u32 = 4; -pub const PEDERSEN_BUILTIN_ROW_RATIO: u32 = 128; -pub const PUBLIC_MEMORY_STEP: u32 = 8; -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 = 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; diff --git a/crates/air/src/layout/recursive/mod.rs b/crates/air/src/layout/recursive/mod.rs index 50f783b..49ef3fe 100644 --- a/crates/air/src/layout/recursive/mod.rs +++ b/crates/air/src/layout/recursive/mod.rs @@ -14,34 +14,34 @@ use swiftness_commitment::table::{commit::table_commit, decommit::table_decommit use super::{CompositionPolyEvalError, LayoutTrait, PublicInputError}; -pub const BITWISE_RATIO: u32 = 8; -pub const BITWISE_ROW_RATIO: u32 = 128; -pub const BITWISE_TOTAL_N_BITS: u32 = 251; -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 N_DYNAMIC_PARAMS: u32 = 0; -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; diff --git a/crates/air/src/layout/recursive_with_poseidon/mod.rs b/crates/air/src/layout/recursive_with_poseidon/mod.rs index cafd759..66233e4 100644 --- a/crates/air/src/layout/recursive_with_poseidon/mod.rs +++ b/crates/air/src/layout/recursive_with_poseidon/mod.rs @@ -18,40 +18,40 @@ use swiftness_commitment::table::{commit::table_commit, decommit::table_decommit use super::{CompositionPolyEvalError, LayoutTrait, PublicInputError}; -pub const BITWISE_RATIO: u32 = 16; -pub const BITWISE_ROW_RATIO: u32 = 256; -pub const BITWISE_TOTAL_N_BITS: u32 = 251; -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 N_DYNAMIC_PARAMS: u32 = 0; -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; diff --git a/crates/air/src/layout/small/mod.rs b/crates/air/src/layout/small/mod.rs index 2381ca9..06d3543 100644 --- a/crates/air/src/layout/small/mod.rs +++ b/crates/air/src/layout/small/mod.rs @@ -14,34 +14,34 @@ use swiftness_commitment::table::{commit::table_commit, decommit::table_decommit use super::{CompositionPolyEvalError, LayoutTrait, PublicInputError}; -pub const CPU_COMPONENT_HEIGHT: u32 = 16; -pub const CPU_COMPONENT_STEP: u32 = 1; -pub const ECDSA_BUILTIN_RATIO: u32 = 512; -pub const ECDSA_BUILTIN_REPETITIONS: u32 = 1; -pub const ECDSA_BUILTIN_ROW_RATIO: u32 = 8192; -pub const ECDSA_ELEMENT_BITS: u32 = 251; -pub const ECDSA_ELEMENT_HEIGHT: u32 = 256; -pub const HAS_BITWISE_BUILTIN: u32 = 0; -pub const HAS_DILUTED_POOL: u32 = 0; -pub const HAS_EC_OP_BUILTIN: u32 = 0; -pub const HAS_ECDSA_BUILTIN: u32 = 1; -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 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("0x736d616c6c"); -pub const LOG_CPU_COMPONENT_HEIGHT: u32 = 4; -pub const N_DYNAMIC_PARAMS: u32 = 0; -pub const PEDERSEN_BUILTIN_RATIO: u32 = 8; -pub const PEDERSEN_BUILTIN_REPETITIONS: u32 = 4; -pub const PEDERSEN_BUILTIN_ROW_RATIO: u32 = 128; -pub const PUBLIC_MEMORY_STEP: u32 = 8; -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 = 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; diff --git a/crates/air/src/layout/starknet/mod.rs b/crates/air/src/layout/starknet/mod.rs index a297abe..c9d519f 100644 --- a/crates/air/src/layout/starknet/mod.rs +++ b/crates/air/src/layout/starknet/mod.rs @@ -20,48 +20,48 @@ use swiftness_commitment::table::{commit::table_commit, decommit::table_decommit use super::{CompositionPolyEvalError, LayoutTrait, PublicInputError}; -pub const BITWISE_RATIO: u32 = 64; -pub const BITWISE_ROW_RATIO: u32 = 1024; -pub const BITWISE_TOTAL_N_BITS: u32 = 251; -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 EC_OP_BUILTIN_RATIO: u32 = 1024; -pub const EC_OP_BUILTIN_ROW_RATIO: u32 = 16384; -pub const EC_OP_N_BITS: u32 = 252; -pub const EC_OP_SCALAR_HEIGHT: u32 = 256; -pub const ECDSA_BUILTIN_RATIO: u32 = 2048; -pub const ECDSA_BUILTIN_REPETITIONS: u32 = 1; -pub const ECDSA_BUILTIN_ROW_RATIO: u32 = 32768; -pub const ECDSA_ELEMENT_BITS: u32 = 251; -pub const ECDSA_ELEMENT_HEIGHT: u32 = 256; -pub const HAS_BITWISE_BUILTIN: u32 = 1; -pub const HAS_DILUTED_POOL: u32 = 1; -pub const HAS_EC_OP_BUILTIN: u32 = 1; -pub const HAS_ECDSA_BUILTIN: u32 = 1; -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 = 64; +pub const BITWISE_ROW_RATIO: usize = 1024; +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 EC_OP_BUILTIN_RATIO: usize = 1024; +pub const EC_OP_BUILTIN_ROW_RATIO: usize = 16384; +pub const EC_OP_N_BITS: usize = 252; +pub const EC_OP_SCALAR_HEIGHT: usize = 256; +pub const ECDSA_BUILTIN_RATIO: usize = 2048; +pub const ECDSA_BUILTIN_REPETITIONS: usize = 1; +pub const ECDSA_BUILTIN_ROW_RATIO: usize = 32768; +pub const ECDSA_ELEMENT_BITS: usize = 251; +pub const ECDSA_ELEMENT_HEIGHT: usize = 256; +pub const HAS_BITWISE_BUILTIN: usize = 1; +pub const HAS_DILUTED_POOL: usize = 1; +pub const HAS_EC_OP_BUILTIN: usize = 1; +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 = 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("0x737461726b6e6574"); -pub const LOG_CPU_COMPONENT_HEIGHT: u32 = 4; -pub const N_DYNAMIC_PARAMS: u32 = 0; -pub const PEDERSEN_BUILTIN_RATIO: u32 = 32; -pub const PEDERSEN_BUILTIN_REPETITIONS: u32 = 1; -pub const PEDERSEN_BUILTIN_ROW_RATIO: u32 = 512; -pub const POSEIDON_M: u32 = 3; -pub const POSEIDON_RATIO: u32 = 32; -pub const POSEIDON_ROUNDS_FULL: u32 = 8; -pub const POSEIDON_ROUNDS_PARTIAL: u32 = 83; -pub const POSEIDON_ROW_RATIO: u32 = 512; -pub const PUBLIC_MEMORY_STEP: u32 = 8; -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 = 32; +pub const PEDERSEN_BUILTIN_REPETITIONS: usize = 1; +pub const PEDERSEN_BUILTIN_ROW_RATIO: usize = 512; +pub const POSEIDON_M: usize = 3; +pub const POSEIDON_RATIO: usize = 32; +pub const POSEIDON_ROUNDS_FULL: usize = 8; +pub const POSEIDON_ROUNDS_PARTIAL: usize = 83; +pub const POSEIDON_ROW_RATIO: usize = 512; +pub const PUBLIC_MEMORY_STEP: usize = 8; +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 = 6; diff --git a/crates/air/src/layout/starknet_with_keccak/mod.rs b/crates/air/src/layout/starknet_with_keccak/mod.rs index 1e8410b..e6cd6b5 100644 --- a/crates/air/src/layout/starknet_with_keccak/mod.rs +++ b/crates/air/src/layout/starknet_with_keccak/mod.rs @@ -22,51 +22,51 @@ use swiftness_commitment::table::{commit::table_commit, decommit::table_decommit use super::{CompositionPolyEvalError, LayoutTrait, PublicInputError}; -pub const BITWISE_RATIO: u32 = 64; -pub const BITWISE_ROW_RATIO: u32 = 1024; -pub const BITWISE_TOTAL_N_BITS: u32 = 251; -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 EC_OP_BUILTIN_RATIO: u32 = 1024; -pub const EC_OP_BUILTIN_ROW_RATIO: u32 = 16384; -pub const EC_OP_N_BITS: u32 = 252; -pub const EC_OP_SCALAR_HEIGHT: u32 = 256; -pub const ECDSA_BUILTIN_RATIO: u32 = 2048; -pub const ECDSA_BUILTIN_REPETITIONS: u32 = 1; -pub const ECDSA_BUILTIN_ROW_RATIO: u32 = 32768; -pub const ECDSA_ELEMENT_BITS: u32 = 251; -pub const ECDSA_ELEMENT_HEIGHT: u32 = 256; -pub const HAS_BITWISE_BUILTIN: u32 = 1; -pub const HAS_DILUTED_POOL: u32 = 1; -pub const HAS_EC_OP_BUILTIN: u32 = 1; -pub const HAS_ECDSA_BUILTIN: u32 = 1; -pub const HAS_KECCAK_BUILTIN: u32 = 1; -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 KECCAK_RATIO: u32 = 2048; -pub const KECCAK_ROW_RATIO: u32 = 32768; +pub const BITWISE_RATIO: usize = 64; +pub const BITWISE_ROW_RATIO: usize = 1024; +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 EC_OP_BUILTIN_RATIO: usize = 1024; +pub const EC_OP_BUILTIN_ROW_RATIO: usize = 16384; +pub const EC_OP_N_BITS: usize = 252; +pub const EC_OP_SCALAR_HEIGHT: usize = 256; +pub const ECDSA_BUILTIN_RATIO: usize = 2048; +pub const ECDSA_BUILTIN_REPETITIONS: usize = 1; +pub const ECDSA_BUILTIN_ROW_RATIO: usize = 32768; +pub const ECDSA_ELEMENT_BITS: usize = 251; +pub const ECDSA_ELEMENT_HEIGHT: usize = 256; +pub const HAS_BITWISE_BUILTIN: usize = 1; +pub const HAS_DILUTED_POOL: usize = 1; +pub const HAS_EC_OP_BUILTIN: usize = 1; +pub const HAS_ECDSA_BUILTIN: usize = 1; +pub const HAS_KECCAK_BUILTIN: usize = 1; +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 KECCAK_RATIO: usize = 2048; +pub const KECCAK_ROW_RATIO: usize = 32768; pub const LAYOUT_CODE: Felt = Felt::from_hex_unchecked("0x737461726b6e65745f776974685f6b656363616b"); -pub const LOG_CPU_COMPONENT_HEIGHT: u32 = 4; -pub const N_DYNAMIC_PARAMS: u32 = 0; -pub const PEDERSEN_BUILTIN_RATIO: u32 = 32; -pub const PEDERSEN_BUILTIN_REPETITIONS: u32 = 1; -pub const PEDERSEN_BUILTIN_ROW_RATIO: u32 = 512; -pub const POSEIDON_M: u32 = 3; -pub const POSEIDON_RATIO: u32 = 32; -pub const POSEIDON_ROUNDS_FULL: u32 = 8; -pub const POSEIDON_ROUNDS_PARTIAL: u32 = 83; -pub const POSEIDON_ROW_RATIO: u32 = 512; -pub const PUBLIC_MEMORY_STEP: u32 = 8; -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 = 32; +pub const PEDERSEN_BUILTIN_REPETITIONS: usize = 1; +pub const PEDERSEN_BUILTIN_ROW_RATIO: usize = 512; +pub const POSEIDON_M: usize = 3; +pub const POSEIDON_RATIO: usize = 32; +pub const POSEIDON_ROUNDS_FULL: usize = 8; +pub const POSEIDON_ROUNDS_PARTIAL: usize = 83; +pub const POSEIDON_ROW_RATIO: usize = 512; +pub const PUBLIC_MEMORY_STEP: usize = 8; +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 = 6; From 13edf21052d611cc20b38f777770c0a5b1336709 Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Wed, 24 Jul 2024 00:15:06 +0200 Subject: [PATCH 4/4] vec alloc fix --- crates/stark/src/commit.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/stark/src/commit.rs b/crates/stark/src/commit.rs index f9736b3..884b49f 100644 --- a/crates/stark/src/commit.rs +++ b/crates/stark/src/commit.rs @@ -1,3 +1,4 @@ +use alloc::vec::Vec; use starknet_crypto::Felt; use swiftness_air::{domains::StarkDomains, layout::LayoutTrait, public_memory::PublicInput}; use swiftness_commitment::table::commit::table_commit; @@ -15,7 +16,7 @@ pub fn stark_commit( ) -> Result, Error> { // Read the commitment of the 'traces' component. let traces_commitment = - Layout::traces_commit(transcript, &unsent_commitment.traces, config.traces.to_owned()); + Layout::traces_commit(transcript, &unsent_commitment.traces, config.traces.clone()); // Generate interaction values after traces commitment. let composition_alpha = transcript.random_felt_to_prover(); @@ -24,7 +25,7 @@ pub fn stark_commit( // Read composition commitment. let composition_commitment = - table_commit(transcript, unsent_commitment.composition, config.composition.to_owned()); + table_commit(transcript, unsent_commitment.composition, config.composition.clone()); // Generate interaction values after composition. let interaction_after_composition = transcript.random_felt_to_prover(); @@ -49,8 +50,7 @@ pub fn stark_commit( powers_array(Felt::ONE, oods_alpha, (Layout::MASK_SIZE + Layout::CONSTRAINT_DEGREE) as u32); // Read fri commitment. - let fri_commitment = - fri_commit(transcript, unsent_commitment.fri.to_owned(), config.fri.to_owned()); + let fri_commitment = fri_commit(transcript, unsent_commitment.fri.clone(), config.fri.clone()); // Proof of work commitment phase. unsent_commitment.proof_of_work.commit(transcript, &config.proof_of_work)?; @@ -60,7 +60,7 @@ pub fn stark_commit( traces: traces_commitment, composition: composition_commitment, interaction_after_composition, - oods_values: unsent_commitment.oods_values.to_owned(), + oods_values: unsent_commitment.oods_values.clone(), interaction_after_oods: oods_coefficients, fri: fri_commitment, })