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 0d93a7955..9fb90f18e 100644 --- a/src/air/constants.cairo +++ b/src/air/constants.cairo @@ -1,40 +1,41 @@ // 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; 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 85271d14f..4ed664d2b 100644 --- a/src/air/traces.cairo +++ b/src/air/traces.cairo @@ -25,7 +25,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. @@ -57,7 +57,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 550904dc5..a4c123ba6 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -42,10 +42,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); @@ -54,7 +50,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..7ee56c792 100644 --- a/src/stark/stark_commit.cairo +++ b/src/stark/stark_commit.cairo @@ -1,20 +1,26 @@ +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}, + 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, }; +#[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 +29,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 +68,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, }