From 135edf4ee3111042cdb93163ac4b35fdbb404501 Mon Sep 17 00:00:00 2001 From: Filip Krawczyk Date: Tue, 10 Sep 2024 08:16:58 +0200 Subject: [PATCH] monolit/split for dex,small,recursive_with_poseidon --- src/air/layouts/dex.cairo | 90 +++++++++++++++--- src/air/layouts/recursive_with_poseidon.cairo | 92 ++++++++++++++++--- src/air/layouts/small.cairo | 90 +++++++++++++++--- src/lib.cairo | 25 ++--- 4 files changed, 247 insertions(+), 50 deletions(-) diff --git a/src/air/layouts/dex.cairo b/src/air/layouts/dex.cairo index 4dc4b223e..8bd9b4771 100644 --- a/src/air/layouts/dex.cairo +++ b/src/air/layouts/dex.cairo @@ -3,16 +3,13 @@ mod constants; mod global_values; mod public_input; mod traces; +#[cfg(feature: 'split')] mod contract; use cairo_verifier::{ air::{ constants::{SHIFT_POINT_X, SHIFT_POINT_Y, StarkCurve}, layouts::dex::{ - contract::{ - IDexLayoutContract1Dispatcher, IDexLayoutContract1DispatcherTrait, - IDexLayoutContract2Dispatcher, IDexLayoutContract2DispatcherTrait, - }, global_values::{GlobalValues, InteractionElements, EcPoint, EcdsaSigConfig}, public_input::DexPublicInputImpl, constants::{ @@ -27,6 +24,79 @@ use cairo_verifier::{ common::{math::{Felt252Div, Felt252PartialOrd, pow}, asserts::assert_range_u128} }; use starknet::ContractAddress; +#[cfg(feature: 'split')] +use cairo_verifier::air::layouts::dex::contract::{ + IDexLayoutContract1Dispatcher, + IDexLayoutContract1DispatcherTrait, + IDexLayoutContract2Dispatcher, + IDexLayoutContract2DispatcherTrait, +}; + +#[cfg(feature: 'split')] +fn eval_composition_polynomial_inner( + mask_values: Span, + constraint_coefficients: Span, + point: felt252, + trace_generator: felt252, + global_values: GlobalValues, + contract_address_1: ContractAddress, +) -> felt252 { + IDexLayoutContract1Dispatcher { + contract_address: contract_address_1 + }.eval_composition_polynomial_inner( + mask_values, constraint_coefficients, point, trace_generator, global_values + ) +} + +#[cfg(feature: 'split')] +fn eval_oods_polynomial_inner( + column_values: Span, + oods_values: Span, + constraint_coefficients: Span, + point: felt252, + oods_point: felt252, + trace_generator: felt252, + contract_address_2: ContractAddress, +) -> felt252 { + IDexLayoutContract2Dispatcher { + contract_address: contract_address_2 + }.eval_oods_polynomial_inner( + column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, + ) +} + +#[cfg(feature: 'monolit')] +use cairo_verifier::air::layouts::dex::autogenerated::{ + eval_composition_polynomial_inner as eval_composition_polynomial_inner_, + eval_oods_polynomial_inner as eval_oods_polynomial_inner_, +}; + +#[cfg(feature: 'monolit')] +fn eval_composition_polynomial_inner( + mask_values: Span, + constraint_coefficients: Span, + point: felt252, + trace_generator: felt252, + global_values: GlobalValues, + contract_address_1: ContractAddress, +) -> felt252 { + eval_composition_polynomial_inner_(mask_values, constraint_coefficients, point, trace_generator, global_values) +} + +#[cfg(feature: 'monolit')] +fn eval_oods_polynomial_inner( + column_values: Span, + oods_values: Span, + constraint_coefficients: Span, + point: felt252, + oods_point: felt252, + trace_generator: felt252, + contract_address_2: ContractAddress, +) -> felt252 { + eval_oods_polynomial_inner_( + column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, + ) +} impl DexAIRCompositionImpl of AIRComposition { fn eval_composition_polynomial( @@ -95,10 +165,8 @@ impl DexAIRCompositionImpl of AIRComposition { range_check16_perm_public_memory_prod: 1, }; - IDexLayoutContract1Dispatcher { - contract_address: contract_address_1 - }.eval_composition_polynomial_inner( - mask_values, constraint_coefficients, point, trace_generator, global_values + eval_composition_polynomial_inner( + mask_values, constraint_coefficients, point, trace_generator, global_values, contract_address_1, ) } } @@ -113,10 +181,8 @@ impl DexAIROodsImpl of AIROods { trace_generator: felt252, contract_address_2: ContractAddress, ) -> felt252 { - IDexLayoutContract2Dispatcher { - contract_address: contract_address_2 - }.eval_oods_polynomial_inner( - column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, + eval_oods_polynomial_inner( + column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, contract_address_2, ) } } diff --git a/src/air/layouts/recursive_with_poseidon.cairo b/src/air/layouts/recursive_with_poseidon.cairo index ad34a9458..8dfae689e 100644 --- a/src/air/layouts/recursive_with_poseidon.cairo +++ b/src/air/layouts/recursive_with_poseidon.cairo @@ -3,18 +3,13 @@ mod constants; mod global_values; mod public_input; mod traces; +#[cfg(feature: 'split')] mod contract; use cairo_verifier::{ air::{ constants::{SHIFT_POINT_X, SHIFT_POINT_Y}, layouts::recursive_with_poseidon::{ - contract::{ - IRecursiveWithPoseidonLayoutContract1Dispatcher, - IRecursiveWithPoseidonLayoutContract1DispatcherTrait, - IRecursiveWithPoseidonLayoutContract2Dispatcher, - IRecursiveWithPoseidonLayoutContract2DispatcherTrait, - }, global_values::{GlobalValues, InteractionElements, EcPoint}, public_input::RecursiveWithPoseidonPublicInputImpl, constants::{ @@ -33,6 +28,79 @@ use cairo_verifier::{ common::{math::{Felt252Div, Felt252PartialOrd, pow}, asserts::assert_range_u128} }; use starknet::ContractAddress; +#[cfg(feature: 'split')] +use cairo_verifier::air::layouts::recursive_with_poseidon::contract::{ + IRecursiveWithPoseidonLayoutContract1Dispatcher, + IRecursiveWithPoseidonLayoutContract1DispatcherTrait, + IRecursiveWithPoseidonLayoutContract2Dispatcher, + IRecursiveWithPoseidonLayoutContract2DispatcherTrait, +}; + +#[cfg(feature: 'split')] +fn eval_composition_polynomial_inner( + mask_values: Span, + constraint_coefficients: Span, + point: felt252, + trace_generator: felt252, + global_values: GlobalValues, + contract_address_1: ContractAddress, +) -> felt252 { + IRecursiveWithPoseidonLayoutContract1Dispatcher { + contract_address: contract_address_1 + }.eval_composition_polynomial_inner( + mask_values, constraint_coefficients, point, trace_generator, global_values + ) +} + +#[cfg(feature: 'split')] +fn eval_oods_polynomial_inner( + column_values: Span, + oods_values: Span, + constraint_coefficients: Span, + point: felt252, + oods_point: felt252, + trace_generator: felt252, + contract_address_2: ContractAddress, +) -> felt252 { + IRecursiveWithPoseidonLayoutContract2Dispatcher { + contract_address: contract_address_2 + }.eval_oods_polynomial_inner( + column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, + ) +} + +#[cfg(feature: 'monolit')] +use cairo_verifier::air::layouts::recursive_with_poseidon::autogenerated::{ + eval_composition_polynomial_inner as eval_composition_polynomial_inner_, + eval_oods_polynomial_inner as eval_oods_polynomial_inner_, +}; + +#[cfg(feature: 'monolit')] +fn eval_composition_polynomial_inner( + mask_values: Span, + constraint_coefficients: Span, + point: felt252, + trace_generator: felt252, + global_values: GlobalValues, + contract_address_1: ContractAddress, +) -> felt252 { + eval_composition_polynomial_inner_(mask_values, constraint_coefficients, point, trace_generator, global_values) +} + +#[cfg(feature: 'monolit')] +fn eval_oods_polynomial_inner( + column_values: Span, + oods_values: Span, + constraint_coefficients: Span, + point: felt252, + oods_point: felt252, + trace_generator: felt252, + contract_address_2: ContractAddress, +) -> felt252 { + eval_oods_polynomial_inner_( + column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, + ) +} impl RecursiveWithPoseidonAIRCompositionImpl of AIRComposition { fn eval_composition_polynomial( @@ -127,10 +195,8 @@ impl RecursiveWithPoseidonAIRCompositionImpl of AIRComposition felt252 { - IRecursiveWithPoseidonLayoutContract2Dispatcher { - contract_address: contract_address_2 - }.eval_oods_polynomial_inner( - column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, + eval_oods_polynomial_inner( + column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, contract_address_2, ) } } diff --git a/src/air/layouts/small.cairo b/src/air/layouts/small.cairo index e7d41a820..f5ff07afb 100644 --- a/src/air/layouts/small.cairo +++ b/src/air/layouts/small.cairo @@ -3,16 +3,13 @@ mod constants; mod global_values; mod public_input; mod traces; +#[cfg(feature: 'split')] mod contract; use cairo_verifier::{ air::{ constants::{SHIFT_POINT_X, SHIFT_POINT_Y, StarkCurve}, layouts::small::{ - contract::{ - ISmallLayoutContract1Dispatcher, ISmallLayoutContract1DispatcherTrait, - ISmallLayoutContract2Dispatcher, ISmallLayoutContract2DispatcherTrait, - }, global_values::{GlobalValues, InteractionElements, EcPoint, EcdsaSigConfig}, public_input::SmallPublicInputImpl, constants::{ @@ -27,6 +24,79 @@ use cairo_verifier::{ common::{math::{Felt252Div, Felt252PartialOrd, pow}, asserts::assert_range_u128} }; use starknet::ContractAddress; +#[cfg(feature: 'split')] +use cairo_verifier::air::layouts::small::contract::{ + ISmallLayoutContract1Dispatcher, + ISmallLayoutContract1DispatcherTrait, + ISmallLayoutContract2Dispatcher, + ISmallLayoutContract2DispatcherTrait, +}; + +#[cfg(feature: 'split')] +fn eval_composition_polynomial_inner( + mask_values: Span, + constraint_coefficients: Span, + point: felt252, + trace_generator: felt252, + global_values: GlobalValues, + contract_address_1: ContractAddress, +) -> felt252 { + ISmallLayoutContract1Dispatcher { + contract_address: contract_address_1 + }.eval_composition_polynomial_inner( + mask_values, constraint_coefficients, point, trace_generator, global_values + ) +} + +#[cfg(feature: 'split')] +fn eval_oods_polynomial_inner( + column_values: Span, + oods_values: Span, + constraint_coefficients: Span, + point: felt252, + oods_point: felt252, + trace_generator: felt252, + contract_address_2: ContractAddress, +) -> felt252 { + ISmallLayoutContract2Dispatcher { + contract_address: contract_address_2 + }.eval_oods_polynomial_inner( + column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, + ) +} + +#[cfg(feature: 'monolit')] +use cairo_verifier::air::layouts::small::autogenerated::{ + eval_composition_polynomial_inner as eval_composition_polynomial_inner_, + eval_oods_polynomial_inner as eval_oods_polynomial_inner_, +}; + +#[cfg(feature: 'monolit')] +fn eval_composition_polynomial_inner( + mask_values: Span, + constraint_coefficients: Span, + point: felt252, + trace_generator: felt252, + global_values: GlobalValues, + contract_address_1: ContractAddress, +) -> felt252 { + eval_composition_polynomial_inner_(mask_values, constraint_coefficients, point, trace_generator, global_values) +} + +#[cfg(feature: 'monolit')] +fn eval_oods_polynomial_inner( + column_values: Span, + oods_values: Span, + constraint_coefficients: Span, + point: felt252, + oods_point: felt252, + trace_generator: felt252, + contract_address_2: ContractAddress, +) -> felt252 { + eval_oods_polynomial_inner_( + column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, + ) +} impl SmallAIRCompositionImpl of AIRComposition { fn eval_composition_polynomial( @@ -95,10 +165,8 @@ impl SmallAIRCompositionImpl of AIRComposition range_check16_perm_public_memory_prod: 1, }; - ISmallLayoutContract1Dispatcher { - contract_address: contract_address_1 - }.eval_composition_polynomial_inner( - mask_values, constraint_coefficients, point, trace_generator, global_values + eval_composition_polynomial_inner( + mask_values, constraint_coefficients, point, trace_generator, global_values, contract_address_1, ) } } @@ -113,10 +181,8 @@ impl SmallAIROodsImpl of AIROods { trace_generator: felt252, contract_address_2: ContractAddress, ) -> felt252 { - ISmallLayoutContract2Dispatcher { - contract_address: contract_address_2 - }.eval_oods_polynomial_inner( - column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, + eval_oods_polynomial_inner( + column_values, oods_values, constraint_coefficients, point, oods_point, trace_generator, contract_address_2, ) } } diff --git a/src/lib.cairo b/src/lib.cairo index 89fbed9fa..a41b745c3 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -38,15 +38,16 @@ use cairo_verifier::air::layouts::starknet_with_keccak::public_input::StarknetWi const SECURITY_BITS: felt252 = 50; -// fn main(mut serialized: Span, cairo_version: CairoVersion) -> (felt252, felt252) { -// let stark_proof_serde = Serde::::deserialize(ref serialized).unwrap(); -// let stark_proof: StarkProof = stark_proof_serde.into(); - -// stark_proof.verify_full(SECURITY_BITS); -// let (program_hash, output_hash) = match cairo_version { -// CairoVersion::Cairo0 => stark_proof.public_input.verify_cairo0(), -// CairoVersion::Cairo1 => stark_proof.public_input.verify_cairo1(), -// }; - -// (program_hash, output_hash) -// } +#[cfg(feature: 'monolit')] +fn main(mut serialized: Span, cairo_version: CairoVersion) -> (felt252, felt252) { + let stark_proof_serde = Serde::::deserialize(ref serialized).unwrap(); + let stark_proof: StarkProof = stark_proof_serde.into(); + + stark_proof.verify_full(SECURITY_BITS, 0.try_into().unwrap(), 0.try_into().unwrap()); + let (program_hash, output_hash) = match cairo_version { + CairoVersion::Cairo0 => stark_proof.public_input.verify_cairo0(), + CairoVersion::Cairo1 => stark_proof.public_input.verify_cairo1(), + }; + + (program_hash, output_hash) +}