From 29e32379098f60b3ceedd9b5706d393f62e730ef Mon Sep 17 00:00:00 2001 From: Neo Date: Fri, 12 Jan 2024 08:13:08 +0100 Subject: [PATCH 01/22] stark commit in progress --- src/air.cairo | 1 + src/air/layout.cairo | 34 +++++++++ src/stark.cairo | 19 +++++ src/stark/stark_commit.cairo | 143 +++++++++++++++++++++++++++++++++++ 4 files changed, 197 insertions(+) create mode 100644 src/air/layout.cairo diff --git a/src/air.cairo b/src/air.cairo index 275d373f9..90358e9ef 100644 --- a/src/air.cairo +++ b/src/air.cairo @@ -8,3 +8,4 @@ mod pedersen; mod autogenerated; mod traces; mod traces_config; +mod layout; diff --git a/src/air/layout.cairo b/src/air/layout.cairo new file mode 100644 index 000000000..83f98239a --- /dev/null +++ b/src/air/layout.cairo @@ -0,0 +1,34 @@ +#[derive(Drop)] +struct Layout { + // Virtual functions. + // Each should be a pointer to a function with the same interface as the function in this file. + // eval_oods_polynomial: felt*, + // Constants. + // n_original_columns: felt252, + // n_interaction_columns: felt252, + n_interaction_elements: felt252, +} + +#[derive(Drop)] +struct AirInstance { + // Virtual functions. + // Each should be a pointer to a function with the same interface as the function in this file. + // public_input_hash: felt*, + // public_input_validate: felt*, + // traces_config_validate: felt*, + // traces_commit: felt*, + // traces_decommit: felt*, + // traces_eval_composition_polynomial: felt*, + // eval_oods_boundary_poly_at_points: felt*, + // Constants. + // n_dynamic_params: felt252, + n_constraints: felt252, + constraint_degree: felt252, + mask_size: felt252, +} + +#[derive(Drop)] +struct AirWithLayout { + air: AirInstance, + layout: Layout, +} diff --git a/src/stark.cairo b/src/stark.cairo index fc6175b7a..41a90170f 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -1,8 +1,11 @@ +use cairo_verifier::air::public_input::PublicInputTrait; use cairo_verifier::{ air::{ + layout::{AirInstance, AirWithLayout, Layout}, traces_config::{TracesConfig, TracesConfigTrait}, public_input::PublicInput, traces::{TracesUnsentCommitment, TracesCommitment, TracesDecommitment, TracesWitness} }, + channel::channel::{Channel, ChannelImpl}, fri::{ fri_config::{FriConfig, FriConfigTrait}, fri::{FriUnsentCommitment, FriWitness, FriCommitment} @@ -38,8 +41,24 @@ struct StarkProof { #[generate_trait] impl StarkProofImpl of StarkProofTrait { fn verify(self: @StarkProof) { + let air = AirWithLayout { + air: AirInstance { n_constraints: 8, constraint_degree: 1, mask_size: 133 }, + layout: Layout { n_interaction_elements: 8 } + }; self.config.validate(SECURITY_BITS); let stark_domains = StarkDomainsImpl::new(self.config); + + let digest = self.public_input.get_public_input_hash(); + let mut channel = ChannelImpl::new(digest); + + stark_commit::stark_commit( + ref channel, + @air, + self.public_input, + self.unsent_commitment, + self.config, + @stark_domains, + ); } } diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index 8b1378917..13e45119b 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -1 +1,144 @@ +use core::array::ArrayTrait; +use core::option::OptionTrait; +use core::traits::Into; +use cairo_verifier::channel::channel::ChannelTrait; +use cairo_verifier::{ + air::{layout::{AirWithLayout, Layout}, public_input::PublicInput, traces::traces_commit,}, + channel::channel::Channel, common::powers_array::powers_array, domains::StarkDomains, + fri::fri::fri_commit, stark::{StarkUnsentCommitment, StarkConfig, StarkCommitment}, + proof_of_work::proof_of_work::proof_of_work_commit, table_commitment::table_commit, + oods::verify_oods, +}; +struct InteractionValuesAfterTraces { + // n_constraints Coefficients for the AIR constraints. + coefficients: Span, +} + +struct InteractionValuesAfterOods { + // n_oods_values coefficients for the boundary polynomial validating the OODS values. + coefficients: Span, +} + +// STARK commitment phase. +fn stark_commit( + ref channel: Channel, + air: @AirWithLayout, + public_input: @PublicInput, + unsent_commitment: @StarkUnsentCommitment, + config: @StarkConfig, + stark_domains: @StarkDomains, +) -> StarkCommitment { + // alloc_locals; + + // Read the commitment of the 'traces' component. + // let (traces_commitment) = traces_commit( + // air=air, + // public_input=public_input, + // unsent_commitment=unsent_commitment.traces, + // config=config.traces, + // ); + let traces_commitment = traces_commit( + ref channel, + *air.layout.n_interaction_elements, + *public_input, + *unsent_commitment.traces, + *config.traces, + ); + + // Generate interaction values after traces commitment. + // let (composition_alpha: felt*) = alloc(); + // random_felts_to_prover(n_elements=1, elements=composition_alpha); + // let (traces_coefficients: felt*) = alloc(); + // compute_powers_array( + // data_ptr=traces_coefficients, alpha=[composition_alpha], cur=1, n=air.n_constraints + // ); + let composition_alpha = channel.random_felt_to_prover(); + let traces_coefficients = powers_array( + 1, composition_alpha, (*air.air.n_constraints).try_into().unwrap() + ); + + // let (interaction_after_traces: InteractionValuesAfterTraces*) = alloc(); + // assert [interaction_after_traces] = InteractionValuesAfterTraces( + // coefficients=traces_coefficients + // ); + let interaction_after_traces = InteractionValuesAfterTraces { + coefficients: traces_coefficients.span(), + }; + + // Read composition commitment. + // let (composition_commitment: TableCommitment*) = table_commit( + // unsent_commitment=unsent_commitment.composition, config=config.composition + // ); + let composition_commitment = table_commit(*unsent_commitment.composition, *config.composition,); + + // Generate interaction values after composition. + // let (interaction_after_composition: InteractionValuesAfterComposition*) = alloc(); + // random_felts_to_prover( + // n_elements=InteractionValuesAfterComposition.SIZE, + // elements=cast(interaction_after_composition, felt*), + // ); + let interaction_after_composition = channel.random_felt_to_prover(); + + // Read OODS values. + // local n_oods_values = air.mask_size + air.constraint_degree; + // let (sent_oods_values) = read_felts_from_prover( + // n_values=n_oods_values, values=unsent_commitment.oods_values + // ); + let n_oods_values = *air.air.mask_size + *air.air.constraint_degree; + let sent_oods_values = channel.read_felts_from_prover(*unsent_commitment.oods_values); + + // Check that the trace and the composition agree at oods_point. + // verify_oods( + // air=air, + // oods_values=sent_oods_values, + // traces_commitment=traces_commitment, + // traces_coefficients=traces_coefficients, + // oods_point=interaction_after_composition.oods_point, + // trace_domain_size=stark_domains.trace_domain_size, + // trace_generator=stark_domains.trace_generator, + // ); + verify_oods(sent_oods_values); + + // Generate interaction values after OODS. + // let (oods_alpha: felt*) = alloc(); + // random_felts_to_prover(n_elements=1, elements=oods_alpha); + // let (oods_coefficients: felt*) = alloc(); + // compute_powers_array(data_ptr=oods_coefficients, alpha=[oods_alpha], cur=1, n=n_oods_values); + // tempvar interaction_after_oods = new InteractionValuesAfterOods(coefficients=oods_coefficients); + let oods_alpha = channel.random_felt_to_prover(); + let oods_coefficients = powers_array(1, oods_alpha, n_oods_values.try_into().unwrap()); + let interaction_after_oods = InteractionValuesAfterOods { + coefficients: oods_coefficients.span() + }; + + // Read fri commitment. + // let (fri_commitment) = fri_commit(unsent_commitment=unsent_commitment.fri, config=config.fri); + let fri_commitment = fri_commit(ref channel, *unsent_commitment.fri, *config.fri); + + // Proof of work commitment phase. + // proof_of_work_commit( + // unsent_commitment=unsent_commitment.proof_of_work, config=config.proof_of_work + // ); + proof_of_work_commit(ref channel, *unsent_commitment.proof_of_work, *config.proof_of_work); + + // Return commitment. + // return ( + // res=new StarkCommitment( + // traces=traces_commitment, + // composition=composition_commitment, + // interaction_after_composition=interaction_after_composition, + // oods_values=sent_oods_values, + // interaction_after_oods=interaction_after_oods, + // fri=fri_commitment, + // ), + // ); + StarkCommitment { + traces: traces_commitment, + composition: composition_commitment, + interaction_after_composition: interaction_after_composition, + oods_values: sent_oods_values, + interaction_after_oods: interaction_after_oods.coefficients, + fri: fri_commitment, + } +} From 3c0070bf65796c4753f723f721ebfb4b28e3878c Mon Sep 17 00:00:00 2001 From: Neo Date: Fri, 12 Jan 2024 13:38:01 +0100 Subject: [PATCH 02/22] remove layout & sorts --- src/air.cairo | 11 +++-- src/air/constants.cairo | 43 +++++++++---------- src/air/layout.cairo | 34 --------------- src/air/traces.cairo | 4 +- src/stark.cairo | 6 --- src/stark/stark_commit.cairo | 80 +++++++----------------------------- 6 files changed, 43 insertions(+), 135 deletions(-) delete mode 100644 src/air/layout.cairo diff --git a/src/air.cairo b/src/air.cairo index 90358e9ef..ba4692015 100644 --- a/src/air.cairo +++ b/src/air.cairo @@ -1,11 +1,10 @@ +mod autogenerated; mod composition; -mod global_values; mod constants; -mod public_input; -mod public_memory; mod diluted; +mod global_values; mod pedersen; -mod autogenerated; -mod traces; +mod public_input; +mod public_memory; mod traces_config; -mod layout; +mod traces; diff --git a/src/air/constants.cairo b/src/air/constants.cairo index 5d9851d2a..63b0a8eef 100644 --- a/src/air/constants.cairo +++ b/src/air/constants.cairo @@ -1,43 +1,44 @@ // Recursive layout -const N_DYNAMIC_PARAMS: felt252 = 0; -const N_CONSTRAINTS: felt252 = 93; -const MASK_SIZE: felt252 = 133; -const PUBLIC_MEMORY_STEP: felt252 = 16; -const HAS_DILUTED_POOL: felt252 = 1; -const DILUTED_SPACING: felt252 = 4; -const DILUTED_N_BITS: felt252 = 16; -const PEDERSEN_BUILTIN_RATIO: felt252 = 128; -const PEDERSEN_BUILTIN_REPETITIONS: felt252 = 1; -const RC_BUILTIN_RATIO: felt252 = 8; -const RC_N_PARTS: felt252 = 8; const BITWISE_RATIO: felt252 = 8; const BITWISE_TOTAL_N_BITS: felt252 = 251; -const HAS_OUTPUT_BUILTIN: felt252 = 1; -const HAS_PEDERSEN_BUILTIN: felt252 = 1; -const HAS_RANGE_CHECK_BUILTIN: felt252 = 1; -const HAS_ECDSA_BUILTIN: felt252 = 0; +const CONSTRAINT_DEGREE: u32 = 2; +const CPU_COMPONENT_HEIGHT: felt252 = 16; +const DILUTED_N_BITS: felt252 = 16; +const DILUTED_SPACING: felt252 = 4; const HAS_BITWISE_BUILTIN: felt252 = 1; +const HAS_DILUTED_POOL: felt252 = 1; const HAS_EC_OP_BUILTIN: felt252 = 0; +const HAS_ECDSA_BUILTIN: felt252 = 0; const HAS_KECCAK_BUILTIN: felt252 = 0; +const HAS_OUTPUT_BUILTIN: felt252 = 1; +const HAS_PEDERSEN_BUILTIN: felt252 = 1; const HAS_POSEIDON_BUILTIN: felt252 = 0; +const HAS_RANGE_CHECK_BUILTIN: felt252 = 1; +const IS_DYNAMIC_AIR: felt252 = 0; const LAYOUT_CODE: felt252 = 0x726563757273697665; -const CONSTRAINT_DEGREE: u32 = 2; -const CPU_COMPONENT_HEIGHT: felt252 = 16; const LOG_CPU_COMPONENT_HEIGHT: felt252 = 4; +const MASK_SIZE: felt252 = 133; const MEMORY_STEP: felt252 = 2; +const N_CONSTRAINTS: felt252 = 93; +const N_DYNAMIC_PARAMS: felt252 = 0; +const N_INTERACTION_ELEMENTS: felt252 = 6; const NUM_COLUMNS_FIRST: u32 = 7; const NUM_COLUMNS_SECOND: u32 = 3; -const IS_DYNAMIC_AIR: felt252 = 0; +const PEDERSEN_BUILTIN_RATIO: felt252 = 128; +const PEDERSEN_BUILTIN_REPETITIONS: felt252 = 1; +const PUBLIC_MEMORY_STEP: felt252 = 16; +const RC_BUILTIN_RATIO: felt252 = 8; +const RC_N_PARTS: felt252 = 8; const MAX_LOG_N_STEPS: felt252 = 50; const MAX_RANGE_CHECK: felt252 = 0xffff; // 2 ** 16 - 1 mod segments { - const PROGRAM: usize = 0; + const BITWISE: usize = 5; const EXECUTION: usize = 1; + const N_SEGMENTS: usize = 6; const OUTPUT: usize = 2; const PEDERSEN: usize = 3; + const PROGRAM: usize = 0; const RANGE_CHECK: usize = 4; - const BITWISE: usize = 5; - const N_SEGMENTS: usize = 6; } diff --git a/src/air/layout.cairo b/src/air/layout.cairo deleted file mode 100644 index 83f98239a..000000000 --- a/src/air/layout.cairo +++ /dev/null @@ -1,34 +0,0 @@ -#[derive(Drop)] -struct Layout { - // Virtual functions. - // Each should be a pointer to a function with the same interface as the function in this file. - // eval_oods_polynomial: felt*, - // Constants. - // n_original_columns: felt252, - // n_interaction_columns: felt252, - n_interaction_elements: felt252, -} - -#[derive(Drop)] -struct AirInstance { - // Virtual functions. - // Each should be a pointer to a function with the same interface as the function in this file. - // public_input_hash: felt*, - // public_input_validate: felt*, - // traces_config_validate: felt*, - // traces_commit: felt*, - // traces_decommit: felt*, - // traces_eval_composition_polynomial: felt*, - // eval_oods_boundary_poly_at_points: felt*, - // Constants. - // n_dynamic_params: felt252, - n_constraints: felt252, - constraint_degree: felt252, - mask_size: felt252, -} - -#[derive(Drop)] -struct AirWithLayout { - air: AirInstance, - layout: Layout, -} diff --git a/src/air/traces.cairo b/src/air/traces.cairo index 313708043..a3e3f0f25 100644 --- a/src/air/traces.cairo +++ b/src/air/traces.cairo @@ -24,7 +24,7 @@ struct TracesUnsentCommitment { // Commitment for the Traces component. #[derive(Drop)] struct TracesCommitment { - public_input: PublicInput, + public_input: @PublicInput, // Commitment to the first trace. original: TableCommitment, // The interaction elements that were sent to the prover after the first trace commitment (e.g. @@ -56,7 +56,7 @@ struct TracesWitness { fn traces_commit( ref channel: Channel, n_interaction_elements: felt252, - public_input: PublicInput, + public_input: @PublicInput, unsent_commitment: TracesUnsentCommitment, config: TracesConfig ) -> TracesCommitment { diff --git a/src/stark.cairo b/src/stark.cairo index 41a90170f..c5304ece0 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -1,7 +1,6 @@ use cairo_verifier::air::public_input::PublicInputTrait; use cairo_verifier::{ air::{ - layout::{AirInstance, AirWithLayout, Layout}, traces_config::{TracesConfig, TracesConfigTrait}, public_input::PublicInput, traces::{TracesUnsentCommitment, TracesCommitment, TracesDecommitment, TracesWitness} }, @@ -41,10 +40,6 @@ struct StarkProof { #[generate_trait] impl StarkProofImpl of StarkProofTrait { fn verify(self: @StarkProof) { - let air = AirWithLayout { - air: AirInstance { n_constraints: 8, constraint_degree: 1, mask_size: 133 }, - layout: Layout { n_interaction_elements: 8 } - }; self.config.validate(SECURITY_BITS); let stark_domains = StarkDomainsImpl::new(self.config); @@ -53,7 +48,6 @@ impl StarkProofImpl of StarkProofTrait { stark_commit::stark_commit( ref channel, - @air, self.public_input, self.unsent_commitment, self.config, diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index 13e45119b..711245ef1 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -1,20 +1,27 @@ +use core::traits::TryInto; use core::array::ArrayTrait; use core::option::OptionTrait; use core::traits::Into; use cairo_verifier::channel::channel::ChannelTrait; use cairo_verifier::{ - air::{layout::{AirWithLayout, Layout}, public_input::PublicInput, traces::traces_commit,}, + air::{ + constants::{CONSTRAINT_DEGREE, N_CONSTRAINTS, N_INTERACTION_ELEMENTS, MASK_SIZE}, + public_input::PublicInput, + traces::traces_commit, + }, channel::channel::Channel, common::powers_array::powers_array, domains::StarkDomains, fri::fri::fri_commit, stark::{StarkUnsentCommitment, StarkConfig, StarkCommitment}, proof_of_work::proof_of_work::proof_of_work_commit, table_commitment::table_commit, oods::verify_oods, }; +#[derive(Drop, Copy)] struct InteractionValuesAfterTraces { // n_constraints Coefficients for the AIR constraints. coefficients: Span, } +#[derive(Drop, Copy)] struct InteractionValuesAfterOods { // n_oods_values coefficients for the boundary polynomial validating the OODS values. coefficients: Span, @@ -23,69 +30,33 @@ struct InteractionValuesAfterOods { // STARK commitment phase. fn stark_commit( ref channel: Channel, - air: @AirWithLayout, public_input: @PublicInput, unsent_commitment: @StarkUnsentCommitment, config: @StarkConfig, stark_domains: @StarkDomains, ) -> StarkCommitment { - // alloc_locals; - - // Read the commitment of the 'traces' component. - // let (traces_commitment) = traces_commit( - // air=air, - // public_input=public_input, - // unsent_commitment=unsent_commitment.traces, - // config=config.traces, - // ); let traces_commitment = traces_commit( ref channel, - *air.layout.n_interaction_elements, - *public_input, + N_INTERACTION_ELEMENTS, + public_input, *unsent_commitment.traces, *config.traces, ); - // Generate interaction values after traces commitment. - // let (composition_alpha: felt*) = alloc(); - // random_felts_to_prover(n_elements=1, elements=composition_alpha); - // let (traces_coefficients: felt*) = alloc(); - // compute_powers_array( - // data_ptr=traces_coefficients, alpha=[composition_alpha], cur=1, n=air.n_constraints - // ); let composition_alpha = channel.random_felt_to_prover(); let traces_coefficients = powers_array( - 1, composition_alpha, (*air.air.n_constraints).try_into().unwrap() + 1, composition_alpha, N_CONSTRAINTS.try_into().unwrap(), ); - // let (interaction_after_traces: InteractionValuesAfterTraces*) = alloc(); - // assert [interaction_after_traces] = InteractionValuesAfterTraces( - // coefficients=traces_coefficients - // ); let interaction_after_traces = InteractionValuesAfterTraces { coefficients: traces_coefficients.span(), }; - // Read composition commitment. - // let (composition_commitment: TableCommitment*) = table_commit( - // unsent_commitment=unsent_commitment.composition, config=config.composition - // ); let composition_commitment = table_commit(*unsent_commitment.composition, *config.composition,); - // Generate interaction values after composition. - // let (interaction_after_composition: InteractionValuesAfterComposition*) = alloc(); - // random_felts_to_prover( - // n_elements=InteractionValuesAfterComposition.SIZE, - // elements=cast(interaction_after_composition, felt*), - // ); let interaction_after_composition = channel.random_felt_to_prover(); - // Read OODS values. - // local n_oods_values = air.mask_size + air.constraint_degree; - // let (sent_oods_values) = read_felts_from_prover( - // n_values=n_oods_values, values=unsent_commitment.oods_values - // ); - let n_oods_values = *air.air.mask_size + *air.air.constraint_degree; + let n_oods_values = MASK_SIZE + CONSTRAINT_DEGREE.into(); let sent_oods_values = channel.read_felts_from_prover(*unsent_commitment.oods_values); // Check that the trace and the composition agree at oods_point. @@ -98,46 +69,23 @@ fn stark_commit( // trace_domain_size=stark_domains.trace_domain_size, // trace_generator=stark_domains.trace_generator, // ); - verify_oods(sent_oods_values); + // verify_oods(sent_oods_values); - // Generate interaction values after OODS. - // let (oods_alpha: felt*) = alloc(); - // random_felts_to_prover(n_elements=1, elements=oods_alpha); - // let (oods_coefficients: felt*) = alloc(); - // compute_powers_array(data_ptr=oods_coefficients, alpha=[oods_alpha], cur=1, n=n_oods_values); - // tempvar interaction_after_oods = new InteractionValuesAfterOods(coefficients=oods_coefficients); let oods_alpha = channel.random_felt_to_prover(); let oods_coefficients = powers_array(1, oods_alpha, n_oods_values.try_into().unwrap()); let interaction_after_oods = InteractionValuesAfterOods { coefficients: oods_coefficients.span() }; - // Read fri commitment. - // let (fri_commitment) = fri_commit(unsent_commitment=unsent_commitment.fri, config=config.fri); let fri_commitment = fri_commit(ref channel, *unsent_commitment.fri, *config.fri); - // Proof of work commitment phase. - // proof_of_work_commit( - // unsent_commitment=unsent_commitment.proof_of_work, config=config.proof_of_work - // ); proof_of_work_commit(ref channel, *unsent_commitment.proof_of_work, *config.proof_of_work); - // Return commitment. - // return ( - // res=new StarkCommitment( - // traces=traces_commitment, - // composition=composition_commitment, - // interaction_after_composition=interaction_after_composition, - // oods_values=sent_oods_values, - // interaction_after_oods=interaction_after_oods, - // fri=fri_commitment, - // ), - // ); StarkCommitment { traces: traces_commitment, composition: composition_commitment, interaction_after_composition: interaction_after_composition, - oods_values: sent_oods_values, + oods_values: array![].span(), interaction_after_oods: interaction_after_oods.coefficients, fri: fri_commitment, } From 4b46d792fb2833121c312e40bab49ea8122ca603 Mon Sep 17 00:00:00 2001 From: Neo Date: Fri, 12 Jan 2024 13:41:15 +0100 Subject: [PATCH 03/22] fmt --- src/stark.cairo | 6 +----- src/stark/stark_commit.cairo | 3 +-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/stark.cairo b/src/stark.cairo index c5304ece0..72a17ade2 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -47,11 +47,7 @@ impl StarkProofImpl of StarkProofTrait { let mut channel = ChannelImpl::new(digest); stark_commit::stark_commit( - ref channel, - self.public_input, - self.unsent_commitment, - self.config, - @stark_domains, + ref channel, self.public_input, self.unsent_commitment, self.config, @stark_domains, ); } } diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index 711245ef1..aeb8cfcb3 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -6,8 +6,7 @@ use cairo_verifier::channel::channel::ChannelTrait; use cairo_verifier::{ air::{ constants::{CONSTRAINT_DEGREE, N_CONSTRAINTS, N_INTERACTION_ELEMENTS, MASK_SIZE}, - public_input::PublicInput, - traces::traces_commit, + public_input::PublicInput, traces::traces_commit, }, channel::channel::Channel, common::powers_array::powers_array, domains::StarkDomains, fri::fri::fri_commit, stark::{StarkUnsentCommitment, StarkConfig, StarkCommitment}, From 235902b173b106c0499cd2d30c152756c4a6bbc8 Mon Sep 17 00:00:00 2001 From: Neo Date: Fri, 12 Jan 2024 17:00:36 +0100 Subject: [PATCH 04/22] mock interaction_elements --- src/air/composition.cairo | 8 ++++---- src/air/global_values.cairo | 6 +++--- src/oods.cairo | 21 ++++++++++++++++----- src/stark.cairo | 6 ++++-- src/stark/stark_commit.cairo | 32 +++++++++++++++++++------------- 5 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/air/composition.cairo b/src/air/composition.cairo index 2ce2fc37f..ca1bf2e50 100644 --- a/src/air/composition.cairo +++ b/src/air/composition.cairo @@ -17,7 +17,7 @@ const SHIFT_POINT_Y: felt252 = 0x3ca0cfe4b3bc6ddf346d49d06ea0ed34e621062c0e056c1 fn eval_composition_polynomial( interaction_elements: InteractionElements, - public_input: PublicInput, + public_input: @PublicInput, mask_values: Array, constraint_coefficients: Array, point: felt252, @@ -41,7 +41,7 @@ fn eval_composition_polynomial( ); // Periodic columns - let n_steps = pow(2, public_input.log_n_steps); + let n_steps = pow(2, *public_input.log_n_steps); let n_pedersen_hash_copies = n_steps / (PEDERSEN_BUILTIN_RATIO * PEDERSEN_BUILTIN_REPETITIONS); assert_range_u128(n_pedersen_hash_copies); let pedersen_point = pow(point, n_pedersen_hash_copies); @@ -57,8 +57,8 @@ fn eval_composition_polynomial( initial_pedersen_addr: *public_input.segments.at(segments::PEDERSEN).begin_addr, initial_rc_addr: *public_input.segments.at(segments::RANGE_CHECK).begin_addr, initial_bitwise_addr: *public_input.segments.at(segments::BITWISE).begin_addr, - rc_min: public_input.rc_min, - rc_max: public_input.rc_max, + rc_min: *public_input.rc_min, + rc_max: *public_input.rc_max, offset_size: 0x10000, // 2**16 half_offset_size: 0x8000, pedersen_shift_point: EcPoint { x: SHIFT_POINT_X, y: SHIFT_POINT_Y }, diff --git a/src/air/global_values.cairo b/src/air/global_values.cairo index 5aa1abd1b..a69fb182e 100644 --- a/src/air/global_values.cairo +++ b/src/air/global_values.cairo @@ -1,11 +1,11 @@ -#[derive(Drop)] +#[derive(Drop, Copy)] struct EcPoint { x: felt252, y: felt252, } // Accumulation of member expressions for auto generated composition polynomial code. -#[derive(Drop)] +#[derive(Drop, Copy)] struct GlobalValues { // Public input. trace_length: felt252, @@ -42,6 +42,7 @@ struct GlobalValues { // Elements that are sent from the prover after the commitment on the original trace. // Used for components after the first interaction, e.g., memory and range check. +#[derive(Drop, Copy)] struct InteractionElements { memory_multi_column_perm_perm_interaction_elm: felt252, memory_multi_column_perm_hash_interaction_elm0: felt252, @@ -50,4 +51,3 @@ struct InteractionElements { diluted_check_interaction_z: felt252, diluted_check_interaction_alpha: felt252 } - diff --git a/src/oods.cairo b/src/oods.cairo index 257eb8354..e6b3dae8f 100644 --- a/src/oods.cairo +++ b/src/oods.cairo @@ -1,3 +1,4 @@ +use core::clone::Clone; use core::array::ArrayTrait; use cairo_verifier::common::array_extend::ArrayExtendTrait; use core::array::SpanTrait; @@ -23,18 +24,29 @@ struct OodsEvaluationInfo { } fn verify_oods( - oods: OodsValues, + oods: Span, interaction_elements: InteractionElements, - public_input: PublicInput, + public_input: @PublicInput, constraint_coefficients: Array, oods_point: felt252, trace_domain_size: felt252, trace_generator: felt252 ) { + let mut mask_values = array![]; + let mut i = 0; + loop { + if i == oods.len() - 2 { + break; + } + + mask_values.append(*oods.at(i)); + + i += 1; + }; let composition_from_trace = eval_composition_polynomial( interaction_elements, public_input, - oods.mask_values, + mask_values, constraint_coefficients, oods_point, trace_domain_size, @@ -42,8 +54,7 @@ fn verify_oods( ); // TODO support degree > 2? - let claimed_composition = *oods.split_polynomials.at(0) - + *oods.split_polynomials.at(1) * oods_point; + let claimed_composition = *oods[oods.len() - 2] + *oods[oods.len() - 1] * oods_point; assert(composition_from_trace == claimed_composition, 'Invalid OODS'); } diff --git a/src/stark.cairo b/src/stark.cairo index 72a17ade2..3d7ff4085 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -10,8 +10,10 @@ use cairo_verifier::{ fri::{FriUnsentCommitment, FriWitness, FriCommitment} }, domains::StarkDomainsImpl, - table_commitment::table_commitment::{ - TableCommitmentConfig, TableCommitmentWitness, TableDecommitment, TableCommitment + oods::OodsValues, + table_commitment::{ + TableCommitmentConfig, TableCommitmentWitness, TableDecommitment, TableUnsentCommitment, + TableCommitment }, proof_of_work::{ config::{ProofOfWorkConfig, ProofOfWorkConfigTrait}, diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index aeb8cfcb3..9955b5f6b 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -6,7 +6,7 @@ use cairo_verifier::channel::channel::ChannelTrait; use cairo_verifier::{ air::{ constants::{CONSTRAINT_DEGREE, N_CONSTRAINTS, N_INTERACTION_ELEMENTS, MASK_SIZE}, - public_input::PublicInput, traces::traces_commit, + global_values::InteractionElements, public_input::PublicInput, traces::traces_commit, }, channel::channel::Channel, common::powers_array::powers_array, domains::StarkDomains, fri::fri::fri_commit, stark::{StarkUnsentCommitment, StarkConfig, StarkCommitment}, @@ -56,19 +56,25 @@ fn stark_commit( let interaction_after_composition = channel.random_felt_to_prover(); let n_oods_values = MASK_SIZE + CONSTRAINT_DEGREE.into(); - let sent_oods_values = channel.read_felts_from_prover(*unsent_commitment.oods_values); + channel.read_felts_from_prover(*unsent_commitment.oods_values); - // Check that the trace and the composition agree at oods_point. - // verify_oods( - // air=air, - // oods_values=sent_oods_values, - // traces_commitment=traces_commitment, - // traces_coefficients=traces_coefficients, - // oods_point=interaction_after_composition.oods_point, - // trace_domain_size=stark_domains.trace_domain_size, - // trace_generator=stark_domains.trace_generator, - // ); - // verify_oods(sent_oods_values); + let interaction_elements = InteractionElements { + memory_multi_column_perm_perm_interaction_elm: 0, + memory_multi_column_perm_hash_interaction_elm0: 0, + rc16_perm_interaction_elm: 0, + diluted_check_permutation_interaction_elm: 0, + diluted_check_interaction_z: 0, + diluted_check_interaction_alpha: 0, + }; + verify_oods( + *unsent_commitment.oods_values, + interaction_elements, + public_input, + traces_coefficients, + interaction_after_composition, + *stark_domains.trace_generator, + *stark_domains.trace_domain_size + ); let oods_alpha = channel.random_felt_to_prover(); let oods_coefficients = powers_array(1, oods_alpha, n_oods_values.try_into().unwrap()); From 42fcb50b7377dcf08c9584fe5c766d7da2ed5af2 Mon Sep 17 00:00:00 2001 From: Neo Date: Fri, 12 Jan 2024 17:03:30 +0100 Subject: [PATCH 05/22] return unsent_commitment.oods_values --- src/stark/stark_commit.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index 9955b5f6b..68ad5d6aa 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -90,7 +90,7 @@ fn stark_commit( traces: traces_commitment, composition: composition_commitment, interaction_after_composition: interaction_after_composition, - oods_values: array![].span(), + oods_values: *unsent_commitment.oods_values, interaction_after_oods: interaction_after_oods.coefficients, fri: fri_commitment, } From 472bde7f07ae8349cd1847f1b2b06d6923a3fa9b Mon Sep 17 00:00:00 2001 From: Neo Date: Fri, 12 Jan 2024 17:07:11 +0100 Subject: [PATCH 06/22] fmt --- src/stark.cairo | 1 - 1 file changed, 1 deletion(-) diff --git a/src/stark.cairo b/src/stark.cairo index 3d7ff4085..071fb3ce0 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -10,7 +10,6 @@ use cairo_verifier::{ fri::{FriUnsentCommitment, FriWitness, FriCommitment} }, domains::StarkDomainsImpl, - oods::OodsValues, table_commitment::{ TableCommitmentConfig, TableCommitmentWitness, TableDecommitment, TableUnsentCommitment, TableCommitment From bdc1c116a1899187b121f60ce5049d2a3ef12dcf Mon Sep 17 00:00:00 2001 From: Neo Date: Fri, 12 Jan 2024 17:12:47 +0100 Subject: [PATCH 07/22] return to original fn --- src/oods.cairo | 18 ++++-------------- src/stark/stark_commit.cairo | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/oods.cairo b/src/oods.cairo index e6b3dae8f..2408a9d3e 100644 --- a/src/oods.cairo +++ b/src/oods.cairo @@ -24,7 +24,7 @@ struct OodsEvaluationInfo { } fn verify_oods( - oods: Span, + oods: OodsValues, interaction_elements: InteractionElements, public_input: @PublicInput, constraint_coefficients: Array, @@ -32,21 +32,10 @@ fn verify_oods( trace_domain_size: felt252, trace_generator: felt252 ) { - let mut mask_values = array![]; - let mut i = 0; - loop { - if i == oods.len() - 2 { - break; - } - - mask_values.append(*oods.at(i)); - - i += 1; - }; let composition_from_trace = eval_composition_polynomial( interaction_elements, public_input, - mask_values, + oods.mask_values, constraint_coefficients, oods_point, trace_domain_size, @@ -54,7 +43,8 @@ fn verify_oods( ); // TODO support degree > 2? - let claimed_composition = *oods[oods.len() - 2] + *oods[oods.len() - 1] * oods_point; + let claimed_composition = *oods.split_polynomials.at(0) + + *oods.split_polynomials.at(1) * oods_point; assert(composition_from_trace == claimed_composition, 'Invalid OODS'); } diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index 68ad5d6aa..35ca1f679 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -9,7 +9,8 @@ use cairo_verifier::{ global_values::InteractionElements, public_input::PublicInput, traces::traces_commit, }, channel::channel::Channel, common::powers_array::powers_array, domains::StarkDomains, - fri::fri::fri_commit, stark::{StarkUnsentCommitment, StarkConfig, StarkCommitment}, + oods::OodsValues, fri::fri::fri_commit, + stark::{StarkUnsentCommitment, StarkConfig, StarkCommitment}, proof_of_work::proof_of_work::proof_of_work_commit, table_commitment::table_commit, oods::verify_oods, }; @@ -66,8 +67,24 @@ fn stark_commit( diluted_check_interaction_z: 0, diluted_check_interaction_alpha: 0, }; + + let oods = *unsent_commitment.oods_values; + let mut mask_values = array![]; + let mut i = 0; + loop { + if i == oods.len() - 2 { + break; + } + + mask_values.append(*oods.at(i)); + + i += 1; + }; + let split_polynomials = array![*oods.at(i), *oods.at(i + 1)]; + let oods_values = OodsValues { mask_values, split_polynomials }; + verify_oods( - *unsent_commitment.oods_values, + oods_values, interaction_elements, public_input, traces_coefficients, From eac880f332f843083221538a4a73bd7f6730f71b Mon Sep 17 00:00:00 2001 From: Neo Date: Fri, 12 Jan 2024 17:13:49 +0100 Subject: [PATCH 08/22] remove unnecessary imports --- src/oods.cairo | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/oods.cairo b/src/oods.cairo index 2408a9d3e..fdaf99d6d 100644 --- a/src/oods.cairo +++ b/src/oods.cairo @@ -1,7 +1,4 @@ -use core::clone::Clone; -use core::array::ArrayTrait; use cairo_verifier::common::array_extend::ArrayExtendTrait; -use core::array::SpanTrait; use cairo_verifier::air::composition::{eval_composition_polynomial, eval_oods_polynomial}; use cairo_verifier::air::global_values::InteractionElements; use cairo_verifier::air::public_input::PublicInput; From 10df9447203fe98b8048112d38fba716fe340655 Mon Sep 17 00:00:00 2001 From: Neo Date: Sat, 13 Jan 2024 14:33:57 +0100 Subject: [PATCH 09/22] remove unnecessary structs --- src/stark/stark_commit.cairo | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index 35ca1f679..37ff96e01 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -15,17 +15,6 @@ use cairo_verifier::{ oods::verify_oods, }; -#[derive(Drop, Copy)] -struct InteractionValuesAfterTraces { - // n_constraints Coefficients for the AIR constraints. - coefficients: Span, -} - -#[derive(Drop, Copy)] -struct InteractionValuesAfterOods { - // n_oods_values coefficients for the boundary polynomial validating the OODS values. - coefficients: Span, -} // STARK commitment phase. fn stark_commit( @@ -48,10 +37,6 @@ fn stark_commit( 1, composition_alpha, N_CONSTRAINTS.try_into().unwrap(), ); - let interaction_after_traces = InteractionValuesAfterTraces { - coefficients: traces_coefficients.span(), - }; - let composition_commitment = table_commit(*unsent_commitment.composition, *config.composition,); let interaction_after_composition = channel.random_felt_to_prover(); @@ -95,9 +80,6 @@ fn stark_commit( let oods_alpha = channel.random_felt_to_prover(); let oods_coefficients = powers_array(1, oods_alpha, n_oods_values.try_into().unwrap()); - let interaction_after_oods = InteractionValuesAfterOods { - coefficients: oods_coefficients.span() - }; let fri_commitment = fri_commit(ref channel, *unsent_commitment.fri, *config.fri); @@ -108,7 +90,7 @@ fn stark_commit( composition: composition_commitment, interaction_after_composition: interaction_after_composition, oods_values: *unsent_commitment.oods_values, - interaction_after_oods: interaction_after_oods.coefficients, + interaction_after_oods: oods_coefficients.span(), fri: fri_commitment, } } From efcdfc4a27db1db700e8bfcce54b900d2b0717f0 Mon Sep 17 00:00:00 2001 From: Neo Date: Tue, 16 Jan 2024 09:13:42 +0100 Subject: [PATCH 10/22] fmt after rebase --- src/stark.cairo | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/stark.cairo b/src/stark.cairo index 071fb3ce0..5e92ec254 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -11,8 +11,7 @@ use cairo_verifier::{ }, domains::StarkDomainsImpl, table_commitment::{ - TableCommitmentConfig, TableCommitmentWitness, TableDecommitment, TableUnsentCommitment, - TableCommitment + TableCommitmentConfig, TableCommitmentWitness, TableDecommitment, TableCommitment }, proof_of_work::{ config::{ProofOfWorkConfig, ProofOfWorkConfigTrait}, From 5a5cfb0981b77f9bbeb84e7d618c40629bfe42b6 Mon Sep 17 00:00:00 2001 From: Neo Date: Tue, 16 Jan 2024 08:50:53 +0000 Subject: [PATCH 11/22] fixes after rebase --- run.sh | 1 + src/stark.cairo | 8 ++++---- src/stark/stark_commit.cairo | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/run.sh b/run.sh index 8beaea595..181e757da 100755 --- a/run.sh +++ b/run.sh @@ -1,3 +1,4 @@ #!/usr/bin/env bash +scarb build && \ cargo run --release -- ./target/dev/cairo_verifier.sierra.json < ./resources/in.txt diff --git a/src/stark.cairo b/src/stark.cairo index 5e92ec254..5faafacbe 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -10,7 +10,7 @@ use cairo_verifier::{ fri::{FriUnsentCommitment, FriWitness, FriCommitment} }, domains::StarkDomainsImpl, - table_commitment::{ + table_commitment::table_commitment::{ TableCommitmentConfig, TableCommitmentWitness, TableDecommitment, TableCommitment }, proof_of_work::{ @@ -46,9 +46,9 @@ impl StarkProofImpl of StarkProofTrait { let digest = self.public_input.get_public_input_hash(); let mut channel = ChannelImpl::new(digest); - stark_commit::stark_commit( - ref channel, self.public_input, self.unsent_commitment, self.config, @stark_domains, - ); + // stark_commit::stark_commit( + // ref channel, self.public_input, self.unsent_commitment, self.config, @stark_domains, + // ); } } diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index 37ff96e01..fe9580e20 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -11,7 +11,7 @@ use cairo_verifier::{ channel::channel::Channel, common::powers_array::powers_array, domains::StarkDomains, oods::OodsValues, fri::fri::fri_commit, stark::{StarkUnsentCommitment, StarkConfig, StarkCommitment}, - proof_of_work::proof_of_work::proof_of_work_commit, table_commitment::table_commit, + proof_of_work::proof_of_work::proof_of_work_commit, table_commitment::table_commitment::table_commit, oods::verify_oods, }; @@ -37,7 +37,7 @@ fn stark_commit( 1, composition_alpha, N_CONSTRAINTS.try_into().unwrap(), ); - let composition_commitment = table_commit(*unsent_commitment.composition, *config.composition,); + let composition_commitment = table_commit(ref channel, *unsent_commitment.composition, *config.composition,); let interaction_after_composition = channel.random_felt_to_prover(); From 44aa09808d4496dae94ecab857882479a6228e7e Mon Sep 17 00:00:00 2001 From: Neo Date: Tue, 16 Jan 2024 09:58:28 +0100 Subject: [PATCH 12/22] fmt --- src/stark.cairo | 7 +++---- src/stark/stark_commit.cairo | 8 +++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/stark.cairo b/src/stark.cairo index 5faafacbe..2592e8fba 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -45,10 +45,9 @@ impl StarkProofImpl of StarkProofTrait { let digest = self.public_input.get_public_input_hash(); let mut channel = ChannelImpl::new(digest); - - // stark_commit::stark_commit( - // ref channel, self.public_input, self.unsent_commitment, self.config, @stark_domains, - // ); + // stark_commit::stark_commit( + // ref channel, self.public_input, self.unsent_commitment, self.config, @stark_domains, + // ); } } diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index fe9580e20..5934152cc 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -11,8 +11,8 @@ use cairo_verifier::{ channel::channel::Channel, common::powers_array::powers_array, domains::StarkDomains, oods::OodsValues, fri::fri::fri_commit, stark::{StarkUnsentCommitment, StarkConfig, StarkCommitment}, - proof_of_work::proof_of_work::proof_of_work_commit, table_commitment::table_commitment::table_commit, - oods::verify_oods, + proof_of_work::proof_of_work::proof_of_work_commit, + table_commitment::table_commitment::table_commit, oods::verify_oods, }; @@ -37,7 +37,9 @@ fn stark_commit( 1, composition_alpha, N_CONSTRAINTS.try_into().unwrap(), ); - let composition_commitment = table_commit(ref channel, *unsent_commitment.composition, *config.composition,); + let composition_commitment = table_commit( + ref channel, *unsent_commitment.composition, *config.composition, + ); let interaction_after_composition = channel.random_felt_to_prover(); From d97227c0ca14b3a1eca14e23e8fe91beddfff6ce Mon Sep 17 00:00:00 2001 From: Neo Date: Tue, 16 Jan 2024 09:27:44 +0000 Subject: [PATCH 13/22] steps before verify_oods working --- src/stark.cairo | 7 +++--- src/stark/stark_commit.cairo | 44 ++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/stark.cairo b/src/stark.cairo index 2592e8fba..72a17ade2 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -45,9 +45,10 @@ impl StarkProofImpl of StarkProofTrait { let digest = self.public_input.get_public_input_hash(); let mut channel = ChannelImpl::new(digest); - // stark_commit::stark_commit( - // ref channel, self.public_input, self.unsent_commitment, self.config, @stark_domains, - // ); + + stark_commit::stark_commit( + ref channel, self.public_input, self.unsent_commitment, self.config, @stark_domains, + ); } } diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index 5934152cc..e8a6d2074 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -23,7 +23,7 @@ fn stark_commit( unsent_commitment: @StarkUnsentCommitment, config: @StarkConfig, stark_domains: @StarkDomains, -) -> StarkCommitment { +) { let traces_commitment = traces_commit( ref channel, N_INTERACTION_ELEMENTS, @@ -70,29 +70,29 @@ fn stark_commit( let split_polynomials = array![*oods.at(i), *oods.at(i + 1)]; let oods_values = OodsValues { mask_values, split_polynomials }; - verify_oods( - oods_values, - interaction_elements, - public_input, - traces_coefficients, - interaction_after_composition, - *stark_domains.trace_generator, - *stark_domains.trace_domain_size - ); + // verify_oods( + // oods_values, + // interaction_elements, + // public_input, + // traces_coefficients, + // interaction_after_composition, + // *stark_domains.trace_generator, + // *stark_domains.trace_domain_size + // ); - let oods_alpha = channel.random_felt_to_prover(); - let oods_coefficients = powers_array(1, oods_alpha, n_oods_values.try_into().unwrap()); + // let oods_alpha = channel.random_felt_to_prover(); + // let oods_coefficients = powers_array(1, oods_alpha, n_oods_values.try_into().unwrap()); - let fri_commitment = fri_commit(ref channel, *unsent_commitment.fri, *config.fri); + // let fri_commitment = fri_commit(ref channel, *unsent_commitment.fri, *config.fri); - proof_of_work_commit(ref channel, *unsent_commitment.proof_of_work, *config.proof_of_work); + // proof_of_work_commit(ref channel, *unsent_commitment.proof_of_work, *config.proof_of_work); - StarkCommitment { - traces: traces_commitment, - composition: composition_commitment, - interaction_after_composition: interaction_after_composition, - oods_values: *unsent_commitment.oods_values, - interaction_after_oods: oods_coefficients.span(), - fri: fri_commitment, - } + // StarkCommitment { + // traces: traces_commitment, + // composition: composition_commitment, + // interaction_after_composition: interaction_after_composition, + // oods_values: *unsent_commitment.oods_values, + // interaction_after_oods: oods_coefficients.span(), + // fri: fri_commitment, + // } } From 9cce31e58faf7b07853eb217d597f948d51d748a Mon Sep 17 00:00:00 2001 From: Neo Date: Tue, 16 Jan 2024 09:54:27 +0000 Subject: [PATCH 14/22] small fixes --- src/air/autogenerated.cairo | 2 +- src/air/composition.cairo | 2 +- src/oods.cairo | 2 +- src/stark.cairo | 7 ++--- src/stark/stark_commit.cairo | 59 +++++++++++++++--------------------- 5 files changed, 31 insertions(+), 41 deletions(-) diff --git a/src/air/autogenerated.cairo b/src/air/autogenerated.cairo index 089bee2b5..040e54161 100644 --- a/src/air/autogenerated.cairo +++ b/src/air/autogenerated.cairo @@ -6,7 +6,7 @@ use cairo_verifier::air::constants::{ fn eval_composition_polynomial_inner( mask_values: Array, - constraint_coefficients: Array, + constraint_coefficients: Span, point: felt252, trace_generator: felt252, global_values: GlobalValues diff --git a/src/air/composition.cairo b/src/air/composition.cairo index ca1bf2e50..1a981880a 100644 --- a/src/air/composition.cairo +++ b/src/air/composition.cairo @@ -19,7 +19,7 @@ fn eval_composition_polynomial( interaction_elements: InteractionElements, public_input: @PublicInput, mask_values: Array, - constraint_coefficients: Array, + constraint_coefficients: Span, point: felt252, trace_domain_size: felt252, trace_generator: felt252 diff --git a/src/oods.cairo b/src/oods.cairo index fdaf99d6d..84387123c 100644 --- a/src/oods.cairo +++ b/src/oods.cairo @@ -24,7 +24,7 @@ fn verify_oods( oods: OodsValues, interaction_elements: InteractionElements, public_input: @PublicInput, - constraint_coefficients: Array, + constraint_coefficients: Span, oods_point: felt252, trace_domain_size: felt252, trace_generator: felt252 diff --git a/src/stark.cairo b/src/stark.cairo index 72a17ade2..2592e8fba 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -45,10 +45,9 @@ impl StarkProofImpl of StarkProofTrait { let digest = self.public_input.get_public_input_hash(); let mut channel = ChannelImpl::new(digest); - - stark_commit::stark_commit( - ref channel, self.public_input, self.unsent_commitment, self.config, @stark_domains, - ); + // stark_commit::stark_commit( + // ref channel, self.public_input, self.unsent_commitment, self.config, @stark_domains, + // ); } } diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index e8a6d2074..81f1cd2fa 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -19,11 +19,12 @@ use cairo_verifier::{ // STARK commitment phase. fn stark_commit( ref channel: Channel, + interaction_elements: InteractionElements, public_input: @PublicInput, unsent_commitment: @StarkUnsentCommitment, config: @StarkConfig, stark_domains: @StarkDomains, -) { +) -> StarkCommitment { let traces_commitment = traces_commit( ref channel, N_INTERACTION_ELEMENTS, @@ -33,9 +34,8 @@ fn stark_commit( ); let composition_alpha = channel.random_felt_to_prover(); - let traces_coefficients = powers_array( - 1, composition_alpha, N_CONSTRAINTS.try_into().unwrap(), - ); + let traces_coefficients = powers_array(1, composition_alpha, N_CONSTRAINTS.try_into().unwrap(),) + .span(); let composition_commitment = table_commit( ref channel, *unsent_commitment.composition, *config.composition, @@ -46,15 +46,6 @@ fn stark_commit( let n_oods_values = MASK_SIZE + CONSTRAINT_DEGREE.into(); channel.read_felts_from_prover(*unsent_commitment.oods_values); - let interaction_elements = InteractionElements { - memory_multi_column_perm_perm_interaction_elm: 0, - memory_multi_column_perm_hash_interaction_elm0: 0, - rc16_perm_interaction_elm: 0, - diluted_check_permutation_interaction_elm: 0, - diluted_check_interaction_z: 0, - diluted_check_interaction_alpha: 0, - }; - let oods = *unsent_commitment.oods_values; let mut mask_values = array![]; let mut i = 0; @@ -70,29 +61,29 @@ fn stark_commit( let split_polynomials = array![*oods.at(i), *oods.at(i + 1)]; let oods_values = OodsValues { mask_values, split_polynomials }; - // verify_oods( - // oods_values, - // interaction_elements, - // public_input, - // traces_coefficients, - // interaction_after_composition, - // *stark_domains.trace_generator, - // *stark_domains.trace_domain_size - // ); + verify_oods( + oods_values, + interaction_elements, + public_input, + traces_coefficients, + interaction_after_composition, + *stark_domains.trace_generator, + *stark_domains.trace_domain_size + ); - // let oods_alpha = channel.random_felt_to_prover(); - // let oods_coefficients = powers_array(1, oods_alpha, n_oods_values.try_into().unwrap()); + let oods_alpha = channel.random_felt_to_prover(); + let oods_coefficients = powers_array(1, oods_alpha, n_oods_values.try_into().unwrap()); - // let fri_commitment = fri_commit(ref channel, *unsent_commitment.fri, *config.fri); + let fri_commitment = fri_commit(ref channel, *unsent_commitment.fri, *config.fri); - // proof_of_work_commit(ref channel, *unsent_commitment.proof_of_work, *config.proof_of_work); + proof_of_work_commit(ref channel, *unsent_commitment.proof_of_work, *config.proof_of_work); - // StarkCommitment { - // traces: traces_commitment, - // composition: composition_commitment, - // interaction_after_composition: interaction_after_composition, - // oods_values: *unsent_commitment.oods_values, - // interaction_after_oods: oods_coefficients.span(), - // fri: fri_commitment, - // } + StarkCommitment { + traces: traces_commitment, + composition: composition_commitment, + interaction_after_composition: interaction_after_composition, + oods_values: *unsent_commitment.oods_values, + interaction_after_oods: oods_coefficients.span(), + fri: fri_commitment, + } } From ceaf6fb88891d33b46c4e939f87367c989079121 Mon Sep 17 00:00:00 2001 From: Neo Date: Tue, 16 Jan 2024 09:59:50 +0000 Subject: [PATCH 15/22] oods as span --- src/air/autogenerated.cairo | 2 +- src/air/composition.cairo | 2 +- src/oods.cairo | 8 ++++---- src/stark/stark_commit.cairo | 17 +---------------- 4 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/air/autogenerated.cairo b/src/air/autogenerated.cairo index 040e54161..f64043162 100644 --- a/src/air/autogenerated.cairo +++ b/src/air/autogenerated.cairo @@ -5,7 +5,7 @@ use cairo_verifier::air::constants::{ }; fn eval_composition_polynomial_inner( - mask_values: Array, + mask_values: Span, constraint_coefficients: Span, point: felt252, trace_generator: felt252, diff --git a/src/air/composition.cairo b/src/air/composition.cairo index 1a981880a..16a3badff 100644 --- a/src/air/composition.cairo +++ b/src/air/composition.cairo @@ -18,7 +18,7 @@ const SHIFT_POINT_Y: felt252 = 0x3ca0cfe4b3bc6ddf346d49d06ea0ed34e621062c0e056c1 fn eval_composition_polynomial( interaction_elements: InteractionElements, public_input: @PublicInput, - mask_values: Array, + mask_values: Span, constraint_coefficients: Span, point: felt252, trace_domain_size: felt252, diff --git a/src/oods.cairo b/src/oods.cairo index 84387123c..b4aa5c92a 100644 --- a/src/oods.cairo +++ b/src/oods.cairo @@ -1,3 +1,4 @@ +use core::array::SpanTrait; use cairo_verifier::common::array_extend::ArrayExtendTrait; use cairo_verifier::air::composition::{eval_composition_polynomial, eval_oods_polynomial}; use cairo_verifier::air::global_values::InteractionElements; @@ -21,7 +22,7 @@ struct OodsEvaluationInfo { } fn verify_oods( - oods: OodsValues, + oods: Span, interaction_elements: InteractionElements, public_input: @PublicInput, constraint_coefficients: Span, @@ -32,7 +33,7 @@ fn verify_oods( let composition_from_trace = eval_composition_polynomial( interaction_elements, public_input, - oods.mask_values, + oods.slice(0, oods.len() - 2), constraint_coefficients, oods_point, trace_domain_size, @@ -40,8 +41,7 @@ fn verify_oods( ); // TODO support degree > 2? - let claimed_composition = *oods.split_polynomials.at(0) - + *oods.split_polynomials.at(1) * oods_point; + let claimed_composition = *oods[oods.len() - 2] + *oods[oods.len() - 1] * oods_point; assert(composition_from_trace == claimed_composition, 'Invalid OODS'); } diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index 81f1cd2fa..b1e6cfec0 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -46,23 +46,8 @@ fn stark_commit( let n_oods_values = MASK_SIZE + CONSTRAINT_DEGREE.into(); channel.read_felts_from_prover(*unsent_commitment.oods_values); - let oods = *unsent_commitment.oods_values; - let mut mask_values = array![]; - let mut i = 0; - loop { - if i == oods.len() - 2 { - break; - } - - mask_values.append(*oods.at(i)); - - i += 1; - }; - let split_polynomials = array![*oods.at(i), *oods.at(i + 1)]; - let oods_values = OodsValues { mask_values, split_polynomials }; - verify_oods( - oods_values, + *unsent_commitment.oods_values, interaction_elements, public_input, traces_coefficients, From a1efa97ebfc396fde06c6b055e4dac6025b8d942 Mon Sep 17 00:00:00 2001 From: Neo Date: Tue, 16 Jan 2024 10:00:27 +0000 Subject: [PATCH 16/22] remove unused struct --- src/oods.cairo | 6 ------ src/stark/stark_commit.cairo | 3 +-- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/oods.cairo b/src/oods.cairo index b4aa5c92a..3f30dc4c5 100644 --- a/src/oods.cairo +++ b/src/oods.cairo @@ -7,12 +7,6 @@ use cairo_verifier::air::traces::TracesDecommitment; use cairo_verifier::table_commitment::table_commitment::TableDecommitment; use cairo_verifier::air::constants::CONSTRAINT_DEGREE; -#[derive(Drop)] -struct OodsValues { - mask_values: Array, - split_polynomials: Array -} - #[derive(Drop)] struct OodsEvaluationInfo { oods_values: Span, diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index b1e6cfec0..4c04c3d29 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -9,8 +9,7 @@ use cairo_verifier::{ global_values::InteractionElements, public_input::PublicInput, traces::traces_commit, }, channel::channel::Channel, common::powers_array::powers_array, domains::StarkDomains, - oods::OodsValues, fri::fri::fri_commit, - stark::{StarkUnsentCommitment, StarkConfig, StarkCommitment}, + fri::fri::fri_commit, stark::{StarkUnsentCommitment, StarkConfig, StarkCommitment}, proof_of_work::proof_of_work::proof_of_work_commit, table_commitment::table_commitment::table_commit, oods::verify_oods, }; From e250a83f96b7d13c549fe3b6d0b4f11e7c374924 Mon Sep 17 00:00:00 2001 From: Neo Date: Tue, 16 Jan 2024 10:39:35 +0000 Subject: [PATCH 17/22] return array --- src/air/constants.cairo | 2 +- src/oods.cairo | 4 ++-- src/stark.cairo | 2 +- src/stark/stark_commit.cairo | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/air/constants.cairo b/src/air/constants.cairo index 63b0a8eef..2316324c1 100644 --- a/src/air/constants.cairo +++ b/src/air/constants.cairo @@ -17,7 +17,7 @@ const HAS_RANGE_CHECK_BUILTIN: felt252 = 1; const IS_DYNAMIC_AIR: felt252 = 0; const LAYOUT_CODE: felt252 = 0x726563757273697665; const LOG_CPU_COMPONENT_HEIGHT: felt252 = 4; -const MASK_SIZE: felt252 = 133; +const MASK_SIZE: u32 = 133; const MEMORY_STEP: felt252 = 2; const N_CONSTRAINTS: felt252 = 93; const N_DYNAMIC_PARAMS: felt252 = 0; diff --git a/src/oods.cairo b/src/oods.cairo index 3f30dc4c5..cd233487c 100644 --- a/src/oods.cairo +++ b/src/oods.cairo @@ -12,7 +12,7 @@ struct OodsEvaluationInfo { oods_values: Span, oods_point: felt252, trace_generator: felt252, - constraint_coefficients: Span, + constraint_coefficients: Array, } fn verify_oods( @@ -93,7 +93,7 @@ fn eval_oods_boundary_poly_at_points( eval_oods_polynomial( column_values.span(), eval_info.oods_values, - eval_info.constraint_coefficients, + eval_info.constraint_coefficients.span(), *points.at(i), eval_info.oods_point, eval_info.trace_generator, diff --git a/src/stark.cairo b/src/stark.cairo index 2592e8fba..7654690f5 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -137,7 +137,7 @@ struct StarkCommitment { composition: TableCommitment, interaction_after_composition: felt252, oods_values: Span, - interaction_after_oods: Span, + interaction_after_oods: Array, fri: FriCommitment, } diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index 4c04c3d29..935a82a7b 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -42,7 +42,7 @@ fn stark_commit( let interaction_after_composition = channel.random_felt_to_prover(); - let n_oods_values = MASK_SIZE + CONSTRAINT_DEGREE.into(); + let n_oods_values = MASK_SIZE + CONSTRAINT_DEGREE; channel.read_felts_from_prover(*unsent_commitment.oods_values); verify_oods( @@ -56,7 +56,7 @@ fn stark_commit( ); let oods_alpha = channel.random_felt_to_prover(); - let oods_coefficients = powers_array(1, oods_alpha, n_oods_values.try_into().unwrap()); + let oods_coefficients = powers_array(1, oods_alpha, n_oods_values); let fri_commitment = fri_commit(ref channel, *unsent_commitment.fri, *config.fri); @@ -67,7 +67,7 @@ fn stark_commit( composition: composition_commitment, interaction_after_composition: interaction_after_composition, oods_values: *unsent_commitment.oods_values, - interaction_after_oods: oods_coefficients.span(), + interaction_after_oods: oods_coefficients, fri: fri_commitment, } } From f25cacd8c3bac2118896fc36afaf32f29912cd90 Mon Sep 17 00:00:00 2001 From: Neo Date: Tue, 16 Jan 2024 11:08:46 +0000 Subject: [PATCH 18/22] make traces_commit returns InteractionElements struct --- src/air/traces.cairo | 14 +++++++++++--- src/stark/stark_commit.cairo | 6 ++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/air/traces.cairo b/src/air/traces.cairo index a3e3f0f25..77b68818a 100644 --- a/src/air/traces.cairo +++ b/src/air/traces.cairo @@ -4,6 +4,7 @@ use cairo_verifier::table_commitment::table_commitment::{ }; use cairo_verifier::air::{public_input::PublicInput, traces_config::TracesConfig}; use cairo_verifier::channel::channel::Channel; +use cairo_verifier::air::global_values::InteractionElements; // A protocol component (see stark.cairo for details about protocol components) for the traces // of the CPU AIR. @@ -29,7 +30,7 @@ struct TracesCommitment { original: TableCommitment, // The interaction elements that were sent to the prover after the first trace commitment (e.g. // memory interaction). - interaction_elements: Array, + interaction_elements: InteractionElements, // Commitment to the second (interaction) trace. interaction: TableCommitment, } @@ -55,7 +56,6 @@ struct TracesWitness { // Returns the commitment, along with GlobalValue required to evaluate the constraint polynomial. fn traces_commit( ref channel: Channel, - n_interaction_elements: felt252, public_input: @PublicInput, unsent_commitment: TracesUnsentCommitment, config: TracesConfig @@ -65,7 +65,15 @@ fn traces_commit( ref channel, unsent_commitment.original, config.original ); // Generate interaction elements for the first interaction. - let interaction_elements = channel.random_felts_to_prover(n_interaction_elements); + let interaction_elements_raw = channel.random_felts_to_prover(6); + let interaction_elements = InteractionElements { + memory_multi_column_perm_perm_interaction_elm: *interaction_elements_raw[0], + memory_multi_column_perm_hash_interaction_elm0: *interaction_elements_raw[1], + rc16_perm_interaction_elm: *interaction_elements_raw[2], + diluted_check_permutation_interaction_elm: *interaction_elements_raw[3], + diluted_check_interaction_z: *interaction_elements_raw[4], + diluted_check_interaction_alpha: *interaction_elements_raw[5], + }; // Read interaction commitment. let interaction_commitment = table_commit( ref channel, unsent_commitment.interaction, config.interaction diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index 935a82a7b..b778aa668 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -6,7 +6,7 @@ use cairo_verifier::channel::channel::ChannelTrait; use cairo_verifier::{ air::{ constants::{CONSTRAINT_DEGREE, N_CONSTRAINTS, N_INTERACTION_ELEMENTS, MASK_SIZE}, - global_values::InteractionElements, public_input::PublicInput, traces::traces_commit, + public_input::PublicInput, traces::traces_commit, }, channel::channel::Channel, common::powers_array::powers_array, domains::StarkDomains, fri::fri::fri_commit, stark::{StarkUnsentCommitment, StarkConfig, StarkCommitment}, @@ -18,7 +18,6 @@ use cairo_verifier::{ // STARK commitment phase. fn stark_commit( ref channel: Channel, - interaction_elements: InteractionElements, public_input: @PublicInput, unsent_commitment: @StarkUnsentCommitment, config: @StarkConfig, @@ -26,7 +25,6 @@ fn stark_commit( ) -> StarkCommitment { let traces_commitment = traces_commit( ref channel, - N_INTERACTION_ELEMENTS, public_input, *unsent_commitment.traces, *config.traces, @@ -47,7 +45,7 @@ fn stark_commit( verify_oods( *unsent_commitment.oods_values, - interaction_elements, + traces_commitment.interaction_elements, public_input, traces_coefficients, interaction_after_composition, From 615c35bebe80e4376ed9404179d19d826cd2990b Mon Sep 17 00:00:00 2001 From: Neo Date: Tue, 16 Jan 2024 11:09:12 +0000 Subject: [PATCH 19/22] fmt --- src/stark/stark_commit.cairo | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index b778aa668..83cd1c53c 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -24,10 +24,7 @@ fn stark_commit( stark_domains: @StarkDomains, ) -> StarkCommitment { let traces_commitment = traces_commit( - ref channel, - public_input, - *unsent_commitment.traces, - *config.traces, + ref channel, public_input, *unsent_commitment.traces, *config.traces, ); let composition_alpha = channel.random_felt_to_prover(); From e4749c837d090fb94fc17aa0f0c49e5fd6dc1624 Mon Sep 17 00:00:00 2001 From: Neo Date: Tue, 16 Jan 2024 11:50:02 +0000 Subject: [PATCH 20/22] remove unnecessary const --- src/air/constants.cairo | 1 - src/air/traces.cairo | 13 ++++++------- src/stark/stark_commit.cairo | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/air/constants.cairo b/src/air/constants.cairo index 2316324c1..f74e85cbf 100644 --- a/src/air/constants.cairo +++ b/src/air/constants.cairo @@ -21,7 +21,6 @@ const MASK_SIZE: u32 = 133; const MEMORY_STEP: felt252 = 2; const N_CONSTRAINTS: felt252 = 93; const N_DYNAMIC_PARAMS: felt252 = 0; -const N_INTERACTION_ELEMENTS: felt252 = 6; const NUM_COLUMNS_FIRST: u32 = 7; const NUM_COLUMNS_SECOND: u32 = 3; const PEDERSEN_BUILTIN_RATIO: felt252 = 128; diff --git a/src/air/traces.cairo b/src/air/traces.cairo index 77b68818a..4e26aea51 100644 --- a/src/air/traces.cairo +++ b/src/air/traces.cairo @@ -65,14 +65,13 @@ fn traces_commit( ref channel, unsent_commitment.original, config.original ); // Generate interaction elements for the first interaction. - let interaction_elements_raw = channel.random_felts_to_prover(6); let interaction_elements = InteractionElements { - memory_multi_column_perm_perm_interaction_elm: *interaction_elements_raw[0], - memory_multi_column_perm_hash_interaction_elm0: *interaction_elements_raw[1], - rc16_perm_interaction_elm: *interaction_elements_raw[2], - diluted_check_permutation_interaction_elm: *interaction_elements_raw[3], - diluted_check_interaction_z: *interaction_elements_raw[4], - diluted_check_interaction_alpha: *interaction_elements_raw[5], + memory_multi_column_perm_perm_interaction_elm: channel.random_felt_to_prover(), + memory_multi_column_perm_hash_interaction_elm0: channel.random_felt_to_prover(), + rc16_perm_interaction_elm: channel.random_felt_to_prover(), + diluted_check_permutation_interaction_elm: channel.random_felt_to_prover(), + diluted_check_interaction_z: channel.random_felt_to_prover(), + diluted_check_interaction_alpha: channel.random_felt_to_prover(), }; // Read interaction commitment. let interaction_commitment = table_commit( diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index 83cd1c53c..02300a125 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -5,8 +5,8 @@ use core::traits::Into; use cairo_verifier::channel::channel::ChannelTrait; use cairo_verifier::{ air::{ - constants::{CONSTRAINT_DEGREE, N_CONSTRAINTS, N_INTERACTION_ELEMENTS, MASK_SIZE}, - public_input::PublicInput, traces::traces_commit, + constants::{CONSTRAINT_DEGREE, N_CONSTRAINTS, MASK_SIZE}, public_input::PublicInput, + traces::traces_commit, }, channel::channel::Channel, common::powers_array::powers_array, domains::StarkDomains, fri::fri::fri_commit, stark::{StarkUnsentCommitment, StarkConfig, StarkCommitment}, From 1b5a4025f1748d6afeaf004476eec29b3062d665 Mon Sep 17 00:00:00 2001 From: Neo Date: Tue, 16 Jan 2024 12:07:11 +0000 Subject: [PATCH 21/22] go back to span --- src/oods.cairo | 4 ++-- src/stark.cairo | 2 +- src/stark/stark_commit.cairo | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/oods.cairo b/src/oods.cairo index cd233487c..3f30dc4c5 100644 --- a/src/oods.cairo +++ b/src/oods.cairo @@ -12,7 +12,7 @@ struct OodsEvaluationInfo { oods_values: Span, oods_point: felt252, trace_generator: felt252, - constraint_coefficients: Array, + constraint_coefficients: Span, } fn verify_oods( @@ -93,7 +93,7 @@ fn eval_oods_boundary_poly_at_points( eval_oods_polynomial( column_values.span(), eval_info.oods_values, - eval_info.constraint_coefficients.span(), + eval_info.constraint_coefficients, *points.at(i), eval_info.oods_point, eval_info.trace_generator, diff --git a/src/stark.cairo b/src/stark.cairo index 7654690f5..2592e8fba 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -137,7 +137,7 @@ struct StarkCommitment { composition: TableCommitment, interaction_after_composition: felt252, oods_values: Span, - interaction_after_oods: Array, + interaction_after_oods: Span, fri: FriCommitment, } diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index 02300a125..de2482fd7 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -62,7 +62,7 @@ fn stark_commit( composition: composition_commitment, interaction_after_composition: interaction_after_composition, oods_values: *unsent_commitment.oods_values, - interaction_after_oods: oods_coefficients, + interaction_after_oods: oods_coefficients.span(), fri: fri_commitment, } } From cd9b9bc84a41299442d9f5254f24f9b53c900157 Mon Sep 17 00:00:00 2001 From: Neo Date: Tue, 16 Jan 2024 12:11:00 +0000 Subject: [PATCH 22/22] N_CONSTRAINTS to u32 --- src/air/constants.cairo | 2 +- src/stark/stark_commit.cairo | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/air/constants.cairo b/src/air/constants.cairo index f74e85cbf..c59b88035 100644 --- a/src/air/constants.cairo +++ b/src/air/constants.cairo @@ -19,7 +19,7 @@ const LAYOUT_CODE: felt252 = 0x726563757273697665; const LOG_CPU_COMPONENT_HEIGHT: felt252 = 4; const MASK_SIZE: u32 = 133; const MEMORY_STEP: felt252 = 2; -const N_CONSTRAINTS: felt252 = 93; +const N_CONSTRAINTS: u32 = 93; const N_DYNAMIC_PARAMS: felt252 = 0; const NUM_COLUMNS_FIRST: u32 = 7; const NUM_COLUMNS_SECOND: u32 = 3; diff --git a/src/stark/stark_commit.cairo b/src/stark/stark_commit.cairo index de2482fd7..db8526d2e 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -28,8 +28,7 @@ fn stark_commit( ); let composition_alpha = channel.random_felt_to_prover(); - let traces_coefficients = powers_array(1, composition_alpha, N_CONSTRAINTS.try_into().unwrap(),) - .span(); + let traces_coefficients = powers_array(1, composition_alpha, N_CONSTRAINTS).span(); let composition_commitment = table_commit( ref channel, *unsent_commitment.composition, *config.composition,